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

numpy-svn@scip... numpy-svn@scip...
Tue Feb 27 21:22:22 CST 2007


Author: oliphant
Date: 2007-02-27 21:22:18 -0600 (Tue, 27 Feb 2007)
New Revision: 3556

Modified:
   trunk/numpy/core/src/arraytypes.inc.src
Log:
Fix copyswap when a field is a sub-array

Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2007-02-28 01:15:59 UTC (rev 3555)
+++ trunk/numpy/core/src/arraytypes.inc.src	2007-02-28 03:22:18 UTC (rev 3556)
@@ -1298,9 +1298,7 @@
 VOID_copyswapn (char *dst, intp dstride, char *src, intp sstride,
                 intp n, int swap, PyArrayObject *arr)
 {
-        int itemsize;
         if (arr == NULL) return;
-        itemsize = arr->descr->elsize;
         if (PyArray_HASFIELDS(arr)) {
                 PyObject *key, *value, *title=NULL;
                 PyArray_Descr *new, *descr;
@@ -1320,8 +1318,30 @@
                 arr->descr = descr;
                 return;
         }
+        if (swap && arr->descr->subarray != NULL) {
+                PyArray_Descr *descr, *new;
+                npy_intp num;                
+                npy_intp i;
+                int subitemsize;
+                char *dstptr, *srcptr;
+                descr = arr->descr;
+                new = descr->subarray->base;
+                arr->descr = new;
+                dstptr = dst;
+                srcptr = src;
+                subitemsize = new->elsize;
+                num = descr->elsize / subitemsize;
+                for (i=0; i<n; i++) {
+                        new->f->copyswapn(dstptr, subitemsize, srcptr,
+                                          subitemsize, num, swap, arr);
+                        dstptr += dstride;
+                        if (srcptr) srcptr += sstride;
+                }
+                arr->descr = descr;
+                return;
+        }
         if (src != NULL) {
-                memcpy(dst, src, itemsize * n);
+                memcpy(dst, src, arr->descr->elsize * n);
         }
         return;
 }
@@ -1349,6 +1369,20 @@
                 arr->descr = descr;
                 return;
         }
+        if (swap && arr->descr->subarray != NULL) {
+                PyArray_Descr *descr, *new;
+                npy_intp num;                
+                int itemsize;
+                descr = arr->descr;
+                new = descr->subarray->base;
+                arr->descr = new;
+                itemsize = new->elsize;
+                num = descr->elsize / itemsize;
+                new->f->copyswapn(dst, itemsize, src,
+                                  itemsize, num, swap, arr);
+                arr->descr = descr;
+                return;
+        }
         if (src != NULL) {
                 memcpy(dst, src, arr->descr->elsize);
         }



More information about the Numpy-svn mailing list