-
-
Save pervognsen/8dafe21038f3b513693e to your computer and use it in GitHub Desktop.
dataflow.py
This file contains hidden or 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
inf = float("+inf") | |
def fix(bottom, n=inf, unwrap=lambda x: x): | |
if not callable(bottom): | |
bottom_value = bottom | |
bottom = lambda *args: bottom_value | |
def decorator(f): | |
def f_fix(*args): | |
me = (f_fix, args) | |
if not fix.calling: | |
value, fix.values[me] = None, bottom(*args) | |
i = 0 | |
while i < n and value != fix.values[me]: | |
fix.calling.add(me) | |
value, fix.values[me] = fix.values[me], unwrap(f(*args)) | |
fix.calling.clear() | |
i += 1 | |
return value | |
if me in fix.calling: | |
return fix.values.get(me, bottom(*args)) | |
fix.calling.add(me) | |
value = fix.values[me] = unwrap(f(*args)) | |
fix.calling.remove(me) | |
return value | |
return f_fix | |
return decorator | |
fix.calling = set() | |
fix.values = {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment