Skip to content

Commit

Permalink
BUG: Fix auxdata initialization in ufunc slow path
Browse files Browse the repository at this point in the history
The reason this was not found earlier is that auxdata is currently
set by most function and the fast path seems to be taken a shocking
amount of times.
There are no further similar missing inits.

Closes numpygh-28117
  • Loading branch information
seberg committed Jan 7, 2025
1 parent 1d77082 commit 834bf31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion numpy/_core/src/umath/ufunc_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ execute_ufunc_loop(PyArrayMethod_Context *context, int masked,
* based on the fixed strides.
*/
PyArrayMethod_StridedLoop *strided_loop;
NpyAuxData *auxdata;
NpyAuxData *auxdata = NULL;
npy_intp fixed_strides[NPY_MAXARGS];

NpyIter_GetInnerFixedStrideArray(iter, fixed_strides);
Expand Down
14 changes: 14 additions & 0 deletions numpy/_core/tests/test_nep50_promotions.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ def test_integer_comparison(sctype, other_val, comp):
assert_array_equal(comp(other_val, val_obj), comp(other_val, val))


@pytest.mark.parametrize("arr", [
np.ones((100, 100), dtype=np.uint8)[::2], # not trivially iterable
np.ones(20000, dtype=">u4"), # cast and >buffersize
np.ones(100, dtype=">u4"), # fast path compatible with cast
])
def test_integer_comparison_with_cast(arr):
# Similar to above, but mainly test a few cases that cover the slow path
# the test is limited to unsigned ints and -1 for simplicity.
res = arr >= -1
assert_array_equal(res, np.ones_like(arr, dtype=bool))
res = arr < -1
assert_array_equal(res, np.zeros_like(arr, dtype=bool))


@pytest.mark.parametrize("comp",
[np.equal, np.not_equal, np.less_equal, np.less,
np.greater_equal, np.greater])
Expand Down

0 comments on commit 834bf31

Please sign in to comment.