[Scipy-svn] r3830 - trunk/scipy/sparse

scipy-svn at scipy.org scipy-svn at scipy.org
Mon Jan 14 14:29:19 EST 2008


Author: wnbell
Date: 2008-01-14 13:29:12 -0600 (Mon, 14 Jan 2008)
New Revision: 3830

Modified:
   trunk/scipy/sparse/bsr.py
   trunk/scipy/sparse/construct.py
   trunk/scipy/sparse/coo.py
   trunk/scipy/sparse/csc.py
   trunk/scipy/sparse/csr.py
   trunk/scipy/sparse/dia.py
   trunk/scipy/sparse/info.py
Log:
fixed docstrings to pass doctests


Modified: trunk/scipy/sparse/bsr.py
===================================================================
--- trunk/scipy/sparse/bsr.py	2008-01-14 12:58:10 UTC (rev 3829)
+++ trunk/scipy/sparse/bsr.py	2008-01-14 19:29:12 UTC (rev 3830)
@@ -62,22 +62,22 @@
 
     >>> from scipy.sparse import *
     >>> from scipy import *
-    >>> bsr_matrix( (3,4), dtype='i' ).todense()
+    >>> bsr_matrix( (3,4), dtype='int32' ).todense()
     matrix([[0, 0, 0, 0],
             [0, 0, 0, 0],
-            [0, 0, 0, 0]])
+            [0, 0, 0, 0]], dtype=int32)
 
-    >>> row = array([0,0,1,2,2,2])
-    >>> col = array([0,2,2,0,1,2])
-    >>> data = kron([1,2,3,4,5,6])
+    >>> row  = array([0,0,1,2,2,2])
+    >>> col  = array([0,2,2,0,1,2])
+    >>> data = array([1,2,3,4,5,6])
     >>> bsr_matrix( (data,(row,col)), shape=(3,3) ).todense()
     matrix([[1, 0, 2],
             [0, 0, 3],
             [4, 5, 6]])
     
-    >>> indptr = array([0,2,3,6])
+    >>> indptr  = array([0,2,3,6])
     >>> indices = array([0,2,2,0,1,2])
-    >>> data = array([1,2,3,4,5,6]).repeat(4).reshape(6,2,2)
+    >>> data    = array([1,2,3,4,5,6]).repeat(4).reshape(6,2,2)
     >>> bsr_matrix( (data,indices,indptr), shape=(6,6) ).todense()
     matrix([[1, 1, 0, 0, 2, 2],
             [1, 1, 0, 0, 2, 2],
@@ -121,6 +121,7 @@
             
             elif len(arg1) == 2:
                 # (data,(row,col)) format
+                from coo import coo_matrix
                 self._set_self( coo_matrix(arg1).tobsr(blocksize=blocksize) )
 
             elif len(arg1) == 3:

Modified: trunk/scipy/sparse/construct.py
===================================================================
--- trunk/scipy/sparse/construct.py	2008-01-14 12:58:10 UTC (rev 3829)
+++ trunk/scipy/sparse/construct.py	2008-01-14 19:29:12 UTC (rev 3830)
@@ -98,21 +98,19 @@
     >>> A = csr_matrix(array([[0,2],[5,0]]))
     >>> B = csr_matrix(array([[1,2],[3,4]]))
     >>> spkron(A,B).todense()
-    matrix([[  0.,   0.,   2.,   4.],
-            [  0.,   0.,   6.,   8.],
-            [  5.,  10.,   0.,   0.],
-            [ 15.,  20.,   0.,   0.]])
+    matrix([[ 0,  0,  2,  4],
+            [ 0,  0,  6,  8],
+            [ 5, 10,  0,  0],
+            [15, 20,  0,  0]])
 
     >>> spkron(A,[[1,2],[3,4]]).todense()
-    matrix([[  0.,   0.,   2.,   4.],
-            [  0.,   0.,   6.,   8.],
-            [  5.,  10.,   0.,   0.],
-            [ 15.,  20.,   0.,   0.]])
+    matrix([[ 0,  0,  2,  4],
+            [ 0,  0,  6,  8],
+            [ 5, 10,  0,  0],
+            [15, 20,  0,  0]])
 
     """
-    #TODO optimize for small dense B and CSR A -> BSR
     B = coo_matrix(B)
-
     
     if (format is None or format == "bsr") and 2*B.nnz >= B.shape[0] * B.shape[1]:
         #B is fairly dense, use BSR

Modified: trunk/scipy/sparse/coo.py
===================================================================
--- trunk/scipy/sparse/coo.py	2008-01-14 12:58:10 UTC (rev 3829)
+++ trunk/scipy/sparse/coo.py	2008-01-14 19:29:12 UTC (rev 3830)
@@ -70,10 +70,10 @@
 
     >>> from scipy.sparse import *
     >>> from scipy import *
-    >>> coo_matrix( (3,4), dtype='i' ).todense()
+    >>> coo_matrix( (3,4), dtype='int32' ).todense()
     matrix([[0, 0, 0, 0],
             [0, 0, 0, 0],
-            [0, 0, 0, 0]])
+            [0, 0, 0, 0]], dtype=int32)
 
     >>> row  = array([0,3,1,0])
     >>> col  = array([0,3,1,2])
@@ -84,7 +84,7 @@
             [0, 0, 0, 0],
             [0, 0, 0, 5]])
 
-    >>> print "example with duplicates"
+    >>> # example with duplicates
     >>> row  = array([0,0,1,3,1,0,0])
     >>> col  = array([0,2,1,3,1,0,0])
     >>> data = array([1,1,1,1,1,1,1])

Modified: trunk/scipy/sparse/csc.py
===================================================================
--- trunk/scipy/sparse/csc.py	2008-01-14 12:58:10 UTC (rev 3829)
+++ trunk/scipy/sparse/csc.py	2008-01-14 19:29:12 UTC (rev 3830)
@@ -63,26 +63,26 @@
 
     >>> from scipy.sparse import *
     >>> from scipy import *
-    >>> csc_matrix( (3,4), dtype='i' ).todense()
+    >>> csc_matrix( (3,4), dtype='int32' ).todense()
     matrix([[0, 0, 0, 0],
             [0, 0, 0, 0],
-            [0, 0, 0, 0]])
+            [0, 0, 0, 0]], dtype=int32)
 
-    >>> row = array([0,0,1,2,2,2])
-    >>> col = array([0,2,2,0,1,2])
+    >>> row = array([0,2,2,0,1,2])
+    >>> col = array([0,0,1,2,2,2])
     >>> data = array([1,2,3,4,5,6])
     >>> csc_matrix( (data,(row,col)), shape=(3,3) ).todense()
-    matrix([[1, 0, 2],
-            [0, 0, 3],
-            [4, 5, 6]])
+    matrix([[1, 0, 4],
+            [0, 0, 5],
+            [2, 3, 6]])
 
     >>> indptr = array([0,2,3,6])
     >>> indices = array([0,2,2,0,1,2])
-    >>> data = array([1,4,6,2,3,5])
+    >>> data = array([1,2,3,4,5,6])
     >>> csc_matrix( (data,indices,indptr), shape=(3,3) ).todense()
-    matrix([[1, 0, 2],
-            [0, 0, 3],
-            [4, 5, 6]])
+    matrix([[1, 0, 4],
+            [0, 0, 5],
+            [2, 3, 6]])
 
     """
 

Modified: trunk/scipy/sparse/csr.py
===================================================================
--- trunk/scipy/sparse/csr.py	2008-01-14 12:58:10 UTC (rev 3829)
+++ trunk/scipy/sparse/csr.py	2008-01-14 19:29:12 UTC (rev 3830)
@@ -65,10 +65,10 @@
 
     >>> from scipy.sparse import *
     >>> from scipy import *
-    >>> csr_matrix( (3,4), dtype='i' ).todense()
+    >>> csr_matrix( (3,4), dtype='int32' ).todense()
     matrix([[0, 0, 0, 0],
             [0, 0, 0, 0],
-            [0, 0, 0, 0]])
+            [0, 0, 0, 0]], dtype=int32)
 
     >>> row = array([0,0,1,2,2,2])
     >>> col = array([0,2,2,0,1,2])

Modified: trunk/scipy/sparse/dia.py
===================================================================
--- trunk/scipy/sparse/dia.py	2008-01-14 12:58:10 UTC (rev 3829)
+++ trunk/scipy/sparse/dia.py	2008-01-14 19:29:12 UTC (rev 3830)
@@ -32,13 +32,12 @@
     Examples
     ========
 
-
     >>> from scipy.sparse import *
     >>> from scipy import *
-    >>> dia_matrix( (3,4), dtype='i').todense()
+    >>> dia_matrix( (3,4), dtype='int32').todense()
     matrix([[0, 0, 0, 0],
             [0, 0, 0, 0],
-            [0, 0, 0, 0]])
+            [0, 0, 0, 0]], dtype=int32)
     
     >>> data = array([[1,2,3,4]]).repeat(3,axis=0)
     >>> diags = array([0,-1,2])

Modified: trunk/scipy/sparse/info.py
===================================================================
--- trunk/scipy/sparse/info.py	2008-01-14 12:58:10 UTC (rev 3829)
+++ trunk/scipy/sparse/info.py	2008-01-14 19:29:12 UTC (rev 3830)
@@ -41,22 +41,22 @@
     >>> A[1, 100:200] = A[0, :100]
     >>> A.setdiag(rand(1000))
 
-    Now convert it to CSR format and solve (A A^T) x = b for x:
+    Now convert it to CSR format and solve A x = b for x:
 
     >>> A = A.tocsr()
     >>> b = rand(1000)
-    >>> x = linsolve.spsolve(A * A.T, b)
+    >>> x = linsolve.spsolve(A, b)
 
     Convert it to a dense matrix and solve, and check that the result
     is the same:
 
-    >>> A_ = A.todense()
-    >>> x_ = linalg.solve(A_ * A_.T, b)
-    >>> err = linalg.norm(x-x_)
+    >>> x_ = linalg.solve(A.todense(), b)
 
-    Now we can print the error norm with:
+    Now we can compute norm of the error with:
 
-    >>> print "Norm error =", err
+    >>> err = linalg.norm(x-x_)
+    >>> err < 1e-10
+    True
 
     It should be small :)
 




More information about the Scipy-svn mailing list