From 3f796602921c948a0e2ca517b7f0046acaa9fdc9 Mon Sep 17 00:00:00 2001 From: ANSHUMAN TRIPATHY Date: Thu, 12 Mar 2020 22:20:13 +0530 Subject: [PATCH] [1] Test case modified for int type (#5012) --- tests/python/relay/test_op_level4.py | 60 +++++++++++++++++++--------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/tests/python/relay/test_op_level4.py b/tests/python/relay/test_op_level4.py index 473ae59a9dbe..bbe2c69d6294 100644 --- a/tests/python/relay/test_op_level4.py +++ b/tests/python/relay/test_op_level4.py @@ -88,33 +88,54 @@ def test_cmp_type(): 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), - (relay.left_shift, np.left_shift), - (relay.mod, np.mod), - (relay.maximum, np.maximum), - (relay.minimum, np.minimum)]: + (relay.left_shift, np.left_shift)]: 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.rand(*x_shape).astype(t1.dtype) - y_data = np.random.rand(*y_shape).astype(t2.dtype) - func = relay.Function([x, y], z) - ref_res = ref(x_data, y_data) + 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, 31, 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) + 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_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(): shape = (3, 4) @@ -341,7 +362,8 @@ def verify(dshape, begin, end, strides, vshape, test_ref=True): test_strided_set() test_binary_op() test_cmp_type() - test_binary_int_broadcast() + test_binary_int_broadcast_1() + test_binary_int_broadcast_2() test_where() test_reduce_functions() test_mean_var_std()