summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Bourque <jay.bourque@continuum.io>2012-11-15 15:54:57 -0600
committerJay Bourque <jay.bourque@continuum.io>2013-08-16 16:39:30 -0500
commit5b7cda079f3a5ce59eb1688af0297eba45d375ea (patch)
treeb7d4c0af7e7054567475fcc314bd1e2ef8e68bdc
parenta8d13b86eeca2e9362219aabca0ff76717f6a2f3 (diff)
downloadnumpy-5b7cda079f3a5ce59eb1688af0297eba45d375ea.tar.gz
Fix issue with 'at' method when indices are all slice objects
-rw-r--r--numpy/core/src/multiarray/mapping.c10
-rw-r--r--numpy/core/tests/test_ufunc.py16
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])