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

numpy-svn@scip... numpy-svn@scip...
Sun Aug 26 04:06:31 CDT 2007


Author: stefan
Date: 2007-08-26 04:06:05 -0500 (Sun, 26 Aug 2007)
New Revision: 4013

Modified:
   trunk/numpy/core/include/numpy/ndarrayobject.h
   trunk/numpy/core/src/arraytypes.inc.src
   trunk/numpy/core/src/multiarraymodule.c
   trunk/numpy/core/tests/test_multiarray.py
Log:
Fix putmask for byte-swapped arrays.


Modified: trunk/numpy/core/include/numpy/ndarrayobject.h
===================================================================
--- trunk/numpy/core/include/numpy/ndarrayobject.h	2007-08-25 22:07:38 UTC (rev 4012)
+++ trunk/numpy/core/include/numpy/ndarrayobject.h	2007-08-26 09:06:05 UTC (rev 4013)
@@ -1050,7 +1050,7 @@
 typedef void (PyArray_FastClipFunc)(void *in, npy_intp n_in, void *min,
                                     void *max, void *out);
 typedef void (PyArray_FastPutmaskFunc)(void *in, void *mask, npy_intp n_in,
-                                    void *values, npy_intp nv);
+                                       void *values, npy_intp nv, npy_intp swap);
 
 typedef struct {
         npy_intp *ptr;

Modified: trunk/numpy/core/src/arraytypes.inc.src
===================================================================
--- trunk/numpy/core/src/arraytypes.inc.src	2007-08-25 22:07:38 UTC (rev 4012)
+++ trunk/numpy/core/src/arraytypes.inc.src	2007-08-26 09:06:05 UTC (rev 4013)
@@ -2109,15 +2109,18 @@
 #type= Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble,cfloat, cdouble, clongdouble#
 */
 static void
-@name@_fastputmask(@type@ *in, Bool *mask, intp ni, @type@ *vals, intp nv)
+@name@_fastputmask(@type@ *in, Bool *mask, intp ni, @type@ *vals, intp nv, int swap)
 {
         register npy_intp i;
         @type@ s_val;
+        int elsize = sizeof(@type@);
+
         if (nv == 1) {
                 s_val = *vals;
                 for (i = 0; i < ni; i++) {
                         if (mask[i]) {
                                 in[i] = s_val;
+                                if (swap) byte_swap_vector(in+i, 1, elsize);
                         }
                 }
         }
@@ -2125,6 +2128,7 @@
                 for (i = 0; i < ni; i++) {
                         if (mask[i]) {
                                 in[i] = vals[i%nv];
+                                if (swap) byte_swap_vector(in+i, 1, elsize);
                         }
                 }
         }

Modified: trunk/numpy/core/src/multiarraymodule.c
===================================================================
--- trunk/numpy/core/src/multiarraymodule.c	2007-08-25 22:07:38 UTC (rev 4012)
+++ trunk/numpy/core/src/multiarraymodule.c	2007-08-26 09:06:05 UTC (rev 4013)
@@ -4138,7 +4138,8 @@
             }
         }
         else {
-            func(dest, mask->data, ni, values->data, nv);
+            func(dest, mask->data, ni, values->data, nv,
+                             !PyArray_ISNOTSWAPPED(self));
         }
     }
 

Modified: trunk/numpy/core/tests/test_multiarray.py
===================================================================
--- trunk/numpy/core/tests/test_multiarray.py	2007-08-25 22:07:38 UTC (rev 4012)
+++ trunk/numpy/core/tests/test_multiarray.py	2007-08-26 09:06:05 UTC (rev 4013)
@@ -443,6 +443,14 @@
         self.failUnlessRaises(ValueError,N.putmask,
                               N.array([1,2,3]),[True],5)
 
+    def tst_byteorder(self,dtype):
+        x = N.array([1,2,3],dtype)
+        N.putmask(x,[True,False,True],-1)
+        assert_array_equal(x,[-1,2,-1])
+
+    def testip_byteorder(self):
+        return ((self.tst_byteorder,dtype) for dtype in ('>i4','<i4'))
+
     def test_record_array(self):
 ##         Not supported yet
 ##



More information about the Numpy-svn mailing list