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.