Skip to content

Commit c547786

Browse files
jackfrancisdaltonpytorchmergebot
authored andcommitted
Update is_sparse doc to mention that it is sparse_coo specific (pytorch#157378)
## Issue being addressed `is_sparse` presents itself as determining if a tensor is sparse. HOWEVER, it only does checks against the tensor for `sparse_coo`. This has lead to confusion from developers as when non-coo sparse tensors are provided it return false, despite those tensors being sparse. ## Considered Remedy Fixing this is do-able however would result in complexity as existing systems may depend on this behavior remaining consistent, and even inside of pytorch is_sparse is used by `bform` which states that it supports only `sparse_csr and sparse_coo` meaning additional work/thought would have to go into solving for `sparse_csc` and `sparse_bsr` ## Remedy provided in this PR In lieu of these complications the lowest risk highest gain action was to add clear warning messaging to the function for now to avoid confusion to developers utilizing the function. The rest of the function behavior remains identical ## Issue content Addresses issue number: pytorch#101385 Original issue: pytorch#101385 Pull Request resolved: pytorch#157378 Approved by: https://github.com/soulitzer
1 parent 81c7445 commit c547786

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

torch/_linalg_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def is_sparse(A):
11-
"""Check if tensor A is a sparse tensor"""
11+
"""Check if tensor A is a sparse COO tensor. All other sparse storage formats (CSR, CSC, etc...) will return False."""
1212
if isinstance(A, torch.Tensor):
1313
return A.layout == torch.sparse_coo
1414

0 commit comments

Comments
 (0)