code: def warp_affine(
      src: Tensor,
      M: Tensor,
      dsize: tuple[int, int],
      mode: str = "bilinear",
      padding_mode: str = "zeros",
      align_corners: bool = True,
      fill_value: Tensor = zeros(3),  # needed for jit
  ) -> Tensor:
      r"""Apply an affine transformation to a tensor.
  
      .. image:: _static/img/warp_affine.png
  
      The function warp_affine transforms the source tensor using
      the specified matrix:
  
      .. math::
          \text{dst}(x, y) = \text{src} \left( M_{11} x + M_{12} y + M_{13} ,
          M_{21} x + M_{22} y + M_{23} \right )
  
      Args:
          src: input tensor of shape :math:`(B, C, H, W)`.
          M: affine transformation of shape :math:`(B, 2, 3)`.
          dsize: size of the output image (height, width).
          mode: interpolation mode to calculate output values ``'bilinear'`` | ``'nearest'``.
          padding_mode: padding mode for outside grid values ``'zeros'`` | ``'border'`` | ``'reflection'`` | ``'fill'``.
          align_corners : mode for grid_generation.
          fill_value: tensor of shape :math:`(3)` that fills the padding area. Only supported for RGB.
  
      Returns:
          the warped tensor with shape :math:`(B, C, H, W)`.
  
      .. note::
          This function is often used in conjunction with :func:`get_rotation_matrix2d`,
          :func:`get_shear_matrix2d`, :func:`get_affine_matrix2d`, :func:`invert_affine_transform`.
  
      .. note::
         See a working example `here <https://kornia.github.io/tutorials/nbs/rotate_affine.html>`__.
  
      Example:
         >>> img = torch.rand(1, 4, 5, 6)
         >>> A = torch.eye(2, 3)[None]
         >>> out = warp_affine(img, A, (4, 2), align_corners=True)
         >>> print(out.shape)
         torch.Size([1, 4, 4, 2])
      """
      if not isinstance(src, Tensor):
          raise TypeError(
              f"Input src type is not a Tensor. Got {type(src)}"
          )
  
      if not isinstance(M, Tensor):
          raise TypeError(
              f"Input M type is not a Tensor. Got {type(M)}"
          )
  
      if not len(src.shape) == 4:
          raise ValueError(
              f"Input src must be a BxCxHxW tensor. Got {src.shape}"
          )
  
      if not (len(M.shape) == 3 or M.shape[-2:] == (2, 3)):
          raise ValueError(
              f"Input M must be a Bx2x3 tensor. Got {M.shape}"
          )
  
      B, C, H, W = src.size()
  
      # we generate a 3x3 transformation matrix from 2x3 affine
      M_3x3: Tensor = convert_affinematrix_to_homography(M)
      dst_norm_trans_src_norm: Tensor = normalize_homography(
          M_3x3, (H, W), dsize
      )
  
      # src_norm_trans_dst_norm = torch.inverse(dst_norm_trans_src_norm)
      src_norm_trans_dst_norm = _torch_inverse_cast(
          dst_norm_trans_src_norm
      )
  
      grid = F.affine_grid(
          src_norm_trans_dst_norm[:, :2, :],
          [B, C, dsize[0], dsize[1]],
          align_corners=align_corners,
      )
  
      if padding_mode == "fill":
          return _fill_and_warp(
              src,
              grid,
              align_corners=align_corners,
              mode=mode,
              fill_value=fill_value,
          )
  
      return F.grid_sample(
          src,
          grid,
          align_corners=align_corners,
          mode=mode,
          padding_mode=padding_mode,
      )
  
imports: from __future__ import annotations
  from typing import Optional
  import torch
  import torch.nn.functional
  from kornia.core import Tensor, concatenate, ones, ones_like, stack, tan, tensor, zeros
  from kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_SHAPE
  from kornia.geometry.conversions import angle_to_rotation_matrix, axis_angle_to_rotation_matrix, convert_affinematrix_to_homography, convert_affinematrix_to_homography3d, deg2rad, normalize_homography, normalize_homography3d, normalize_pixel_coordinates
  from kornia.geometry.linalg import transform_points
  from kornia.utils import create_meshgrid, create_meshgrid3d, eye_like
  from kornia.utils.helpers import _torch_inverse_cast, _torch_solve_cast
label_desc: Use image node_id 2 for calling a global function with example usage: warp_affine(src, M, dsize, mode, padding_mode, align_corners, fill_value) and returns: F, _fill_and_warp