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

Function test_expr_constructor

tests/python/tirx-base/test_tir_constructor.py:39–194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37
38
39def test_expr_constructor():
40 x = tvm.tirx.Var("xx", "float32")
41 assert isinstance(x, tvm.tirx.Var)
42 assert x.name == "xx"
43
44 x = tvm.tirx.Reduce(None, [1], [tvm.tirx.IterVar((0, 1), "x", 2)], None, 0)
45 assert isinstance(x, tvm.tirx.Reduce)
46 assert x.combiner is None
47 assert x.value_index == 0
48
49 x = tvm.tirx.FloatImm("float32", 1.0)
50 assert isinstance(x, tvm.tirx.FloatImm)
51 assert x.value == 1.0
52 assert x.dtype == "float32"
53
54 x = tvm.tirx.IntImm("int64", 2)
55 assert isinstance(x, tvm.tirx.IntImm)
56 assert x.value == 2
57 assert x.dtype == "int64"
58
59 x = tvm.tirx.StringImm("xyza")
60 assert isinstance(x, tvm.tirx.StringImm)
61 assert x.value == "xyza"
62
63 x = tvm.tirx.Cast("float32", tvm.tirx.IntImm("uint32", 1))
64 assert isinstance(x, tvm.tirx.Cast)
65 assert x.dtype == "float32"
66 assert x.value.value == 1
67
68 a = tvm.tirx.const(1.0, dtype="float32")
69 b = tvm.tirx.Var("x", "float32")
70
71 for cls in [
72 tvm.tirx.Add,
73 tvm.tirx.Sub,
74 tvm.tirx.Mul,
75 tvm.tirx.Div,
76 tvm.tirx.Mod,
77 tvm.tirx.Min,
78 tvm.tirx.Max,
79 tvm.tirx.LT,
80 tvm.tirx.LE,
81 tvm.tirx.GT,
82 tvm.tirx.GE,
83 ]:
84 x = cls(a, b)
85 assert isinstance(x, cls)
86 assert x.a == a
87 assert x.b.same_as(b)
88
89 a = tvm.runtime.convert(tvm.tirx.Var("x", "int32") > 1)
90 b = tvm.runtime.convert(tvm.tirx.Var("x", "int32") == 1)
91
92 for cls in [tvm.tirx.And, tvm.tirx.Or]:
93 x = cls(a, b)
94 assert isinstance(x, cls)
95 assert x.a == a
96 assert x.b.same_as(b)

Callers

nothing calls this directly

Calls 5

expr_deep_equalFunction · 0.90
ReplaceVarClass · 0.85
same_asMethod · 0.45
convertMethod · 0.45
scriptMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…