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

Function _check

tests/python/arith/test_arith_solve_linear_equations.py:37–63  ·  view source on GitHub ↗
(num_vars, num_formulas, coef=(-5, 5), bounds=(-20, 20))

Source from the content-addressed store, hash-verified

35 random.seed(seed)
36
37 def _check(num_vars, num_formulas, coef=(-5, 5), bounds=(-20, 20)):
38 variables = [tvm.tirx.Var("x" + str(i), "int32") for i in range(num_vars)]
39
40 relations = []
41 for i in range(num_formulas):
42 s1 = sum([v * random.randint(coef[0], coef[1]) for v in variables])
43 s1 += random.randint(coef[0], coef[1])
44 s2 = sum([v * random.randint(coef[0], coef[1]) for v in variables])
45 s2 += random.randint(coef[0], coef[1])
46 if random.random() < 0.7:
47 op = tvm.tirx.EQ
48 else:
49 # we also make sure it can correctly handle inequalities
50 op = random.choice([tvm.tirx.LE, tvm.tirx.LT, tvm.tirx.GE, tvm.tirx.GT])
51 relations.append(op(s1, s2))
52
53 vranges = {v: tvm.ir.expr.Range(bounds[0], bounds[1] + 1) for v in variables}
54 solution = arith.solve_linear_equations(relations, variables, vranges)
55
56 testing.check_int_constraints_trans_consistency(solution)
57
58 # leaving some variables as parameters should also be ok
59 for k in [1, 2]:
60 if len(variables) > k:
61 solution = arith.solve_linear_equations(relations, variables[:-k], vranges)
62 param_ranges = {v: vranges[v] for v in variables[-k:]}
63 testing.check_int_constraints_trans_consistency(solution, param_ranges)
64
65 for i in range(2):
66 _check(num_vars=1, num_formulas=1)

Callers 1

Calls 3

strFunction · 0.85
sumFunction · 0.50
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…