示例#1
0
def test_hypermap_python():
    # Normal
    assert hyper_map(scalar_add, 10, 20) == 30
    assert hyper_map(scalar_add, (1, 2), (10, 20)) == (11, 22)
    assert hyper_map(scalar_add, [1, 2, 3], [3, 2, 1]) == [4, 4, 4]
    assert (
        hyper_map(scalar_add, numpy.ones((2, 2)), numpy.ones((2, 2)))
        == 2 * numpy.ones((2, 2))
    ).all()

    # Broadcast
    assert hyper_map(scalar_add, [1, 2, 3], 10) == [11, 12, 13]
    assert hyper_map(
        scalar_add, Point([1, 2], (3, 4)), Point(10, 100)
    ) == Point([11, 12], (103, 104))
    assert (
        hyper_map(scalar_add, numpy.ones((2, 2)), 9) == 10 * numpy.ones((2, 2))
    ).all()

    # Provide fn_leaf
    adder = HyperMap(fn_leaf=scalar_add)
    assert adder((1, 2), (10, 20)) == (11, 22)
    assert (
        adder(numpy.ones((2, 2)), numpy.ones((2, 2))) == 2 * numpy.ones((2, 2))
    ).all()
示例#2
0
@infer((i64, i64, i64, InferenceError))
def test_dataclass_bad_inst(x, y, z):
    return Point(x, y, z)


@infer((Ty(ANYTHING), i64, i64, InferenceError))
def test_dataclass_bad_inst2(cls, x, y):
    return make_record(cls, x, y)


@infer((Point(i64, i64), InferenceError))
def test_dataclass_wrong_field(pt):
    return pt.z


hyper_map = HyperMap()
hyper_map_notuple = HyperMap(nonleaf=(A, Class))
hyper_map_nobroadcast = HyperMap(broadcast=False)


@infer(
    (i64, i64, i64),
    (f64, f64, f64),
    ([f64], [f64], [f64]),
    ([[f64]], [[f64]], [[f64]]),
    ([f64], f64, InferenceError),
    ([f64], [[f64]], InferenceError),
    ((i64, f64), (i64, f64), (i64, f64)),
    (Point(i64, i64), Point(i64, i64), Point(i64, i64)),
    (ai64_of(2, 5), ai64_of(2, 5), ai64_of(2, 5)),
    (ai64_of(2, 5), i64, ai64_of(2, 5)),
示例#3
0

@infer((Point(i64, i64), i64, Point(i64, i64)),
       (Point(i64, i64), f64, InferenceError))
def test_record_setitem_2(pt, x):
    return record_setitem(pt, 'x', x)


@infer((Thing(i64), f64, InferenceError))
def test_record_setitem_wrong_field(thing, x):
    return record_setitem(thing, 'shfifty_five', x)


hyper_map_notuple = HyperMap(
    nonleaf=(abstract.AbstractArray,
             abstract.AbstractUnion,
             abstract.AbstractClassBase)
)
hyper_map_nobroadcast = HyperMap(broadcast=False)


@infer(
    (i64, i64, i64),
    (f64, f64, f64),
    ([f64], [f64], [f64]),
    ([[f64]], [[f64]], [[f64]]),
    ((i64, f64), (i64, f64), (i64, f64)),
    (Point(i64, i64), Point(i64, i64), Point(i64, i64)),
    (ai64_of(2, 5), ai64_of(2, 5), ai64_of(2, 5)),
    (ai64_of(2, 5), i64, ai64_of(2, 5)),
    (ai64_of(1, 5), ai64_of(2, 1), ai64_of(2, 5)),
示例#4
0
    MB,
    Point,
    Point3D,
    U,
    af64_of,
    ai64_of,
    f64,
    i64,
)
from myia.testing.multitest import mt, run, run_debug
from myia.utils import tags

from ..test_algos import make_tree
from ..test_infer import infer_scalar

hyper_map_notuple = HyperMap(nonleaf=(lib.AbstractArray, lib.AbstractUnion,
                                      lib.AbstractClassBase))
hyper_map_nobroadcast = HyperMap(broadcast=False)


@mt(
    infer_scalar(i64, i64, result=i64),
    infer_scalar(f64, f64, result=f64),
    infer_scalar([f64], [f64], result=[f64]),
    infer_scalar([[f64]], [[f64]], result=[[f64]]),
    infer_scalar((i64, f64), (i64, f64), result=(i64, f64)),
    infer_scalar(Point(i64, i64), Point(i64, i64), result=Point(i64, i64)),
    infer_scalar(ai64_of(2, 5), ai64_of(2, 5), result=ai64_of(2, 5)),
    infer_scalar(ai64_of(2, 5), i64, result=ai64_of(2, 5)),
    infer_scalar(ai64_of(1, 5), ai64_of(2, 1), result=ai64_of(2, 5)),
    infer_scalar(i64, f64, result=InferenceError),
    infer_scalar(ai64_of(2, 5), af64_of(2, 5), result=InferenceError),
示例#5
0
def test_dataclass_bad_inst2(cls, x, y):
    return make_record(cls, x, y)


@infer((Point(i64, i64), InferenceError))
def test_dataclass_wrong_field(pt):
    return pt.z


@infer((Thing(i64), i64))
def test_dataclass_call(thing):
    return thing()


hyper_map_notuple = HyperMap(nonleaf=(abstract.AbstractArray,
                                      abstract.AbstractList,
                                      abstract.AbstractClass))
hyper_map_nobroadcast = HyperMap(broadcast=False)


@infer(
    (i64, i64, i64),
    (f64, f64, f64),
    ([f64], [f64], [f64]),
    ([[f64]], [[f64]], [[f64]]),
    ((i64, f64), (i64, f64), (i64, f64)),
    (Point(i64, i64), Point(i64, i64), Point(i64, i64)),
    (ai64_of(2, 5), ai64_of(2, 5), ai64_of(2, 5)),
    (ai64_of(2, 5), i64, ai64_of(2, 5)),
    (ai64_of(1, 5), ai64_of(2, 1), ai64_of(2, 5)),
    (i64, f64, InferenceError),