[Numpy-svn] r3392 - trunk/numpy/core/src

numpy-svn at scipy.org numpy-svn at scipy.org
Wed Oct 25 01:15:47 CDT 2006


Author: oliphant
Date: 2006-10-25 01:15:40 -0500 (Wed, 25 Oct 2006)
New Revision: 3392

Modified:
   trunk/numpy/core/src/arraymethods.c
   trunk/numpy/core/src/arrayobject.c
Log:
Fix optimization so that array's of 1-element are not interpeted as integers.

Modified: trunk/numpy/core/src/arraymethods.c
===================================================================
--- trunk/numpy/core/src/arraymethods.c	2006-10-24 21:51:42 UTC (rev 3391)
+++ trunk/numpy/core/src/arraymethods.c	2006-10-25 06:15:40 UTC (rev 3392)
@@ -402,6 +402,9 @@
 }
 
 
+/* This should grow an order= keyword to be consistent
+ */
+
 static PyObject *
 array_tofile(PyArrayObject *self, PyObject *args, PyObject *kwds)
 {

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-10-24 21:51:42 UTC (rev 3391)
+++ trunk/numpy/core/src/arrayobject.c	2006-10-25 06:15:40 UTC (rev 3392)
@@ -2793,7 +2793,29 @@
 }
 
 
+/* return -1 if tuple-object seq is not a tuple of integers.
+   otherwise fill vals with converted integers
+*/
 static int
+_tuple_of_integers(PyObject *seq, intp *vals, int maxvals)
+{
+        int i;
+        PyObject *obj;
+        intp temp;
+
+        for (i=0; i<maxvals; i++) {
+                obj = PyTuple_GET_ITEM(seq, i);
+                if ((PyArray_Check(obj) && PyArray_NDIM(obj) > 0) ||
+                    PyList_Check(obj)) return -1;
+                temp = PyArray_PyIntAsIntp(obj);
+                if (error_converting(temp)) return -1;
+                vals[i] = temp;
+        }
+        return 0;
+}
+
+
+static int
 array_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)
 {
         int ret, oned, fancy;
@@ -2857,9 +2879,9 @@
         }
         
         /* optimization for integer-tuple */
-        if (self->nd > 1 && 
+        if (self->nd > 1 &&
             (PyTuple_Check(index) && (PyTuple_GET_SIZE(index) == self->nd)) 
-            && PyArray_IntpFromSequence(index, vals, self->nd) == self->nd) {
+            && (_tuple_of_integers(index, vals, self->nd) >= 0)) {
                 int i;
                 char *item;
                 for (i=0; i<self->nd; i++) {
@@ -2934,7 +2956,7 @@
         /* optimization for a tuple of integers */
         if (self->nd > 1 && PyTuple_Check(op) &&
             (PyTuple_GET_SIZE(op) == self->nd)
-            && PyArray_IntpFromSequence(op, vals, self->nd) == self->nd) {
+            && (_tuple_of_integers(op, vals, self->nd) >= 0)) {
                 int i;
                 char *item;
                 for (i=0; i<self->nd; i++) {
@@ -4862,6 +4884,7 @@
 }
 
 
+
 /* Check whether the given array is stored contiguously (row-wise) in
    memory. */
 



More information about the Numpy-svn mailing list