8000 BUG: Fix auxdata initialization in ufunc slow path · numpy/numpy@834bf31 · GitHub
[go: up one dir, main page]

Skip to content

Commit 834bf31

Browse files
committed
BUG: Fix auxdata initialization in ufunc slow path
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 gh-28117
1 parent 1d77082 commit 834bf31

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

numpy/_core/src/umath/ufunc_object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ execute_ufunc_loop(PyArrayMethod_Context *context, int masked,
11081108
* based on the fixed strides.
11091109
*/
11101110
PyArrayMethod_StridedLoop *strided_loop;
1111-
NpyAuxData *auxdata;
1111+
NpyAuxData *auxdata = NULL;
11121112
npy_intp fixed_strides[NPY_MAXARGS];
11131113

11141114
NpyIter_GetInnerFixedStrideArray(iter, fixed_strides);

numpy/_core/tests/test_nep50_promotions.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,20 @@ def test_integer_comparison(sctype, other_val, comp):
237237
assert_array_equal(comp(other_val, val_obj), comp(other_val, val))
238238

239239

240+
@pytest.mark.parametrize("arr", [
241+
np.ones((100, 100), dtype=np.uint8)[::2], # not trivially iterable
242+
np.ones(20000, dtype=">u4"), # cast and >buffersize
243+
np.ones(100, dtype=">u4"), # fast path compatible with cast
244+
])
245+
def test_integer_comparison_with_cast(arr):
246+
# Similar to above, but mainly test a few cases that cover the slow path
247+
# the test is limited to unsigned ints and -1 for simplicity.
248+
res = arr >= -1
249+
assert_array_equal(res, np.ones_like(arr, dtype=bool))
250+
res = arr < -1
251+
assert_array_equal(res, np.zeros_like(arr, dtype=bool))
252+
253+
240254
@pytest.mark.parametrize("comp",
241255
[np.equal, np.not_equal, np.less_equal, np.less,
242256
np.greater_equal, np.greater])

0 commit comments

Comments
 (0)
0