code: def test_forward_backward(
      seed,
      ishape,
      k,
      abs,
      reduce,
      base_axis,
      largest,
      with_index,
      ctx,
      fname,
  ):
      # Use unique random numbers because sorting algorithm for top-k
      # is not stable.
      rng = np.random.RandomState(seed)
      n = np.prod(ishape)
      x = np.arange(n)
      x[np.arange(n, step=2)] *= -1  # Negate even number
      rng.shuffle(x)
      x = x.reshape(ishape).astype(np.float32)
  
      ref_grad = (
          ref_top_k_data_bw_with_index
          if with_index
          else ref_top_k_data_bw
      )
      function_tester(
          rng,
          F.top_k_data,
          ref_top_k_data_fw,
          [x],
          ctx=ctx,
          func_name=fname,
          ref_grad=ref_grad,
          func_args=[k, abs, reduce, base_axis, largest, with_index],
          disable_half_test=k > 10,
      )
  
file_path: nnabla/python/test/function/test_top_k_data.py
imports: import pytest
  import numpy
  import nnabla.functions
  from nbla_test_utils import list_context, function_tester
label_desc: Use image node_id 5 for calling a global function with example usage: test_forward_backward(seed, ishape, k, abs, reduce, base_axis, largest, with_index, ctx, fname) without return types