Changeset 6158 for anuga_core/source/anuga/utilities/sparse.py
- Timestamp:
- Jan 14, 2009, 9:48:37 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/sparse.py
r5897 r6158 1 1 """Proof of concept sparse matrix code 2 2 """ 3 4 import Numeric as num 3 5 4 6 … … 17 19 18 20 if len(args) == 1: 19 from Numeric import array20 21 try: 21 A = array(args[0])22 A = num.array(args[0]) 22 23 except: 23 24 raise 'Input must be convertable to a Numeric array' … … 92 93 93 94 def todense(self): 94 from Numeric import zeros, Float 95 96 D = zeros( (self.M, self.N), Float) 95 D = num.zeros( (self.M, self.N), num.Float) 97 96 98 97 for i in range(self.M): … … 109 108 """ 110 109 111 from Numeric import array, zeros, Float112 113 110 try: 114 B = array(other)111 B = num.array(other) 115 112 except: 116 113 msg = 'FIXME: Only Numeric types implemented so far' … … 130 127 assert B.shape[0] == self.N, msg 131 128 132 R = zeros(self.M,Float) #Result129 R = num.zeros(self.M, num.Float) #Result 133 130 134 131 # Multiply nonzero elements … … 140 137 141 138 142 R = zeros((self.M, B.shape[1]),Float) #Result matrix139 R = num.zeros((self.M, B.shape[1]), num.Float) #Result matrix 143 140 144 141 # Multiply nonzero elements … … 162 159 """ 163 160 164 from Numeric import array, zeros, Float165 166 161 new = other.copy() 167 162 for key in self.Data.keys(): … … 177 172 """ 178 173 179 from Numeric import array, zeros, Float180 181 174 try: 182 175 other = float(other) … … 200 193 """ 201 194 202 from Numeric import array, zeros, Float203 204 195 try: 205 B = array(other)196 B = num.array(other) 206 197 except: 207 198 print 'FIXME: Only Numeric types implemented so far' … … 214 205 assert B.shape[0] == self.M, 'Mismatching dimensions' 215 206 216 R = zeros((self.N,),Float) #Result207 R = num.zeros((self.N,), num.Float) #Result 217 208 218 209 #Multiply nonzero elements … … 251 242 """ 252 243 253 from Numeric import array, Float, Int254 255 244 if isinstance(A,Sparse): 256 245 257 from Numeric import zeros258 246 keys = A.Data.keys() 259 247 keys.sort() 260 248 nnz = len(keys) 261 data = zeros ( (nnz,),Float)262 colind = zeros ( (nnz,),Int)263 row_ptr = zeros ( (A.M+1,),Int)249 data = num.zeros ( (nnz,), num.Float) 250 colind = num.zeros ( (nnz,), num.Int) 251 row_ptr = num.zeros ( (A.M+1,), num.Int) 264 252 current_row = -1 265 253 k = 0 … … 299 287 300 288 def todense(self): 301 from Numeric import zeros, Float 302 303 D = zeros( (self.M, self.N), Float) 289 D = num.zeros( (self.M, self.N), num.Float) 304 290 305 291 for i in range(self.M): … … 314 300 """ 315 301 316 from Numeric import array, zeros, Float317 318 302 try: 319 B = array(other)303 B = num.array(other) 320 304 except: 321 305 print 'FIXME: Only Numeric types implemented so far' … … 334 318 # A little selftest 335 319 336 from Numeric import allclose, array, Float337 338 320 A = Sparse(3,3) 339 321 … … 366 348 u = A*v 367 349 print u 368 assert allclose(u, [6,14,4])350 assert num.allclose(u, [6,14,4]) 369 351 370 352 u = A.trans_mult(v) 371 353 print u 372 assert allclose(u, [6,6,10])354 assert num.allclose(u, [6,6,10]) 373 355 374 356 #Right hand side column 375 v = array([[2,4],[3,4],[4,4]])357 v = num.array([[2,4],[3,4],[4,4]]) 376 358 377 359 u = A*v[:,0] 378 assert allclose(u, [6,14,4])360 assert num.allclose(u, [6,14,4]) 379 361 380 362 #u = A*v[:,1]
Note: See TracChangeset
for help on using the changeset viewer.