summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2023-01-22 21:55:07 +0200
committermattip <matti.picus@gmail.com>2023-01-30 21:32:35 +0200
commit3ba259d20ec57052ee8df915eab308370e4a7bae (patch)
treeac16830a8048dd1253acdf305460d863f95ac3cf /numpy/core/src
parent90243f53f8efa200e22ee13ef1f0a8e1120b1c3a (diff)
downloadnumpy-3ba259d20ec57052ee8df915eab308370e4a7bae.tar.gz
refactor ufunc_at to first get the inner loop, then create the iterators
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/umath/ufunc_object.c81
1 files changed, 40 insertions, 41 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 792a373a5..8739a5095 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -6238,49 +6238,11 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args)
}
}
- /*
- * Create a map iterator (there is no multi-mapiter, so we need at least 2
- * iterators: one for the mapping, and another for the second operand)
- */
- iter = (PyArrayMapIterObject *)PyArray_MapIterArrayCopyIfOverlap(
- op1_array, idx, 1, op2_array);
- if (iter == NULL) {
- goto fail;
- }
- op1_array = iter->array; /* May be updateifcopied on overlap */
-
- if (op2_array != NULL) {
- /*
- * May need to swap axes so that second operand is
- * iterated over correctly
- */
- if ((iter->subspace != NULL) && (iter->consec)) {
- PyArray_MapIterSwapAxes(iter, &op2_array, 0);
- if (op2_array == NULL) {
- /* only on memory allocation failure */
- goto fail;
- }
- }
-
- /*
- * Create array iter object for second operand that
- * "matches" the map iter object for the first operand.
- * Then we can just iterate over the first and second
- * operands at the same time and not have to worry about
- * picking the correct elements from each operand to apply
- * the ufunc to.
- */
- if ((iter2 = (PyArrayIterObject *)\
- PyArray_BroadcastToShape((PyObject *)op2_array,
- iter->dimensions, iter->nd))==NULL) {
- goto fail;
- }
- }
-
PyArrayMethodObject *ufuncimpl = NULL;
-
{
/* Do all the dtype handling and find the correct ufuncimpl */
+ Py_INCREF(PyArray_DESCR(op1_array));
+
PyArrayObject *tmp_operands[3] = {NULL, NULL, NULL};
PyArray_DTypeMeta *signature[3] = {NULL, NULL, NULL};
@@ -6343,7 +6305,44 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args)
}
}
- Py_INCREF(PyArray_DESCR(op1_array));
+ /*
+ * Create a map iterator (there is no multi-mapiter, so we need at least 2
+ * iterators: one for the mapping, and another for the second operand)
+ */
+ iter = (PyArrayMapIterObject *)PyArray_MapIterArrayCopyIfOverlap(
+ op1_array, idx, 1, op2_array);
+ if (iter == NULL) {
+ goto fail;
+ }
+ op1_array = iter->array; /* May be updateifcopied on overlap */
+
+ if (op2_array != NULL) {
+ /*
+ * May need to swap axes so that second operand is
+ * iterated over correctly
+ */
+ if ((iter->subspace != NULL) && (iter->consec)) {
+ PyArray_MapIterSwapAxes(iter, &op2_array, 0);
+ if (op2_array == NULL) {
+ /* only on memory allocation failure */
+ goto fail;
+ }
+ }
+
+ /*
+ * Create array iter object for second operand that
+ * "matches" the map iter object for the first operand.
+ * Then we can just iterate over the first and second
+ * operands at the same time and not have to worry about
+ * picking the correct elements from each operand to apply
+ * the ufunc to.
+ */
+ if ((iter2 = (PyArrayIterObject *)\
+ PyArray_BroadcastToShape((PyObject *)op2_array,
+ iter->dimensions, iter->nd))==NULL) {
+ goto fail;
+ }
+ }
PyArrayMethod_Context context = {
.caller = (PyObject *)ufunc,