code: def test_topk(
      target, dev, topk, axis, topk_ret_type, is_ascend, dtype
  ):
      np.random.seed(0)
  
      shape = (20, 100)
      data_dtype = "float32"
      data = te.placeholder(shape, name="data", dtype=data_dtype)
  
      np_data = np.random.uniform(size=shape).astype(data_dtype)
      if is_ascend:
          np_indices = np.argsort(np_data, axis=axis)
      else:
          np_indices = np.argsort(-np_data, axis=axis)
      kk = topk if topk >= 1 else shape[axis]
      if axis == 0:
          np_indices = np_indices[:kk, :]
          np_values = np.zeros(np_indices.shape).astype(data_dtype)
          for i in range(shape[1]):
              np_values[:, i] = np_data[np_indices[:, i], i]
      else:
          np_indices = np_indices[:, :kk]
          np_values = np.zeros(np_indices.shape).astype(data_dtype)
          for i in range(shape[0]):
              np_values[i, :] = np_data[i, np_indices[i, :]]
      np_indices = np_indices.astype(dtype)
  
      with tvm.target.Target(target):
          fcompute, fschedule = tvm.topi.testing.dispatch(
              target, _topk_implement
          )
          outs = fcompute(
              data, topk, axis, topk_ret_type, is_ascend, dtype
          )
          outs = outs if isinstance(outs, list) else [outs]
          s = fschedule(outs)
      tvm_data = tvm.nd.array(np_data, dev)
      tvm_res = []
      for t in outs:
          tvm_res.append(
              tvm.nd.empty(t.shape, dtype=t.dtype, device=dev)
          )
      f = tvm.build(s, [data] + outs, target)
      f(tvm_data, *tvm_res)
      if topk_ret_type == "both":
          tvm.testing.assert_allclose(tvm_res[0].numpy(), np_values)
          tvm.testing.assert_allclose(tvm_res[1].numpy(), np_indices)
      elif topk_ret_type == "values":
          tvm.testing.assert_allclose(tvm_res[0].numpy(), np_values)
      else:
          tvm.testing.assert_allclose(tvm_res[0].numpy(), np_indices)
  
file_path: tvm/tests/python/topi/test_topi_sort.py
imports: import sys
  import numpy
  import pytest
  import tvm
  import tvm.testing
  import tvm.topi.testing
  from tvm import te, topi
label_desc: Use image node_id 3 for calling a global function with example usage: test_topk(target, dev, topk, axis, topk_ret_type, is_ascend, dtype) without return types