pytorch sparse (sparse_coo_tensor) broadcast dense shape in multiplication

Viewed 490

Using broadcasting in normal tensors, the following works

torch.ones(3, 1)*torch.ones(3, 10)

I need to extend this behavior to sparse vectors, but I can't:

i = torch.tensor([[0, 1, 1],
                  [2, 0, 2]])
a = torch.sparse_coo_tensor(i, torch.ones(3, 1), [2, 4, 1])
b = torch.sparse_coo_tensor(i, torch.ones(3, 10), [2, 4, 10])
a*b
# gives RuntimeError: mul operands have incompatible sizes

Why shouldn't this work? Is there an pytorch function to do this? If not what is the best alternative algorithm?

0 Answers
Related