Ë
    þÍ:jŸ  ã                   ó´   — d dl mZ d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 	 ddedee   d	ed
ee   def
d„Z	 	 	 	 ddedee   d	eded   d
ee   defd„Zy)é    )ÚOptionalN)ÚTensor)ÚLiteral)Ú_check_inputÚ_reduce_distance_matrix)ÚTorchMetricsUserErrorÚxÚyÚexponentÚzero_diagonalÚreturnc                 ó  — t        | ||«      \  } }}t        |t        t        f«      r|dk\  st	        d|› �«      ‚| j
                  }| j                  t        j                  «      } |j                  t        j                  «      }| j                  d«      |j                  d«      z
  j                  «       j                  |«      j                  d«      j                  d|z  «      }|r|j                  d«       |j                  |«      S )ac  Calculate the pairwise minkowski distance matrix.

    Args:
        x: tensor of shape ``[N,d]``
        y: tensor of shape ``[M,d]``
        exponent: int or float larger than 1, exponent to which the difference between preds and target is to be raised
        zero_diagonal: determines if the diagonal of the distance matrix should be set to zero

    é   z>Argument ``p`` must be a float or int greater than 1, but got r   éÿÿÿÿg      ð?)r   Ú
isinstanceÚfloatÚintr   ÚdtypeÚtoÚtorchÚfloat64Ú	unsqueezeÚabsÚpowÚsumÚfill_diagonal_)r	   r
   r   r   Ú_orig_dtypeÚdistances         ú/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torchmetrics/functional/pairwise/minkowski.pyÚ#_pairwise_minkowski_distance_updater       sÚ   € ô ' q¨!¨]Ó;Ñ€A€qˆ-Ü�x¤%¬ Ô.°8¸q²=Ü#Ð&dÐemÐdnÐ$oÓpÐpà—'‘'€KØ	�‰ŒU�]‰]Ó€AØ	�‰ŒU�]‰]Ó€AØ—‘˜A“ §¡¨Q£Ñ/×4Ñ4Ó6×:Ñ:¸8ÓD×HÑHÈÓL×PÑPÐQTÐW_ÑQ_Ó`€HÙØ×Ñ Ô"Ø�;‰;�{Ó#Ð#ó    Ú	reduction)Úmeanr   ÚnoneNc                 ó6   — t        | |||«      }t        ||«      S )a™  Calculate pairwise minkowski distances.

    .. math::
        d_{minkowski}(x,y,p) = ||x - y||_p = \sqrt[p]{\sum_{d=1}^D (x_d - y_d)^p}

    If both :math:`x` and :math:`y` are passed in, the calculation will be performed pairwise between the rows of
    :math:`x` and :math:`y`. If only :math:`x` is passed in, the calculation will be performed between the rows
    of :math:`x`.

    Args:
        x: Tensor with shape ``[N, d]``
        y: Tensor with shape ``[M, d]``, optional
        exponent: int or float larger than 1, exponent to which the difference between preds and target is to be raised
        reduction: reduction to apply along the last dimension. Choose between `'mean'`, `'sum'`
            (applied along column dimension) or  `'none'`, `None` for no reduction
        zero_diagonal: if the diagonal of the distance matrix should be set to 0. If only `x` is given
            this defaults to `True` else if `y` is also given it defaults to `False`

    Returns:
        A ``[N,N]`` matrix of distances if only ``x`` is given, else a ``[N,M]`` matrix

    Example:
        >>> import torch
        >>> from torchmetrics.functional.pairwise import pairwise_minkowski_distance
        >>> x = torch.tensor([[2, 3], [3, 5], [5, 8]], dtype=torch.float32)
        >>> y = torch.tensor([[1, 0], [2, 1]], dtype=torch.float32)
        >>> pairwise_minkowski_distance(x, y, exponent=4)
        tensor([[3.0092, 2.0000],
                [5.0317, 4.0039],
                [8.1222, 7.0583]])
        >>> pairwise_minkowski_distance(x, exponent=4)
        tensor([[0.0000, 2.0305, 5.1547],
                [2.0305, 0.0000, 3.1383],
                [5.1547, 3.1383, 0.0000]])

    )r    r   )r	   r
   r   r"   r   r   s         r   Úpairwise_minkowski_distancer&   1   s"   € ôV 3°1°a¸À=ÓQ€HÜ" 8¨YÓ7Ð7r!   )Né   N)Nr'   NN)Útypingr   r   r   Útyping_extensionsr   Ú(torchmetrics.functional.pairwise.helpersr   r   Ú!torchmetrics.utilities.exceptionsr   r   Úboolr    r&   © r!   r   ú<module>r.      s±   ðõ ã Ý Ý %ç ZÝ Cð aeñ$Øð$Ø˜6Ñ"ð$Ø5:ð$ØOWÐX\É~ð$àó$ð6 ØØ6:Ø$(ñ,8Øð,8à�Ñð,8ð ð,8ð Ð2Ñ3ð	,8ð
 ˜D‘>ð,8ð ô,8r!   