code: def _transform_boxes(
      boxes: torch.Tensor, M: torch.Tensor
  ) -> torch.Tensor:
      """Transforms 3D and 2D in kornia format by applying the transformation matrix M. Boxes and the transformation
      matrix could be batched or not.
  
      Args:
          boxes: 2D quadrilaterals or 3D hexahedrons in kornia format.
          M: the transformation matrix of shape :math:`(3, 3)` or :math:`(B, 3, 3)` for 2D and :math:`(4, 4)` or
              :math:`(B, 4, 4)` for 3D hexahedron.
      """
      M = M if M.is_floating_point() else M.float()
  
      # Work with batch as kornia.transform_points only supports a batch of points.
      (
          boxes_per_batch,
          n_points_per_box,
          coordinates_dimension,
      ) = boxes.shape[-3:]
      if boxes_per_batch == 0:
          return boxes
      points = boxes.view(
          -1, n_points_per_box * boxes_per_batch, coordinates_dimension
      )
      M = M if M.ndim == 3 else M.unsqueeze(0)
  
      if points.shape[0] != M.shape[0]:
          raise ValueError(
              f"Batch size mismatch. Got {points.shape[0]} for boxes and {M.shape[0]} for the transformation matrix."
          )
  
      transformed_boxes: torch.Tensor = transform_points(M, points)
      transformed_boxes = transformed_boxes.view_as(boxes)
      return transformed_boxes
  
imports: from __future__ import annotations
  from typing import Optional, cast
  import torch
  from torch import Size
  from kornia.core import Tensor, stack, zeros
  from kornia.geometry.bbox import validate_bbox
  from kornia.geometry.linalg import transform_points
  from kornia.utils import eye_like
label_desc: Use image node_id 3 for calling a global function with example usage: _transform_boxes(boxes, M) and returns: transformed_boxes, boxes