-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from skumblex/dev
Dev
- Loading branch information
Showing
25 changed files
with
618 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
/plots/*.pdf | ||
/plots/* | ||
|
||
tmp/* | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# functools | ||
from functools import wraps | ||
|
||
|
||
def cached_member(f_uncached): | ||
# Define the cache as a dictionary | ||
cache = {} | ||
cT = {"_": -1.} | ||
|
||
# Define the wrapper function | ||
@wraps(f_uncached) | ||
def f_cached(*args): | ||
T = args[-1] | ||
# Drop the first argument 'self' | ||
# ! only for member functions ! | ||
pargs = args[1:] | ||
|
||
# For each new temperature, | ||
# clear the cache and start over | ||
if T != cT["_"]: | ||
cT["_"] = T | ||
cache.clear() | ||
|
||
if pargs not in cache: | ||
cache[pargs] = f_uncached(*args) | ||
|
||
return cache[pargs] | ||
|
||
return f_cached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.