Sparse tensor multiplication throws a run-time error


#1

Hi,

I am trying to use torch.mul() for a sparse tensor, but unfortunately the code below throws a run-time error:

a = torch.tensor([0.92], requires_grad=True)

i = torch.LongTensor([[0,0,0,0], [0,0,1,1], [0,0,2,2], [0,0,3,3]])
v = torch.FloatTensor([1, 2, 1, 1])

# A 4D sparse tensor
t = torch.sparse.FloatTensor(i.t(), v, torch.Size([2,2,5,5]))

# multiplication
y = torch.mul(a,t)

Error:

Traceback (most recent call last):
  File "test3.py", line 59, in <module>
    y = torch.mul(a,t)
RuntimeError: sparse tensors do not have strides

Is sparse matrix multiplication not supported at the moment?

Thanks


#2

According to #8853, mul/mul_ for (Sparse, Sparse) -> Sparse and (Sparse, Scalar) -> Sparse exist, but (Sparse, Dense) is still on todo list.