[Numpy-svn] r5146 - trunk/numpy/core/tests

numpy-svn at scipy.org numpy-svn at scipy.org
Wed May 7 20:33:45 EDT 2008


Author: peridot
Date: 2008-05-07 19:33:43 -0500 (Wed, 07 May 2008)
New Revision: 5146

Modified:
   trunk/numpy/core/tests/test_defmatrix.py
Log:
Additional tests of matrix indexing.


Modified: trunk/numpy/core/tests/test_defmatrix.py
===================================================================
--- trunk/numpy/core/tests/test_defmatrix.py	2008-05-08 00:15:02 UTC (rev 5145)
+++ trunk/numpy/core/tests/test_defmatrix.py	2008-05-08 00:33:43 UTC (rev 5146)
@@ -2,6 +2,7 @@
 set_package_path()
 import numpy.core;reload(numpy.core)
 from numpy.core import *
+import numpy as np
 restore_path()
 
 class TestCtor(NumpyTestCase):
@@ -180,7 +181,8 @@
         assert_equal(x, [[0,1],[0,0],[0,0]])
 
 class TestNewScalarIndexing(NumpyTestCase):
-    a = matrix([[1, 2],[3,4]])
+    def setUp(self):
+        self.a = matrix([[1, 2],[3,4]])
 
     def check_dimesions(self):
         a = self.a
@@ -194,7 +196,7 @@
 
     def check_array_to_list(self):
         a = self.a
-        assert a.tolist() == [[1, 2], [3, 4]]
+        assert_equal(a.tolist(),[[1, 2], [3, 4]])
 
     def check_fancy_indexing(self):
         a = self.a
@@ -219,6 +221,32 @@
 ##         assert_equal(x[0],0)
 ##         assert_equal(x[:,0].shape,x.shape)
 
+    def check_scalar_indexing(self):
+        x = asmatrix(zeros((3,2),float))
+        assert_equal(x[0,0],x[0][0])
 
+    def check_row_column_indexing(self):
+        x = asmatrix(np.eye(2))
+        assert_array_equal(x[0,:],[[1,0]])
+        assert_array_equal(x[1,:],[[0,1]])
+        assert_array_equal(x[:,0],[[1],[0]])
+        assert_array_equal(x[:,1],[[0],[1]])
+
+    def check_boolean_indexing(self):
+        A = arange(6)
+        A.shape = (3,2)
+        x = asmatrix(A)
+        assert_array_equal(x[:,array([True,False])],x[:,0])
+        assert_array_equal(x[array([True,False,False]),:],x[0,:])
+
+    def check_list_indexing(self):
+        A = arange(6)
+        A.shape = (3,2)
+        x = asmatrix(A)
+        assert_array_equal(x[:,[1,0]],x[:,::-1])
+        assert_array_equal(x[[2,1,0],:],x[::-1,:])
+
+
+        
 if __name__ == "__main__":
     NumpyTest().run()




More information about the Numpy-svn mailing list