Fix incorrect sparse add behavior when the sparse tensor has non-contiguous values (#18179)
Summary:
Currently, this code gives incorrect result:
```python
import torch
indices=torch.tensor([[7, 1, 3]])
values=torch.tensor([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]])
x = torch.sparse_coo_tensor(indices, values, size=(10, 3))
values=torch.tensor(1.).expand(3, 3)
y = torch.sparse_coo_tensor(indices, values, size=(10, 3))
z = x + y
tensor(indices=tensor([[7, 1, 3]]),
values=tensor([[2., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]]),
size=(10, 3), nnz=3, layout=torch.sparse_coo)
```
This PR fixes the bug by adding special handling for sparse tensors with non-contiguous values in the addition function (specifically, by cat'ing the indices and values together).
This PR closes https://github.com/pytorch/pytorch/issues/17950 and https://github.com/pytorch/pytorch/issues/17919.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/18179
Reviewed By: ezyang
Differential Revision: D14569591
Pulled By: yf225
fbshipit-source-id: f5a14c4a31337fc95eab64596212066b4fb18b1a