MCPcopy Index your code
hub / github.com/apache/tvm / add

Method add

python/tvm/script/parser/core/parser.py:249–274  ·  view source on GitHub ↗

Add a new variable to variable table. Parameters ---------- var : str The name of variable. value : Any The value of variable. allow_shadowing : bool The options of whether variable shadowing allowed for this variable.

(self, var: str, value: Any, allow_shadowing: bool = False)

Source from the content-addressed store, hash-verified

247 return _deferred(pop_frame)
248
249 def add(self, var: str, value: Any, allow_shadowing: bool = False):
250 """Add a new variable to variable table.
251
252 Parameters
253 ----------
254 var : str
255 The name of variable.
256
257 value : Any
258 The value of variable.
259
260 allow_shadowing : bool
261 The options of whether variable shadowing allowed for this variable.
262 """
263 # Skip if the key and value are equal to those in the var_table
264 if self.name2value[var] and isinstance(self.name2value[var][-1], type(value)):
265 if isinstance(value, np.ndarray) and (self.name2value[var][-1] == value).all():
266 return
267 elif self.name2value[var][-1] == value:
268 return
269 if allow_shadowing and var in self.frames[-1].vars:
270 # Shadowing
271 self.name2value[var][-1] = value
272 else:
273 self.frames[-1].add(var)
274 self.name2value[var].append(value)
275
276 def get(self) -> dict[str, Any]:
277 """Get a variable dictionary of latest variables.

Callers 14

_visit_class_defFunction · 0.45
__call__Method · 0.45
addMethod · 0.45
parseMethod · 0.45
eval_assignMethod · 0.45
_visit_exprMethod · 0.45
_collect_tir_varFunction · 0.45
next_posMethod · 0.45
auto_inline_intoFunction · 0.45
mainFunction · 0.45
__init__Method · 0.45

Calls 1

appendMethod · 0.45

Tested by

no test coverage detected