MCPcopy
hub / github.com/tinygrad/tinygrad / deconstruct_function

Function deconstruct_function

tinygrad/uop/ops.py:1268–1275  ·  view source on GitHub ↗
(fxn:Callable)

Source from the content-addressed store, hash-verified

1266 return res
1267
1268def deconstruct_function(fxn:Callable) -> tuple:
1269 new_globals = {k:v for k,v in fxn.__globals__.items() if k in fxn.__code__.co_names}
1270 for co in fxn.__code__.co_consts:
1271 if isinstance(co, types.CodeType): new_globals.update({k:v for k,v in fxn.__globals__.items() if k in co.co_names})
1272 # NOTE: optional round trip through pickle!
1273 assert fxn.__closure__ is None, "closures are not supported in pattern matchers"
1274 ret = fxn.__code__, new_globals, fxn.__name__, fxn.__defaults__
1275 return pickle.loads(pickle.dumps(ret)) if getenv("TEST_PICKLE") else ret
1276
1277@functools.cache
1278def upat_interpret(p:UPat, fxn:Callable) -> Callable:

Callers 3

upat_compileFunction · 0.90
upat_interpretFunction · 0.85
__reduce__Method · 0.85

Calls 2

getenvFunction · 0.90
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…