diff options
author | mattip <matti.picus@gmail.com> | 2023-03-27 09:55:35 +0300 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2023-03-27 09:55:35 +0300 |
commit | 47df67bb6c83d68c3254b69a44426b02d3f24caa (patch) | |
tree | d4f21798b4535b99afb7ce0bc6d8281c0ef6f7d8 /numpy/core | |
parent | 7761175e3df8ef30b09e2d71113251cd2de8f6f9 (diff) | |
download | numpy-47df67bb6c83d68c3254b69a44426b02d3f24caa.tar.gz |
BUG: in the fastest path form ufunc.at, properly increment args[2]
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 3 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 11 |
2 files changed, 14 insertions, 0 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index a5e8f4cbe..d4aced05f 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -5935,6 +5935,9 @@ trivial_at_loop(PyArrayMethodObject *ufuncimpl, NPY_ARRAYMETHOD_FLAGS flags, res = ufuncimpl->contiguous_indexed_loop( context, args, inner_size, steps, NULL); + if (args[2] != NULL) { + args[2] += (*inner_size) * steps[2]; + } } while (res == 0 && iter->outer_next(iter->outer)); if (res == 0 && !(flags & NPY_METH_NO_FLOATINGPOINT_ERRORS)) { diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 498a654c8..04add9fa7 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -2054,6 +2054,17 @@ class TestUfunc: # If it is [-1, -1, -1, -100, 0] then the regular strided loop was used assert np.all(arr == [-1, -1, -1, -200, -1]) + def test_ufunc_at_large(self): + # issue gh-23457 + indices = np.zeros(8195, dtype=np.int16) + b = np.zeros(8195, dtype=float) + b[0] = 10 + b[1] = 5 + b[8192:] = 100 + a = np.zeros(1, dtype=float) + np.add.at(a, indices, b) + assert a[0] == b.sum() + def test_cast_index_fastpath(self): arr = np.zeros(10) values = np.ones(100000) |