GeezerVison is showing github.com — Merge pull request #24183 from charris/backport-24150 · numpy/numpy@c9b63e8
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: numpy/core/src/umath/ufunc_object.c +8-3Lines changed: 8 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5955,14 +5955,19 @@ trivial_at_loop(PyArrayMethodObject *ufuncimpl, NPY_ARRAYMETHOD_FLAGS flags, |
5955 | 5955 | } |
5956 | 5956 | } |
5957 | 5957 |
|
5958 | | - npy_intp *inner_size = NpyIter_GetInnerLoopSizePtr(iter->outer); |
5959 | | - |
5960 | 5958 | if (!(flags & NPY_METH_NO_FLOATINGPOINT_ERRORS)) { |
5961 | 5959 | npy_clear_floatstatus_barrier((char *)context); |
5962 | 5960 | } |
5963 | 5961 |
|
5964 | 5962 | do { |
5965 | | - args[1] = (char *) iter->outer_ptrs[0]; |
| 5963 | + npy_intp *inner_size = NpyIter_GetInnerLoopSizePtr(iter->outer); |
| 5964 | + npy_intp * indxP = (npy_intp *)iter->outer_ptrs[0]; |
| 5965 | + for (npy_intp i=0; i < *inner_size; i++) { |
| 5966 | + if (indxP[i] < 0) { |
| 5967 | + indxP[i] += iter->fancy_dims[0]; |
| 5968 | + } |
| 5969 | + } |
| 5970 | + args[1] = (char *)indxP; |
5966 | 5971 | steps[1] = iter->outer_strides[0]; |
5967 | 5972 |
|
5968 | 5973 | res = ufuncimpl->contiguous_indexed_loop( |
|
Collapse file
Copy file name to clipboardExpand all lines: numpy/core/tests/test_ufunc.py +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2215,6 +2215,14 @@ def test_ufunc_at_advanced(self): |
2215 | 2215 | np.maximum.at(a, [0], 0) |
2216 | 2216 | assert_equal(a, np.array([1, 2, 3])) |
2217 | 2217 |
|
| 2218 | + def test_at_negative_indexes(self): |
| 2219 | + a = np.arange(10) |
| 2220 | + indxs = np.array([-1, 1, -1, 2]) |
| 2221 | + np.add.at(a, indxs, 1) |
| 2222 | + assert a[-1] == 11 # issue 24147 |
| 2223 | + assert a[1] == 2 |
| 2224 | + assert a[2] == 3 |
| 2225 | + |
2218 | 2226 | def test_at_not_none_signature(self): |
2219 | 2227 | # Test ufuncs with non-trivial signature raise a TypeError |
2220 | 2228 | a = np.ones((2, 2, 2)) |
|