Skip to content

[feature request]New pytorch op for something like combinatoric iterators in itertools #7580

@zasdfgbnm

Description

@zasdfgbnm

Hi, I want some ops that is similar to combinatoric iterators in itertools. These functions do the same thing as in itertools. For example:

>>> A = torch.tensor([1,2,3])
>>> B = torch.tensor([4,5,6])
>>> cartesian_prod(A,B)
tensor([[ 1,  1,  1,  2,  2,  2,  3,  3,  3],
        [ 4,  5,  6,  4,  5,  6,  4,  5,  6]])
>>> combinations(A, 2)
tensor([[ 1,  1,  2],
        [ 2,  3,  3]])
>>> combinations_with_replacement(A, 2)
tensor([[ 1,  1,  1,  2,  2,  3],
        [ 1,  2,  3,  2,  3,  3]])

I already have a python implementation of these ops, supporting tensors of arbitrary rank, implemented using torch.unbind, torch.stack, and torch.cat. But this implementation is very slow, and is a bottleneck of my application.

So I'm just asking, is pytorch interested in supporting these natively? If yes, I'm happy to contribute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions