Skip to content

Fix empty edge indices handling #332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion torch_sparse/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def __init__(
self._csr2csc = csr2csc
self._csc2csr = csc2csr

if not is_sorted:
if not is_sorted and self._col.numel() > 0:
idx = self._col.new_zeros(self._col.numel() + 1)
idx[1:] = self.row()
idx[1:] *= self._sparse_sizes[1]
Expand Down
2 changes: 2 additions & 0 deletions torch_sparse/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ def numel(self) -> int:
return self.nnz()

def density(self) -> float:
if self.sparse_size(0) == 0 or self.sparse_size(1) == 0:
return 0.0
return self.nnz() / (self.sparse_size(0) * self.sparse_size(1))

def sparsity(self) -> float:
Expand Down