def test_amerge(): a = T([S(1), S(t=ty.Int[64])]) b = T([S(1), S(t=ty.Int[64])]) c = T([S(t=ty.Int[64]), S(t=ty.Int[64])]) assert amerge(a, b, forced=False) is a assert amerge(a, c, forced=False) == c assert amerge(c, a, forced=False) is c with pytest.raises(MyiaTypeError): amerge(a, c, forced=True) assert amerge(1, 2, forced=False) is ANYTHING with pytest.raises(MyiaTypeError): assert amerge(1, 2, forced=True) with pytest.raises(MyiaTypeError): assert amerge("hello", "world", forced=False) assert amerge(ty.Int, ty.Int[64], forced=False) is ty.Int assert amerge(ty.Int[64], ty.Int, forced=False) is ty.Int with pytest.raises(MyiaTypeError): amerge(ty.Float, ty.Int, forced=False) with pytest.raises(MyiaTypeError): amerge(ty.Int[64], ty.Int, forced=True) loop = asyncio.new_event_loop() p = PendingFromList([ty.Int[64], ty.Float[64]], None, None, loop=loop) assert amerge(ty.Number, p, forced=False, bind_pending=False) \ is ty.Number assert amerge(p, ty.Number, forced=False, bind_pending=False) \ is ty.Number with pytest.raises(MyiaTypeError): print(amerge(p, ty.Number, forced=True, bind_pending=False)) assert amerge(AbstractError(DEAD), AbstractError(ANYTHING), forced=False) is AbstractError(ANYTHING) d1 = {'x': 1} d2 = {'y': 2} with pytest.raises(MyiaTypeError): print(amerge(d1, d2)) td1 = TrackDict({ALIASID: 1}) td2 = TrackDict({}) with pytest.raises(MyiaTypeError): print(amerge(td1, td2, forced=True))
def test_repr(): s1 = to_abstract_test(1) assert repr(s1) == 'AbstractScalar(Int[64] = 1)' s2 = to_abstract_test(f32) assert repr(s2) == 'AbstractScalar(Float[32])' t1 = to_abstract_test((1, f32)) assert repr(t1) == f'AbstractTuple((Int[64] = 1, Float[32]))' l1 = to_abstract_test([f32]) assert repr(l1) == f'AbstractList([Float[32]])' a1 = to_abstract_test(af32_of(4, 5)) assert repr(a1) == f'AbstractArray(Float[32] x 4 x 5)' p1 = to_abstract_test(Point(1, f32)) assert repr(p1) == \ f'AbstractClass(Point(x :: Int[64] = 1, y :: Float[32]))' j1 = AbstractJTagged(to_abstract_test(1)) assert repr(j1) == f'AbstractJTagged(J(Int[64] = 1))' ty1 = Ty(f32) assert repr(ty1) == 'AbstractType(Ty(Float[32]))' e1 = AbstractError(DEAD) assert repr(e1) == 'AbstractError(E(DEAD))' f1 = AbstractFunction(P.scalar_mul) assert repr(f1) == 'AbstractFunction(scalar_mul)'
def test_repr(): s1 = to_abstract_test(1) assert repr(s1) == 'S(VALUE=1, TYPE=Int[64])' s2 = to_abstract_test(f32) assert repr(s2) == 'S(TYPE=Float[32])' t1 = to_abstract_test((1, f32)) assert repr(t1) == f'T({s1}, {s2})' l1 = to_abstract_test([f32]) assert repr(l1) == f'L({s2})' a1 = to_abstract_test(af32_of(4, 5)) assert repr(a1) == f'A({s2}, SHAPE=(4, 5))' p1 = to_abstract_test(Point(1, f32)) assert repr(p1) == f'*Point(x={s1}, y={s2})' j1 = AbstractJTagged(to_abstract_test(1)) assert repr(j1) == f'J({s1})' ty1 = Ty(f32) assert repr(ty1) == 'Ty(Float[32])' e1 = AbstractError(DEAD) assert repr(e1) == 'E(DEAD)' f1 = AbstractFunction(P.scalar_mul) assert repr(f1) == 'Fn(Possibilities({scalar_mul}))'
def test_amerge(): a = T([S(1), S(t=ty.Int[64])]) b = T([S(1), S(t=ty.Int[64])]) c = T([S(t=ty.Int[64]), S(t=ty.Int[64])]) assert amerge(a, b, forced=False) is a assert amerge(a, c, forced=False) == c assert amerge(c, a, forced=False) is c with pytest.raises(MyiaTypeError): amerge(a, c, forced=True) assert amerge(1, 2, forced=False) is ANYTHING with pytest.raises(MyiaTypeError): assert amerge(1, 2, forced=True) with pytest.raises(MyiaTypeError): assert amerge("hello", "world", forced=False) assert amerge(ty.Int, ty.Int[64], forced=False) is ty.Int assert amerge(ty.Int[64], ty.Int, forced=False) is ty.Int with pytest.raises(MyiaTypeError): amerge(ty.Float, ty.Int, forced=False) with pytest.raises(MyiaTypeError): amerge(ty.Int[64], ty.Int, forced=True) assert amerge(AbstractError(DEAD), AbstractError(ANYTHING), forced=False) is AbstractError(ANYTHING) d1 = {'x': 1} d2 = {'y': 2} with pytest.raises(MyiaTypeError): print(amerge(d1, d2)) td1 = TrackDict({ALIASID: 1}) td2 = TrackDict({}) with pytest.raises(MyiaTypeError): print(amerge(td1, td2, forced=True))
def test_repr(): s1 = to_abstract_test(1) assert repr(s1) == "AbstractScalar(Int[64] = 1)" s2 = to_abstract_test(f32) assert repr(s2) == "AbstractScalar(Float[32])" t1 = to_abstract_test((1, f32)) assert repr(t1) == f"AbstractTuple((Int[64] = 1, Float[32]))" a1 = to_abstract_test(af32_of(4, 5)) assert repr(a1) == f"AbstractArray(Float[32] x 4 x 5)" p1 = to_abstract_test(Point(1, f32)) assert repr( p1) == f"AbstractClass(Point(x :: Int[64] = 1, y :: Float[32]))" j1 = AbstractJTagged(to_abstract_test(1)) assert repr(j1) == f"AbstractJTagged(J(Int[64] = 1))" h1 = AbstractHandle(to_abstract_test(1)) assert repr(h1) == f"AbstractHandle(H(Int[64] = 1))" kw1 = AbstractKeywordArgument("bucket", to_abstract_test(1)) assert repr(kw1) == f"AbstractKeywordArgument(KW(bucket :: Int[64] = 1))" ty1 = Ty(f32) assert repr(ty1) == "AbstractType(Ty(AbstractScalar(Float[32])))" e1 = AbstractError(DEAD) assert repr(e1) == "AbstractError(E(DEAD))" f1 = AbstractFunction(P.scalar_mul) assert repr(f1) == "AbstractFunction(scalar_mul)" fa = AbstractFunction(value=ANYTHING) assert repr(fa) == "AbstractFunction(ANYTHING)" tu1 = AbstractTaggedUnion([[13, s2], [4, to_abstract_test(i16)]]) assert repr(tu1) == "AbstractTaggedUnion(U(4 :: Int[16], 13 :: Float[32]))" bot = AbstractBottom() assert repr(bot) == "AbstractBottom(⊥)"
def test_repr(): s1 = to_abstract_test(1) assert repr(s1) == 'AbstractScalar(Int[64] = 1)' s2 = to_abstract_test(f32) assert repr(s2) == 'AbstractScalar(Float[32])' t1 = to_abstract_test((1, f32)) assert repr(t1) == f'AbstractTuple((Int[64] = 1, Float[32]))' a1 = to_abstract_test(af32_of(4, 5)) assert repr(a1) == f'AbstractArray(Float[32] x 4 x 5)' p1 = to_abstract_test(Point(1, f32)) assert repr(p1) == \ f'AbstractClass(Point(x :: Int[64] = 1, y :: Float[32]))' j1 = AbstractJTagged(to_abstract_test(1)) assert repr(j1) == f'AbstractJTagged(J(Int[64] = 1))' kw1 = AbstractKeywordArgument('bucket', to_abstract_test(1)) assert repr(kw1) == f'AbstractKeywordArgument(KW(bucket :: Int[64] = 1))' ty1 = Ty(f32) assert repr(ty1) == 'AbstractType(Ty(Float[32]))' e1 = AbstractError(DEAD) assert repr(e1) == 'AbstractError(E(DEAD))' f1 = AbstractFunction(P.scalar_mul) assert repr(f1) == 'AbstractFunction(scalar_mul)' tu1 = AbstractTaggedUnion([[13, s2], [4, to_abstract_test(i16)]]) assert repr(tu1) == \ 'AbstractTaggedUnion(U(4 :: Int[16], 13 :: Float[32]))' @macro def mackerel(info): pass assert repr(mackerel) == '<Macro mackerel>'