BUG: (1.25.0) ufunc.at
returns wrong results when indices
is an array containing negative ints
#24147
Labels
ufunc.at
returns wrong results when indices
is an array containing negative ints
#24147
Describe the issue:
According to docs,
numpy.add.at(x, indices, v)
should be equivalent tox[indices] += v
(other than whenindices
contains repeat elements). As of numpy 1.25.0 this is no longer the case whenindices
is an array (or list) containing negative values.For example, here is the issue demonstrated via
numpy.add.at
And via
numpy.multiply.at
Reproduce the code example:
The following code demonstrates that the discrepancy occurs specifically when
indices
is an array (not a scalar) of negative ints.Error message:
No response
Runtime information:
Context for the issue:
This is a major bug, as ufuncs are silently returning incorrect results for common usage patterns. E.g., this is causing mygrad's CI to fail (and ultimately segfault - but I am not 100% sure that this issue is the precise cause for the segfault).
P.S. I caught this bug using the property based testing library Hypothesis 😄
The text was updated successfully, but these errors were encountered: