Skip to content

Commit 49b8cca

Browse files
Try eagerly evaluating primitives for speed
1 parent eb118bb commit 49b8cca

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

python/egglog/egraph.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,6 +1889,13 @@ def try_evaling(schedule: Schedule, expr: Expr, prim_expr: _EvalsTo[T]) -> T:
18891889
if it fails, display the egraph and raise an error.
18901890
"""
18911891
egraph = EGraph.current or EGraph()
1892+
with egraph.set_current():
1893+
try:
1894+
return prim_expr.eval()
1895+
except BaseException: # noqa: S110
1896+
pass
1897+
# If this primitive doesn't exist in the egraph, we need to try to create it by
1898+
# registering the expression and running the schedule
18921899
egraph.register(expr)
18931900
egraph.run(Schedule.current or schedule)
18941901
try:

0 commit comments

Comments
 (0)