code: def test_nd_array_narrow_get_cast(self, ctx_name):
      self.try_to_set_ctx(ctx_name)
  
      a = nn.NdArray(2, 2)
      a.fill(3)
      a = F.identity(a)
  
      b = a.narrow(0, 0, 1)
      c = b.narrow(0, 0, 1)
  
      assert (a.get_data(mode="r") == np.full([2, 2], 3)).all()
      assert (b.get_data(mode="r") == np.full([1, 2], 3)).all()
      assert (c.get_data(mode="r") == np.full([1, 2], 3)).all()
  
      # get_data with type conversion is allowed only when read-only-mode.
      b.get_data(mode="r", dtype=np.float16)
      c.get_data(mode="r", dtype=np.float16)
  
      with pytest.raises(RuntimeError):
          b.get_data(mode="rw", dtype=np.float16)
  
      with pytest.raises(RuntimeError):
          c.get_data(mode="rw", dtype=np.float16)
  
      # Check the change is reflected in parent array after cast.
      # Only the same dtype of cast for narrow array is allowed.
      b.cast(dtype=np.float32, ctx=nn.get_current_context())
      b += 1
      assert (a.get_data(mode="r") == np.array([[4, 4], [3, 3]])).all()
  
      c.cast(dtype=np.float32, ctx=nn.get_current_context())
      c += 1
      assert (a.get_data(mode="r") == np.array([[5, 5], [3, 3]])).all()
  
      with pytest.raises(RuntimeError):
          b.cast(dtype=np.float16)
  
      with pytest.raises(RuntimeError):
          c.cast(dtype=np.float16)
  
      assert a.dtype == np.float32
      assert b.dtype == np.float32
      assert c.dtype == np.float32
  
      # cast for parent array is allowed.
      a.cast(dtype=np.float16)
      assert a.dtype == np.float16
  
      # If parent array is cast, dtype in narrow array also changes.
      assert b.dtype == np.float16
      assert c.dtype == np.float16
  
      # Value of `a` remains the same and the parent-child relationship is maintained.
      assert (a.data == np.array([[5, 5], [3, 3]])).all()
      b.fill(0)
      assert (a.data == np.array([[0, 0], [3, 3]])).all()
      assert (c.data == np.array([[0, 0]])).all()
  
imports: import numpy
  import nnabla
  import pytest
  from nnabla.ext_utils import get_extension_context
  import nnabla.functions
label_desc: Use image node_id 7 for calling the TestNdArrayNarrow obj's underlying member method code with example usage: obj.test_nd_array_narrow_get_cast(ctx_name) without return types