[Numpy-svn] r4466 - in trunk/numpy/core: src tests

numpy-svn@scip... numpy-svn@scip...
Sun Nov 18 14:50:19 CST 2007


Author: stefan
Date: 2007-11-18 14:49:47 -0600 (Sun, 18 Nov 2007)
New Revision: 4466

Modified:
   trunk/numpy/core/src/arrayobject.c
   trunk/numpy/core/tests/test_regression.py
Log:
Fix indexing with booleans (patch by Achim Gaedke). Closes #614.


Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2007-11-18 00:00:37 UTC (rev 4465)
+++ trunk/numpy/core/src/arrayobject.c	2007-11-18 20:49:47 UTC (rev 4466)
@@ -9336,7 +9336,14 @@
                         "boolean index array should have 1 dimension");
         return -1;
     }
+
     index = ind->dimensions[0];
+    if (index > self->size) {
+        PyErr_SetString(PyExc_ValueError,
+                        "boolean index array has too many values");
+        return -1;
+    }
+
     strides = ind->strides[0];
     dptr = ind->data;
     PyArray_ITER_RESET(self);

Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py	2007-11-18 00:00:37 UTC (rev 4465)
+++ trunk/numpy/core/tests/test_regression.py	2007-11-18 20:49:47 UTC (rev 4466)
@@ -756,5 +756,12 @@
             assert_equal(N.arange(0.5,dtype=dt).dtype,dt)
             assert_equal(N.arange(5,dtype=dt).dtype,dt)
 
+    def check_bool_indexing_invalid_nr_elements(self, level=rlevel):
+        s = N.ones(10,dtype=float)
+        x = N.array((15,),dtype=float)
+        def ia(x,s): x[(s>0)]=1.0
+        self.failUnlessRaises(ValueError,ia,x,s)
+
+
 if __name__ == "__main__":
     NumpyTest().run()



More information about the Numpy-svn mailing list