コード例 #1
0
ファイル: test_ir_utils.py プロジェクト: strint/myia
def test_print_graph():
    g = Graph()
    g.debug.name = "testfn"
    p = g.add_parameter()
    p.debug.name = "a"
    p2 = g.add_parameter()
    p2.debug.name = "b"
    c = g.constant(1)
    g.output = g.apply(g, c, p2)
    g.output.debug.name = "_apply0"

    s = print_graph(g)
    assert (s == """graph testfn(%a, %b) {
  %_apply0 = @testfn(1, %b)
  return %_apply0
}
""")

    # We use fake types here because we only care about the printing logic,
    # not the proper use of types.
    p.abstract = "int64"
    p2.abstract = "float32"
    g.output.abstract = "bool"
    g.return_.abstract = "bool"

    s = print_graph(g)
    assert (s == """graph testfn(%a : int64, %b : float32) -> bool {
  %_apply0 = @testfn(1, %b) ; type=bool
  return %_apply0
}
""")
コード例 #2
0
ファイル: test_ir_utils.py プロジェクト: strint/myia
def test_print_node():
    g = Graph()
    g.debug.name = "testfn"
    p = g.add_parameter()
    p.debug.name = "a"
    p2 = g.add_parameter()
    p2.debug.name = "b"
    c = g.constant(1)
    g.output = g.apply(g, c, p2)
    g.output.debug.name = "_apply0"
    s = print_node(g.output)
    assert s == "%_apply0 = @testfn(1, %b)\n"
コード例 #3
0
def test_print_graph():
    g = Graph()
    g.debug.name = 'testfn'
    p = g.add_parameter()
    p.debug.name = 'a'
    p2 = g.add_parameter()
    p2.debug.name = 'b'
    c = g.constant(1)
    g.output = g.apply(g, c, p2)
    g.output.debug.name = '_apply0'

    s = print_graph(g)
    assert s == """graph testfn(%a, %b) {
コード例 #4
0
ファイル: test_ir_utils.py プロジェクト: strint/myia
def test_print_cycle():
    g = Graph()
    g.debug.name = "testfn"
    p = g.add_parameter()
    p.debug.name = "a"
    p2 = g.add_parameter()
    p2.debug.name = "b"
    node = g.apply("make_tuple", p)
    node2 = g.apply("make_tuple", p2, node)
    node.inputs.append(node2)
    g.output = node2

    with pytest.raises(ValueError, match="cycle"):
        print_graph(g, allow_cycles=False)

    print_graph(g)
コード例 #5
0
ファイル: test_ir_utils.py プロジェクト: xyz3021/myia
def test_print_graph():
    g = Graph()
    g.debug.name = "testfn"
    p = g.add_parameter()
    p.debug.name = "a"
    p2 = g.add_parameter()
    p2.debug.name = "b"
    c = g.constant(1)
    g.output = g.apply(g, c, p2)
    g.output.debug.name = "_apply0"

    s = print_graph(g)
    assert (s == """graph testfn(%a, %b) {
  %_apply0 = @testfn(1, %b)
  return %_apply0
}
""")
コード例 #6
0
 async def bad(info, x):
     badg = Graph()
     badg.debug.name = 'badg'
     p = badg.add_parameter()
     p.debug.name = 'parameter'
     badg.output = badg.apply(P.scalar_add, p, p)
     # The return value of the macro can't directly refer to badg.output
     # because that node can only be accessed from the scope of a call to
     # badg. The error raised by Myia should reflect this.
     return info.graph.apply(P.transpose, badg.output)
コード例 #7
0
ファイル: test_ir_utils.py プロジェクト: strint/myia
def test_print_closure():
    g = Graph()
    g.debug.name = "testfn"
    p = g.add_parameter()
    p.debug.name = "a"
    n = g.apply("make_tuple", p, p)
    n.debug.name = "_apply0"
    g2 = Graph()
    g2.debug.name = "sub"
    n2 = g2.apply("tuple_getitem", n, 0)
    n2.debug.name = "_apply1"
    g2.output = n2
    g.output = g.apply(g2)

    s = print_graph(g2)

    assert (s == """graph sub() {
  %_apply1 = tuple_getitem(%_apply0, 0)
  return %_apply1
}
""")
    s = print_node(n2)

    assert s == "%_apply1 = tuple_getitem(%_apply0, 0)\n"
コード例 #8
0
    assert v is v2


def test_dump_undefined():
    with pytest.raises(Exception):
        dumpload(object())


def test_exception():
    e2 = dumpload(Exception("this is bad"))
    assert e2.message == "Exception: this is bad\n"
    assert repr(e2) == 'LoadedException'


g = Graph()
p1 = g.add_parameter()
p1.abstract = to_abstract_test(2)
p2 = g.add_parameter()
p2.abstract = to_abstract_test(2)
mid = g.apply(scalar_add, p1, p2)
mid.abstract = to_abstract_test(4)
c = Constant(1)
c.abstract = to_abstract_test(1)
g.output = g.apply(scalar_add, mid, c)
g.output.abstract = to_abstract_test(5)
g.return_.abstract = to_abstract_test(5)
g.return_.inputs[0].abstract = None


@parametrize('node', [
    p1,