parameters: (x, grid, name=None)
return_statement: return out
docstring: This operation samples input X by using bilinear interpolation based on
      flow field grid, which is usually generated by :code:`affine_grid` . The grid of
      shape [N, H, W, 2] is the concatenation of (x, y) coordinates
      with shape [N, H, W] each, where x is indexing the 4th dimension
      (in width dimension) of input data x and y is indexing the 3rd
      dimension (in height dimension), finally results is the bilinear
      interpolation value of 4 nearest corner points. The output tensor
      shape will be [N, C, H, W].
  
      .. code-block:: text
  
          Step 1:
          Get (x, y) grid coordinates and scale to [0, H-1/W-1].
  
          .. code-block:: text
  
              grid_x = 0.5 * (grid[:, :, :, 0] + 1) * (W - 1)
              grid_y = 0.5 * (grid[:, :, :, 1] + 1) * (H - 1)
  
          Step 2:
          Indices input data X with grid (x, y) in each [H, W] area, and bilinear
          interpolate point value by 4 nearest points.
  
            wn ------- y_n ------- en
            |           |           |
            |          d_n          |
            |           |           |
           x_w --d_w-- grid--d_e-- x_e
            |           |           |
            |          d_s          |
            |           |           |
            ws ------- y_s ------- wn
  
          x_w = floor(x)              // west side x coord
          x_e = x_w + 1               // east side x coord
          y_n = floor(y)              // north side y coord
          y_s = y_s + 1               // south side y coord
  
          d_w = grid_x - x_w          // distance to west side
          d_e = x_e - grid_x          // distance to east side
          d_n = grid_y - y_n          // distance to north side
          d_s = y_s - grid_y          // distance to south side
  
          wn = X[:, :, y_n, x_w]      // north-west point value
          en = X[:, :, y_n, x_e]      // north-east point value
          ws = X[:, :, y_s, x_w]      // south-east point value
          es = X[:, :, y_s, x_w]      // north-east point value
  
          output = wn * d_e * d_s + en * d_w * d_s
                 + ws * d_e * d_n + es * d_w * d_n
  
      Args:
          x(Variable): The input tensor, which is a 4-D tensor with shape
                       [N, C, H, W], N is the batch size, C is the channel
                       number, H and W is the feature height and width.
                       The data type is float32 or float64.
          grid(Variable): Input grid tensor of shape [N, H, W, 2]. The
                          data type is float32 or float64.
          name(str, optional): For detailed information, please refer
                               to :ref:`api_guide_Name`. Usually name is no need to set and
                               None by default.
  
      Returns:
          Variable: Output of shape [N, C, H, W] data samples input X
                    using bilnear interpolation based on input grid.
                    The data type is same as input tensor.
  
      Examples:
  
          .. code-block:: python
  
              import paddle.fluid as fluid
              import paddle.fluid as fluid
              import paddle
  
              paddle.enable_static()
              # use with affine_grid
              x = fluid.data(name='x', shape=[None, 10, 32, 32], dtype='float32')
              theta = fluid.layers.data(name='theta', shape=[2, 3], dtype='float32')
              grid = fluid.layers.affine_grid(theta=theta, out_shape=[3, 10, 32, 32])
              out = fluid.layers.grid_sampler(x=x, grid=grid)
function: def grid_sampler(x, grid, name=None):
      """
  
      This operation samples input X by using bilinear interpolation based on
      flow field grid, which is usually generated by :code:`affine_grid` . The grid of
      shape [N, H, W, 2] is the concatenation of (x, y) coordinates
      with shape [N, H, W] each, where x is indexing the 4th dimension
      (in width dimension) of input data x and y is indexing the 3rd
      dimension (in height dimension), finally results is the bilinear
      interpolation value of 4 nearest corner points. The output tensor
      shape will be [N, C, H, W].
  
      .. code-block:: text
  
          Step 1:
          Get (x, y) grid coordinates and scale to [0, H-1/W-1].
  
          .. code-block:: text
  
              grid_x = 0.5 * (grid[:, :, :, 0] + 1) * (W - 1)
              grid_y = 0.5 * (grid[:, :, :, 1] + 1) * (H - 1)
  
          Step 2:
          Indices input data X with grid (x, y) in each [H, W] area, and bilinear
          interpolate point value by 4 nearest points.
  
            wn ------- y_n ------- en
            |           |           |
            |          d_n          |
            |           |           |
           x_w --d_w-- grid--d_e-- x_e
            |           |           |
            |          d_s          |
            |           |           |
            ws ------- y_s ------- wn
  
          x_w = floor(x)              // west side x coord
          x_e = x_w + 1               // east side x coord
          y_n = floor(y)              // north side y coord
          y_s = y_s + 1               // south side y coord
  
          d_w = grid_x - x_w          // distance to west side
          d_e = x_e - grid_x          // distance to east side
          d_n = grid_y - y_n          // distance to north side
          d_s = y_s - grid_y          // distance to south side
  
          wn = X[:, :, y_n, x_w]      // north-west point value
          en = X[:, :, y_n, x_e]      // north-east point value
          ws = X[:, :, y_s, x_w]      // south-east point value
          es = X[:, :, y_s, x_w]      // north-east point value
  
          output = wn * d_e * d_s + en * d_w * d_s
                 + ws * d_e * d_n + es * d_w * d_n
  
      Args:
          x(Variable): The input tensor, which is a 4-D tensor with shape
                       [N, C, H, W], N is the batch size, C is the channel
                       number, H and W is the feature height and width.
                       The data type is float32 or float64.
          grid(Variable): Input grid tensor of shape [N, H, W, 2]. The
                          data type is float32 or float64.
          name(str, optional): For detailed information, please refer
                               to :ref:`api_guide_Name`. Usually name is no need to set and
                               None by default.
  
      Returns:
          Variable: Output of shape [N, C, H, W] data samples input X
                    using bilnear interpolation based on input grid.
                    The data type is same as input tensor.
  
      Examples:
  
          .. code-block:: python
  
              import paddle.fluid as fluid
              import paddle.fluid as fluid
              import paddle
  
              paddle.enable_static()
              # use with affine_grid
              x = fluid.data(name='x', shape=[None, 10, 32, 32], dtype='float32')
              theta = fluid.layers.data(name='theta', shape=[2, 3], dtype='float32')
              grid = fluid.layers.affine_grid(theta=theta, out_shape=[3, 10, 32, 32])
              out = fluid.layers.grid_sampler(x=x, grid=grid)
  
      """
      helper = LayerHelper("grid_sampler", **locals())
  
      check_variable_and_dtype(x, 'x', ['float32', 'float64'], 'grid_sampler')
      check_variable_and_dtype(grid, 'grid', ['float32', 'float64'],
                               'grid_sampler')
      if not isinstance(x, Variable):
          return ValueError("The x should be a Variable")
  
      if not isinstance(grid, Variable):
          return ValueError("The grid should be a Variable")
  
      out = helper.create_variable_for_type_inference(x.dtype)
      ipts = {'X': x, 'Grid': grid}
  
      attrs = {'use_cudnn': False} if core.is_compiled_with_rocm() else {}
  
      helper.append_op(
          type='grid_sampler', inputs=ipts, outputs={'Output': out}, attrs=attrs)
      return out
function_tokens: def grid_sampler ( x , grid , name = None ) : helper = LayerHelper ( "grid_sampler" , * * locals ( ) ) check_variable_and_dtype ( x , 'x' , [ 'float32' , 'float64' ] , 'grid_sampler' ) check_variable_and_dtype ( grid , 'grid' , [ 'float32' , 'float64' ] , 'grid_sampler' ) if not isinstance ( x , Variable ) : return ValueError ( "The x should be a Variable" ) if not isinstance ( grid , Variable ) : return ValueError ( "The grid should be a Variable" ) out = helper . create_variable_for_type_inference ( x . dtype ) ipts = { 'X' : x , 'Grid' : grid } attrs = { 'use_cudnn' : False } if core . is_compiled_with_rocm ( ) else { } helper . append_op ( type = 'grid_sampler' , inputs = ipts , outputs = { 'Output' : out } , attrs = attrs ) return out