summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2021-04-27 16:02:45 -0500
committerSebastian Berg <sebastian@sipsolutions.net>2021-04-27 16:58:44 -0500
commit6d871ca31abad2ce7065469ca8b530e4daa4996f (patch)
tree60764d10534ce0b3d1e6af626c04205edf93198e /numpy
parent694f5c704736e99c0e92204dab797b1430d2424c (diff)
downloadnumpy-6d871ca31abad2ce7065469ca8b530e4daa4996f.tar.gz
MAINT: Remove dead codepath in generalized ufuncs
If the iterator has size zero, then that means that the outer iteration has size. Since the outer iteration is unaffected by core dimensions, in that case the output always has size zero and the code does nothing but unnecessary checking the array sizes.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/umath/ufunc_object.c30
1 files changed, 1 insertions, 29 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index f17dd1e61..527e0d74d 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -2457,7 +2457,7 @@ PyUFunc_GeneralizedFunctionInternal(PyUFuncObject *ufunc, PyArrayObject **op,
/* Fill in any allocated outputs */
{
PyArrayObject **operands = NpyIter_GetOperandArray(iter);
- for (i = 0; i < nop; ++i) {
+ for (i = nin; i < nop; ++i) {
if (op[i] == NULL) {
op[i] = operands[i];
Py_INCREF(op[i]);
@@ -2592,34 +2592,6 @@ PyUFunc_GeneralizedFunctionInternal(PyUFuncObject *ufunc, PyArrayObject **op,
if (!needs_api && !NpyIter_IterationNeedsAPI(iter)) {
NPY_END_THREADS;
}
- } else {
- /**
- * For each output operand, check if it has non-zero size,
- * and assign the identity if it does. For example, a dot
- * product of two zero-length arrays will be a scalar,
- * which has size one.
- */
- npy_bool reorderable;
- PyObject *identity = _get_identity(ufunc, &reorderable);
- if (identity == NULL) {
- retval = -1;
- goto fail;
- }
-
- for (i = nin; i < nop; ++i) {
- if (PyArray_SIZE(op[i]) != 0) {
- if (identity == Py_None) {
- PyErr_Format(PyExc_ValueError,
- "ufunc %s ",
- ufunc_name);
- Py_DECREF(identity);
- retval = -1;
- goto fail;
- }
- PyArray_FillWithScalar(op[i], identity);
- }
- }
- Py_DECREF(identity);
}
/* Check whether any errors occurred during the loop */