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

Function test_struct_info

tests/python/relax/test_ast_printer.py:283–346  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

281
282
283def test_struct_info():
284 printer = ASTPrinter()
285
286 assert printer.visit_struct_info_(rx.ObjectStructInfo()) == "ObjectStructInfo()"
287
288 assert printer.visit_struct_info_(rx.PrimStructInfo("int32")) == "PrimStructInfo(dtype=int32)"
289
290 # empty shape
291 empty_ssi = rx.ShapeStructInfo()
292 assert printer.visit_struct_info_(empty_ssi) == "ShapeStructInfo(ndim=-1)"
293
294 # include some dimensions
295 shape_info = rx.ShapeStructInfo([tirx.IntImm("int64", 1), tirx.IntImm("int64", 2)])
296 assert strip_whitespace(printer.visit_struct_info_(shape_info)) == strip_whitespace(
297 """
298 ShapeStructInfo(
299 ndim=2,
300 values=[
301 PrimExpr(value=`T.int64(1)`),
302 PrimExpr(value=`T.int64(2)`)
303 ]
304 )
305 """
306 )
307
308 # tensor struct info
309 default_tsi = rx.TensorStructInfo()
310 assert (
311 strip_whitespace(printer.visit_struct_info_(default_tsi))
312 == "TensorStructInfo(dtype=float32,ndim=-1)"
313 )
314
315 # use a var as the shape
316 x = rx.Var("x", struct_info=rx.ShapeStructInfo(values=[]))
317 var_tsi = rx.TensorStructInfo(shape=x, dtype="int32")
318 assert strip_whitespace(printer.visit_struct_info_(var_tsi)) == strip_whitespace(
319 """
320 TensorStructInfo(
321 dtype=int32,
322 shape=Var(
323 name_hint="x",
324 struct_info=ShapeStructInfo(ndim=0, values=[])
325 )
326 )
327 """
328 )
329
330 empty_tuple = rx.TupleStructInfo([])
331 assert printer.visit_struct_info_(empty_tuple) == "TupleStructInfo(fields=[])"
332
333 tuple_of_shape = rx.TupleStructInfo([empty_ssi])
334 assert strip_whitespace(printer.visit_struct_info_(tuple_of_shape)) == strip_whitespace(
335 """
336 TupleStructInfo(fields=[
337 ShapeStructInfo(ndim=-1)
338 ])
339 """
340 )

Callers

nothing calls this directly

Calls 3

visit_struct_info_Method · 0.95
ASTPrinterClass · 0.90
strip_whitespaceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…