@memoize¶
-
memoize(hash_function=None, store=5, func_name=None, debug=0)¶ -
A decorator for memoization of functions. This allows to use a saved value when calling several time a function on the same argument.
Usage:
python@memoize() def func(x): return x+3 func(3) # Compute the function by calling func func(3) # Use the already computed value func(5) # Compute the function by calling func@memoize()can also be used with functions supporting multiple arguments.python@memoize() def func(x1,x2): return x1+x2- Parameters:
hash_function – a custom hash function for hashing function arguments. By default, the hash function is hashlib.sha256 applied to the either the string representation of the argument, or the bytes representation if the argument is a numpy array.
store (int) – Number of stored values in the hash table.
func_name (str) – the name of the function printed when debugging
debug (int) – an integer tuning the level of verbosity. When greater than 0, information about whether the original function or its memoization is displayed.