Example #1
0
def test_constant_variable():
    def before(x):
        return Q(15) + Q(x)

    def after(x):
        return P(15) + Q(x)

    Qct_to_P = psub((Q, V), (P, V), name='Qct_to_P')

    _check_opt(before, after, Qct_to_P)
Example #2
0
specialize = scalar_pipeline \
    .configure({
        'resources.convert.object_map': Merge({
            operations.getitem: prim.tuple_getitem
        })
    }) \
    .select('resources', 'parse', 'resolve', 'infer', 'specialize')

# We will optimize patterns of these fake primitives

P = Primitive('P')
Q = Primitive('Q')
R = Primitive('R')

idempotent_P = psub((P, (P, X)), (P, X), name='idempotent_P')

elim_R = psub((R, X), X, name='elim_R')

Q0_to_R = psub((Q, 0), (R, 0), name='Q0_to_R')

QP_to_QR = psub((Q, (P, X)), (Q, (R, X)), name='QP_to_QR')

multiply_by_zero_l = psub((prim.scalar_mul, 0, X),
                          0,
                          name='multiply_by_zero_l')

multiply_by_zero_r = psub((prim.scalar_mul, X, 0),
                          0,
                          name='multiply_by_zero_r')
Example #3
0

specialize = scalar_pipeline.configure(
    {"convert.object_map": Merge({operations.getitem: prim.tuple_getitem})}
).with_steps(steps.step_parse, steps.step_infer, steps.step_specialize)


# We will optimize patterns of these fake primitives


P = Primitive("P")
Q = Primitive("Q")
R = Primitive("R")


idempotent_P = psub((P, (P, X)), (P, X), name="idempotent_P")

elim_R = psub((R, X), X, name="elim_R")

Q0_to_R = psub((Q, 0), (R, 0), name="Q0_to_R")

QP_to_QR = psub((Q, (P, X)), (Q, (R, X)), name="QP_to_QR")

multiply_by_zero_l = psub((prim.scalar_mul, 0, X), 0, name="multiply_by_zero_l")

multiply_by_zero_r = psub((prim.scalar_mul, X, 0), 0, name="multiply_by_zero_r")

add_zero_l = psub((prim.scalar_add, 0, X), X, name="add_zero_l")

add_zero_r = psub((prim.scalar_add, X, 0), X, name="add_zero_r")