[Numpy-svn] r3279 - in trunk/numpy/lib: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Fri Oct 6 21:23:37 CDT 2006


Author: oliphant
Date: 2006-10-06 21:23:35 -0500 (Fri, 06 Oct 2006)
New Revision: 3279

Modified:
   trunk/numpy/lib/shape_base.py
   trunk/numpy/lib/tests/test_shape_base.py
Log:
Add tests for tile and fix error.

Modified: trunk/numpy/lib/shape_base.py
===================================================================
--- trunk/numpy/lib/shape_base.py	2006-10-07 02:12:09 UTC (rev 3278)
+++ trunk/numpy/lib/shape_base.py	2006-10-07 02:23:35 UTC (rev 3279)
@@ -604,8 +604,8 @@
     c = _nx.array(A,copy=False,subok=True,ndmin=d)
     shape = list(c.shape)
     n = c.size
-    if (d < A.ndim):
-        tup = (1,)*(A.ndim-d) + tup
+    if (d < c.ndim):
+        tup = (1,)*(c.ndim-d) + tup
     for i, nrep in enumerate(tup):
         if nrep!=1:
             c = c.reshape(-1,n).repeat(nrep,0)

Modified: trunk/numpy/lib/tests/test_shape_base.py
===================================================================
--- trunk/numpy/lib/tests/test_shape_base.py	2006-10-07 02:12:09 UTC (rev 3278)
+++ trunk/numpy/lib/tests/test_shape_base.py	2006-10-07 02:23:35 UTC (rev 3279)
@@ -386,6 +386,17 @@
                 assert False, "ValueError expected"
 
 
+class test_tile(NumpyTestCase):
+    def check_basic(self):
+        a = array([0,1,2])
+        b = [[1,2],[3,4]]
+        assert_equal(tile(a,2), [0,1,2,0,1,2])
+        assert_equal(tile(a,(2,2)), [[0,1,2,0,1,2],[0,1,2,0,1,2]])
+        assert_equal(tile(a,(1,2)), [[0,1,2,0,1,2]])
+        assert_equal(tile(b, 2), [[1,2,1,2],[3,4,3,4]])
+        assert_equal(tile(b,(2,1)),[[1,2],[3,4],[1,2],[3,4]])
+        assert_equal(tile(b,(2,2)),[[1,2,1,2],[3,4,3,4],[1,2,1,2],[3,4,3,4]])
+        
 # Utility
 
 def compare_results(res,desired):



More information about the Numpy-svn mailing list