code: def pad(
      tens: Tensor,
      padding: Union[int, Tuple],
      fill: int = 0,
      padding_mode="constant",
  ) -> Tensor:
      r"""
          Pad the given image on all sides with specified padding mode and fill value.
  
      Args:
          tens (Tensor): image to be padded.
          padding (int or tuple): Padding on each border. If a single int is provided this
              is used to pad all borders. If tuple of length 2 is provided this is the padding
              on left/right and top/bottom respectively. If a tuple of length 4 is provided
              this is the padding for the left, top, right and bottom borders
              respectively.
          fill: Pixel fill value for constant fill. Default is 0. If a tuple of
              length 3, it is used to fill R, G, B channels respectively.
              This value is only used when the padding_mode is constant
          padding_mode: Type of padding. Should be: constant, edge, reflect or symmetric. Default is constant.
              - constant: pads with a constant value, this value is specified with fill
              - edge: pads with the last value on the edge of the image
              - reflect: pads with reflection of image (without repeating the last value on the edge)
                         padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
                         will result in [3, 2, 1, 2, 3, 4, 3, 2]
              - symmetric: pads with reflection of image (repeating the last value on the edge)
                           padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
                           will result in [2, 1, 1, 2, 3, 4, 4, 3]
  
      Returns:
          Tensor of shape ``(height, width, channels)``.
  
      """
      if not isinstance(padding, (tuple, list)):
          raise TypeError("Got inappropriate padding argument")
  
      if not isinstance(fill, (str, tuple)):
          raise TypeError("Got inappropriate fill argument")
  
      if not isinstance(padding_mode, str):
          raise TypeError("Got inappropriate padding_mode argument")
  
      if isinstance(padding, collections.Sequence) and len(
          padding
      ) not in [2, 4]:
          raise ValueError(
              f"Padding must be an int or a 2, or 4 element tuple, not a {len(padding)} element tuple"
          )
  
      assert padding_mode in [
          "constant",
          "edge",
          "reflect",
          "symmetric",
      ], "Padding mode should be either constant, edge, reflect or symmetric"
  
      if isinstance(padding, int):
          pad_left = pad_right = pad_top = pad_bottom = padding
  
      if (
          isinstance(padding, collections.Sequence)
          and len(padding) == 2
      ):
          pad_left = pad_right = padding[0]
          pad_top = pad_bottom = padding[1]
  
      if (
          isinstance(padding, collections.Sequence)
          and len(padding) == 4
      ):
          pad_left = padding[0]
          pad_top = padding[1]
          pad_right = padding[2]
          pad_bottom = padding[3]
  
          tens = cv.copyMakeBorder(
              tens,
              top=pad_top,
              bottom=pad_bottom,
              left=pad_left,
              right=pad_right,
              borderType=pad_to_str[padding_mode],
              value=fill,
          )
  
          return to_tensor(tens, override_checks=True)
  
imports: import numpy
  import cv2
  import random
  import collections
  from ..coreten import Tensor, to_tensor
  from .._internal import _check_target_size
  from ..globals import INTER_AREA, INTER_CUBIC, INTER_NEAREST, INTER_LINEAR
  from ..annotations import Union, Tuple, Optional
label_desc: Use image node_id 12 for calling a global function with example usage: pad(tens, padding, fill, padding_mode) and returns: to_tensor