-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
GCXS
matmul => slice leads to incorrect results
#607
Comments
Hey @matbryan52, I went through the observation you shared. I believe the problem might be related to Updating the indices after the dot product resulted in the following responses which might be inline with our expected result: Output - 01 import numpy as np
from sparse import GCXS
import sparse as sp
left = GCXS.from_numpy(np.ones((4, 16)))
right = GCXS.from_numpy(np.ones((16, 2)))
tmp1 = GCXS.from_numpy(16*np.ones((4, 2)), fill_value=0, compressed_axes=(0,))
tmp1.fill_value = 0
dotprod = left @ right
dotprod.indices = tmp1.indices
print('-'*90)
print(tmp1)
print(dotprod)
print('-'*90)
print(tmp1.data)
print(dotprod.data)
print('-'*90)
x = tmp1[0]
y = dotprod[0]
print(x.data)
print(y.data)
print('-'*90)
print(x.data.shape)
print(y.data.shape)
print('-'*90)
print(x)
print(y)
print('-'*90)
print(x.data)
print(y.data)
print('-'*90)
print(vars(tmp1))
print(vars(dotprod))
print('-'*90) Output - 01
while without replacing the indices I got this response . Output - 02
would like to hear your take on this, can I pick this issue up ? |
Anyone is welcome to pick up the issue. 😉 |
Hi everyone, as @SudhanshuJoshi09 suggested the problem is related to Specifically, the method It seems that the algorithm returns indices and data in reversed order. Inverting only indices leads to incorrect results once Code
Output
So, the easiest solution would be to reverse indices and data in |
Thanks @EuGig for the detailed analysis. I'd be willing to accept a PR if you make one. |
Describe the bug
Performing matmul
@
between twoGCXS
arrays then slicing the output can lead to incorrect results, most commonly an array of all zeros.To Reproduce
Expected behavior
Slicing the sparse result should be consistent with slicing the dense result.
System
sparse
version 0.14.0Additional context
I wonder if there is a link to #602 which also refers to slicing? The result array has an unsorted
indices
(array([1, 0, 1, 0, 1, 0, 1, 0])
with indptrarray([0, 2, 4, 6, 8])
).The text was updated successfully, but these errors were encountered: