Changeset 587 for inundation/ga/storm_surge/pyvolution/sparse.py
- Timestamp:
- Nov 17, 2004, 11:40:28 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/sparse.py
r586 r587 302 302 print 'FIXME: Only Numeric types implemented so far' 303 303 304 305 ## R = csr_mv(self,B) 306 304 307 #Assume numeric types from now on 305 308 … … 337 340 338 341 return R 342 343 def csr_mv_python(self, B): 344 345 from Numeric import zeros, Float 339 346 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 366 import compile 367 if compile.can_use_C_extension('sparse_ext.c'): 368 #Replace python version with c implementations 369 from sparse_ext import csr_mv 370 340 371 341 372 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.