In my humble opinion, torch.Tensor.is_sparse should return True for all possible layouts of sparse matrices.
For now, I think it only does so for COO tensors. You can reproduce with the following snippet:
import torch
a = torch.tensor([[1, 2, 3], [0, 0, 7]])
b = a.to_sparse().to_sparse_csc()
b.is_sparse
An alternative (if it makes sense): is_sparse could be deprecated in favor of is_dense and more specific is_sparse_*, as currently the supported ops are very specific for this or that sparse layout
🐛 Describe the bug
In my humble opinion,
torch.Tensor.is_sparse
should returnTrue
for all possible layouts of sparse matrices. For now, I think it only does so for COO tensors. You can reproduce with the following snippet:I think that this function is the culprit: https://github.com/pytorch/pytorch/blob/7dd8e08817ee59c926922409062e25f30408469b/torch/_linalg_utils.py#L11-L19
Checking for all possible sparse layouts should probably be the default scenario. Maybe checking that
"sparse"
is in the layout name would work.yields
Versions