官术网_书友最值得收藏!

Joblib

A simple library that, among other things, provides a simple on-disk cache is joblib. The package can be used in a similar way as lru_cache, except that the results will be stored on disk and will persist between runs.

The joblib module can be installed from PyPI using the pip install joblib command.

The joblib module provides the Memory class that can be used to memoize functions using the Memory.cache decorator:

    from joblib import Memory
memory
= Memory(cachedir='/path/to/cachedir')

@memory.cache
def sum2(a, b):
return a + b

The function will behave similar to lru_cache, with the exception that the results will be stored on-disk in the directory specified by the cachedir argument during Memory initialization. Additionally, the cached results will persist over subsequent runs!

The Memory.cache method also allows to limit recomputation only when certain arguments change, and the resulting decorated function supports basic functionalities to clear and analyze the cache. 

Perhaps the best joblib feature is that, thanks to intelligent hashing algorithms, it provides efficient memoization of functions that operate on numpy arrays, and is particularly useful in scientific and engineering applications.

主站蜘蛛池模板: 昌图县| 德庆县| 砀山县| 沧州市| 康定县| 平遥县| 十堰市| 沐川县| 双流县| 达孜县| 朝阳区| 建昌县| 清徐县| 庄河市| 托克托县| 镇江市| 神池县| 栾城县| 轮台县| 沧州市| 盐津县| 德庆县| 抚远县| 镇原县| 台北市| 宁安市| 环江| 拉萨市| 当雄县| 托克托县| 汉中市| 曲阜市| 延边| 红河县| 新乡市| 囊谦县| 龙南县| 霍山县| 邵阳市| 灵台县| 磐石市|