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

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.

主站蜘蛛池模板: 建宁县| 施甸县| 日照市| 新宾| 阿拉善右旗| 保亭| 贺兰县| 泽普县| 雷山县| 老河口市| 兴文县| 石门县| 方正县| 镇雄县| 隆林| 天台县| 修武县| 宜宾市| 额敏县| 鸡西市| 神农架林区| 马边| 平乡县| 巴彦县| 大厂| 庆云县| 大同县| 错那县| 云阳县| 义乌市| 江城| 通州市| 三门县| 合水县| 景宁| 文山县| 富平县| 清镇市| 高安市| 五指山市| 高清|