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

Method get_at_depth

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

Get variables visible at the given frame depth, using current values. For each variable name that appears in frames 0..depth-1, count how many times it was pushed (to handle shadowing), then index into name2value at count-1 to retrieve the latest value visible at that depth.

(self, depth: int)

Source from the content-addressed store, hash-verified

284 return {key: values[-1] for key, values in self.name2value.items() if values}
285
286 def get_at_depth(self, depth: int) -> dict[str, Any]:
287 """Get variables visible at the given frame depth, using current values.
288
289 For each variable name that appears in frames 0..depth-1, count how many
290 times it was pushed (to handle shadowing), then index into name2value at
291 count-1 to retrieve the latest value visible at that depth.
292
293 Parameters
294 ----------
295 depth : int
296 The frame depth (number of frames visible).
297
298 Returns
299 -------
300 res : dict[str, Any]
301 Variable dictionary of values visible at the given depth.
302 """
303 result: dict[str, Any] = {}
304 name_count: dict[str, int] = defaultdict(int)
305 for frame_idx in range(min(depth, len(self.frames))):
306 for name in self.frames[frame_idx].vars:
307 name_count[name] += 1
308 for name, count in name_count.items():
309 if self.name2value[name]:
310 result[name] = self.name2value[name][count - 1]
311 return result
312
313 def exist(self, value: Any) -> bool:
314 """Check if any value exists in variable table.

Callers 1

__call__Method · 0.80

Calls 2

minFunction · 0.50
itemsMethod · 0.45

Tested by

no test coverage detected