Recurse down struct info and print their ASTs too
(self, struct_info_node: relax.StructInfo)
| 266 | raise ValueError(f"Invalid Relax Type {type_node} ({type(type_node)})") |
| 267 | |
| 268 | def visit_struct_info_(self, struct_info_node: relax.StructInfo) -> str: |
| 269 | """ |
| 270 | Recurse down struct info and print their ASTs too |
| 271 | """ |
| 272 | if isinstance(struct_info_node, relax.ShapeStructInfo): |
| 273 | fields = {} |
| 274 | fields["ndim"] = str(struct_info_node.ndim) |
| 275 | if struct_info_node.values is not None: |
| 276 | fields["values"] = self.build_list( |
| 277 | map(self.visit_prim_expr_, struct_info_node.values) |
| 278 | ) |
| 279 | return self.build_ast_node("ShapeStructInfo", **fields) |
| 280 | elif isinstance(struct_info_node, relax.ObjectStructInfo): |
| 281 | return self.build_ast_node("ObjectStructInfo") |
| 282 | elif isinstance(struct_info_node, relax.PrimStructInfo): |
| 283 | return self.build_ast_node("PrimStructInfo", dtype=struct_info_node.dtype) |
| 284 | elif isinstance(struct_info_node, relax.TensorStructInfo): |
| 285 | fields = {} |
| 286 | fields["dtype"] = struct_info_node.dtype |
| 287 | if struct_info_node.shape: |
| 288 | fields["shape"] = self.visit_expr(struct_info_node.shape) |
| 289 | else: |
| 290 | fields["ndim"] = str(struct_info_node.ndim) |
| 291 | return self.build_ast_node("TensorStructInfo", **fields) |
| 292 | elif isinstance(struct_info_node, relax.TupleStructInfo): |
| 293 | return self.build_ast_node( |
| 294 | "TupleStructInfo", |
| 295 | fields=self.build_list(map(self.visit_struct_info_, struct_info_node.fields)), |
| 296 | ) |
| 297 | elif isinstance(struct_info_node, relax.FuncStructInfo): |
| 298 | fields = {} |
| 299 | if struct_info_node.params is not None: |
| 300 | fields["params"] = self.build_list( |
| 301 | map(self.visit_struct_info_, struct_info_node.params) |
| 302 | ) |
| 303 | fields["ret"] = self.visit_struct_info_(struct_info_node.ret) |
| 304 | fields["purity"] = bool(struct_info_node.purity) |
| 305 | return self.build_ast_node("FuncStructInfo", **fields) |
| 306 | else: |
| 307 | raise ValueError( |
| 308 | f"Invalid Relax StructInfo {struct_info_node} ({type(struct_info_node)})" |
| 309 | ) |
| 310 | |
| 311 | def visit_binding_block_(self, block: relax.BindingBlock) -> str: |
| 312 | """ |