You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using a 64 bit Linux computer with the main development branch of NumPy. When the dtype of the indices parameter of np.add.at is not a 64 bit integer, and the length of indices is greater than 8192, and the third parameter b is an array with the same length as indices, I get an incorrect result from np.add.at(a, indices, b). In the example below, instead of adding the value from b at index 8192, it appears to wrap around and add the value from index 0 again. So instead of getting the expected value 115, a[0] is 25.
importnumpyasnp# The result is incorrect for n > 8192n=8193# The result is incorrect for dtypes int16 and int32; int64 is OK.indices=np.zeros(n, dtype=np.int16)
b=np.zeros(n)
b[0] =10b[1] =5b[8192:] =100a=np.zeros(1)
np.add.at(a, indices, b)
print(f'{a[0] =}')
print(f'expected = {b.sum()}')
I ran into this while experimenting with a method to use numpy.add.at to multiply a sparse COO matrix by a regular 1d NumPy array. It worked for small arrays, but then broke for larger ones.
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Describe the issue:
I'm using a 64 bit Linux computer with the main development branch of NumPy. When the dtype of the
indices
parameter ofnp.add.at
is not a 64 bit integer, and the length ofindices
is greater than 8192, and the third parameterb
is an array with the same length asindices
, I get an incorrect result fromnp.add.at(a, indices, b)
. In the example below, instead of adding the value fromb
at index 8192, it appears to wrap around and add the value from index 0 again. So instead of getting the expected value115
,a[0]
is 25.Git bisect points the finger at #23136.
Reproduce the code example:
Error message:
Runtime information:
Context for the issue:
I ran into this while experimenting with a method to use
numpy.add.at
to multiply a sparse COO matrix by a regular 1d NumPy array. It worked for small arrays, but then broke for larger ones.The text was updated successfully, but these errors were encountered: