8000 Merge pull request #23467 from mattip/ufunc_at3 · numpy/numpy@0a0346a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a0346a

Browse files
authored
Merge pull request #23467 from mattip/ufunc_at3
BUG: in the fastest path form ufunc.at, properly increment args[2]
2 parents 7761175 + 47df67b commit 0a0346a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

numpy/core/src/umath/ufunc_object.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5935,6 +5935,9 @@ trivial_at_loop(PyArrayMethodObject *ufuncimpl, NPY_ARRAYMETHOD_FLAGS flags,
59355935

59365936
res = ufuncimpl->contiguous_indexed_loop(
59375937
context, args, inner_size, steps, NULL);
5938+
if (args[2] != NULL) {
5939+
args[2] += (*inner_size) * steps[2];
5940+
}
59385941
} while (res == 0 && iter->outer_next(iter->outer));
59395942

59405943
if (res == 0 && !(flags & NPY_METH_NO_FLOATINGPOINT_ERRORS)) {

numpy/core/tests/test_ufunc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,17 @@ def test_ufunc_at_negative(self):
20542054
# If it is [-1, -1, -1, -100, 0] then the regular strided loop was used
20552055
assert np.all(arr == [-1, -1, -1, -200, -1])
20562056

2057+
def test_ufunc_at_large(self):
2058+
# issue gh-23457
2059+
indices = np.zeros(8195, dtype=np.int16)
2060+
b = np.zeros(8195, dtype=float)
2061+
b[0] = 10
2062+
b[1] = 5
2063+
b[8192:] = 100
2064+
a = np.zeros(1, dtype=float)
2065+
np.add.at(a, indices, b)
2066+
assert a[0] == b.sum()
2067+
20572068
def test_cast_index_fastpath(self):
20582069
arr = np.zeros(10)
20592070
values = np.ones(100000)

0 commit comments

Comments
 (0)
0