- Python High Performance(Second Edition)
- Gabriele Lanaro
- 191字
- 2021-07-09 21:01:56
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 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.
- Learn Blockchain Programming with JavaScript
- C語言程序設(shè)計(jì)(第3版)
- 騰訊iOS測試實(shí)踐
- JavaScript語言精髓與編程實(shí)踐(第3版)
- Android Application Development Cookbook(Second Edition)
- PHP+MySQL網(wǎng)站開發(fā)技術(shù)項(xiàng)目式教程(第2版)
- INSTANT Sencha Touch
- PHP從入門到精通(第4版)(軟件開發(fā)視頻大講堂)
- C語言從入門到精通
- 智能手機(jī)故障檢測與維修從入門到精通
- Maker基地嘉年華:玩轉(zhuǎn)樂動(dòng)魔盒學(xué)Scratch
- Learning Grunt
- 基于GPU加速的計(jì)算機(jī)視覺編程:使用OpenCV和CUDA實(shí)時(shí)處理復(fù)雜圖像數(shù)據(jù)
- Learning Android Application Development
- TensorFlow+Keras深度學(xué)習(xí)算法原理與編程實(shí)戰(zhàn)