code: def test_random_shift_forward_backward(
      seed, inshape, shifts, border_mode, constant_value, ctx, func_name
  ):
      from nbla_test_utils import function_tester
  
      rng = np.random.RandomState(seed)
      inputs = [rng.randn(*inshape).astype(np.float32)]
      i = nn.Variable(inputs[0].shape, need_grad=True)
      i.d = inputs[0]
      # NNabla forward
      with nn.context_scope(ctx), nn.auto_forward():
          o = F.random_shift(
              i, shifts, border_mode, constant_value, 0, seed
          )
      result_shifts = (0, 0, 0)
      max_correl = 0
      for shift_amount in itertools.product(
          *map(
              tuple,
              map(
                  lambda x: range(*x),
                  [(-2, 3) for _ in range(len(inshape))],
              ),
          )
      ):
          r = scipy_shift(
              inputs[0],
              shift_amount,
              mode=border_mode,
              cval=constant_value,
          )
          correl_and_p = pearsonr(o.d.flatten(), r.flatten())
          if correl_and_p[0] > max_correl:
              result_shifts = shift_amount
              max_correl = correl_and_p[0]
      ref = scipy_shift(
          inputs[0],
          result_shifts,
          mode=border_mode,
          cval=constant_value,
      )
      if shifts is None:
          shifts = (0,) * len(inputs[0].shape)
      for result, shift_range in zip(result_shifts, shifts):
          assert abs(result) <= shift_range
  
      assert_allclose(o.d, ref)
      assert o.parent.name == func_name
  
      # Skipping Backward check
      g = np.random.randn(*i.shape)
      i.g = g
      o_grad = np.random.randn(*o.shape)
      o.g = o_grad
      o.parent.backward([i], [o])
      ref_grad = i.g.copy() - g
  
      # Check accum=False with NaN gradient
      i.g = np.float32("nan")
      o.parent.backward([i], [o], [False])
      assert not np.any(np.isnan(i.g))
  
      # Check if accum option works
      i.g[...] = 1
      o.g = o_grad
      o.parent.backward([i], [o], [False])
      assert_allclose(i.g, ref_grad, atol=1e-6)
  
      # Check if need_grad works
      i.g[...] = 0
      i.need_grad = False
      o_grad = rng.randn(*i.shape).astype(i.data.dtype)
      o.backward(o_grad)
      assert np.all(i.g == 0)
  
file_path: nnabla/python/test/function/test_random_shift.py
imports: import pytest
  import itertools
  import numpy
  from scipy.ndimage.interpolation import shift
  from scipy.stats import pearsonr
  import nnabla
  import nnabla.functions
  from nbla_test_utils import list_context
  from nnabla.testing import assert_allclose
label_desc: Use image node_id 1 for calling a global function with example usage: test_random_shift_forward_backward(seed, inshape, shifts, border_mode, constant_value, ctx, func_name) without return types