Changeset 596 for branches


Ignore:
Timestamp:
11/20/12 12:42:04 (3 years ago)
Author:
mmckerns
Message:

update caching to explicitly use deep_round

Location:
branches/UQ/math/legacy/envelope
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/UQ/math/legacy/envelope/Looper_BoLiSurr_Cy.py

    r592 r596  
    119119 
    120120  # generate primary constraints function 
    121 # @memoized(tol=3) 
     121# @memoized(tol=3, deep=True) 
    122122  def constraints(rv): 
    123123    rrv = range(len(rv)) 
  • branches/UQ/math/legacy/envelope/memoize.py

    r592 r596  
    5050 
    5151 
     52def simple_round_factory(tol): 
     53  def simple_round(*args, **kwds): 
     54    argstype = type(args)  
     55    _args = list(args) 
     56    _kwds = kwds.copy() 
     57    for i,j in enumerate(args): 
     58      if isinstance(j, float): _args[i] = round(j, tol) # don't round int 
     59    for i,j in kwds.items(): 
     60      if isinstance(j, float): _kwds[i] = round(j, tol) 
     61    return argstype(_args), _kwds 
     62  return simple_round 
     63 
     64def simple_round(tol=0): #NOTE: only rounds floats, nothing else 
     65  def dec(f): 
     66    def func(*args, **kwds): 
     67      _simple_round = simple_round_factory(tol) 
     68      _args,_kwds = _simple_round(*args, **kwds) 
     69      return f(*_args, **_kwds) 
     70    return func 
     71  return dec 
     72 
     73 
    5274def get_archive(archive): 
    5375    import dill as pickle 
     
    101123#FIXME: resolve signature difference...  @memoized versus @memoized() 
    102124 
    103 def memoized0_nopickle_round(tol=0): 
     125def memoized0_nopickle_round(tol=0, deep=False): 
    104126    """Decorator that memoizes a function's return value each time it is called. 
    105127    If called later with the same arguments, the memoized value is returned, and 
     
    111133    memo = {} 
    112134 
    113     @deep_round(tol) 
     135    if deep: rounded = deep_round 
     136    else: rounded = simple_round 
     137 
     138    @rounded(tol) 
    114139    def rounded_args(*args, **kwds): 
    115140        return (args, kwds) 
     
    130155 
    131156 
    132 def memoized0_round(tol=0): 
     157def memoized0_round(tol=0, deep=False): 
    133158    """Decorator that memoizes a function's return value each time it is called. 
    134159    If called later with the same arguments, the memoized value is returned, and 
     
    139164    memo = {} 
    140165 
    141     @deep_round(tol) 
     166    if deep: rounded = deep_round 
     167    else: rounded = simple_round 
     168 
     169    @rounded(tol) 
    142170    def rounded_args(*args, **kwds): 
    143171        return (args, kwds) 
  • branches/UQ/math/legacy/envelope/otm_hvi.py

    r592 r596  
    3333from memoize import memoized0_nopickle_round as memoized 
    3434 
    35 @memoized(tol=3) 
     35@memoized(tol=3, deep=True) 
    3636def eureka(x, root_path="."): 
    3737    """ Notes for now, will be fixed in the future!!! 
  • branches/UQ/math/legacy/envelope/otm_hvi_new.py

    r592 r596  
    3333from memoize import memoized0_nopickle_round as memoized 
    3434 
    35 @memoized(tol=3) 
     35@memoized(tol=3, deep=True) 
    3636def eureka(x, root_path="."): 
    3737    """ Notes for now, will be fixed in the future!!! 
  • branches/UQ/math/legacy/envelope/sausage.py

    r592 r596  
    103103from memoize import memoized0_nopickle_round as memoized 
    104104# vectorize 'sausage_bounds' to find min/max for every evaluation point 
    105 @memoized(tol=3) 
     105@memoized(tol=3, deep=True) 
    106106def model_sausage(x): 
    107107  "find the boundary of the sausage in Y for the given x" 
Note: See TracChangeset for help on using the changeset viewer.