8000 MAINT: elide the generic_wrapped_legacy_loop wrapper out of the hot loop · numpy/numpy@154c293 · GitHub
[go: up one dir, main page]

Skip to content

Commit 154c293

Browse files
committed
MAINT: elide the generic_wrapped_legacy_loop wrapper out of the hot loop
1 parent 7853cbc commit 154c293

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

numpy/core/src/umath/legacy_array_method.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ int
9595
is_generic_wrapped_legacy_loop(PyArrayMethod_StridedLoop *strided_loop) {
9696
return strided_loop == generic_wrapped_legacy_loop;
9797
}
98+
99+
PyUFuncGenericFunction
100+
get_inner_loop(void * auxdata) {
101+
legacy_array_method_auxdata *ldata = (legacy_array_method_auxdata *)auxdata;
102+
return ldata->loop;
103+
}
104+
105+
int
106+
get_pyerr_check(void * auxdata) 10000 {
107+
legacy_array_method_auxdata *ldata = (legacy_array_method_auxdata *)auxdata;
108+
return ldata->pyerr_check;
109+
}
110+
98111
/*
99112
* Signal that the old type-resolution function must be used to resolve
100113
* the descriptors (mainly/only used for datetimes due to the unit).

numpy/core/src/umath/ufunc_object.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5944,15 +5944,15 @@ new_array_op(PyArrayObject *op_array, char *data)
59445944
}
59455945

59465946
int is_generic_wrapped_legacy_loop(PyArrayMethod_StridedLoop *strided_loop);
5947+
PyUFuncGenericFunction get_inner_loop(void * auxdata);
5948+
int get_pyerr_check(void * auxdata);
59475949

59485950
static int
59495951
ufunc_at__fast_iter(PyUFuncObject *ufunc, NPY_ARRAYMETHOD_FLAGS flags,
59505952
PyArrayMapIterObject *iter, PyArrayIterObject *iter2,
59515953
PyArrayObject *op1_array, PyArrayObject *op2_array,
5952-
PyArrayMethod_StridedLoop *strided_loop,
5953-
PyArrayMethod_Context *context,
5954-
npy_intp strides[3],
5955-
NpyAuxData *auxdata
5954+
PyUFuncGenericFunction loop, int pyerr_check,
5955+
npy_intp strides[3]
59565956
)
59575957
{
59585958
int buffersize;
@@ -5998,8 +5998,9 @@ ufunc_at__fast_iter(PyUFuncObject *ufunc, NPY_ARRAYMETHOD_FLAGS flags,
59985998
dataptr[2] = NULL;
59995999
}
60006000

6001-
res = strided_loop(context, dataptr, &count, strides, auxdata);
6002-
if (res != 0) {
6001+
loop(dataptr, &count, strides, NULL);
6002+
if (pyerr_check && PyErr_Occurred()) {
6003+
res = -1;
60036004
break;
60046005
}
60056006

@@ -6435,8 +6436,10 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args)
64356436
}
64366437
}
64376438
if (fast_path) {
6438-
res = ufunc_at__fast_iter(ufunc, flags, iter, iter2, op1_array, op2_array,
6439-
strided_loop, &context, strides, auxdata);
6439+
PyUFuncGenericFunction loop = get_inner_loop(auxdata);
6440+
6441+
res = ufunc_at__fast_iter(ufunc, flags, iter, iter2, op1_array,
6442+
op2_array, loop, get_pyerr_check(auxdata), strides);
64406443
} else {
64416444
res = ufunc_at__slow_iter(ufunc, flags, iter, iter2, op1_array, op2_array,
64426445
operation_descrs, strided_loop, &context, strides, auxdata);

0 commit comments

Comments
 (0)
0