code: def match_nn(
      desc1: Tensor, desc2: Tensor, dm: Optional[Tensor] = None
  ) -> Tuple[Tensor, Tensor]:
      r"""Function, which finds nearest neighbors in desc2 for each vector in desc1.
  
      If the distance matrix dm is not provided, :py:func:`torch.cdist` is used.
  
      Args:
          desc1: Batch of descriptors of a shape :math:`(B1, D)`.
          desc2: Batch of descriptors of a shape :math:`(B2, D)`.
          dm: Tensor containing the distances from each descriptor in desc1
            to each descriptor in desc2, shape of :math:`(B1, B2)`.
  
      Returns:
          - Descriptor distance of matching descriptors, shape of :math:`(B1, 1)`.
          - Long tensor indexes of matching descriptors in desc1 and desc2, shape of :math:`(B1, 2)`.
      """
      KORNIA_CHECK_SHAPE(desc1, ["B", "DIM"])
      KORNIA_CHECK_SHAPE(desc2, ["B", "DIM"])
      if (len(desc1) == 0) or (len(desc2) == 0):
          return _no_match(desc1)
      distance_matrix = _get_lazy_distance_matrix(desc1, desc2, dm)
      match_dists, idxs_in_2 = torch.min(distance_matrix, dim=1)
      idxs_in1 = torch.arange(
          0, idxs_in_2.size(0), device=idxs_in_2.device
      )
      matches_idxs = concatenate(
          [idxs_in1.view(-1, 1), idxs_in_2.view(-1, 1)], 1
      )
      return match_dists.view(-1, 1), matches_idxs.view(-1, 2)
  
imports: from typing import Any, ClassVar, Dict, List, Optional, Tuple
  import torch
  from kornia.core import Module, Tensor, concatenate
  from kornia.core.check import KORNIA_CHECK_DM_DESC, KORNIA_CHECK_SHAPE
  from kornia.feature.laf import get_laf_center
  from kornia.testing import is_mps_tensor_safe
  from .adalam import get_adalam_default_config, match_adalam
label_desc: Use image node_id 5 for calling a global function with example usage: match_nn(desc1, desc2, dm) and returns: match_dists,  matches_idxs, _no_match