Skip to content

Commit

Permalink
Adds missing caching
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanKossaifi committed Nov 14, 2022
1 parent 993ae4f commit 8000f98
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tensorly/tenalg/einsum_tenalg/caching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
EINSUM_PATH_CACHE = dict()


def einsum_path_cached(fun):
def wrapped(key, *args, **kwargs):
name = fun.__name__
try:
cache = EINSUM_PATH_CACHE[name]
except KeyError:
EINSUM_PATH_CACHE[name] = dict()
cache = EINSUM_PATH_CACHE[name]
try:
equation = cache[key]
except KeyError:
equation = fun(*args, **kwargs)
cache[key] = equation

return equation

return wrapped

0 comments on commit 8000f98

Please sign in to comment.