diff options
author | Julian Taylor <juliantaylor108@gmail.com> | 2014-03-23 21:36:13 +0100 |
---|---|---|
committer | Julian Taylor <juliantaylor108@gmail.com> | 2014-03-23 21:36:13 +0100 |
commit | a0bbdcfda546a112b36353f8b5c6dd2c0e07f916 (patch) | |
tree | 0c511eb621636f593f8d4f9951d28837394b3d8c | |
parent | 730bff388f4847a4c1148fb72d3fcb3aa4f0a41a (diff) | |
parent | adf38debadf55932961211f77646bc16187859d8 (diff) | |
download | numpy-a0bbdcfda546a112b36353f8b5c6dd2c0e07f916.tar.gz |
Merge pull request #4538 from seberg/size1_reductions
BUG: nditer: Initialize buffer reduce pos
-rw-r--r-- | numpy/core/src/multiarray/nditer_api.c | 12 | ||||
-rw-r--r-- | numpy/core/src/multiarray/nditer_constr.c | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 1 |
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 |