code: def warp_perspective3d(
      src: Tensor,
      M: Tensor,
      dsize: tuple[int, int, int],
      flags: str = "bilinear",
      border_mode: str = "zeros",
      align_corners: bool = False,
  ) -> Tensor:
      r"""Apply a perspective transformation to an image.
  
      The function warp_perspective transforms the source image using
      the specified matrix:
  
      .. math::
          \text{dst} (x, y) = \text{src} \left(
          \frac{M_{11} x + M_{12} y + M_{13}}{M_{31} x + M_{32} y + M_{33}} ,
          \frac{M_{21} x + M_{22} y + M_{23}}{M_{31} x + M_{32} y + M_{33}}
          \right )
  
      Args:
          src: input image with shape :math:`(B, C, D, H, W)`.
          M: transformation matrix with shape :math:`(B, 4, 4)`.
          dsize: size of the output image (height, width).
          flags: interpolation mode to calculate output values
            ``'bilinear'`` | ``'nearest'``.
          border_mode: padding mode for outside grid values
            ``'zeros'`` | ``'border'`` | ``'reflection'``.
          align_corners: interpolation flag.
  
      Returns:
          the warped input image :math:`(B, C, D, H, W)`.
  
      .. note::
          This function is often used in conjunction with :func:`get_perspective_transform3d`.
      """
      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) == 5:
          raise ValueError(
              f"Input src must be a BxCxDxHxW tensor. Got {src.shape}"
          )
  
      if not (len(M.shape) == 3 or M.shape[-2:] == (4, 4)):
          raise ValueError(
              f"Input M must be a Bx4x4 tensor. Got {M.shape}"
          )
  
      # launches the warper
      d, h, w = src.shape[-3:]
      return _transform_warp_impl3d(
          src, M, (d, h, w), dsize, flags, border_mode, align_corners
      )
  
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 21 for calling a global function with example usage: warp_perspective3d(src, M, dsize, flags, border_mode, align_corners) and returns: _transform_warp_impl3d