cache_fn#
- ivy.cache_fn(func)[source]#
Cache function outputs.
A decorator to wrap a function, such that computed outputs are cached to avoid recalculating them later.
- Parameters:
func (
Callable
) – The function to wrap, whose output should be cached for later.- Return type:
Callable
- Returns:
ret – The newly cache wrapped function.
Examples
With positional arguments only:
>>> def my_sum(val1:float, val2:float)->float: return val1 + val2 >>> cached_sum = ivy.cache_fn(my_sum) >>> print(cached_sum(3, 5)) 8
With keyword arguments:
>>> def line_eq(x:float, /, *, slp:float=2, itc:float=0)->float: return x*slp+itc >>> cached_line_eq = ivy.cache_fn(line_eq) >>> print(cached_line_eq(3, itc=5, slp=2)) 11