return einsum("ij->", a) @run_debug(MA(3, 4), MB(3, 4)) def test_einsum_elemwise2d(a, b): return einsum("ij,ij->ij", a, b) @run_debug(MA(3, 4), MB(4, 3)) def test_einsum_elemwise2d_T(a, b): return einsum("ij,ji->ij", a, b) @mt( run_debug(MA(2, 3), MB(3, 4)), infer(MA(2, 3), MB(4, 3), result=InferenceError), infer(MA(2, 3), MB(3, 4)[1], result=InferenceError), infer(MA(2, 3), MB(3, 4), MA(2, 2), result=InferenceError), ) def test_einsum_mm(a, b): return einsum("ij,jk->ik", a, b) @run_debug(MA(2, 3), MB(4, 3)) def test_einsum_inner2d(a, b): return einsum("ij,kj->ik", a, b) @run_debug(MA(2, 3), MB(4, 3)) def test_einsum_rowmul(a, b): return einsum("ij,kj->ikj", a, b)
from myia.testing.common import Ty, af16_of, af64_of, ai16_of, ai32_of, au64_of from myia.testing.multitest import infer, mt, run from myia.utils.errors import MyiaTypeError from myia.xtype import f64, i32, i64 from .examples.operations import composite_full, composite_simple def Shp(*values): """Convert values to a tuple of numpy unsigned integers.""" return tuple(np.uint64(value) for value in values) @mt( # An error should be raised if wrong values are given as types. infer(Shp(2, 3), i32, "bad string", result=MyiaTypeError), 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(
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))
from myia.operations import ( make_handle, typeof, universe_getitem, universe_setitem, ) from myia.testing.common import H, f64, i64 from myia.testing.multitest import infer, mt, run_debug from myia.utils import HandleInstance, InferenceError, new_universe from myia.xtype import EnvType, UniverseType @mt( infer(UniverseType, i64, result=H(i64)), infer(UniverseType, (i64, f64), result=H((i64, f64))), ) def test_make_handle(U, x): return make_handle(typeof(x), U)[1] @mt( infer(UniverseType, H(i64), result=i64), infer(EnvType, H(i64), result=InferenceError), infer(UniverseType, i64, result=InferenceError), ) def test_universe_getitem(U, h): return universe_getitem(U, h) @mt( infer(UniverseType, H(i64), i64, result=UniverseType),
ai32_of, ai64_of, au64_of, ) 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):