summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatti Picus <matti.picus@gmail.com>2021-05-06 22:57:50 +0300
committerGitHub <noreply@github.com>2021-05-06 22:57:50 +0300
commitb5cd0b5fae949222485011bdd577d911cc320e25 (patch)
tree3cabaa2fec5aa222950941756431daad8c33ad9d
parentc753b23e84a5474c39999fec1f2a6d1ccd54b9a3 (diff)
parent18ffb74487c0e121a369fd8b4e2824caa7a20b95 (diff)
downloadnumpy-b5cd0b5fae949222485011bdd577d911cc320e25.tar.gz
Merge pull request #18864 from seberg/delete-nonsense-code-from-gufuncs
MAINT: Remove dead codepath in generalized ufuncs
-rw-r--r--numpy/core/src/umath/ufunc_object.c30
-rw-r--r--numpy/core/tests/test_multiarray.py10
2 files changed, 11 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 */
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 1ac2abba1..b355c4618 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -6529,6 +6529,16 @@ class TestMatmul(MatmulCommon):
c = c.astype(tgt.dtype)
assert_array_equal(c, tgt)
+ def test_empty_out(self):
+ # Check that the output cannot be broadcast, so that it cannot be
+ # size zero when the outer dimensions (iterator size) has size zero.
+ arr = np.ones((0, 1, 1))
+ out = np.ones((1, 1, 1))
+ assert self.matmul(arr, arr).shape == (0, 1, 1)
+
+ with pytest.raises(ValueError, match=r"non-broadcastable"):
+ self.matmul(arr, arr, out=out)
+
def test_out_contiguous(self):
a = np.ones((5, 2), dtype=float)
b = np.array([[1, 3], [5, 7]], dtype=float)