summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2020-05-11 17:31:19 -0500
committerSebastian Berg <sebastian@sipsolutions.net>2020-05-11 18:42:14 -0500
commitc65acda08500c5c17e6f08235f8f76038763655d (patch)
treea0798eb206d639a1ff2602ea4b655293dd2c8f33 /numpy
parent729b9ca93c43ac3442484929bd52574da8bee4c7 (diff)
downloadnumpy-c65acda08500c5c17e6f08235f8f76038763655d.tar.gz
DOC: Slightly improve error message on incorrectly shaped reductions
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/nditer_constr.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c
index 7bc40f03a..c717f290f 100644
--- a/numpy/core/src/multiarray/nditer_constr.c
+++ b/numpy/core/src/multiarray/nditer_constr.c
@@ -1420,13 +1420,15 @@ check_mask_for_writemasked_reduction(NpyIter *iter, int iop)
*/
static int
npyiter_check_reduce_ok_and_set_flags(
- NpyIter *iter, npy_uint32 flags, npyiter_opitflags *op_itflags) {
+ NpyIter *iter, npy_uint32 flags, npyiter_opitflags *op_itflags,
+ int dim) {
/* If it's writeable, this means a reduction */
if (*op_itflags & NPY_OP_ITFLAG_WRITE) {
if (!(flags & NPY_ITER_REDUCE_OK)) {
- PyErr_SetString(PyExc_ValueError,
- "output operand requires a reduction, but reduction is"
- "not enabled");
+ PyErr_Format(PyExc_ValueError,
+ "output operand requires a reduction along dimension %d, "
+ "but the reduction is not enabled. The dimension size of 1 "
+ "does not match the expected output shape.", dim);
return 0;
}
if (!(*op_itflags & NPY_OP_ITFLAG_READ)) {
@@ -1706,7 +1708,7 @@ npyiter_fill_axisdata(NpyIter *iter, npy_uint32 flags, npyiter_opitflags *op_itf
goto operand_different_than_broadcast;
}
if (!npyiter_check_reduce_ok_and_set_flags(
- iter, flags, &op_itflags[iop])) {
+ iter, flags, &op_itflags[iop], i)) {
return 0;
}
}
@@ -1717,7 +1719,7 @@ npyiter_fill_axisdata(NpyIter *iter, npy_uint32 flags, npyiter_opitflags *op_itf
else {
strides[iop] = 0;
if (!npyiter_check_reduce_ok_and_set_flags(
- iter, flags, &op_itflags[iop])) {
+ iter, flags, &op_itflags[iop], i)) {
return 0;
}
}
@@ -2614,7 +2616,7 @@ npyiter_new_temp_array(NpyIter *iter, PyTypeObject *subtype,
*/
if (!reduction_axis && NAD_SHAPE(axisdata) != 1) {
if (!npyiter_check_reduce_ok_and_set_flags(
- iter, flags, op_itflags)) {
+ iter, flags, op_itflags, i)) {
return NULL;
}
}