ymwangg commented on a change in pull request #7441:
URL: https://github.com/apache/tvm/pull/7441#discussion_r579580281
##########
File path: tests/python/relay/test_op_level3.py
##########
@@ -1453,5 +1453,53 @@ def verify_scatter_nd_with_stack(data_np, indices_np,
shape, ref_res, rtol=1e-5,
verify_scatter_nd_with_stack(data, indices, shape, out)
[email protected]_gpu
+def test_unique():
+ def calc_numpy_unique(data, is_sorted=False):
+ uniq, index, inverse, counts = np.unique(
+ data, return_index=True, return_inverse=True, return_counts=True
+ )
+ num_uniq = np.array([len(uniq)]).astype("int32")
+ if not is_sorted:
+ order = np.argsort(index)
+ reverse_order = np.argsort(order)
+ uniq = uniq[order].astype(data.dtype)
+ inverse = np.array([reverse_order[i] for i in
inverse]).astype("int32")
+ counts = counts[order].astype("int32")
+ return [uniq.astype(data.dtype), inverse.astype("int32"), counts,
num_uniq]
+
+ def verify_unique(n, dtype, is_dyn=False, is_sorted=False):
+ if is_dyn:
+ x = relay.var("x", relay.TensorType([relay.Any()], dtype))
+ else:
+ x = relay.var("x", relay.TensorType([n], dtype))
+ outs = relay.unique(x, is_sorted)
+ outs = outs.astuple()
+ func = relay.Function([x], outs)
+ x_data = np.random.randint(50, size=n).astype(dtype)
+
+ if is_dyn:
+ backends = ["vm", "debug"]
+ else:
+ backends = ["graph", "debug"]
+ for target, ctx in tvm.testing.enabled_targets():
Review comment:
thanks, will fix it.
----------------------------------------------------------------
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]