summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2014-03-23 20:08:23 +0100
committerSebastian Berg <sebastian@sipsolutions.net>2014-03-23 20:23:00 +0100
commitadf38debadf55932961211f77646bc16187859d8 (patch)
tree0c511eb621636f593f8d4f9951d28837394b3d8c
parent730bff388f4847a4c1148fb72d3fcb3aa4f0a41a (diff)
downloadnumpy-adf38debadf55932961211f77646bc16187859d8.tar.gz
BUG: nditer: Initialize buffer reduce pos
The FirstVisit function uses this, but when the reduction is over a single element it isn't considered a reduction. This is fine, however the reduce pos must still be initialized to 0 in that case. Also changes the check order so that it is not necessary to initialize the outerstrides as well. See also gh-4134, and gh-4535.
-rw-r--r--numpy/core/src/multiarray/nditer_api.c12
-rw-r--r--numpy/core/src/multiarray/nditer_constr.c6
-rw-r--r--numpy/core/tests/test_ufunc.py1
3 files changed, 9 insertions, 10 deletions
diff --git a/numpy/core/src/multiarray/nditer_api.c b/numpy/core/src/multiarray/nditer_api.c
index beb68da9e..17108f02c 100644
--- a/numpy/core/src/multiarray/nditer_api.c
+++ b/numpy/core/src/multiarray/nditer_api.c
@@ -758,14 +758,6 @@ NpyIter_IsFirstVisit(NpyIter *iter, int iop)
NpyIter_AxisData *axisdata;
npy_intp sizeof_axisdata;
- /*
- * size 1 reduction iterators are not full initialized but each visit is
- * always the first, gh-4134
- */
- if (NPY_UNLIKELY(NIT_ITERSIZE(iter) == 1)) {
- return 1;
- }
-
sizeof_axisdata = NIT_AXISDATA_SIZEOF(itflags, ndim, nop);
axisdata = NIT_AXISDATA(iter);
@@ -793,8 +785,8 @@ NpyIter_IsFirstVisit(NpyIter *iter, int iop)
if (itflags&NPY_ITFLAG_BUFFER) {
NpyIter_BufferData *bufferdata = NIT_BUFFERDATA(iter);
/* The outer reduce loop */
- if (NBF_REDUCE_OUTERSTRIDES(bufferdata)[iop] == 0 &&
- NBF_REDUCE_POS(bufferdata) != 0) {
+ if (NBF_REDUCE_POS(bufferdata) != 0 &&
+ NBF_REDUCE_OUTERSTRIDES(bufferdata)[iop] == 0) {
return 0;
}
}
diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c
index 41f0b97c4..b7f700e60 100644
--- a/numpy/core/src/multiarray/nditer_constr.c
+++ b/numpy/core/src/multiarray/nditer_constr.c
@@ -261,6 +261,12 @@ NpyIter_AdvancedNew(int nop, PyArrayObject **op_in, npy_uint32 flags,
buffersize = NIT_ITERSIZE(iter);
}
NBF_BUFFERSIZE(bufferdata) = buffersize;
+
+ /*
+ * Initialize for use in FirstVisit, which may be called before
+ * the buffers are filled and the reduce pos is updated.
+ */
+ NBF_REDUCE_POS(bufferdata) = 0;
}
/*
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index 6415b2a3f..080606dce 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -589,6 +589,7 @@ class TestUfunc(TestCase):
assert_equal(np.max(a), True)
assert_equal(np.min(a), False)
assert_equal(np.array([[1]], dtype=object).sum(), 1)
+ assert_equal(np.array([[[1, 2]]], dtype=object).sum((0, 1)), [1, 2])
def test_object_scalar_multiply(self):
# Tickets #2469 and #4482