MCPcopy Create free account
hub / github.com/pytorch/executorch / eval_expr

Function eval_expr

exir/sym_util.py:17–35  ·  view source on GitHub ↗

Evaluate a symint to int. Returns None if symint's symoblic expr can not be evaluated to valid integer according to the hints.

(symint: Union[int, torch.SymInt])

Source from the content-addressed store, hash-verified

15
16
17def eval_expr(symint: Union[int, torch.SymInt]) -> Optional[int]:
18 """
19 Evaluate a symint to int. Returns None if symint's symoblic expr
20 can not be evaluated to valid integer according to the hints.
21 """
22 if isinstance(symint, int):
23 return symint
24 node = symint.node
25 shape_env = node.shape_env
26 expr = node.expr
27 try:
28 if hasattr(shape_env, "guarding_hint_or_throw"):
29 output = shape_env.guarding_hint_or_throw(expr)
30 else:
31 # size_hint is deprecated, delete this code path.
32 output = shape_env.size_hint(expr)
33 except torch.fx.experimental.symbolic_shapes.GuardOnDataDependentSymNode:
34 return None
35 return int(output)
36
37
38def eval_upper_bound(maybe_symint: Union[int, torch.SymInt]) -> int:

Callers 6

nonzeroFunction · 0.90
index_TensorFunction · 0.90
eval_symint_to_ubvalMethod · 0.90
define_nodeMethod · 0.90
define_nodeMethod · 0.90
eval_shapeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected