Unverified Commit 923b4a26 by ANSHUMAN TRIPATHY Committed by GitHub

[1] Test case modified for int type (#5012)

parent 173b4fc4
...@@ -88,33 +88,54 @@ def test_cmp_type(): ...@@ -88,33 +88,54 @@ def test_cmp_type():
tvm.testing.assert_allclose(op_res.asnumpy(), ref_res) tvm.testing.assert_allclose(op_res.asnumpy(), ref_res)
def test_binary_int_broadcast(): def test_binary_int_broadcast_1():
for op, ref in [(relay.right_shift, np.right_shift), for op, ref in [(relay.right_shift, np.right_shift),
(relay.left_shift, np.left_shift), (relay.left_shift, np.left_shift)]:
(relay.mod, np.mod),
(relay.maximum, np.maximum),
(relay.minimum, np.minimum)]:
x = relay.var("x", relay.TensorType((10, 4), "int32")) x = relay.var("x", relay.TensorType((10, 4), "int32"))
y = relay.var("y", relay.TensorType((5, 10, 1), "int32")) y = relay.var("y", relay.TensorType((5, 10, 1), "int32"))
z = op(x, y) z = op(x, y)
zz = run_infer_type(z) zz = run_infer_type(z)
assert zz.checked_type == relay.TensorType((5, 10, 4), "int32") assert zz.checked_type == relay.TensorType((5, 10, 4), "int32")
if ref is not None: if ref is not None:
x_shape = (10, 4) x_shape = (10, 4)
y_shape = (5, 10, 1) y_shape = (5, 10, 1)
t1 = relay.TensorType(x_shape, 'int32') t1 = relay.TensorType(x_shape, 'int32')
t2 = relay.TensorType(y_shape, 'int32') t2 = relay.TensorType(y_shape, 'int32')
x_data = np.random.rand(*x_shape).astype(t1.dtype) x_data = np.random.randint(1, 10000, size=(x_shape)).astype(t1.dtype)
y_data = np.random.rand(*y_shape).astype(t2.dtype) y_data = np.random.randint(1, 31, size=(y_shape)).astype(t2.dtype)
func = relay.Function([x, y], z) func = relay.Function([x, y], z)
ref_res = ref(x_data, y_data) ref_res = ref(x_data, y_data)
for target, ctx in ctx_list(): for target, ctx in ctx_list():
intrp = relay.create_executor("graph", ctx=ctx, target=target) intrp = relay.create_executor("graph", ctx=ctx, target=target)
op_res = intrp.evaluate(func)(x_data, y_data) op_res = intrp.evaluate(func)(x_data, y_data)
tvm.testing.assert_allclose(op_res.asnumpy(), ref_res) tvm.testing.assert_allclose(op_res.asnumpy(), ref_res)
def test_binary_int_broadcast_2():
for op, ref in [(relay.maximum, np.maximum),
(relay.minimum, np.minimum),
(relay.mod, np.mod)]:
x = relay.var("x", relay.TensorType((10, 4), "int32"))
y = relay.var("y", relay.TensorType((5, 10, 1), "int32"))
z = op(x, y)
zz = run_infer_type(z)
assert zz.checked_type == relay.TensorType((5, 10, 4), "int32")
if ref is not None:
x_shape = (10, 4)
y_shape = (5, 10, 1)
t1 = relay.TensorType(x_shape, 'int32')
t2 = relay.TensorType(y_shape, 'int32')
x_data = np.random.randint(1, 10000, size=(x_shape)).astype(t1.dtype)
y_data = np.random.randint(1, 10000, size=(y_shape)).astype(t2.dtype)
func = relay.Function([x, y], z)
ref_res = ref(x_data, y_data)
for target, ctx in ctx_list():
intrp = relay.create_executor("graph", ctx=ctx, target=target)
op_res = intrp.evaluate(func)(x_data, y_data)
tvm.testing.assert_allclose(op_res.asnumpy(), ref_res)
def test_where(): def test_where():
shape = (3, 4) shape = (3, 4)
...@@ -341,7 +362,8 @@ if __name__ == "__main__": ...@@ -341,7 +362,8 @@ if __name__ == "__main__":
test_strided_set() test_strided_set()
test_binary_op() test_binary_op()
test_cmp_type() test_cmp_type()
test_binary_int_broadcast() test_binary_int_broadcast_1()
test_binary_int_broadcast_2()
test_where() test_where()
test_reduce_functions() test_reduce_functions()
test_mean_var_std() test_mean_var_std()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment