refactor #1

Merged
augustin_s merged 159 commits from refactor into main 2024-10-12 17:09:10 +02:00
Showing only changes of commit 7b56e45cb6 - Show all commits

View File

@@ -5,8 +5,10 @@ import numpy as np
def npmemo(func):
"""
numpy array aware memoizer
numpy array aware memoizer with size limit
"""
maxsize = 10
order = []
cache = {}
@functools.wraps(func)
@@ -15,6 +17,10 @@ def npmemo(func):
try:
return cache[key]
except KeyError:
if len(cache) >= maxsize:
oldest = order.pop(0)
cache.pop(oldest)
order.append(key)
cache[key] = res = func(*args)
return res
@@ -71,6 +77,10 @@ if __name__ == "__main__":
a = np.array(a)
test(a, o)
for a, o in zip(arrays, offsets):
a = np.array(a)
test(a, o)
# print(expensive.cache)