Can't Construct Sparse Tensor with cuda.Tensor

Hi there,

I am writing autograd for sparse tensor.

Why it gets Error when I construct torch.sparse.FloatTensor(i, v, size), that i,v are cuda.Tensor? Is it necessary to transform to cpu every time?

Thanks

You can use torch.cuda.sparse.FloatTensor:

i = torch.LongTensor([[0, 1, 1],
                          [2, 0, 2]]).cuda()
v = torch.FloatTensor([3, 4, 5]).cuda()
torch.cuda.sparse.FloatTensor(i,v, torch.Size([2,3]))

Best regards

Thomas

Yeah it works. Thank you!

But doesn’t this mean I need to rewrite the code to change from cpu to gpu platform?