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

Function is_defined_in_class

python/tvm/script/parser/core/utils.py:174–212  ·  view source on GitHub ↗

Check whether a object is defined in a class scope. Parameters ---------- frames : List[FrameType] The frame stack of the object, obtained by `inspect.stack()`. Returns ------- res : bool The result if the object is defined in a class scope.

(frames: list[FrameType], obj: Any)

Source from the content-addressed store, hash-verified

172
173
174def is_defined_in_class(frames: list[FrameType], obj: Any) -> bool:
175 """Check whether a object is defined in a class scope.
176
177 Parameters
178 ----------
179 frames : List[FrameType]
180 The frame stack of the object, obtained by `inspect.stack()`.
181
182 Returns
183 -------
184 res : bool
185 The result if the object is defined in a class scope.
186 """
187
188 def _is_tvmscript_class_annotator(line: str) -> bool:
189 """Checks if the line contains a TVMScript annotator for a class
190
191 These match either `@I.ir_module` or `@R.rewriter`, or their
192 imported names `@ir_module` or `@rewriter`.
193 """
194
195 return line.startswith("@") and ("ir_module" in line or "rewriter" in line)
196
197 if len(frames) > 2:
198 frame_info = frames[2]
199 code_context = frame_info.code_context
200 if code_context is None:
201 return False
202 line = code_context[0].strip()
203 if _is_tvmscript_class_annotator(line):
204 return True
205 if line.startswith("class"):
206 lineno = frame_info.lineno
207 if lineno >= 2:
208 source, _ = findsource(obj)
209 line = source[lineno - 2].strip()
210 if _is_tvmscript_class_annotator(line):
211 return True
212 return False

Callers

nothing calls this directly

Calls 2

findsourceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…