Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@lru_cache(maxsize=3, cache=None, purge=True)
def bar(x):
return -x
@memoize(keymap=hasher, ignore=('self','**'))
def _add(x, *args, **kwds):
debug = kwds.get('debug', False)
if debug:
print ('debug:', x, args, kwds)
return sum((x,)+args)
@klepto.lru_cache()
def squared(x):
return x**2
@memoize(keymap=hasher, ignore=('self','**'))
def __call__(self, x, *args, **kwds):
debug = kwds.get('debug', False)
if debug:
print ('debug:', x, args, kwds)
return sum((x,)+args)
add = __call__
@lru_cache(maxsize=3, cache=dict_archive('test'), purge=False)
def inverse(x):
return -x
def _memoize(self, solver, tol=1, all=False, size=None):
"""apply caching to ensemble solver instance"""
archive = self.archive if all else self.cache
from klepto import lru_cache as _cache #XXX: or lru_? or ?
from klepto.keymaps import keymap
km = keymap()
ca = _cache(maxsize=size, ignore=('**','out'),
tol=tol, cache=archive, keymap=km)
@ca
def memo(*args, **kwds):
return kwds['out']
l = -1 if self._inv else 1
if all: #FIXME: applied *after* _solve; should be *during* _solve
cache = memo.__cache__()
for _solver in solver._allSolvers:
if _solver._evalmon:
param = _solver._evalmon._x
cost = _solver._evalmon._y #FIXME: python2.5
cache.update((tuple(x),l*y) for (x,y) in zip(param,cost))
else:
for _solver in solver._allSolvers: