Skip to content

fix(SparseTensor.__getitem__): support np.ndarray and fix `List[b… #194

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 5 commits into from
Jan 14, 2022

Conversation

bwdeng20
Copy link
Contributor

The following snippet can reproduce errors this pull request aims to eliminate.

import torch
from torch_sparse import SparseTensor
def index1(spm,key):
    npm=spm[:, key]
    print(get_dense(npm.to_dense()))
    return npm

n=5
a=torch.arange(n*n).reshape(n,n)
tsa=SparseTensor.from_dense(a)

# index-based
Slist=[0,2,1]
Snp=np.array(Slist,copy=True)

# bool-based
Dlist=[False]*n
for i in Slist:
    Dlist[i]=True
Dnp=np.array(Dlist,copy=True)

# uncomment to check error
# index1(tsa,Snp) # ambiguous error
# index1(tsa,Dlist) # wrong result

…ool]`

support indexing with np.ndarray & fix bug merging from indexing with
List[bool]
@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2022

Codecov Report

Merging #194 (cd434f7) into master (efc9808) will increase coverage by 3.09%.
The diff coverage is 100.00%.

❗ Current head cd434f7 differs from pull request most recent head 9a56fb4. Consider uploading reports for the commit 9a56fb4 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #194      +/-   ##
==========================================
+ Coverage   69.20%   72.29%   +3.09%     
==========================================
  Files          28       28              
  Lines        1117     1119       +2     
==========================================
+ Hits          773      809      +36     
+ Misses        344      310      -34     
Impacted Files Coverage Δ
torch_sparse/tensor.py 48.71% <100.00%> (+2.63%) ⬆️
torch_sparse/masked_select.py 77.35% <0.00%> (+60.37%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update efc9808...9a56fb4. Read the comment docs.

tim and others added 3 commits January 14, 2022 12:15
support indexing with np.ndarray & fix bug merging from indexing
with
List[bool]
@rusty1s rusty1s self-assigned this Jan 14, 2022
@rusty1s rusty1s added the enhancement New feature or request label Jan 14, 2022
Copy link
Owner

@rusty1s rusty1s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@rusty1s rusty1s merged commit 88c6ceb into rusty1s:master Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants