[Scipy-svn] r2885 - in trunk/Lib/ndimage: src tests

scipy-svn@scip... scipy-svn@scip...
Wed Mar 28 16:54:38 CDT 2007


Author: stefan
Date: 2007-03-28 16:54:24 -0500 (Wed, 28 Mar 2007)
New Revision: 2885

Modified:
   trunk/Lib/ndimage/src/ni_interpolation.c
   trunk/Lib/ndimage/tests/test_ndimage.py
Log:
Fix ndimage tests. Add brief comment in map_coordinates code.


Modified: trunk/Lib/ndimage/src/ni_interpolation.c
===================================================================
--- trunk/Lib/ndimage/src/ni_interpolation.c	2007-03-28 19:10:01 UTC (rev 2884)
+++ trunk/Lib/ndimage/src/ni_interpolation.c	2007-03-28 21:54:24 UTC (rev 2885)
@@ -141,9 +141,9 @@
         in = 0;
       } else {
         maybelong sz = len;
-        in += sz * (maybelong)(-in / sz); 
-        if (in < 0)
-          in += sz;
+        // Integer division of -in/sz gives (-in mod sz)
+        // Note that 'in' is negative
+        in += sz * ((maybelong)(-in / sz) + 1);
       }
       break;
     case NI_EXTEND_NEAREST:
@@ -180,7 +180,7 @@
         in = 0;
       } else {
         maybelong sz = len;
-        in -= sz * (maybelong)(in / sz); 
+        in -= sz * (maybelong)(in / sz);
       }
       break;
     case NI_EXTEND_NEAREST:

Modified: trunk/Lib/ndimage/tests/test_ndimage.py
===================================================================
--- trunk/Lib/ndimage/tests/test_ndimage.py	2007-03-28 19:10:01 UTC (rev 2884)
+++ trunk/Lib/ndimage/tests/test_ndimage.py	2007-03-28 21:54:24 UTC (rev 2885)
@@ -1856,7 +1856,7 @@
         for order in range(0, 6):
             out = ndimage.affine_transform(data, [[0.5]],
                                           output_shape = (4,), order=order)
-            self.failUnless(diff(out, [1, 1, 1, 1]) < eps)
+            self.failUnless(diff(out, [1, 1, 1, 0]) < eps)
 
     def test_affine_transform11(self):
         "affine transform 11"
@@ -2072,7 +2072,7 @@
         data = numpy.ones([2], numpy.float64)
         for order in range(0, 6):
             out = ndimage.zoom(data, 2.0, order=order)
-            self.failUnless(diff(out, [1, 1, 1, 1]) < eps)
+            self.failUnless(diff(out, [1, 1, 1, 0]) < eps)
 
     def test_zoom02(self):
         "zoom 2"
@@ -2212,39 +2212,46 @@
 
     def test_rotate05(self):
         "rotate 5"
-        data = numpy.array([[[0, 0, 0, 0, 0],
-                                [0, 1, 1, 0, 0],
-                                [0, 0, 0, 0, 0]]] * 3,
-                              dtype = numpy.float64)
-        true = numpy.array([[[0, 0, 0],
-                                [0, 0, 0],
-                                [0, 1, 0],
-                                [0, 1, 0],
-                                [0, 0, 0]]] * 3, dtype = numpy.float64)
+        data = numpy.empty((4,3,3))
+        for i in range(3):
+            data[:,:,i] = numpy.array([[0,0,0],
+                                       [0,1,0],
+                                       [0,1,0],
+                                       [0,0,0]], dtype = numpy.float64)
+
+        true = numpy.array([[0,0,0,0],
+                            [0,1,1,0],
+                            [0,0,0,0]], dtype = numpy.float64)
+
         for order in range(0, 6):
             out = ndimage.rotate(data, 90)
-            self.failUnless(diff(out, true) < eps)
-
+            for i in range(3):
+                self.failUnless(diff(out[:,:,i], true) < eps)
+                
     def test_rotate06(self):
         "rotate 6"
-        data = numpy.array([[[0, 0, 0, 0, 0],
-                                [0, 1, 1, 0, 0],
-                                [0, 0, 0, 0, 0]]] * 3,
-                              dtype = numpy.float64)
-        true = numpy.array([[[0, 0, 0, 0, 0],
-                                [0, 0, 1, 0, 0],
-                                [0, 0, 1, 0, 0]]] * 3,
-                              dtype = numpy.float64)
+        data = numpy.empty((3,4,3))
+        for i in range(3):
+            data[:,:,i] = numpy.array([[0,0,0,0],
+                                       [0,1,1,0],
+                                       [0,0,0,0]], dtype = numpy.float64)
+
+        true = numpy.array([[0,0,0],
+                            [0,1,0],
+                            [0,1,0],
+                            [0,0,0]], dtype = numpy.float64)
+
         for order in range(0, 6):
-            out = ndimage.rotate(data, 90, reshape = False)
-            self.failUnless(diff(out, true) < eps)
-
+            out = ndimage.rotate(data, 90)
+            for i in range(3):
+                self.failUnless(diff(out[:,:,i], true) < eps)
+                
     def test_rotate07(self):
         "rotate 7"
         data = numpy.array([[[0, 0, 0, 0, 0],
-                                [0, 1, 1, 0, 0],
-                                [0, 0, 0, 0, 0]]] * 2,
-                              dtype = numpy.float64)
+                             [0, 1, 1, 0, 0],
+                             [0, 0, 0, 0, 0]]] * 2,
+                           dtype = numpy.float64)
         data = data.transpose()
         true = numpy.array([[[0, 0, 0],
                                 [0, 1, 0],



More information about the Scipy-svn mailing list