Ignore:
Timestamp:
Nov 17, 2004, 11:40:28 PM (20 years ago)
Author:
steve
Message:

testing sparse

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/sparse.py

    r586 r587  
    302302            print 'FIXME: Only Numeric types implemented so far'
    303303
     304
     305##        R = csr_mv(self,B)
     306       
    304307        #Assume numeric types from now on
    305308       
     
    337340
    338341        return R
     342
     343def csr_mv_python(self, B):
     344
     345    from Numeric import zeros, Float
    339346   
     347    if len(B.shape) == 1:
     348        #Vector
     349        assert B.shape[0] == self.N, 'Mismatching dimensions'
     350
     351        R = zeros(self.M, Float) #Result
     352           
     353        #Multiply nonzero elements
     354        for i in range(self.M):
     355            for ckey in range(self.row_ptr[i],self.row_ptr[i+1]):
     356                j = self.colind[ckey]
     357                R[i] += self.data[ckey]*B[j]           
     358
     359        return R
     360    else:
     361        raise ValueError, 'Dimension too high: d=%d' %len(B.shape)
     362
     363    return R
     364
     365
     366import compile
     367if compile.can_use_C_extension('sparse_ext.c'):
     368    #Replace python version with c implementations     
     369    from sparse_ext import csr_mv
     370
    340371
    341372if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.