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

numpy-svn at scipy.org numpy-svn at scipy.org
Thu Oct 5 19:36:50 EDT 2006


Author: oliphant
Date: 2006-10-05 18:36:47 -0500 (Thu, 05 Oct 2006)
New Revision: 3266

Modified:
   trunk/numpy/core/src/arrayobject.c
Log:
Re-work flat index setting to handle integer case better for objects arrays.

Modified: trunk/numpy/core/src/arrayobject.c
===================================================================
--- trunk/numpy/core/src/arrayobject.c	2006-10-05 19:05:47 UTC (rev 3265)
+++ trunk/numpy/core/src/arrayobject.c	2006-10-05 23:36:47 UTC (rev 3266)
@@ -9244,7 +9244,6 @@
         PyArray_Descr *type;
         PyArray_Descr *indtype=NULL;
         int swap, retval=-1;
-        int itemsize;
         intp start, step_size;
         intp n_steps;
         PyObject *obj=NULL;
@@ -9266,8 +9265,33 @@
         }
 
         type = self->ao->descr;
-        itemsize = type->elsize;
 
+        /* Check for Boolean -- this is first becasue
+           Bool is a subclass of Int */
+
+        if (PyBool_Check(ind)) {
+                retval = 0;
+                if (PyObject_IsTrue(ind)) {
+                        retval = type->f->setitem(val, self->dataptr, self->ao);
+                }
+                goto finish;
+        }
+
+        start = PyArray_PyIntAsIntp(ind);
+        if (start==-1 && PyErr_Occurred()) PyErr_Clear();
+        else {
+                if (start < -self->size || start >= self->size) {
+                        PyErr_Format(PyExc_ValueError,
+                                     "index (%d) out of range", start);
+                        goto finish;
+                }
+                retval = 0;
+                PyArray_ITER_GOTO1D(self, start);
+                retval = type->f->setitem(val, self->dataptr, self->ao);
+                PyArray_ITER_RESET(self);
+                goto finish;
+        }
+
         Py_INCREF(type);
         arrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);
         if (arrval==NULL) return -1;
@@ -9275,23 +9299,12 @@
         if (val_it==NULL) goto finish;
         if (val_it->size == 0) {retval = 0; goto finish;}
 
-        /* Check for Boolean -- this is first becasue
-           Bool is a subclass of Int */
-
         copyswap = PyArray_DESCR(arrval)->f->copyswap;
         swap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));
-        if (PyBool_Check(ind)) {
-                if (PyObject_IsTrue(ind)) {
-                        copyswap(self->dataptr, PyArray_DATA(arrval),
-                                  swap, arrval);
-                }
-                retval=0;
-                goto finish;
-        }
+        
+        /* Check Slice */
 
-        /* Check for Integer or Slice */
-
-        if (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {
+        if (PySlice_Check(ind)) {
                 start = parse_subindex(ind, &step_size, &n_steps,
                                        self->size);
                 if (start == -1) goto finish;
@@ -9325,12 +9338,8 @@
         /* convert to INTP array if Integer array scalar or List */
 
         indtype = PyArray_DescrFromType(PyArray_INTP);
-        if (PyArray_IsScalar(ind, Integer)) {
+        if (PyList_Check(ind)) {
                 Py_INCREF(indtype);
-                obj = PyArray_FromScalar(ind, indtype);
-        }
-        else if (PyList_Check(ind)) {
-                Py_INCREF(indtype);
                 obj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);
         }
         else {




More information about the Numpy-svn mailing list