code: def _cdist(d1: Tensor, d2: Tensor) -> Tensor:
      r"""Manual `torch.cdist` for M1."""
      if (not is_mps_tensor_safe(d1)) and (not is_mps_tensor_safe(d2)):
          return torch.cdist(d1, d2)
      d1_sq = (d1**2).sum(dim=1, keepdim=True)
      d2_sq = (d2**2).sum(dim=1, keepdim=True)
      dm = (
          d1_sq.repeat(1, d2.size(0))
          + d2_sq.repeat(1, d1.size(0)).t()
          - 2.0 * d1 @ d2.t()
      )
      dm = dm.clamp(min=0.0).sqrt()
      return dm
  
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 1 for calling a global function with example usage: _cdist(d1, d2) and returns: dm, torch