Esempio n. 1
0
def test_env():
    pip1 = scalar_debug_pipeline.select('parse', 'export')
    pip2 = scalar_debug_pipeline

    def f(x, y):
        e1 = env_setitem(newenv, embed(x), 100)

        e2 = newenv
        e2 = env_setitem(newenv, embed(x), 10)
        e2 = env_setitem(e2, embed(y), 20)

        e3 = env_add(e1, e2)

        a = env_getitem(e3, embed(x), 0)
        b = env_getitem(e3, embed(y), 0)
        c = env_getitem(e3, embed(a), 0)

        return (a, b, c)

    res = pip1.run(input=f)['output'](3, 4)
    assert res == (110, 20, 0)

    res = pip2.run(input=f,
                   argspec=(to_abstract_test(i64),
                            to_abstract_test(i64)))['output'](3, 4)
    assert res == (110, 20, 0)
Esempio n. 2
0
from myia.ir import manage
from myia.opt import LambdaLiftRewriter
from myia.pipeline import scalar_debug_pipeline, steps


def step_cconv(resources, graph, use_llift):
    if use_llift:
        graph.manager.keep_roots(graph)
        llift = LambdaLiftRewriter(resources.opt_manager)
        llift.run()
    closure_convert(graph)
    return {"graph": graph}


cconv_pipeline = scalar_debug_pipeline.select("resources", "parse", {
    "resolve": steps.step_resolve
}, "export").insert_after("resolve", cconv=step_cconv)


def check_no_free_variables(root):
    mng = manage(root)
    for g, nodes in mng.nodes.items():
        if not g:
            continue
        if g.parent is not None:
            raise Exception(f"Nested graph detected: {g}")
        for node in nodes:
            assert node.graph is g
            for inp in node.inputs:
                if inp.graph is not None and inp.graph is not g:
                    raise Exception(f"Free variable detected: {node}")
Esempio n. 3
0
    scalar_uadd,
    scalar_usub,
    switch,
    tagged,
)
from myia.pipeline import scalar_debug_pipeline, standard_debug_pipeline

from .common import Point, U, f64, i64, mysum
from .multitest import mt, run

specialize_pipeline = scalar_debug_pipeline.select(
    "resources",
    "parse",
    "infer",
    "specialize",
    "simplify_types",
    "opt2",
    "llift",
    "validate",
    "export",
    "wrap",
).configure({"opt2.phases.main": []})

specialize_pipeline_std = standard_debug_pipeline.select(
    "resources",
    "parse",
    "infer",
    "specialize",
    "simplify_types",
    "opt",
    "opt2",
    "llift",
Esempio n. 4
0
from pytest import mark

from myia.pipeline import scalar_debug_pipeline, steps

from .common import Point, mysum
from .multitest import mt, run, run_debug

lang_pipeline = scalar_debug_pipeline.select(
    "resources", "parse", {"resolve": steps.step_resolve}, "llift", "export"
)


run_lang = run.configure(pipeline=lang_pipeline, backend=False)


#############
# Constants #
#############


@run_lang()
def test_constant():
    return 1


###################
# Some primitives #
###################


@mt(run_lang(1, 4), run_lang(5, -13))