§
    ’©º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dS )é    )ÚOptionalN)ÚTensor)ÚLiteral)Ú_check_inputÚ_reduce_distance_matrix)ÚTorchMetricsUserErroré   ÚxÚyÚexponentÚzero_diagonalÚreturnc                 óh  — t          | ||¦  «        \  } }}t          |t          t          f¦  «        r|dk    st	          d|› �¦  «        ‚| j        }|                      t          j        ¦  «        } |                     t          j        ¦  «        }|  	                    d¦  «        | 	                    d¦  «        z
   
                    ¦   «                              |¦  «                             d¦  «                             d|z  ¦  «        }|r|                     d¦  «         |                     |¦  «        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         úz/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/pairwise/minkowski.pyÚ#_pairwise_minkowski_distance_updater!      s	  € õ ' q¨!¨]Ñ;Ô;Ñ€A€qˆ-Ý�x¥%­ Ñ.Ô.ð q°8¸q²=°=Ý#Ð$oÐemÐ$oÐ$oÑpÔpÐpà”'€KØ	�Š�UŒ]ÑÔ€AØ	�Š�UŒ]ÑÔ€AØ—’˜A‘” §¢¨Q¡¤Ñ/×4Ò4Ñ6Ô6×:Ò:¸8ÑDÔD×HÒHÈÑLÔL×PÒPÐQTÐW_ÑQ_Ñ`Ô`€HØð #Ø×Ò Ñ"Ô"Ð"Ø�;Š;�{Ñ#Ô#Ð#ó    Ú	reduction)Úmeanr   ÚnoneNc                 óF   — 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ÔQ€HÝ" 8¨YÑ7Ô7Ð7r"   )Nr	   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Ð ZÐ ZÐ ZÐ ZÐ ZÐ ZÐ ZØ CÐ CÐ CÐ CÐ CÐ Cð aeð$ð $Øð$Ø˜6Ô"ð$Ø5:ð$ØOWÐX\Ì~ð$àð$ð $ð $ð $ð6 ØØ6:Ø$(ð,8ð ,8Øð,8à�Ôð,8ð ð,8ð Ð2Ô3ð	,8ð
 ˜D”>ð,8ð ð,8ð ,8ð ,8ð ,8ð ,8ð ,8r"   