[Scipy-svn] r2241 - in trunk/Lib/sandbox/numexpr: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Thu Oct 5 08:09:28 CDT 2006


Author: tim_hochberg
Date: 2006-10-04 23:08:32 -0500 (Wed, 04 Oct 2006)
New Revision: 2241

Modified:
   trunk/Lib/sandbox/numexpr/interpreter.c
   trunk/Lib/sandbox/numexpr/tests/test_numexpr.py
   trunk/Lib/sandbox/numexpr/timing.py
Log:
Make copies of record arrays when they are not aligned correctly.

Modified: trunk/Lib/sandbox/numexpr/interpreter.c
===================================================================
--- trunk/Lib/sandbox/numexpr/interpreter.c	2006-10-05 05:55:13 UTC (rev 2240)
+++ trunk/Lib/sandbox/numexpr/interpreter.c	2006-10-05 04:08:32 UTC (rev 2241)
@@ -1082,10 +1082,11 @@
             }
         } else {
             PyObject *origA = a;
-            /* Check discontiguous strides appear only on the last dimension. */
-            for (j = PyArray_NDIM(a)-2; j >= 0; j--) {
-                if (PyArray_STRIDE(a, j) != 
-                        PyArray_STRIDE(a, j+1) * PyArray_DIM(a, j+1)) {
+            int inner_size = -1; 
+            /* Check array is contiguous */
+            for (j = PyArray_NDIM(a)-1; j >= 0; j--) {
+                if ((inner_size == -1 && PyArray_STRIDE(a, j) % PyArray_ITEMSIZE(a)) ||
+                    (inner_size != -1 && PyArray_STRIDE(a, j) != inner_size)) {
                     intp dims[1] = {BLOCK_SIZE1};
                     inddata[i+1].count = PyArray_NDIM(a);
                     inddata[i+1].findex = -1;
@@ -1100,6 +1101,7 @@
                     PyTuple_SET_ITEM(a_inputs, i+2*n_inputs, a);  /* steals reference */
                     break;
                 }
+                inner_size = PyArray_STRIDE(a, j) * PyArray_DIM(a, j);
             }
 
             self->memsteps[i+1] = PyArray_STRIDE(a, PyArray_NDIM(a)-1);

Modified: trunk/Lib/sandbox/numexpr/tests/test_numexpr.py
===================================================================
--- trunk/Lib/sandbox/numexpr/tests/test_numexpr.py	2006-10-05 05:55:13 UTC (rev 2240)
+++ trunk/Lib/sandbox/numexpr/tests/test_numexpr.py	2006-10-05 04:08:32 UTC (rev 2241)
@@ -139,6 +139,13 @@
         a = arange(100).reshape(10,10)[::2]
         b = arange(50).reshape(5,10)
         assert_array_equal(evaluate("a+b"), a+b)
+        c = empty([10], dtype=[('c1', int32), ('c2', uint16)])
+        c['c1'] = arange(10)
+        c['c2'].fill(0xaaaa)
+        c1 = c['c1']
+        a0 = a[0]
+        assert_array_equal(evaluate("c1"), c1) 
+        assert_array_equal(evaluate("a0+c1"), a0+c1)
         
         
     def check_broadcasting(self):

Modified: trunk/Lib/sandbox/numexpr/timing.py
===================================================================
--- trunk/Lib/sandbox/numexpr/timing.py	2006-10-05 05:55:13 UTC (rev 2240)
+++ trunk/Lib/sandbox/numexpr/timing.py	2006-10-05 04:08:32 UTC (rev 2241)
@@ -58,7 +58,7 @@
 try: from scipy.weave import blitz
 except: pass
 from numexpr import evaluate
-a = arange(%f)
+a = arange(2*%f)[::2]
 b = arange(%f)
 result = arange(%f)
 """ % ((array_size,)*3)
@@ -70,7 +70,7 @@
 try: from scipy.weave import blitz
 except: pass
 from numexpr import evaluate
-a = arange(%f)
+a = arange(2*%f)[::2]
 b = arange(%f)
 result = arange(%f)
 """ % ((array_size,)*3)
@@ -82,7 +82,7 @@
 try: from scipy.weave import blitz
 except: pass
 from numexpr import evaluate
-a = arange(%f, dtype=float)
+a = arange(2*%f, dtype=float)[::2]
 b = arange(%f, dtype=float)
 result = arange(%f, dtype=float)
 """ % ((array_size,)*3)



More information about the Scipy-svn mailing list