diff options
author | Jay Bourque <jay.bourque@continuum.io> | 2012-11-15 15:54:57 -0600 |
---|---|---|
committer | Jay Bourque <jay.bourque@continuum.io> | 2013-08-16 16:39:30 -0500 |
commit | 5b7cda079f3a5ce59eb1688af0297eba45d375ea (patch) | |
tree | b7d4c0af7e7054567475fcc314bd1e2ef8e68bdc | |
parent | a8d13b86eeca2e9362219aabca0ff76717f6a2f3 (diff) | |
download | numpy-5b7cda079f3a5ce59eb1688af0297eba45d375ea.tar.gz |
Fix issue with 'at' method when indices are all slice objects
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 10 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 16 |
2 files changed, 24 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index a7c1c854c..d8af546a3 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -1663,7 +1663,9 @@ PyArray_MapIterReset(PyArrayMapIterObject *mit) mit->index = 0; - copyswap = PyArray_DESCR(mit->iters[0]->ao)->f->copyswap; + if (mit->numiter > 0) { + copyswap = PyArray_DESCR(mit->iters[0]->ao)->f->copyswap; + } if (mit->subspace != NULL) { memcpy(coord, mit->bscoord, sizeof(npy_intp)*PyArray_NDIM(mit->ait->ao)); @@ -1714,7 +1716,11 @@ PyArray_MapIterNext(PyArrayMapIterObject *mit) if (mit->index >= mit->size) { return; } - copyswap = PyArray_DESCR(mit->iters[0]->ao)->f->copyswap; + + if (mit->numiter > 0) { + copyswap = PyArray_DESCR(mit->iters[0]->ao)->f->copyswap; + } + /* Sub-space iteration */ if (mit->subspace != NULL) { PyArray_ITER_NEXT(mit->subspace); diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 5b3b1ce02..8aac509a6 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -939,6 +939,22 @@ class TestUfunc(TestCase): [21, 22, 23], [24, 25, 26]]]) + a = np.arange(27).reshape(3,3,3) + b = np.array([100,200,300]) + np.add.at(a, (slice(None), slice(None), slice(None)), b) + assert_equal(a, + [[[100,201,302], + [103,204,305], + [106,207,308]], + + [[109,210,311], + [112,213,314], + [115,216,317]], + + [[118,219,320], + [121,222,323], + [124,225,326]]]) + a = np.arange(10) np.negative.at(a, [2,5,2]) assert_equal(a, [0, 1, 2, 3, 4, -5, 6, 7, 8, 9]) |