Beispiel #1
0
    def test_new_affine_error_symbol(self):
        e1 = LinExp.new_affine_error_symbol()
        e2 = LinExp.new_affine_error_symbol()

        assert e1.is_symbol
        assert isinstance(e1.symbol, AAError)
        assert e2.is_symbol
        assert isinstance(e2.symbol, AAError)

        assert e1 != e2
def test_find_analysis_filter_bounds():
    expr = (1 * LinExp(("pixel", 0, 0)) + 2 * LinExp(
        ("pixel", 1, 0)) + -4 * LinExp(
            ("pixel", 2, 0)) + 10 * LinExp.new_affine_error_symbol() + 1)
    lower_bound, upper_bound = analysis_filter_bounds(expr)
    assert lower_bound == 3 * LinExp("signal_min") + -4 * LinExp(
        "signal_max") - 10 + 1
    assert upper_bound == -4 * LinExp("signal_min") + 3 * LinExp(
        "signal_max") + 10 + 1
def test_find_synthesis_filter_bounds():
    coeff_arrays = make_symbol_coeff_arrays(1, 0)

    expr = (1 * coeff_arrays[0]["LL"][0, 0] + 2 * coeff_arrays[0]["LL"][1, 0] +
            -4 * coeff_arrays[0]["LL"][2, 0] +
            10 * coeff_arrays[1]["HH"][0, 0] +
            20 * coeff_arrays[1]["HH"][1, 0] +
            -40 * coeff_arrays[1]["HH"][2, 0] +
            100 * LinExp.new_affine_error_symbol() + 1)

    lower_bound, upper_bound = synthesis_filter_bounds(expr)
    assert lower_bound == (3 * LinExp("coeff_0_LL_min") +
                           -4 * LinExp("coeff_0_LL_max") +
                           30 * LinExp("coeff_1_HH_min") +
                           -40 * LinExp("coeff_1_HH_max") + -100 + 1)
    assert upper_bound == (-4 * LinExp("coeff_0_LL_min") +
                           3 * LinExp("coeff_0_LL_max") +
                           -40 * LinExp("coeff_1_HH_min") +
                           30 * LinExp("coeff_1_HH_max") + +100 + 1)
from vc2_bit_widths.pattern_generation import (
    get_maximising_inputs,
    make_analysis_maximising_pattern,
    make_synthesis_maximising_pattern,
)


@pytest.mark.parametrize(
    "expression,exp",
    [
        # Empty/constant expression
        (0, {}),
        (123, {}),
        (LinExp(123), {}),
        # Error terms should be omitted
        (LinExp.new_affine_error_symbol(), {}),
        (LinExp.new_affine_error_symbol() + 123, {}),
        # Terms should be extracted correctly
        (LinExp(("p", 0, 0)), {
            ("p", 0, 0): 1
        }),
        # Only the signs of the coefficients should be preserved
        (-4 * LinExp(("p", 0, 0)), {
            ("p", 0, 0): -1
        }),
        # Combination of everything
        (
            2 * LinExp(("p", 0, 0)) - 3 * LinExp(
                ("p", 1, 2)) + LinExp.new_affine_error_symbol() + 123,
            {
                ("p", 0, 0): 1,
Beispiel #5
0
def test_strip_error_terms():
    a = LinExp.new_affine_error_symbol() + 1 + LinExp("x")
    assert strip_affine_errors(a) == LinExp("x") + 1
Beispiel #6
0
        assert str(three) == "3"


def test_strip_error_terms():
    a = LinExp.new_affine_error_symbol() + 1 + LinExp("x")
    assert strip_affine_errors(a) == LinExp("x") + 1


@pytest.mark.parametrize(
    "expr_in,lower,upper",
    [
        # Pure number (not a sympy type)
        (0, 0, 0),
        (123, 123, 123),
        # Single error
        (LinExp.new_affine_error_symbol(), -1, 1),
        (-LinExp.new_affine_error_symbol(), -1, 1),
        # Scaled error
        (3 * LinExp.new_affine_error_symbol(), -3, 3),
        # Several errors
        (3 * LinExp.new_affine_error_symbol() +
         2 * LinExp.new_affine_error_symbol(), -5, 5),
        (3 * LinExp.new_affine_error_symbol() +
         2 * LinExp.new_affine_error_symbol() + 5, 0, 10),
        # Errors and other values
        (LinExp("a") + 5 + 3 * LinExp.new_affine_error_symbol(),
         LinExp("a") + 2, LinExp("a") + 8),
    ])
def test_affine_bounds(expr_in, lower, upper):
    assert affine_lower_bound(expr_in) == lower
    assert affine_upper_bound(expr_in) == upper