The indices don’t align with the values. In the example given on the website, by this logic, seems like it’s indexing the columns first and that the indices are in reverse order to their values. Seems like [0, 1]
corresponds to 4 and [2, 0]
corresponds to 3.
i = torch.LongTensor([[0, 1], [2, 0]])
v = torch.FloatTensor([3, 4])
torch.sparse.FloatTensor(i, v, torch.Size([2,3])).to_dense()
0 0 3
4 0 0
[torch.FloatTensor of size 2x3]
If I change the indices to [0, 1]
and [0, 1]
, I get
i = torch.LongTensor([[0, 1], [0,1]])
v = torch.FloatTensor([3, 4])
torch.sparse.FloatTensor(i, v, torch.Size([2,3])).to_dense()
3 0 0
0 4 0
[torch.FloatTensor of size 2x3]
…this seems like unexpected behavior.
Also if I try - should be intuitive - putting a value in position [1, 1]
i = torch.LongTensor([[0, 1], [2, 0], [1,1]])
v = torch.FloatTensor([3, 4, 5])
torch.sparse.FloatTensor(i, v, torch.Size([2,3])).to_dense()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: invalid argument 2: number of dimensions must be nDimI + nDimV at /pytorch/torch/lib/THS/generic/THSTensor.c:169
Help please?