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

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.

主站蜘蛛池模板: 萨迦县| 二手房| 宜州市| 赣州市| 山阴县| 太谷县| 福泉市| 永兴县| 宁明县| 丹阳市| 海安县| 阜新市| 临安市| 武平县| 朔州市| 汉源县| 舒城县| 宽甸| 万源市| 丹凤县| 崇仁县| 井陉县| 连州市| 瑞安市| 江口县| 淮滨县| 乌鲁木齐市| 龙里县| 博客| 大庆市| 禹州市| 琼结县| 余江县| 剑川县| 望谟县| 涡阳县| 湖州市| 襄城县| 石城县| 平顶山市| 临武县|