Ignore:
Timestamp:
Oct 30, 2007, 5:13:17 PM (17 years ago)
Author:
ole
Message:

Retired all Python code which is superseded by C implementations.
This has made the code base much smaller and there is less confusion when people try to understand the algorithms.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/sparse.py

    r3832 r4769  
    320320
    321321
    322 
    323 def csr_mv(self, B):
    324     """Python version of sparse (CSR) matrix multiplication
    325     """
    326 
    327     from Numeric import zeros, Float
    328 
    329 
    330     #Assume numeric types from now on
    331        
    332     if len(B.shape) == 0:
    333         #Scalar - use __rmul__ method
    334         R = B*self
    335        
    336     elif len(B.shape) == 1:
    337         #Vector
    338         assert B.shape[0] == self.N, 'Mismatching dimensions'
    339        
    340         R = zeros(self.M, Float) #Result
    341        
    342         #Multiply nonzero elements
    343         for i in range(self.M):
    344             for ckey in range(self.row_ptr[i],self.row_ptr[i+1]):
    345                 j = self.colind[ckey]
    346                 R[i] += self.data[ckey]*B[j]           
    347                
    348     elif len(B.shape) == 2:
    349        
    350         R = zeros((self.M, B.shape[1]), Float) #Result matrix
    351        
    352         #Multiply nonzero elements
    353        
    354         for col in range(R.shape[1]):
    355             #For each column
    356             for i in range(self.M):
    357                 for ckey in range(self.row_ptr[i],self.row_ptr[i+1]):
    358                     j = self.colind[ckey]
    359                     R[i, col] += self.data[ckey]*B[j,col]           
    360                    
    361     else:
    362         raise ValueError, 'Dimension too high: d=%d' %len(B.shape)
    363    
    364     return R
    365 
    366 
    367 
    368 #Setup for C extensions
     322# Setup for C extensions
    369323from anuga.utilities import compile
    370324if compile.can_use_C_extension('sparse_ext.c'):
    371     #Replace python version with c implementation
     325    # Access underlying c implementations
    372326    from sparse_ext import csr_mv
    373327
     328
    374329if __name__ == '__main__':
    375 
     330    # A little selftest
     331   
    376332    from Numeric import allclose, array, Float
    377333   
Note: See TracChangeset for help on using the changeset viewer.