We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0355738 commit 40693abCopy full SHA for 40693ab
torch_sparse/storage.py
@@ -146,7 +146,7 @@ def __init__(
146
self._csr2csc = csr2csc
147
self._csc2csr = csc2csr
148
149
- if not is_sorted:
+ if not is_sorted and self._col.numel() > 0:
150
idx = self._col.new_zeros(self._col.numel() + 1)
151
idx[1:] = self.row()
152
idx[1:] *= self._sparse_sizes[1]
torch_sparse/tensor.py
@@ -357,6 +357,8 @@ def numel(self) -> int:
357
return self.nnz()
358
359
def density(self) -> float:
360
+ if self.sparse_size(0) == 0 or self.sparse_size(1) == 0:
361
+ return 0.0
362
return self.nnz() / (self.sparse_size(0) * self.sparse_size(1))
363
364
def sparsity(self) -> float:
0 commit comments