Test expression mutator that replaces variables
()
| 226 | |
| 227 | |
| 228 | def test_variable_replacer(): |
| 229 | """Test expression mutator that replaces variables""" |
| 230 | x = Var("x", dtype="int32") |
| 231 | y = Var("y", dtype="int32") |
| 232 | expr = Add(x, Mul(y, IntImm("int32", 3))) |
| 233 | |
| 234 | replacer = VariableReplacer({"x": 10, "y": 5}) |
| 235 | result = replacer.visit_expr(expr) |
| 236 | |
| 237 | # Should be Add(IntImm(10), Mul(IntImm(5), IntImm(3))) |
| 238 | assert isinstance(result, Add) |
| 239 | assert isinstance(result.a, IntImm) |
| 240 | assert result.a.value == 10 |
| 241 | assert isinstance(result.b, Mul) |
| 242 | assert isinstance(result.b.a, IntImm) |
| 243 | assert result.b.a.value == 5 |
| 244 | |
| 245 | |
| 246 | def test_add_to_sub_mutator(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…