def test_unscoped_cached_dec(): lru = LRU() inner_func = CountingCallable() func = cached(lru)(inner_func) other_inner_func = CountingCallable() other_func = cached(lru)(other_inner_func) assert inner_func.call_count == 0 func('a') assert inner_func.call_count == 1 func('a') other_func('a') assert other_inner_func.call_count == 0 return
def test_unscoped_cached_dec(): lru = LRU() inner_func = CountingCallable() func = cached(lru)(inner_func) other_inner_func = CountingCallable() other_func = cached(lru)(other_inner_func) assert inner_func.call_count == 0 func('a') assert inner_func.call_count == 1 func('a') other_func('a') assert other_inner_func.call_count == 0 return
def __init__(self, stimuli, fixations, max_fixations_in_cache=500*1000*1000): self.stimuli = stimuli self.fixations = fixations cache_size = int(max_fixations_in_cache / len(self.fixations.x)) self.cache = LRU(cache_size) self.nonfixations_for_image = cached(self.cache)(self._nonfixations_for_image) self.widths = np.asarray([s[1] for s in stimuli.sizes]).astype(float) self.heights = np.asarray([s[0] for s in stimuli.sizes]).astype(float)
def __init__(self, stimuli, fixations, max_fixations_in_cache=500*1000*1000): self.stimuli = stimuli self.fixations = fixations cache_size = int(max_fixations_in_cache / len(self.fixations.x)) self.cache = LRU(cache_size) self.nonfixations_for_image = cached(self.cache)(self._nonfixations_for_image) self.widths = np.asarray([s[1] for s in stimuli.sizes]).astype(float) self.heights = np.asarray([s[0] for s in stimuli.sizes]).astype(float)
def test_cached_dec(): lru = LRU() inner_func = CountingCallable() func = cached(lru)(inner_func) assert inner_func.call_count == 0 func() assert inner_func.call_count == 1 func() assert inner_func.call_count == 1 func('man door hand hook car door') assert inner_func.call_count == 2 return
def test_cached_dec(): lru = LRU() inner_func = CountingCallable() func = cached(lru)(inner_func) assert inner_func.call_count == 0 func() assert inner_func.call_count == 1 func() assert inner_func.call_count == 1 func('man door hand hook car door') assert inner_func.call_count == 2 return
def test_callable_cached_dec(): lru = LRU() get_lru = lambda: lru inner_func = CountingCallable() func = cached(get_lru)(inner_func) assert inner_func.call_count == 0 func() assert inner_func.call_count == 1 func() assert inner_func.call_count == 1 lru.clear() func() assert inner_func.call_count == 2 func() assert inner_func.call_count == 2 print(repr(func)) return
def test_callable_cached_dec(): lru = LRU() get_lru = lambda: lru inner_func = CountingCallable() func = cached(get_lru)(inner_func) assert inner_func.call_count == 0 func() assert inner_func.call_count == 1 func() assert inner_func.call_count == 1 lru.clear() func() assert inner_func.call_count == 2 func() assert inner_func.call_count == 2 print(repr(func)) return