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

scipy-svn@scip... scipy-svn@scip...
Thu Jan 31 21:13:32 CST 2008


Author: wnbell
Date: 2008-01-31 21:13:28 -0600 (Thu, 31 Jan 2008)
New Revision: 3885

Modified:
   trunk/scipy/sparse/bsr.py
   trunk/scipy/sparse/coo.py
   trunk/scipy/sparse/csc.py
   trunk/scipy/sparse/spfuncs.py
Log:
make CSR the default for ->BSR conversions


Modified: trunk/scipy/sparse/bsr.py
===================================================================
--- trunk/scipy/sparse/bsr.py	2008-02-01 03:06:35 UTC (rev 3884)
+++ trunk/scipy/sparse/bsr.py	2008-02-01 03:13:28 UTC (rev 3885)
@@ -395,7 +395,7 @@
     
     def tobsr(self,blocksize=None,copy=False):
         if blocksize not in [None, self.blocksize]:
-            return self.tocoo(copy=False).tobsr(blocksize=blocksize)
+            return self.tocsr().tobsr(blocksize=blocksize)
         if copy:
             return self.copy()
         else:

Modified: trunk/scipy/sparse/coo.py
===================================================================
--- trunk/scipy/sparse/coo.py	2008-02-01 03:06:35 UTC (rev 3884)
+++ trunk/scipy/sparse/coo.py	2008-02-01 03:13:28 UTC (rev 3885)
@@ -314,63 +314,7 @@
 
         return dok
 
-#    def tobsc(self,blocksize=None):
-#        if blocksize in [None, (1,1)]:
-#            return self.tocsc().tobsc(blocksize)
-#        else:
-#            return self.transpose().tobsr().transpose()
 
-    def tobsr(self,blocksize=None):
-        from bsr import bsr_matrix
-
-        if self.nnz == 0:
-            return bsr_matrix(self.shape,blocksize=blocksize,dtype=self.dtype)
-
-        if blocksize is None:
-            blocksize = estimate_blocksize(self)
-        elif blocksize in (1,1):
-            return self.tocsr().tobsr(blocksize)
-
-        M,N = self.shape
-        X,Y = blocksize
-    
-        if (M % X) != 0 or (N % Y) != 0:
-            raise ValueError, 'shape must be multiple of blocksize'
-    
-        i_block,i_sub = divmod(self.row, X)
-        j_block,j_sub = divmod(self.col, Y)
-    
-        perm = lexsort( keys=[j_block,i_block] )
-    
-        i_block = i_block[perm]
-        j_block = j_block[perm]
-    
-        mask = (i_block[1:] != i_block[:-1]) + (j_block[1:] != j_block[:-1])
-        mask = concatenate((array([True]),mask))
-    
-        #map self.data[n] -> data[map[n],i_sub[n],j_sub[n]]
-        map = cumsum(mask)
-        num_blocks = map[-1]
-        map -= 1
-        
-        iperm = empty_like(perm) #inverse permutation
-        iperm[perm] = arange(len(perm))
-        
-        data = zeros( (num_blocks,X,Y), dtype=self.dtype )
-        data[map[iperm],i_sub,j_sub] = self.data
-    
-        row = i_block[mask]
-        col = j_block[mask]
-    
-        # now row,col,data form BOO format 
-    
-        temp = cumsum(bincount(row))
-        indptr = zeros( M/X + 1, dtype=intc )
-        indptr[1:len(temp)+1] = temp
-        indptr[len(temp)+1:] = temp[-1]
-       
-        return bsr_matrix((data,col,indptr),shape=self.shape)
-
     # needed by _data_matrix
     def _with_data(self,data,copy=True):
         """Returns a matrix with the same sparsity structure as self,

Modified: trunk/scipy/sparse/csc.py
===================================================================
--- trunk/scipy/sparse/csc.py	2008-02-01 03:06:35 UTC (rev 3884)
+++ trunk/scipy/sparse/csc.py	2008-02-01 03:13:28 UTC (rev 3885)
@@ -131,16 +131,6 @@
         A.has_sorted_indices = True
         return A
 
-    def tobsr(self, blocksize=None):
-        if blocksize == (1,1):
-            from bsr import bsr_matrix
-            csr = self.tocsr()
-            arg1 = (csr.data.reshape(-1,1,1),csr.indices,csr.indptr)  
-            return bsr_matrix( arg1, shape=self.shape )
-        else:
-            #TODO make this more efficient
-            return self.tocoo(copy=False).tobsr(blocksize=blocksize)
-
     def get_submatrix( self, slice0, slice1 ):
         """Return a submatrix of this matrix (new matrix is created).
         Contigous range of rows and columns can be selected using:

Modified: trunk/scipy/sparse/spfuncs.py
===================================================================
--- trunk/scipy/sparse/spfuncs.py	2008-02-01 03:06:35 UTC (rev 3884)
+++ trunk/scipy/sparse/spfuncs.py	2008-02-01 03:13:28 UTC (rev 3885)
@@ -44,6 +44,9 @@
     if not (isspmatrix_csr(A) or isspmatrix_csc(A)):
         A = csr_matrix(A)
 
+    if A.nnz == 0:
+        return (1,1)
+
     if not 0 < efficiency < 1.0:
         raise ValueError,'efficiency must satisfy 0.0 < efficiency < 1.0'
 



More information about the Scipy-svn mailing list