summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wiebe <mwwiebe@gmail.com>2013-01-07 10:57:46 -0800
committerMark Wiebe <mwwiebe@gmail.com>2013-08-12 18:04:53 -0700
commite083ceabda5c1f81426d79c51d40ba3093dcfd1f (patch)
tree3fcb722feb98f8201e577a7fd4470c918060a807
parent2fe0783be04f0b4eed3025da4705c4addd4f8e9a (diff)
downloadnumpy-e083ceabda5c1f81426d79c51d40ba3093dcfd1f.tar.gz
BUG: Fix ufunc.reduceat regression with empty index (gh-2892)
-rw-r--r--numpy/core/src/umath/ufunc_object.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index bea15c65c..cb0f6a9ae 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -3337,12 +3337,24 @@ PyUFunc_Reduceat(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *ind,
op[1] = arr;
op[2] = ind;
- /* Likewise with accumulate, must do UPDATEIFCOPY */
if (out != NULL || ndim > 1 || !PyArray_ISALIGNED(arr) ||
!PyArray_EquivTypes(op_dtypes[0], PyArray_DESCR(arr))) {
need_outer_iterator = 1;
}
+ /* Special case when the index array's size is zero */
+ if (ind_size == 0) {
+ need_outer_iterator = 0;
+ if (out != NULL) {
+ if (PyArray_NDIM(out) != 1 || PyArray_DIM(out, 0) != 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "output operand shape for reduceat is "
+ "incompatible with index array of shape (0,)");
+ goto fail;
+ }
+ }
+ }
+
if (need_outer_iterator) {
npy_uint32 flags = NPY_ITER_ZEROSIZE_OK|
NPY_ITER_REFS_OK|
@@ -3350,7 +3362,8 @@ PyUFunc_Reduceat(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *ind,
/*
* The way reduceat is set up, we can't do buffering,
- * so make a copy instead when necessary.
+ * so make a copy instead when necessary using
+ * the UPDATEIFCOPY flag
*/
/* The per-operand flags for the outer loop */