Skip to content

Commit 539e206

Browse files
committed
bandwidth
1 parent 172640e commit 539e206

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

torch_sparse/tensor.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,15 @@ def avg_row_length(self) -> float:
243243
def avg_col_length(self) -> float:
244244
return self.nnz() / self.sparse_size(1)
245245

246+
def bandwidth(self) -> int:
247+
row, col, _ = self.coo()
248+
return int((row - col).abs_().max())
249+
250+
def bandwidth_proportion(self, bandwidth: int) -> float:
251+
row, col, _ = self.coo()
252+
tmp = (row - col).abs_()
253+
return int((tmp <= bandwidth).sum()) / self.nnz()
254+
246255
def is_quadratic(self) -> bool:
247256
return self.sparse_size(0) == self.sparse_size(1)
248257

0 commit comments

Comments
 (0)