code: def sample(
      image: type_alias.TensorLike,
      warp: type_alias.TensorLike,
      resampling_type: ResamplingType = ResamplingType.BILINEAR,
      border_type: BorderType = BorderType.ZERO,
      pixel_type: PixelType = PixelType.HALF_INTEGER,
      name: Optional[str] = "sample",
  ) -> tf.Tensor:
      """Samples an image at user defined coordinates.
  
      Note:
        The warp maps target to source. In the following, A1 to An are optional
        batch dimensions.
  
      Args:
        image: A tensor of shape `[B, H_i, W_i, C]`, where `B` is the batch size,
          `H_i` the height of the image, `W_i` the width of the image, and `C` the
          number of channels of the image.
        warp: A tensor of shape `[B, A_1, ..., A_n, 2]` containing the x and y
          coordinates at which sampling will be performed. The last dimension must
          be 2, representing the (x, y) coordinate where x is the index for width
          and y is the index for height.
       resampling_type: Resampling mode. Supported values are
         `ResamplingType.NEAREST` and `ResamplingType.BILINEAR`.
        border_type: Border mode. Supported values are `BorderType.ZERO` and
          `BorderType.DUPLICATE`.
        pixel_type: Pixel mode. Supported values are `PixelType.INTEGER` and
          `PixelType.HALF_INTEGER`.
        name: A name for this op. Defaults to "sample".
  
      Returns:
        Tensor of sampled values from `image`. The output tensor shape
        is `[B, A_1, ..., A_n, C]`.
  
      Raises:
        ValueError: If `image` has rank != 4. If `warp` has rank < 2 or its last
        dimension is not 2. If `image` and `warp` batch dimension does not match.
      """
      with tf.name_scope(name):
          image = tf.convert_to_tensor(value=image, name="image")
          warp = tf.convert_to_tensor(value=warp, name="warp")
  
          shape.check_static(image, tensor_name="image", has_rank=4)
          shape.check_static(
              warp,
              tensor_name="warp",
              has_rank_greater_than=1,
              has_dim_equals=(-1, 2),
          )
          shape.compare_batch_dimensions(
              tensors=(image, warp),
              last_axes=0,
              broadcast_compatible=False,
          )
  
          if pixel_type == PixelType.HALF_INTEGER:
              warp -= 0.5
  
          if resampling_type == ResamplingType.NEAREST:
              warp = tf.math.round(warp)
  
          if border_type == BorderType.ZERO:
              image = tf.pad(image, ((0, 0), (1, 1), (1, 1), (0, 0)))
              warp = warp + 1
  
          warp_shape = tf.shape(warp)
          flat_warp = tf.reshape(warp, (warp_shape[0], -1, 2))
          flat_sampled = tfa_image.interpolate_bilinear(
              image, flat_warp, indexing="xy"
          )
          output_shape = tf.concat(
              (warp_shape[:-1], tf.shape(flat_sampled)[-1:]), 0
          )
          return tf.reshape(flat_sampled, output_shape)
  
file_path: graphics/tensorflow_graphics/image/transformer.py
imports: import enum
  from typing import Optional
  from six.moves import range
  import tensorflow
  from tensorflow_addons import image
  from tensorflow_graphics.geometry.representation import grid
  from tensorflow_graphics.util import export_api
  from tensorflow_graphics.util import shape
  from tensorflow_graphics.util import type_alias
label_desc: Use image node_id 1 for calling a global function with example usage: sample(image, warp, resampling_type, border_type, pixel_type, name) and returns: tf