Ignore:
Timestamp:
Nov 6, 2008, 4:22:22 PM (15 years ago)
Author:
rwilson
Message:

NumPy? conversion.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source_numpy_conversion/anuga/caching/caching.py

    r5860 r5909  
    5050else:
    5151  unix = 1
     52
     53import numpy
     54
    5255
    5356cache_dir = '.python_cache'
     
    13391342
    13401343  from types import TupleType, ListType, DictType, InstanceType 
    1341   from Numeric import ArrayType, average
    13421344
    13431345   
     
    13781380      I.sort()   
    13791381      val = myhash(I, ids)
    1380   elif type(T) == ArrayType:
     1382  elif isinstance(T, numpy.ndarray):
    13811383      # Use mean value for efficiency 
    1382       val = hash(average(T.flat))
     1384      val = hash(numpy.average(T.ravel()))
    13831385  elif type(T) == InstanceType:
    13841386      val = myhash(T.__dict__, ids)
     
    14041406
    14051407    from types import TupleType, ListType, DictType, InstanceType
    1406     from Numeric import ArrayType, alltrue   
    14071408   
    14081409    # Keep track of unique id's to protect against infinite recursion
     
    14471448            identical = compare(a, b, ids)
    14481449           
    1449     elif type(A) == ArrayType:
     1450    elif isinstance(A, numpy.ndarray):
    14501451        # Use element by element comparison
    1451         identical = alltrue(A==B)
     1452        identical = numpy.alltrue(A==B)
    14521453
    14531454    elif type(A) == InstanceType:
     
    23962397      argstr = argstr + "'"+str(args)+"'"
    23972398    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
    24042404#        can work with non-contiguous  arrays
    2405         if len(Numeric.ravel(args)) > textwidth:
     2405        if len(numpy.ravel(args)) > textwidth:
    24062406          args = 'Array: ' + str(args.shape)
    24072407
Note: See TracChangeset for help on using the changeset viewer.