code: def inverse_transformation(trans_12: Tensor) -> Tensor:
      r"""Function that inverts a 4x4 homogeneous transformation.
  
       :math:`T_1^{2} = \begin{bmatrix} R_1 & t_1 \\ \mathbf{0} & 1 \end{bmatrix}`
  
      The inverse transformation is computed as follows:
  
      .. math::
  
          T_2^{1} = (T_1^{2})^{-1} = \begin{bmatrix} R_1^T & -R_1^T t_1 \\
          \mathbf{0} & 1\end{bmatrix}
  
      Args:
          trans_12: transformation tensor of shape :math:`(N, 4, 4)` or :math:`(4, 4)`.
  
      Returns:
          tensor with inverted transformations with shape :math:`(N, 4, 4)` or :math:`(4, 4)`.
  
      Example:
          >>> trans_12 = torch.rand(1, 4, 4)  # Nx4x4
          >>> trans_21 = inverse_transformation(trans_12)  # Nx4x4
      """
      KORNIA_CHECK_IS_TENSOR(trans_12)
  
      if not (
          (trans_12.dim() in (2, 3)) and (trans_12.shape[-2:] == (4, 4))
      ):
          raise ValueError(
              f"Input size must be a Nx4x4 or 4x4. Got {trans_12.shape}"
          )
      # unpack input tensor
      rmat_12 = trans_12[..., :3, 0:3]  # Nx3x3
      tvec_12 = trans_12[..., :3, 3:4]  # Nx3x1
  
      # compute the actual inverse
      rmat_21 = torch.transpose(rmat_12, -1, -2)
      tvec_21 = torch.matmul(-rmat_21, tvec_12)
  
      # pack to output tensor
      trans_21 = zeros_like(trans_12)
      trans_21[..., :3, 0:3] += rmat_21
      trans_21[..., :3, -1:] += tvec_21
      trans_21[..., -1, -1:] += 1.0
      return trans_21
  
file_path: kornia/kornia/geometry/linalg.py
imports: from __future__ import annotations
  import torch
  from kornia.core import Tensor, zeros_like
  from kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_IS_TENSOR, KORNIA_CHECK_SHAPE
  from kornia.geometry.conversions import convert_points_from_homogeneous, convert_points_to_homogeneous
label_desc: Use image node_id 2 for calling a global function with example usage: inverse_transformation(trans_12) and returns: trans_21