How to use the klepto.safe.inf_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
assert add(1,2,3.00012) == 6.0000999999999998
        assert add(1,2,3.0234)  == 6.0234000000000005
        assert add(1,2,3.023)   == 6.0234000000000005
        assert add.info().hit  == 2
        assert add.info().miss == 2
        assert add.info().load == 0

        def cost(x,y):
           #print ('new: %s or %s' % (str(x), str(y)))
            x = asarray(x)
            y = asarray(y)
            return sum(x**2 - y**2)

        cost1 = memoized(keymap=dumps, tol=1)(cost)
        cost0 = memoized(keymap=dumps, tol=0)(cost)
        costD = memoized(keymap=dumps, tol=0, deep=True)(cost)

       #print ("rounding to one decimals...")
        cost1([1,2,3.1234], 3.9876)# == -32.94723372
        cost1([1,2,3.1234], 3.9876)# == -32.94723372
        cost1([1,2,3.1234], 3.6789)# == -25.84728807
        cost1([1,2,3.4321], 3.6789)# == -23.82360522
        assert cost1.info().hit  == 1
        assert cost1.info().miss == 3
        assert cost1.info().load == 0

       #print ("\nrerun the above with rounding to zero decimals...")
        cost0([1,2,3.1234], 3.9876)# == -32.94723372
        cost0([1,2,3.1234], 3.9876)# == -32.94723372
        cost0([1,2,3.1234], 3.6789)# == -32.94723372
        cost0([1,2,3.4321], 3.6789)# == -23.82360522
        assert cost0.info().hit  == 2
github uqfoundation / klepto / tests / test_cache.py View on Github external
    @memoized(keymap=dumps, ignore='self')
    def eggs(self, *args, **kwds):
       #print ('new:', args, kwds)
        from random import random
        return int(100 * random())
github uqfoundation / klepto / tests / test_cache.py View on Github external
assert add(1,2,3.0001)  == 6.0000999999999998
        assert add(1,2,3.00012) == 6.0000999999999998
        assert add(1,2,3.0234)  == 6.0234000000000005
        assert add(1,2,3.023)   == 6.0234000000000005
        assert add.info().hit  == 2
        assert add.info().miss == 2
        assert add.info().load == 0

        def cost(x,y):
           #print ('new: %s or %s' % (str(x), str(y)))
            x = asarray(x)
            y = asarray(y)
            return sum(x**2 - y**2)

        cost1 = memoized(keymap=dumps, tol=1)(cost)
        cost0 = memoized(keymap=dumps, tol=0)(cost)
        costD = memoized(keymap=dumps, tol=0, deep=True)(cost)

       #print ("rounding to one decimals...")
        cost1([1,2,3.1234], 3.9876)# == -32.94723372
        cost1([1,2,3.1234], 3.9876)# == -32.94723372
        cost1([1,2,3.1234], 3.6789)# == -25.84728807
        cost1([1,2,3.4321], 3.6789)# == -23.82360522
        assert cost1.info().hit  == 1
        assert cost1.info().miss == 3
        assert cost1.info().load == 0

       #print ("\nrerun the above with rounding to zero decimals...")
        cost0([1,2,3.1234], 3.9876)# == -32.94723372
        cost0([1,2,3.1234], 3.9876)# == -32.94723372
        cost0([1,2,3.1234], 3.6789)# == -32.94723372
        cost0([1,2,3.4321], 3.6789)# == -23.82360522
github uqfoundation / klepto / tests / test_cache.py View on Github external
assert add(1,2,3.0001)  == 6.0000999999999998
        assert add(1,2,3.00012) == 6.0000999999999998
        assert add(1,2,3.0234)  == 6.0234000000000005
        assert add(1,2,3.023)   == 6.0234000000000005
        assert add.info().hit  == 2
        assert add.info().miss == 2
        assert add.info().load == 0

        def cost(x,y):
           #print ('new: %s or %s' % (str(x), str(y)))
            x = asarray(x)
            y = asarray(y)
            return sum(x**2 - y**2)

        cost1 = memoized(keymap=dumps, tol=1)(cost)
        cost0 = memoized(keymap=dumps, tol=0)(cost)
        costD = memoized(keymap=dumps, tol=0, deep=True)(cost)

       #print ("rounding to one decimals...")
        cost1([1,2,3.1234], 3.9876)# == -32.94723372
        cost1([1,2,3.1234], 3.9876)# == -32.94723372
        cost1([1,2,3.1234], 3.6789)# == -25.84728807
        cost1([1,2,3.4321], 3.6789)# == -23.82360522
        assert cost1.info().hit  == 1
        assert cost1.info().miss == 3
        assert cost1.info().load == 0

       #print ("\nrerun the above with rounding to zero decimals...")
        cost0([1,2,3.1234], 3.9876)# == -32.94723372
        cost0([1,2,3.1234], 3.9876)# == -32.94723372
        cost0([1,2,3.1234], 3.6789)# == -32.94723372
github uqfoundation / klepto / tests / test_cache.py View on Github external
        @memoized(keymap=dumps, tol=3)
        def add(*args):
           #print ('new:', args)
            return sum(args)
github uqfoundation / klepto / tests / test_cache.py View on Github external
    @memoized(keymap=dumps)
    def add(x,y):
        return x+y
    add(1,2)
github uqfoundation / klepto / klepto / safe.py View on Github external
def __new__(cls, *args, **kwds):
        maxsize = kwds.get('maxsize', -1)
        if maxsize == 0:
            return no_cache(*args, **kwds)
        if maxsize is None:
            return inf_cache(*args, **kwds)
        return object.__new__(cls)