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

Function test_const_fold3

tests/python/tirx-base/test_tir_ops.py:67–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65
66
67def test_const_fold3():
68 # Test that using ints with logic operations is forbidden
69 x = tvm.tirx.Var("x", "int32")
70 for val in [0, 1]:
71 for func in [tvm.tirx.all, tvm.tirx.any]:
72 check_throws(lambda: func(tvm.tirx.const(val, "bool"), x))
73 check_throws(lambda: func(x, tvm.tirx.const(val, "bool")))
74
75 # Test const folding when both arguments are const
76 for tvm_func, py_func in [
77 (tvm.tirx.all, lambda a, b: a and b),
78 (tvm.tirx.any, lambda a, b: a or b),
79 ]:
80 for v1 in [0, 1]:
81 for v2 in [0, 1]:
82 tvm.ir.assert_structural_equal(
83 tvm_func(tvm.tirx.const(v1, "bool"), tvm.tirx.const(v2, "bool")),
84 tvm.tirx.const(py_func(v1, v2), "bool"),
85 )
86
87 x = tvm.tirx.Var("x", "bool")
88 true = tvm.tirx.const(1, "bool")
89 false = tvm.tirx.const(0, "bool")
90
91 assert tvm.tirx.all(x, true).same_as(x)
92 assert tvm.tirx.all(true, x).same_as(x)
93 assert tvm.tirx.any(x, false).same_as(x)
94 assert tvm.tirx.any(false, x).same_as(x)
95
96 assert tvm.tirx.all(x, false).same_as(false)
97 assert tvm.tirx.all(false, x).same_as(false)
98 assert tvm.tirx.any(x, true).same_as(true)
99 assert tvm.tirx.any(true, x).same_as(true)
100
101
102def test_const_fold4():

Callers

nothing calls this directly

Calls 3

check_throwsFunction · 0.85
funcFunction · 0.70
same_asMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…