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

scipy-svn at scipy.org scipy-svn at scipy.org
Sat Dec 8 11:12:05 EST 2007


Author: wnbell
Date: 2007-12-08 10:11:42 -0600 (Sat, 08 Dec 2007)
New Revision: 3621

Modified:
   trunk/scipy/sparse/sparse.py
Log:
added lil_matrix.tolil()


Modified: trunk/scipy/sparse/sparse.py
===================================================================
--- trunk/scipy/sparse/sparse.py	2007-12-08 02:54:55 UTC (rev 3620)
+++ trunk/scipy/sparse/sparse.py	2007-12-08 16:11:42 UTC (rev 3621)
@@ -1316,6 +1316,10 @@
         row = searchsorted(self.indptr, ind+1)-1
         return (row, col)
 
+
+#    def tolil(self):
+#        pass
+
     def tocsr(self, copy=False):
         return self.toself(copy)
 
@@ -2513,13 +2517,18 @@
         # csr -> csc conversion
         return self.tocsr().transpose()
 
-    def tocsr(self, nzmax=None):
+    def tolil(self, copy=False):
+        if copy:
+            return self.copy()
+        else:
+            return self
+
+    def tocsr(self):
         """ Return Compressed Sparse Row format arrays for this matrix.
         """
         nnz = self.getnnz()
-        nzmax = max(nnz, nzmax)
-        data = zeros(nzmax, dtype=self.dtype)
-        colind = zeros(nzmax, dtype=intc)
+        data = zeros(nnz, dtype=self.dtype)
+        colind = zeros(nnz, dtype=intc)
         row_ptr = empty(self.shape[0]+1, dtype=intc)
         row_ptr[:] = nnz
         k = 0
@@ -2530,12 +2539,12 @@
             k += len(row)
 
         row_ptr[-1] = nnz           # last row number + 1
-        return csr_matrix((data, colind, row_ptr), dims=self.shape, nzmax=nzmax)
+        return csr_matrix((data, colind, row_ptr), dims=self.shape)
 
-    def tocsc(self, nzmax=None):
+    def tocsc(self):
         """ Return Compressed Sparse Column format arrays for this matrix.
         """
-        return self.tocsr(nzmax).tocsc()
+        return self.tocsr().tocsc()
 
 
 




More information about the Scipy-svn mailing list