How to resize a sparse tensor?

I am trying to do (3D-sparse x 2D-dense) multiplication.

However, I can’t resize the 3D-sparse tensor to a 2D-sparse, e.g:

t1 = to_sparse(torch.randn((A,B,C)))
t2 = torch.randn((C,D))
# (A,B,C)x(C,D) -> (A,B,D)
t3 = torch.mm(t1.view(-1,C),t2).view(A,B,D)

Gives the error:

RuntimeError: view is not implemented for type torch.sparse.FloatTensor

einsum for my particular case would have been ideal, unfortunately though, it is not yet implemented for sparse tensors.

Is there any other way to resize a sparse tensor?

2 Likes