我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用joblib.Memory()。
def cached(*args, **kargs): import joblib as jb from .. import CACHE memo = getattr(cached, 'memo', None) if memo is None: cached.memo = memo = jb.Memory(CACHE, verbose=0) return memo.cache(*args, **kargs)
def setUp(self): self.tempdir = tempfile.TemporaryDirectory() self.memory = Memory(self.tempdir.name, verbose=0)
def __init__(self, data): self.classes_ = data.classes_ self.data_dir = data.data_dir self.unsup_docs = data.unsup_docs self.distant_docs = data.distant_docs self.distant_labels = LazyLabels(data.distant_labels) self.train_docs = data.train_docs self.train_labels = LazyLabels(data.train_labels) self.val_docs = data.val_docs self.val_labels = LazyLabels(data.val_labels) self.test_docs = data.test_docs self.memory = Memory(cachedir='cache', verbose=0)
def add_caching_to_funcs(obj, funcNames): mem = Memory('../.add_caching_to_funcs', verbose=11) if obj is None or funcNames is None: return if isScalar(funcNames): funcNames = [funcNames] for name in funcNames: func = getattr(obj, name, None) if func is not None: setattr(obj, name, mem.cache(func))