infer(Shp(2, 3), i32, 10, result=MyiaTypeError), infer(Shp(2, 3), i32, (), result=MyiaTypeError), # Otherwise, output type should be specified d-type. infer(Shp(2, 3), i64, Ty(np.int16), result=ai16_of(2, 3)), infer(Shp(2, 3), i64, Ty(np.float16), result=af16_of(2, 3)), infer(Shp(2, 3), i64, Ty(np.float64), result=af64_of(2, 3)), infer(Shp(2, 3), f64, Ty(np.int16), result=ai16_of(2, 3)), infer(Shp(2, 3), f64, Ty(np.int32), result=ai32_of(2, 3)), infer(Shp(2, 3), f64, Ty(np.uint64), result=au64_of(2, 3)), ) def test_infer_composite_full(shape, value, dtype): return composite_full(shape, value, dtype) @mt( run(Shp(2, 3), 0, np.float64, result=np.zeros((2, 3))), run(Shp(8), 1, np.float16, result=np.ones((8, ), "float16")), run(Shp(1, 4), -2.5, np.float64, result=(-2.5 * np.ones((1, 4)))), run(Shp(1, 4), -2.5, np.double, result=(-2.5 * np.ones((1, 4), "double"))), broad_specs=(False, False, False), ) def test_composite_full(shape, fill_value, dtype): return composite_full(shape, fill_value, dtype) @mt( infer(i32, result=i32), infer(f64, result=f64), infer(i64, result=i64), ) def test_infer_composite_simple(x):
}, result=InferenceError), # Generic broadcasting tests infer_scalar([f64], f64, result=[f64]), infer_scalar([[f64]], [[f64]], result=[[f64]]), infer_scalar((i64, i64), i64, result=(i64, i64)), infer_scalar(i64, (i64, i64), result=(i64, i64)), infer_scalar(Point(i64, i64), i64, result=Point(i64, i64)), # Various errors infer_scalar((i64, i64), (i64, i64, i64), result=InferenceError), infer_scalar(Point(i64, i64), Point3D(i64, i64, i64), result=InferenceError), infer_scalar((i64, i64), [i64], result=InferenceError), # Full tests run(MA(2, 3), MB(2, 3)), run(Point(1, 2), Point(3, 4)), run((MA(2, 3), 7.5, MB(1, 3)), 3.5), ) def test_hyper_map(x, y): return hyper_map(scalar_add, x, y) @mt( infer_scalar((i64, f64), (i64, f64), result=InferenceError), infer_scalar([f64], f64, result=[f64]), ) def test_hyper_map_notuple(x, y): return hyper_map_notuple(scalar_add, x, y)
raise ValueError("test") register_backend(name, f, format) with pytest.raises(LoadingError): load_backend(name) del _backends[name] @run(MA(2, 3)) def test_reshape2(x): return reshape(x, (6, )) @mt(run(MA(2, 3)), run(MA(1, 3))) def test_array_reduce(x): return array_reduce(scalar_add, x, (1, 3)) @run(MA(2, 3)) def test_array_reduce2(x): return array_reduce(scalar_add, x, (3, )) @run_gpu(MA(1, 1)) def test_array_to_scalar(x): return array_to_scalar(reshape(x, ())) @mt(run(2, 3), run(2.0, 3.0))
def cost(model, x, y): yy = model.apply(x) diff = yy - y return (array_reduce(scalar_add, diff ** 2, ())).item() @mt( infer_standard(make_model(), MC(3, 6), result=af64_of(3, 8)), infer_standard(make_model("float32"), MC(3, 6), result=InferenceError), infer_standard( make_model("float32"), MC(3, 6, dtype="float32"), result=af32_of(3, 8) ), infer_standard(make_model(), MC(3, 9), result=InferenceError), run(make_model(), MC(3, 6)), ) def test_forward(model, x): return model.apply(x) @mt( infer_standard(make_model(), MC(3, 6), MC(3, 8), result=make_model()), infer_standard(make_model(), MC(3, 6), MC(3, 9), result=InferenceError), infer_standard( make_model("float32"), MC(3, 6), MC(3, 8), result=InferenceError ), infer_standard( make_model("float32"), MC(3, 6, dtype="float32"), MC(3, 8, dtype="float32"),
from myia.testing.common import Pair, f64, i64 from myia.testing.multitest import backend_all, bt, mt, run, run_debug from .test_grad import gradient from .test_infer import infer_scalar from .test_monomorphize import mono_scalar ######################### # Arithmetic algorithms # ######################### @mt( infer_scalar(i64, result=i64), infer_scalar(f64, result=f64), run(3), run(4.8), gradient(2.0), ) def test_pow10(x): v = x j = 0 while j < 3: i = 0 while i < 3: v = v * x i = i + 1 j = j + 1 return v
from myia.lib import InferenceError from myia.operations import dtype, scalar_cast from myia.testing.common import MA, Ty, af32_of, f32, i64, to_abstract_test from myia.testing.multitest import infer, mt, run @mt( infer(i64, result=InferenceError), infer(af32_of(4, 5), result=Ty(to_abstract_test(f32))), ) def test_dtype(arr): return dtype(arr) @mt(infer(af32_of(4, 5), i64, result=f32), run(MA(2, 3), 7, result=7.0)) def test_cast_to_dtype(arr, x): return scalar_cast(x, dtype(arr))
steps.step_compile, steps.step_wrap, )) @run(2, 3) def test_simple(x, y): return x + y @run(42) def test_constant(x): return x == 42 @mt(run(False, True), run(True, True), run(True, False), run(False, False)) def test_bool_and(x, y): return bool_and(x, y) @mt(run(22), run(3.0)) def test_dict(v): return {"x": v} @run({"x": 22, "y": 3.0}) def test_dict_getitem(d): return d["x"] @mt(run(33, 42), run(42, 33))
) from myia.testing.multitest import infer, mt, run from myia.utils.errors import MyiaTypeError from myia.xtype import Bool, Nil, f16, f32, f64, i8, i16, i32, i64, u32, u64 def Shp(*values): """Convert values to a tuple of numpy unsigned integers.""" return tuple(np.uint64(value) for value in values) @mt( infer(u32, u32, result=u32), infer(i32, i32, result=i32), infer(i64, i64, result=i64), run(5, 7, result=5), ) def test_bitwise_and(a, b): return a & b @mt( infer(u32, u32, result=u32), infer(i32, i32, result=i32), infer(i64, i64, result=i64), run(5, 2, result=7), ) def test_bitwise_or(a, b): return a | b