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

Method build_list

python/tvm/relax/testing/ast_printer.py:98–114  ·  view source on GitHub ↗

Builds a list of the members given, appropriately indented, with each field on a line. (special case: if there is only one field, then we do not put it on a new line unless that field contains a newline or `force_newline` is set to true). `open_tok` and `clos

(
        self, members: Iterable[str], open_tok="[", close_tok="]", force_newline=False
    )

Source from the content-addressed store, hash-verified

96 return self.build_ast_node(nodename, force_newline=force_newline, **fields)
97
98 def build_list(
99 self, members: Iterable[str], open_tok="[", close_tok="]", force_newline=False
100 ) -> str:
101 """
102 Builds a list of the members given, appropriately indented,
103 with each field on a line.
104 (special case: if there is only one field, then we do not put it on a new line
105 unless that field contains a newline or `force_newline` is set to true).
106 `open_tok` and `close_tok` are used to open and close the list, respectively.
107 """
108 mem_list = list(members)
109 if not mem_list:
110 return f"{open_tok}{close_tok}"
111 if len(mem_list) == 1 and not force_newline and "\n" not in mem_list[0]:
112 return f"{open_tok}{mem_list[0]}{close_tok}"
113 member_lines = ",\n".join(map(self.indent, mem_list))
114 return f"{open_tok}\n{member_lines}\n{close_tok}"
115
116 def visit_constant_(self, op: relax.Constant) -> str:
117 # simple rule of thumb: keep scalars inline, but anything larger goes on a new one

Callers 10

build_ast_nodeMethod · 0.95
visit_tuple_Method · 0.95
visit_shape_expr_Method · 0.95
visit_function_Method · 0.95
visit_call_Method · 0.95
visit_seq_expr_Method · 0.95
visit_type_Method · 0.95
visit_struct_info_Method · 0.95
visit_binding_block_Method · 0.95
visit_dataflow_block_Method · 0.95

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected