MCPcopy Create free account
hub / github.com/apache/tvm / _eval_assign

Function _eval_assign

python/tvm/script/parser/core/evaluator.py:563–604  ·  view source on GitHub ↗

Expression assignment evaluation implementation for TVMScript parser. Parameters ---------- target : doc.expr The root node of AST tree node of assigned expression to evaluate. source : Any The source to be assigned with evaluated expression. Returns ------

(
    target: doc.expr,
    source: Any,
)

Source from the content-addressed store, hash-verified

561
562
563def _eval_assign(
564 target: doc.expr,
565 source: Any,
566) -> dict[str, Any]:
567 """Expression assignment evaluation implementation for TVMScript parser.
568
569 Parameters
570 ----------
571 target : doc.expr
572 The root node of AST tree node of assigned expression to evaluate.
573
574 source : Any
575 The source to be assigned with evaluated expression.
576
577 Returns
578 -------
579 res : Any
580 The evaluation result.
581 """
582 target = doc.from_doc(target)
583 assert isinstance(target, ast.expr)
584 RHS_VAR_NAME = "__tvm_rhs_var__" # pylint: disable=invalid-name
585 rhs_var_name = RHS_VAR_NAME
586 dict_locals = {rhs_var_name: source}
587 mod = ast.fix_missing_locations(
588 ast.Module(
589 body=[
590 ast.Assign(
591 targets=[target],
592 value=ast.Name(
593 id=rhs_var_name,
594 ctx=ast.Load(),
595 ),
596 )
597 ],
598 type_ignores=[],
599 )
600 )
601 exe = compile(mod, filename="<ast>", mode="exec")
602 exec(exe, {}, dict_locals) # pylint: disable=exec-used
603 del dict_locals[rhs_var_name]
604 return dict_locals

Callers 1

eval_assignFunction · 0.85

Calls 3

ModuleMethod · 0.80
NameMethod · 0.80
compileFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…