How to use the klepto.lru_cache function in klepto

To help you get started, we’ve selected a few klepto examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uqfoundation / klepto / tests / test_cache.py View on Github external
    @lru_cache(maxsize=3, cache=None, purge=True)
    def bar(x):
        return -x
github uqfoundation / klepto / tests / test_workflow.py View on Github external
    @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)
github uqfoundation / klepto / tests / test_pickles.py View on Github external
@klepto.lru_cache()
def squared(x):
    return x**2
github uqfoundation / klepto / tests / test_workflow.py View on Github external
    @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__
github uqfoundation / klepto / tests / test_cache.py View on Github external
    @lru_cache(maxsize=3, cache=dict_archive('test'), purge=False)
    def inverse(x):
        return -x
github uqfoundation / mystic / mystic / search.py View on Github external
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: