Changeset 4338


Ignore:
Timestamp:
Mar 29, 2007, 4:36:47 PM (18 years ago)
Author:
ole
Message:

Brought back caching at the file_function level which was moved down in
changeset:4278

I used the command svn merge -r4278:4277 util.py

The problem was that the input arguments to cahing were so large that it took a long time to hash them. File_function is much faster now and I believe the original problem was fixed when None, True and False were treated explicitly in cahing.myhash (changeset:4198 and changeset:4270).

If a problem arises again, let us write a unit test and then deal with it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/util.py

    r4320 r4338  
    7070              'interpolation_points': interpolation_points,
    7171              'time_thinning': time_thinning,                   
    72               'verbose': verbose,
    73               'use_cache': use_cache
    74               }
    75 
    76     #caching moved to deeper within the function to avoid caching an
    77     #instance of an object, which isn't generally good.
    78     f = apply(_file_function,
     72              'verbose': verbose}
     73
     74
     75    # Call underlying engine with or without caching
     76    if use_cache is True:
     77        try:
     78            from caching import cache
     79        except:
     80            msg = 'Caching was requested, but caching module'+\
     81                  'could not be imported'
     82            raise msg
     83
     84        f = cache(_file_function,
     85                  args, kwargs,
     86                  dependencies=[filename],
     87                  compression=False,                 
     88                  verbose=verbose)
     89
     90    else:
     91        f = apply(_file_function,
    7992                  args, kwargs)
    8093
     
    92105                   quantities=None,
    93106                   interpolation_points=None,
    94                    time_thinning=1,
    95                    verbose=False,
    96                    use_cache=False):
     107                   time_thinning=1,                                               
     108                   verbose=False):
    97109    """Internal function
    98110   
     
    134146                                        interpolation_points,
    135147                                        time_thinning=time_thinning,
    136                                         verbose=verbose,
    137                                         use_cache=use_cache)
     148                                        verbose=verbose)
    138149    else:
    139150        raise 'Must be a NetCDF File'
     
    146157                             interpolation_points=None,
    147158                             time_thinning=1,                             
    148                              verbose=False,
    149                              use_cache=False):
     159                             verbose=False):
    150160    """Read time history of spatial data from NetCDF sww file and
    151161    return a callable object f(t,x,y)
     
    315325        vertex_coordinates = triangles = interpolation_points = None         
    316326
    317    
    318  
    319     args = (time, quantities, quantity_names, vertex_coordinates,
    320             triangles, interpolation_points, )
    321            
    322     kwargs = {'time_thinning': time_thinning,
    323               'verbose': verbose
    324               }
    325    
    326 #    print'CACHING FROM UTIL.py for interpolation_function', use_cache
    327 #    from anuga.caching import myhash
    328     if use_cache is True:
    329         from caching import cache
    330        
    331         interpolation_function = cache(Interpolation_function,
    332                                        args, kwargs,
    333                                        verbose=verbose,
    334                                        compression=False)
    335     else:
    336         interpolation_function = apply(Interpolation_function,
    337                                        args, kwargs)
    338 #    print 'myhash', myhash(interpolation_function)
    339     return interpolation_function
    340 
     327    return Interpolation_function(time,
     328                                  quantities,
     329                                  quantity_names,
     330                                  vertex_coordinates,
     331                                  triangles,
     332                                  interpolation_points,
     333                                  time_thinning=time_thinning,
     334                                  verbose=verbose)
    341335
    342336
Note: See TracChangeset for help on using the changeset viewer.