code: def test_random_erase_forward(
      ctx,
      func_name,
      seed,
      prob,
      area_ratios,
      aspect_ratios,
      replacements,
      n,
      share,
      inplace,
      base_axis,
      func_seed,
      channel_last,
  ):
      if channel_last and func_name == "RandomErase":
          pytest.skip(
              "RandomErase with channel_last is only supported in CUDA."
          )
  
      lb = replacements[0]
      rng = np.random.RandomState(seed)
      b, c, h, w = 4, 3, 32, 32
      ishape = [b, h, w, c] if channel_last else [b, c, h, w]
      x = nn.Variable.from_numpy_array(rng.rand(*ishape) + 1.0)
      with nn.context_scope(ctx):
          y0 = F.random_erase(
              x,
              prob=prob,
              area_ratios=area_ratios,
              aspect_ratios=aspect_ratios,
              replacements=replacements,
              n=n,
              share=share,
              inplace=inplace,
              base_axis=base_axis,
              seed=func_seed,
              channel_last=channel_last,
          )
      # Deterministic check
      y0.forward()
      if prob == 1.0:
          assert np.any(y0.d >= lb)
  
      # Random but with same seed check
      if func_seed != -1:
          with nn.context_scope(ctx):
              y1 = F.random_erase(
                  x,
                  prob=prob,
                  area_ratios=area_ratios,
                  aspect_ratios=aspect_ratios,
                  replacements=replacements,
                  n=n,
                  share=share,
                  inplace=inplace,
                  base_axis=base_axis,
                  seed=func_seed,
                  channel_last=channel_last,
              )
          y1.forward()
          assert_allclose(y0.d, y1.d)
  
      # Random but with different seed check
      with nn.context_scope(ctx):
          y2 = F.random_erase(
              x,
              prob=prob,
              area_ratios=area_ratios,
              aspect_ratios=aspect_ratios,
              replacements=replacements,
              n=n,
              share=share,
              inplace=inplace,
              base_axis=base_axis,
              seed=func_seed + 2,
              channel_last=channel_last,
          )
      y2.forward()
      assert np.any(y0.d != y2.d)
  
file_path: nnabla/python/test/function/test_random_erase.py
imports: import pytest
  import numpy
  import nnabla
  import nnabla.functions
  from test_flip import ref_flip
  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_erase_forward(ctx, func_name, seed, prob, area_ratios, aspect_ratios, replacements, n, share, inplace, base_axis, func_seed, channel_last) without return types