Exemplo n.º 1
0
def test_type_tracking():

    pip = scalar_pipeline.select(
        "resources",
        "parse",
        "infer",
        "specialize",
        "simplify_types",
        "opt",
        "validate",
    ).configure({"opt.phases.main": [opt_ok1, opt_ok2, opt_err1]})

    def fn_ok1(x, y):
        return x + y

    pip.run(input=fn_ok1,
            argspec=(to_abstract_test(i64), to_abstract_test(i64)))

    def fn_ok2(x):
        return -x

    pip.run(input=fn_ok2, argspec=(to_abstract_test(i64), ))

    def fn_err1(x, y):
        return x - y

    with pytest.raises(ValidationError):
        pip.run(
            input=fn_err1,
            argspec=(to_abstract_test(i64), to_abstract_test(i64)),
        )
Exemplo n.º 2
0
def test_forward_reference():
    def g():
        return h()

    # No resolve
    parse2 = scalar_pipeline.select("resources", "parse").make_transformer(
        "input", "graph")

    parse2(g)

    def h():
        return 2 + 2
Exemplo n.º 3
0
    return prim


@_test_op
def _tern(x: Number, y: Number, z: Number) -> Number:
    return x + y + z


@_test_op
def _to_i64(x: Number) -> Int[64]:
    return int(x)


infer_pipeline = scalar_pipeline.select('parse', 'infer').configure({
    'py_implementations':
    pyimpl_test,
    'inferrer.constructors':
    abstract_inferrer_cons_test,
})

infer_pipeline_std = standard_pipeline.select('parse', 'infer').configure({
    'py_implementations':
    pyimpl_test,
    'inferrer.constructors':
    abstract_inferrer_cons_test,
})


def _is_exc_type(cls):
    return isinstance(cls, type) and issubclass(cls, Exception)

Exemplo n.º 4
0
    SHAPE,
    TYPE,
    AbstractArray,
    AbstractFunction,
    VirtualFunction,
)
from myia.frontends.pytorch_abstract_types import PyTorchTensor
from myia.operations import partial, primitives as P
from myia.pipeline import scalar_parse, scalar_pipeline
from myia.validate import ValidationError, validate, validate_abstract

from .common import Point, f64, i64, to_abstract_test

Point_a = Point(i64, i64)

pip = scalar_pipeline.select("resources", "parse", "infer", "specialize",
                             "validate")

pip_ec = scalar_pipeline.select("resources", "parse", "infer", "specialize",
                                "simplify_types", "validate")


def run(pip, fn, types):
    res = pip.run(input=fn, argspec=[to_abstract_test(t) for t in types])
    return res["graph"]


def valid(*types):
    def deco(fn):
        run(pip, fn, types)

    return deco
Exemplo n.º 5
0
from myia.ir import isomorphic
from myia.operations import switch
from myia.pipeline import scalar_parse, scalar_pipeline, steps

llift = scalar_pipeline.select(
    "resources",
    "parse",
    {
        "resolve": steps.step_resolve
    },
    "llift",
).make_transformer("input", "graph")


def test_lambda_lift_simple():
    @llift
    def f1(x, y):
        def g(z):
            return x + z

        return g(y)

    @scalar_parse
    def f2(x, y):
        def g(z, _x):
            return _x + z

        return g(y, x)

    assert isomorphic(f1, f2)
Exemplo n.º 6
0
    async def infer_type(track, x):
        rv = RestrictedVar({i16, f64})
        return track.engine.loop.create_var(rv, None, 0)

    async def infer_shape(track, x):
        return NOSHAPE


infer_pipeline = scalar_pipeline.select('parse', 'infer').configure({
    'py_implementations':
    pyimpl_test,
    'inferrer.erase_value':
    False,
    'inferrer.tracks.value.max_depth':
    10,
    'inferrer.tracks.value.constructors':
    value_inferrer_cons_test,
    'inferrer.tracks.type.constructors':
    type_inferrer_cons_test,
    'inferrer.tracks.shape.constructors':
    shape_inferrer_cons_test,
})

infer_pipeline_std = standard_pipeline.select('parse', 'infer').configure({
    'py_implementations':
    pyimpl_test,
    'inferrer.erase_value':
    False,
    'inferrer.tracks.value.max_depth':
    10,
    'inferrer.tracks.value.constructors':