pytorch_sparse icon indicating copy to clipboard operation
pytorch_sparse copied to clipboard

Whether SparseTensor supports element-wise operations (add, mul)?

Open VeritasYin opened this issue 3 years ago • 3 comments
trafficstars

Hello,

Recently, I work on a task needs better support of SparseTensor for Pytorch and pytorch-sparse helps me a lot. It seems like currently it does not support operations between two SparseTensors. As I checked, the func 'add' and 'mul' can only accept one sparse tensor and one dense tensor. Is there a way to get around this? Thanks!

~/anaconda3/lib/python3.8/site-packages/torch_sparse/mul.py in <lambda>(self, other)
     64 
     65 
---> 66 SparseTensor.mul = lambda self, other: mul(self, other)
     67 SparseTensor.mul_ = lambda self, other: mul_(self, other)
     68 SparseTensor.mul_nnz = lambda self, other, layout=None: mul_nnz(

~/anaconda3/lib/python3.8/site-packages/torch_sparse/mul.py in mul(src, other)
     15     else:
     16         raise ValueError(
---> 17             f'Size mismatch: Expected size ({src.size(0)}, 1, ...) or '
     18             f'(1, {src.size(1)}, ...), but got size {other.size()}.')
     19 

TypeError: size() missing 1 required positional argument: 'dim'

VeritasYin avatar Jun 08 '22 23:06 VeritasYin

Thanks for your interest. We have support for add between two SparseTensor instances (see here), but mul is indeed missing. Happy to accept any PR on this one if you are interested.

rusty1s avatar Jun 09 '22 06:06 rusty1s

Thanks for the quick response. I will certainly look into it.

VeritasYin avatar Jun 09 '22 16:06 VeritasYin

This issue had no activity for 6 months. It will be closed in 2 weeks unless there is some new activity. Is this issue already resolved?

github-actions[bot] avatar Dec 07 '22 01:12 github-actions[bot]