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

scipy-svn@scip... scipy-svn@scip...
Tue Jan 22 16:25:32 CST 2008


Author: wnbell
Date: 2008-01-22 16:25:28 -0600 (Tue, 22 Jan 2008)
New Revision: 3855

Modified:
   trunk/scipy/sparse/tests/test_base.py
Log:
added sparse unittests


Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py	2008-01-22 15:06:22 UTC (rev 3854)
+++ trunk/scipy/sparse/tests/test_base.py	2008-01-22 22:25:28 UTC (rev 3855)
@@ -33,7 +33,6 @@
 
 
 
-#TODO test spmatrix( [[1,2],[3,4]] ) format
 #TODO check that invalid shape in constructor raises exception
 #TODO check that spmatrix( ... , copy=X ) is respected
 #TODO test repr(spmatrix)
@@ -97,6 +96,10 @@
         assert_array_equal(self.spmatrix(A.A).todense(),A)
         assert_array_equal(self.spmatrix(A.tolist()).todense(),A)
 
+    def test_fromlist(self):
+        A = matrix([[1,0,0],[2,3,4],[0,5,0],[0,0,0]])
+        assert_array_equal(self.spmatrix(A.tolist()).todense(),A)
+
     def test_todense(self):
         chk = self.datsp.todense()
         assert_array_equal(chk,self.dat)
@@ -122,7 +125,19 @@
         check2 = dot(self.datsp.toarray(), b)
         assert_array_equal(dense_dot_dense, check2)
 
+    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.astype('int16').asfptype().dtype , 'float32' )
+        assert_equal( A.astype('complex128').asfptype().dtype , 'complex128' )
+        
+        B = A.asfptype()
+        C = B.asfptype()
+        assert( B is C )
+
+
     def test_mul_scalar(self):
         assert_array_equal(self.dat*2,(self.datsp*2).todense())
         assert_array_equal(self.dat*17.3,(self.datsp*17.3).todense())
@@ -415,20 +430,7 @@
     #    assert_array_equal(dense_dot_dense, dense_dot_sparse)
 
 
-    def test_extract_diagonal(self):
-        """
-        Test extraction of main diagonal from sparse matrices
-        """
-        L = []
-        L.append(array([[0,0,3],[1,6,4],[5,2,0]]))
-        L.append(array([[1,2,3]]))
-        L.append(array([[7],[6],[5]]))
-        L.append(array([[2]]))
 
-        for A in L:
-            assert_array_equal(numpy.diag(A),extract_diagonal(self.spmatrix(A)))
-
-
 class _TestInplaceArithmetic:
     def test_imul_scalar(self):
         a = self.datsp.copy()



More information about the Scipy-svn mailing list