Example #1
0
def test_interpolation_chain_simplification(chain_length):
    t = Value(0)
    exp = Interpolation(1, 0, t)
    for i in range(chain_length):
        exp = Interpolation(exp, i + 1, t)
    print(id(exp))
    with reduce_to_const(exp):
        t.fix()
Example #2
0
def test_interpolation_const_to_const_simplification(check_dump, range_4):
    val1 = Value(1, 2, 3) if range_4 % 1 else Constant(1, 2, 3)
    val2 = Value(1, 2, 3) if range_4 % 2 else Constant(1, 2, 3)
    exp = Interpolation(val1, val2, Value(0.5))
    with reduce_to_const(exp):
        if range_4 % 1:
            val1.fix()
        if range_4 % 2:
            val2.fix()
Example #3
0
def test_value_fix_1():
    exp = Value(6)
    exp.fix()
    assert exp == 6
    with pytest.raises(ValueError):
        exp.set(4)
    assert exp == 6
    assert simplify(exp) == 6
    assert isinstance(simplify(exp), Constant)
Example #4
0
def test_box():
    name = 'Boxed variable'
    val = Value(0, 0, 0)
    exp = Box(name, val)
    assert all(exp == (0, 0, 0))
    assert exp.pretty_name == name
    val.fix(3, 3, 3)
    assert all(exp == (3, 3, 3))
    exp.value = Value(6, 6, 6)
    assert all(exp == (6, 6, 6))
Example #5
0
def test_complex_concat_simplification(check_dump):
    val1 = Value(1)
    val2 = Value(4, 5)
    cat = Concat(val1, 2, 3, val2)
    assert all(cat == (1, 2, 3, 4, 5))
    check_dump(cat, """
        Concat <1.0, 2.0, 3.0, 4.0, 5.0>:
          Value <1.0>
          Constant <2.0, 3.0>
          Value <4.0, 5.0>
    """)
    val1.fix()
    val2.fix()
    check_dump(simplify(cat), 'Constant <1.0, 2.0, 3.0, 4.0, 5.0>')
Example #6
0
def test_reduce_simplification(cls):
    v1 = Value(1)
    v2 = Value(2)
    v3 = Value(3)
    with reduce_to_const(cls([v1, v2, v3])) as exp:
        v1.fix()
        v2.fix()
        assert len(exp.children) == 2
        v3.fix()
Example #7
0
def test_concat_simplification():
    v1 = Value(1)
    v2 = Value(2)
    v3 = Value(3)
    with reduce_to_const(Concat(v1, v2, v3)) as exp:
        v1.fix()
        v2.fix()
        assert len(exp.children) == 2
        v3.fix()
Example #8
0
def test_neg_simplification():
    val = Value(1, 2, 3, 4)
    with reduce_to_const(Neg(val)):
        val.fix()
Example #9
0
def test_slice_simplification(start, end):
    val = Value(1, 2, 3, 4)
    with reduce_to_const(Slice(val, slice(start, end))):
        val.fix()
Example #10
0
def test_concat_of_slice_simplification_0(i, check_dump):
    val = Value(0, 1, 2)
    exp = Concat(val[0], val[1], val[2])
    val.fix()
    exp = simplify(exp[i])
    check_dump(exp, "Constant <%s.0>" % i)