code: def test_bool_scatter_inplace(
      seed, ctx, func_name, gshape, mask_shape
  ):
      from nbla_test_utils import inplace_function_test_helper
  
      rng = np.random.RandomState(seed)
      gdata0 = rng.randn(*gshape).astype(np.float32)
      mask = rng.randint(0, 2, size=mask_shape)
      sdata = gdata0[mask.astype(bool)]
      gdata1 = rng.randn(*gshape).astype(np.float32)
  
      v_sdata = nn.Variable.from_numpy_array(sdata).apply(
          need_grad=True
      )
      v_mask = nn.Variable.from_numpy_array(mask)
      v_gdata1 = nn.Variable.from_numpy_array(gdata1).apply(
          need_grad=True
      )
  
      with nn.auto_forward():
          v_gdata2 = F.bool_scatter(v_sdata, v_mask, v_gdata1)
  
      # inplace check
      np.testing.assert_allclose(
          v_gdata2.d,
          v_gdata1.d,
          err_msg="F.bool_scatter(inplace) is not inplaced.",
      )
  
      # ref check
      gdata2 = ref_bool_scatter_inplace(sdata, mask, gdata1)
      np.testing.assert_allclose(
          v_gdata2.d, gdata2, err_msg="F.bool_scatter(inplace) fails."
      )
  
      # backward wrt inplaced variable (wrt sdata is checked in not-inplaced case)
      egrad = rng.randn(*gdata2.shape)
      mask = (
          mask
          if mask.shape == gdata1.shape
          else mask.reshape(
              mask.shape + (1,) * (gdata1.ndim - mask.ndim)
          )
      )
      ref_grad = egrad * (1 - mask)
      v_gdata1.grad.fill(0)
      v_gdata2.backward(egrad)
      np.testing.assert_allclose(
          v_gdata1.g,
          ref_grad,
          err_msg="F.bool_scatter(inplace) backward wrt inplace data fails.",
      )
  
      bgrad = rng.randn(*gdata1.shape)
      v_gdata1.g = bgrad
      v_gdata2.backward(egrad)
      np.testing.assert_allclose(
          v_gdata1.g - bgrad,
          ref_grad,
          atol=1e-6,
          err_msg="F.bool_scatter(inplace) backward (accum) wrt inplace data fails.",
      )
  
      # nn.grad (wrt sdata is checked in not-inplaced case)
      with nn.auto_forward():
          d_gdata1 = nn.grad(
              [v_gdata2], [v_gdata1], grad_outputs=[egrad]
          )
      np.testing.assert_allclose(
          d_gdata1[0].d,
          ref_grad,
          atol=1e-6,
          err_msg="nn.grad (F.bool_scatter(inplace)) wrt inplace data fails.",
      )
  
file_path: nnabla/python/test/function/test_bool_scatter.py
imports: import pytest
  import numpy
  import nnabla
  import nnabla.functions
  from nbla_test_utils import list_context
label_desc: Use image node_id 5 for calling a global function with example usage: test_bool_scatter_inplace(seed, ctx, func_name, gshape, mask_shape) without return types