[Scipy-svn] r4857 - trunk/scipy/sparse/tests

scipy-svn at scipy.org scipy-svn at scipy.org
Mon Oct 27 00:23:01 EDT 2008


Author: wnbell
Date: 2008-10-26 23:22:59 -0500 (Sun, 26 Oct 2008)
New Revision: 4857

Modified:
   trunk/scipy/sparse/tests/test_base.py
Log:
test that .astype(dtype) preserves sparse format


Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py	2008-10-27 04:14:53 UTC (rev 4856)
+++ trunk/scipy/sparse/tests/test_base.py	2008-10-27 04:22:59 UTC (rev 4857)
@@ -224,12 +224,24 @@
         dense_dot_dense = dot(dat, b)
         check2 = dot(self.datsp.toarray(), b)
         assert_array_equal(dense_dot_dense, check2)
+    
+    def test_astype(self):
+        D = array([[1.0 + 3j,       0,      0],
+                   [       0, 2.0 + 5,      0],
+                   [       0,       0,      0]])
+        S = self.spmatrix(D)
 
+        for x in supported_dtypes:
+            assert_equal(S.astype(x).dtype,     D.astype(x).dtype)  # correct type
+            assert_equal(S.astype(x).toarray(), D.astype(x))        # correct values
+            assert_equal(S.astype(x).format,    S.format)           # format preserved
+
     def test_asfptype(self):
         A = self.spmatrix( arange(6,dtype='int32').reshape(2,3) )
 
         assert_equal( A.dtype , 'int32' )
         assert_equal( A.asfptype().dtype, 'float64' )
+        assert_equal( A.asfptype().format, A.format )
         assert_equal( A.astype('int16').asfptype().dtype , 'float32' )
         assert_equal( A.astype('complex128').asfptype().dtype , 'complex128' )
 
@@ -815,21 +827,6 @@
         self.Asp = self.spmatrix(self.A)
         self.Bsp = self.spmatrix(self.B)
 
-    def test_astype(self):
-        self.arith_init()
-
-        #check whether dtype and value is preserved in conversion
-        for x in supported_dtypes:
-            A = self.A.astype(x)
-            B = self.B.astype(x)
-
-            Asp = self.spmatrix(A)
-            Bsp = self.spmatrix(B)
-            assert_equal(Asp.dtype,A.dtype)
-            assert_equal(Bsp.dtype,B.dtype)
-            assert_array_equal(Asp.todense(),A)
-            assert_array_equal(Bsp.todense(),B)
-
     def test_add_sub(self):
         self.arith_init()
 




More information about the Scipy-svn mailing list