code: def _forward(self, inputs):
      x, grid = inputs
      xp = backend.get_array_module(x)
      B, C, H, W = x.shape
      _, _, out_H, out_W = grid.shape
  
      grid = grid.reshape(grid.shape[:2] + (-1,))
  
      u = grid[:, 0]
      v = grid[:, 1]
  
      # Pad the image so that pixels locating outside of the original
      # image's size can be sampled.
      x_pad = xp.pad(
          x, ((0, 0), (0, 0), (1, 1), (1, 1)), mode="constant"
      )
  
      # Rescale coordinates from [-1, 1] to [0, width or height - 1],
      # and adjust them to the padded image.
      u = (u + 1) * (W - 1) / 2 + 1
      v = (v + 1) * (H - 1) / 2 + 1
  
      u_clipped = u.clip(0, W + 1)
      v_clipped = v.clip(0, H + 1)
  
      # indices of the 2x2 pixel neighborhood surrounding the coordinates
      u0 = xp.floor(u_clipped).astype(numpy.int32)
      u0 = u0.clip(0, W)
      u1 = u0 + 1
      v0 = xp.floor(v_clipped).astype(numpy.int32)
      v0 = v0.clip(0, H)
      v1 = v0 + 1
  
      # weights
      w1 = (u1 - u_clipped) * (v1 - v_clipped)
      w2 = (u_clipped - u0) * (v1 - v_clipped)
      w3 = (u1 - u_clipped) * (v_clipped - v0)
      w4 = (u_clipped - u0) * (v_clipped - v0)
      w1 = w1.astype(x_pad.dtype, copy=False)
      w2 = w2.astype(x_pad.dtype, copy=False)
      w3 = w3.astype(x_pad.dtype, copy=False)
      w4 = w4.astype(x_pad.dtype, copy=False)
  
      x_indexed_1 = xp.concatenate(
          [
              xp.expand_dims(x_pad[b, :, v0[b], u0[b]], axis=0)
              for b in range(B)
          ],
          axis=0,
      )
      x_indexed_2 = xp.concatenate(
          [
              xp.expand_dims(x_pad[b, :, v0[b], u1[b]], axis=0)
              for b in range(B)
          ],
          axis=0,
      )
      x_indexed_3 = xp.concatenate(
          [
              xp.expand_dims(x_pad[b, :, v1[b], u0[b]], axis=0)
              for b in range(B)
          ],
          axis=0,
      )
      x_indexed_4 = xp.concatenate(
          [
              xp.expand_dims(x_pad[b, :, v1[b], u1[b]], axis=0)
              for b in range(B)
          ],
          axis=0,
      )
      y = w1[:, :, None] * x_indexed_1
      y += w2[:, :, None] * x_indexed_2
      y += w3[:, :, None] * x_indexed_3
      y += w4[:, :, None] * x_indexed_4
  
      y = y.reshape(B, out_H, out_W, C).transpose(0, 3, 1, 2)
      return (y,)
  
file_path: chainer/chainer/functions/array/spatial_transformer_sampler.py
imports: import numpy
  import chainer
  from chainer import backend
  from chainer.backends import cuda
  from chainer import function
  from chainer.utils import argument
  from chainer.utils import type_check
label_desc: Use image node_id 4 for calling the SpatialTransformerSampler obj's underlying member method code with example usage: obj._forward(inputs) and returns: y