siju-samuel commented on a change in pull request #5495:
URL: https://github.com/apache/incubator-tvm/pull/5495#discussion_r439784162



##########
File path: tests/python/frontend/tflite/test_forward.py
##########
@@ -1679,48 +1564,6 @@ def test_forward_squeeze():
     _test_squeeze(np.arange(6).reshape((2, 1, 3, 1)), [1, 3])
 
 
-#######################################################################
-# Quantize/DeQuantize
-# -------------------
-
-def _test_quantize_dequantize(data):

Review comment:
       _test_quantize_dequantize also missed during conflict resolve?

##########
File path: tests/python/frontend/tflite/test_forward.py
##########
@@ -901,79 +859,6 @@ def test_all_resize():
     if 'RESIZE_NEAREST_NEIGHBOR' in dir(BuiltinOperator()):
         _test_resize(tf.image.resize_nearest_neighbor, data, 
align_corners=False)
 
-#######################################################################
-# Range
-# -----
-def _test_range(start, limit, delta):

Review comment:
       _test_range why removed?  i think this is lost during resolving conflict.

##########
File path: tests/python/frontend/tflite/test_forward.py
##########
@@ -2498,9 +2362,10 @@ def test_forward_mediapipe_hand_landmark():
     test_forward_stridedslice()
     test_forward_depthtospace()
     test_forward_spacetodepth()
+    if package_version.parse(tf.VERSION) >= package_version.parse('1.14.0'):

Review comment:
       Move this check inside `test_forward_reverse_sequence` 

##########
File path: tests/python/relay/test_op_level3.py
##########
@@ -663,6 +663,73 @@ def verify_reverse(dshape, axis):
     verify_reverse((2, 3, 4), -1)
 
 
+def test_reverse_sequence():
+    def verify_reverse_sequence(x_data, seq_lengths, batch_axis, seq_axis, 
ref_res):
+        seq_lengths_data = np.array(seq_lengths).astype("int32")
+        x = relay.var("x", relay.TensorType(x_data.shape, str(x_data.dtype)))
+        z = relay.reverse_sequence(x, relay.const(seq_lengths_data), seq_axis, 
batch_axis)
+        zz = run_infer_type(z)
+        assert zz.checked_type == x.type_annotation
+        func = relay.Function([x], z)
+
+        for target, ctx in ctx_list():
+            for kind in ["graph", "debug"]:
+                intrp = relay.create_executor(kind, ctx=ctx, target=target)
+                op_res = intrp.evaluate(func)(x_data)
+                tvm.testing.assert_allclose(op_res.asnumpy(), ref_res, 
rtol=1e-5)
+
+    indata = np.array(np.arange(0, 16)).reshape([4, 4]).astype("int32")
+    result = [[0, 5, 10, 15],
+              [4, 1, 6, 11],
+              [8, 9, 2, 7],
+              [12, 13, 14, 3]]
+    verify_reverse_sequence(indata, [1, 2, 3, 4], 1, 0, np.array(result))
+    verify_reverse_sequence(indata, [1, 2, 3, 4], -1, 0, np.array(result))
+    verify_reverse_sequence(indata.astype("float32"), [1, 2, 3, 4], 1, 0, 
np.array(result).astype("float32"))
+
+    indata = np.array(np.arange(0, 16)).reshape([4, 4]).astype("int32")
+    result = [[0, 1, 2, 3],
+              [5, 4, 6, 7],
+              [10, 9, 8, 11],
+              [15, 14, 13, 12]]
+    verify_reverse_sequence(indata, [1, 2, 3, 4], 0, 1, np.array(result))
+    verify_reverse_sequence(indata, [1, 2, 3, 4], 0, -1, np.array(result))
+    verify_reverse_sequence(indata.astype("float32"), [1, 2, 3, 4], 0, 1, 
np.array(result).astype("float32"))
+
+    indata = np.array(np.arange(0, 16)).reshape([4, 4]).astype("int32")
+    result = [[0, 1, 2, 3],
+              [4, 5, 6, 7],
+              [8, 9, 10, 11],
+              [15, 14, 13, 12]]
+    verify_reverse_sequence(indata, [-1, 0, 1, 5], 0, 1, np.array(result))
+
+    indata = np.array(np.arange(0, 54)).reshape([2, 3, 3, 3]).astype("int32")
+    result = [[[[18, 19, 20], [21, 22, 23], [24, 25, 26]],
+               [[9, 10, 11], [12, 13, 14], [15, 16, 17]],
+               [[0,  1,  2], [3,  4,  5], [6,  7,  8]]],
+              [[[45, 46, 47], [48, 49, 50], [51, 52, 53]],
+               [[36, 37, 38], [39, 40, 41], [42, 43, 44]],
+               [[27, 28, 29], [30, 31, 32], [33, 34, 35]]]]
+    verify_reverse_sequence(indata, [3, 3], 0, 1, np.array(result))
+
+    indata = np.array(np.arange(0, 54)).reshape([2, 3, 3, 3]).astype("int32")
+    result = [[[[9, 10, 11], [21, 22, 23], [15, 16, 17]],
+               [[0, 1, 2], [12, 13, 14], [6, 7, 8]],
+               [[18, 19, 20], [3, 4, 5], [24, 25, 26]]],
+              [[[36, 37, 38], [48, 49, 50], [42, 43, 44]],
+               [[27, 28, 29], [39, 40, 41], [33, 34, 35]],
+               [[45, 46, 47], [30, 31, 32], [51, 52, 53]]]]
+    verify_reverse_sequence(indata, [2, 3, 2], 2, 1, np.array(result))
+
+    indata = np.array(np.arange(0, 16)).reshape([4, 4]).astype("int32")
+    result = []
+    with pytest.raises(Exception) as exexcinfo:

Review comment:
       exexcinfo > execinfo

##########
File path: topi/tests/python/test_topi_transform.py
##########
@@ -289,6 +290,85 @@ def check_device(device):
     for device in ["llvm", "cuda", "opencl", "sdaccel", "aocl_sw_emu"]:
         check_device(device)
 
+
+def test_reverse_sequence():
+    def verify_reverse_sequence(in_data, seq_lengths, batch_axis, seq_axis, 
ref_res):
+        seq_lengths = np.array(seq_lengths).astype("int32")
+        A = te.placeholder(shape=in_data.shape, name="A", 
dtype=str(in_data.dtype))
+        B = te.placeholder(shape=seq_lengths.shape, name="B", 
dtype=str(seq_lengths.dtype))
+        C = topi.reverse_sequence(A, B, seq_axis, batch_axis)
+
+        def check_device(device):
+            ctx = tvm.context(device, 0)
+            if not ctx.exist:
+                print("Skip because %s is not enabled" % device)
+                return
+            print("Running on target: %s" % device)
+            with tvm.target.create(device):
+                s = topi.testing.get_injective_schedule(device)(C)
+
+            foo = tvm.build(s, [A, B, C], device, name="reverse_sequence")
+
+            data_nd = tvm.nd.array(in_data, ctx)
+            seq_lengths_nd = tvm.nd.array(seq_lengths, ctx)
+            out_nd = tvm.nd.empty(in_data.shape, ctx=ctx, dtype=A.dtype)
+            foo(data_nd, seq_lengths_nd, out_nd)
+            tvm.testing.assert_allclose(out_nd.asnumpy(), ref_res)
+
+        for device in get_all_backend():
+            check_device(device)
+
+    indata = np.array(np.arange(0, 16)).reshape([4, 4]).astype("int32")
+    result = [[0, 5, 10, 15],
+              [4, 1, 6, 11],
+              [8, 9, 2, 7],
+              [12, 13, 14, 3]]
+    verify_reverse_sequence(indata, [1, 2, 3, 4], 1, 0, np.array(result))
+    verify_reverse_sequence(indata, [1, 2, 3, 4], -1, 0, np.array(result))
+    verify_reverse_sequence(indata.astype("float32"), [1, 2, 3, 4], 1, 0, 
np.array(result).astype("float32"))
+
+    indata = np.array(np.arange(0, 16)).reshape([4, 4]).astype("int32")
+    result = [[0, 1, 2, 3],
+              [5, 4, 6, 7],
+              [10, 9, 8, 11],
+              [15, 14, 13, 12]]
+    verify_reverse_sequence(indata, [1, 2, 3, 4], 0, 1, np.array(result))
+    verify_reverse_sequence(indata, [1, 2, 3, 4], 0, -1, np.array(result))
+    verify_reverse_sequence(indata.astype("float32"), [1, 2, 3, 4], 0, 1, 
np.array(result).astype("float32"))
+
+    indata = np.array(np.arange(0, 16)).reshape([4, 4]).astype("int32")
+    result = [[0, 1, 2, 3],
+              [4, 5, 6, 7],
+              [8, 9, 10, 11],
+              [15, 14, 13, 12]]
+    verify_reverse_sequence(indata, [-1, 0, 1, 5], 0, 1, np.array(result))
+
+    indata = np.array(np.arange(0, 54)).reshape([2, 3, 3, 3]).astype("int32")
+    result = [[[[18, 19, 20], [21, 22, 23], [24, 25, 26]],
+               [[9, 10, 11], [12, 13, 14], [15, 16, 17]],
+               [[0,  1,  2], [3,  4,  5], [6,  7,  8]]],
+              [[[45, 46, 47], [48, 49, 50], [51, 52, 53]],
+               [[36, 37, 38], [39, 40, 41], [42, 43, 44]],
+               [[27, 28, 29], [30, 31, 32], [33, 34, 35]]]]
+    verify_reverse_sequence(indata, [3, 3], 0, 1, np.array(result))
+
+    indata = np.array(np.arange(0, 54)).reshape([2, 3, 3, 3]).astype("int32")
+    result = [[[[9, 10, 11], [21, 22, 23], [15, 16, 17]],
+               [[0, 1, 2], [12, 13, 14], [6, 7, 8]],
+               [[18, 19, 20], [3, 4, 5], [24, 25, 26]]],
+              [[[36, 37, 38], [48, 49, 50], [42, 43, 44]],
+               [[27, 28, 29], [39, 40, 41], [33, 34, 35]],
+               [[45, 46, 47], [30, 31, 32], [51, 52, 53]]]]
+    verify_reverse_sequence(indata, [2, 3, 2], 2, 1, np.array(result))
+
+    indata = np.array(np.arange(0, 16)).reshape([4, 4]).astype("int32")
+    result = []
+    with pytest.raises(Exception) as exexcinfo:

Review comment:
       exexcinfo > execinfo




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to