MCPcopy Index your code
hub / github.com/apache/tvm / test_if

Function test_if

tests/python/relax/test_analysis_well_formed.py:222–251  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

220
221
222def test_if():
223 # Error: Var defined in true/false branch is invisible in the outer scope
224 # except the return Var, i.e the var in the last stmt
225 # v_in_if is invisible in the outer scope
226 v_in_if = rx.Var("v_in_if", R.Tensor([m, n], "float32"))
227 # gv0 is visible in the outer scope
228 gv0 = rx.Var("gv0", R.Tensor([m, n], "float32"))
229 # build true branch
230 true_bindings = [
231 rx.VarBinding(v_in_if, rx.op.add(x, x)),
232 rx.VarBinding(gv0, rx.op.multiply(x, x)),
233 ]
234 true_blocks = [rx.BindingBlock(true_bindings)]
235 true_seq_expr = rx.SeqExpr(true_blocks, true_blocks[-1].bindings[-1].var)
236 # build false branch
237 false_bindings = [
238 rx.VarBinding(v_in_if, rx.op.multiply(x, x)),
239 rx.VarBinding(gv0, rx.op.add(x, x)),
240 ]
241 false_blocks = [rx.BindingBlock(false_bindings)]
242 false_seq_expr = rx.SeqExpr(false_blocks, false_blocks[-1].bindings[-1].var)
243 # build If node
244 if_node = rx.If(cond=cond, true_branch=true_seq_expr, false_branch=false_seq_expr)
245 gv1 = rx.Var("gv1", R.Tensor([m, n], "float32"))
246 # try to call v_in_if defined in the true/false branch
247 bindings = [rx.VarBinding(gv0, if_node), rx.VarBinding(gv1, v_in_if)]
248 blocks = [rx.BindingBlock(bindings)]
249 func = build_function(blocks)
250 mod = tvm.IRModule({rx.GlobalVar("foo"): func})
251 assert not rx.analysis.check_well_formed(mod, check_struct_info=True)
252
253
254def test_if_non_seq_body():

Callers

nothing calls this directly

Calls 4

build_functionFunction · 0.85
TensorMethod · 0.80
addMethod · 0.45
multiplyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…