Can I use torch.sparse with batch size >1. AttributeError: 'torch.sparse.FloatTensor' object has no attribute 'unsqueeze'

Hi,
I am trying to use sparse matrix. When I typing to load the batch I am getting the following error:
for i, data in enumerate(train_loader, 0):
File “/usr/local/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 259, in next
batch = self.collate_fn([self.dataset[i] for i in indices])
File “/usr/local/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 135, in default_collate
return [default_collate(samples) for samples in transposed]
File “/usr/local/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 135, in
return [default_collate(samples) for samples in transposed]
File “/usr/local/lib/python3.5/site-packages/torch/utils/data/dataloader.py”, line 112, in default_collate
return torch.stack(batch, 0, out=out)
File “/usr/local/lib/python3.5/site-packages/torch/functional.py”, line 62, in stack
inputs = [t.unsqueeze(dim) for t in sequence]
File “/usr/local/lib/python3.5/site-packages/torch/functional.py”, line 62, in
inputs = [t.unsqueeze(dim) for t in sequence]
AttributeError: ‘torch.sparse.FloatTensor’ object has no attribute ‘unsqueeze’

The version I am using is 0.3.1.

Thanks,
Ortal

Like the error says, you can’t use unsqueeze with this kinds of object. I don’t know what dimensions you wish to get but maybe you can use resize_as_ instead?

I am also dealing with sparse tensors for one project and I am having hard time understanding how to correctly deal with them without reinventing the wheel.

Is there any documentation where you found this resize_as_ function ? How should we use it ? Is there any other useful functions ? Because this function is not listed in the documentation (http://pytorch.org/docs/master/sparse.html).

I have the same problem of using sparse matrices. Please post if you find any solution.

@richard is working on unsqueeze for sparse: https://github.com/pytorch/pytorch/pull/5236