I iam trying to run a simple code as below.
I have features of two graphs of type sparse tensor, stored in a list
feature= [tensor(indices=tensor([[ 0, 1, 2, ..., 1896, 1897, 1898],
[ 0, 1, 2, ..., 1896, 1897, 1898]]),
values=tensor([1., 1., 1., ..., 1., 1., 1.]),
size=(1899, 1899), nnz=1899, layout=torch.sparse_coo), tensor(indices=tensor([[ 0, 1, 2, ..., 1896, 1897, 1898],
[ 0, 1, 2, ..., 1896, 1897, 1898]]),
values=tensor([1., 1., 1., ..., 1., 1., 1.]),
size=(1899, 1899), nnz=1899, layout=torch.sparse_coo)]
when I convert the feature above to dense tensor, i get the following result
print('this is feature 0', feature[0].to_dense())
print('this is feature 1', feature[1].to_dense())
this is feature 0 tensor([[1., 0., 0., ..., 0., 0., 0.],
[0., 1., 0., ..., 0., 0., 0.],
[0., 0., 1., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 1., 0., 0.],
[0., 0., 0., ..., 0., 1., 0.],
[0., 0., 0., ..., 0., 0., 1.]])
this is feature 1 tensor([[1., 0., 0., ..., 0., 0., 0.],
[0., 1., 0., ..., 0., 0., 0.],
[0., 0., 1., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 1., 0., 0.],
[0., 0., 0., ..., 0., 1., 0.],
[0., 0., 0., ..., 0., 0., 1.]])
how ever when I do the same in the loop as below, i am getting surprising result
for i in range(2):
feature=feature[i]
print('these are new features: ',feature )
result to
tensor(indices=tensor([[ 0, 1, 2, ..., 1896, 1897, 1898],
[ 0, 1, 2, ..., 1896, 1897, 1898]]),
values=tensor([1., 1., 1., ..., 1., 1., 1.]),
size=(1899, 1899), nnz=1899, layout=torch.sparse_coo)
tensor(indices=tensor([[1]]),
values=tensor([1.]),
size=(1899,), nnz=1, layout=torch.sparse_coo)
and when I convert the same to dense tensor in the loop, like this
for i in range(2):
feature=feature[i]
print('these are new features: ',feature )
i get this error
RuntimeError: Could not run 'aten::to_dense' with arguments from the 'CPU' backend
What is the problem? how can I solve it? Any help will be much appeciated