Emulate make/cmake/SCons functionality within python code through function decorators. pyRecall can save computation time after kernel restarts or when functions are called repetitively.
import numpy as np
from pyRecall import recall
mat = np.random.rand(2000, 2000)
@recall(timer=True)
def slow_func(mat):
"""Compute determinant"""
return np.linalg.det(mat)
#Initial call
slow_func(mat)
>>> Execution time: 130.9 ms
#Repetitive call reverts to return of initial call
slow_func(mat)
>>> Execution time: 0.2 ms
pyRecall uses adaptive pickling/unpickling of function returns and hashing, and is thereby not limited to the most recent function call (similar to functools.lru_cache).
mat1 = np.random.rand(2000, 2000)
mat2 = np.random.rand(2000, 2000)
slow_func(mat1)
>>> Execution time: 108.1 ms
slow_func(mat2)
>>> Execution time: 104.1 ms
slow_func(mat1)
>>> Execution time: 0.1 ms
Since the hashing is also taking the function code into account, pyRecall is compliant with code changes.
Clearing pyRecall's history works as follows
from pyRecall import purgeRecalls
purgeRecalls()
##Installation In case, Python3 is standard
git clone https://github.com/peberg/pyRecall
python setup.py install
otherwise
python3 setup.py install