nnmt.utils._cache¶
-
nnmt.utils.
_cache
(network, func, params, result_keys, units=None)[source]¶ Save result of
func(**params)
into network dicts using result_keys.This function serves as a wrapper for functions that calculate quantities which are to be stored in the network’s result dicts. First it creates a hash using the function name, the passed parameters, and the result keys, and checks whether this hash is a key of the network’s
results_hash_dict
. If this is the case, the old result is returned.If not, the new result is calculated and stored in the
results_hash_dict
and theresults
dict. The unit of the returned result is stored in the network’sresult_units dict
. Then the new result is returned.Parameters: - networkNetwork object or child class instance.
The network whose dicts are used for storing the results.
- funcfunction
Function whose return value should be cached.
- paramsdict
Parameters passed on to func.
- result_keysstr or list of str
Specifies under which keys the result should be stored.
- unitsstr or list of str
Units of results. Default is None.
Returns: func(**params)