()
| 65 | |
| 66 | |
| 67 | def 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 | |
| 102 | def test_const_fold4(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…