Esempio n. 1
0
def test_broaden_recursive():
    s1 = S(1)
    t1 = T.empty()
    t1.__init__([s1, t1])
    t1 = t1.intern()

    sa = S(t=ty.Int[64])
    ta = T.empty()
    ta.__init__([sa, ta])
    ta = ta.intern()

    assert broaden(t1) is ta
    assert broaden(ta) is ta

    t2 = T.empty()
    u2 = AbstractUnion.empty()
    u2.__init__([s1, t2])
    t2.__init__([s1, u2])
    t2 = t2.intern()

    tb = T.empty()
    ub = AbstractUnion.empty()
    ub.__init__([sa, tb])
    tb.__init__([sa, ub])
    tb = tb.intern()

    assert broaden(t2) is tb
    assert broaden(tb) is tb
Esempio n. 2
0
    async def coro():
        s1 = S(t=ty.Int[32])
        s2 = S(t=ty.Int[64])
        assert (await upcast_async(s1)) is s2

        a1 = T([s1, L(s1)])
        assert (await upcast_async(a1)) is T([s2, L(s2)])

        f1 = AbstractFunction(P.scalar_add, P.scalar_mul)
        assert (await upcast_async(f1)) is f1

        u1 = AbstractUnion([s1])
        assert (await upcast_async(u1)) is AbstractUnion([s2])
Esempio n. 3
0
def test_annotation_merge():
    with pytest.raises(MyiaTypeError):
        annotation_merge(
            AbstractUnion(
                [AbstractScalar({TYPE: i16}),
                 AbstractScalar({TYPE: f32})]),
            AbstractScalar({TYPE: i32}),
        )

    scalar = AbstractScalar({TYPE: f32})
    union = AbstractUnion([AbstractScalar({TYPE: i16}), scalar])
    assert annotation_merge(union, scalar) is scalar
    assert annotation_merge(union, scalar, forced=True) is union

    generic_list_type = type_to_abstract(list)
    specific_list_type = to_abstract([1, 2])
    assert isinstance(generic_list_type, AbstractUnion)
    assert (annotation_merge(generic_list_type,
                             specific_list_type,
                             forced=True) is generic_list_type)
    assert isinstance(annotation_merge(generic_list_type, specific_list_type),
                      AbstractADT)
Esempio n. 4
0
def U(*opts):
    opts = [to_abstract_test(x) for x in opts]
    return AbstractUnion(opts)
Esempio n. 5
0
File: common.py Progetto: tor4z/myia
def U(*opts):
    """Generate a symbolic union."""
    opts = [to_abstract_test(x) for x in opts]
    return AbstractUnion(opts)