Skip to content

Commit

Permalink
Merge pull request #4535 from juliantaylor/itersize-1
Browse files Browse the repository at this point in the history
BUG: fix uninitialized use of size 1 reductions
  • Loading branch information
charris committed Mar 23, 2014
2 parents 51c65c1 + 3302291 commit e5b803c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions numpy/core/src/multiarray/nditer_api.c
Expand Up @@ -758,6 +758,14 @@ 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);

Expand Down
1 change: 1 addition & 0 deletions numpy/core/tests/test_ufunc.py
Expand Up @@ -588,6 +588,7 @@ def test_object_array_reduction(self):
assert_equal(np.all(a), False)
assert_equal(np.max(a), True)
assert_equal(np.min(a), False)
assert_equal(np.array([[1]], dtype=object).sum(), 1)

def test_object_scalar_multiply(self):
# Tickets #2469 and #4482
Expand Down

0 comments on commit e5b803c

Please sign in to comment.