Changeset 5909
- Timestamp:
- Nov 6, 2008, 4:22:22 PM (15 years ago)
- Location:
- anuga_core/source_numpy_conversion/anuga/caching
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source_numpy_conversion/anuga/caching/caching.py
r5860 r5909 50 50 else: 51 51 unix = 1 52 53 import numpy 54 52 55 53 56 cache_dir = '.python_cache' … … 1339 1342 1340 1343 from types import TupleType, ListType, DictType, InstanceType 1341 from Numeric import ArrayType, average1342 1344 1343 1345 … … 1378 1380 I.sort() 1379 1381 val = myhash(I, ids) 1380 elif type(T) == ArrayType:1382 elif isinstance(T, numpy.ndarray): 1381 1383 # Use mean value for efficiency 1382 val = hash( average(T.flat))1384 val = hash(numpy.average(T.ravel())) 1383 1385 elif type(T) == InstanceType: 1384 1386 val = myhash(T.__dict__, ids) … … 1404 1406 1405 1407 from types import TupleType, ListType, DictType, InstanceType 1406 from Numeric import ArrayType, alltrue1407 1408 1408 1409 # Keep track of unique id's to protect against infinite recursion … … 1447 1448 identical = compare(a, b, ids) 1448 1449 1449 elif type(A) == ArrayType:1450 elif isinstance(A, numpy.ndarray): 1450 1451 # Use element by element comparison 1451 identical = alltrue(A==B)1452 identical = numpy.alltrue(A==B) 1452 1453 1453 1454 elif type(A) == InstanceType: … … 2396 2397 argstr = argstr + "'"+str(args)+"'" 2397 2398 else: 2398 # Truncate large Numeric arrays before using str() 2399 import Numeric 2400 if type(args) == Numeric.ArrayType: 2401 # if len(args.flat) > textwidth: 2402 # Changed by Duncan and Nick 21/2/07 .flat has problems with 2403 # non-contigous arrays and ravel is equal to .flat except it 2399 # Truncate large arrays before using str() 2400 if isinstance(args, numpy.ndarray): 2401 # if len(args.ravel()) > textwidth: 2402 # Changed by Duncan and Nick 21/2/07 .ravel() has problems with 2403 # non-contigous arrays and ravel is equal to .ravel() except it 2404 2404 # can work with non-contiguous arrays 2405 if len( Numeric.ravel(args)) > textwidth:2405 if len(numpy.ravel(args)) > textwidth: 2406 2406 args = 'Array: ' + str(args.shape) 2407 2407 -
anuga_core/source_numpy_conversion/anuga/caching/test_caching.py
r5860 r5909 1 2 1 import unittest 3 from Numeric import arange, array2 import numpy 4 3 5 4 from copy import deepcopy … … 128 127 129 128 # Make some test input arguments 130 A0 = arange(5)131 B0 = array([1.1, 2.2, 0.0, -5, -5])129 A0 = numpy.arange(5) 130 B0 = numpy.array([1.1, 2.2, 0.0, -5, -5]) 132 131 133 132 A1 = A0.copy() … … 159 158 160 159 161 assert T1 == T2, 'Cached result does not match computed result'162 assert T2 == T3, 'Cached result does not match computed result'160 assert numpy.alltrue(T1 == T2), 'Cached result does not match computed result' 161 assert numpy.alltrue(T2 == T3), 'Cached result does not match computed result' 163 162 164 163 … … 172 171 173 172 # Make test input arguments 174 A0 = arange(5)*1.0173 A0 = numpy.arange(5)*1.0 175 174 B = ('x', 15) 176 175 177 176 # Create different A that hashes to the same address (having the same average) 178 A1 = array([2.0, 2.0, 2.0, 2.0, 2.0])177 A1 = numpy.array([2.0, 2.0, 2.0, 2.0, 2.0]) 179 178 180 179 assert myhash(A0) == myhash(A1) … … 203 202 204 203 205 #print T1206 #print T2207 assert T2 != T1204 print 'T1=%s' % str(T1) 205 print 'T2=%s' % str(T2) 206 assert numpy.alltrue(T2 != T1) 208 207 209 208 … … 389 388 A = Dummy(5, 7) 390 389 B = {'x': 10, 'A': A} 391 C = [B, array([1.2, 3, 5, 0.1])]390 C = [B, numpy.array([1.2, 3, 5, 0.1])] 392 391 A.value = C # Make it circular 393 392 … … 395 394 AA = Dummy(None, None) 396 395 BB = {'A': AA, 'x': 10} 397 CC = [BB, array([1.200, 3.000, 5.00, 1.0/10])]396 CC = [BB, numpy.array([1.200, 3.000, 5.00, 1.0/10])] 398 397 AA.value = CC # Make it circular 399 398 AA.another = 3+4
Note: See TracChangeset
for help on using the changeset viewer.