§
    ’©ºjf  ã                   ó    — d dl mZ d dlmZmZmZ d dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZmZ esd
gZ G d„ de¦  «        ZdS )é    )ÚSequence)ÚAnyÚOptionalÚUnionN)ÚTensor)ÚLiteral)ÚMetric)Úprocrustes_disparity)Ú_MATPLOTLIB_AVAILABLE)Ú_AX_TYPEÚ_PLOT_OUT_TYPEzProcrustesDisparity.plotc                   ó  ‡ — e Zd ZU dZeed<   eed<   dZeed<   dZeed<   dZ	eed<   dZ
eed	<   d
Zeed<   dded         deddfˆ fd„Zdej        dej        ddfd„Zdej        fd„Zddeeee         df         dee         defd„Zˆ xZS )ÚProcrustesDisparityak  Compute the `Procrustes Disparity`_.

    The Procrustes Disparity is defined as the sum of the squared differences between two datasets after
    applying a Procrustes transformation. The Procrustes Disparity is useful to compare two datasets
    that are similar but not aligned.

    The metric works similar to ``scipy.spatial.procrustes`` but for batches of data points. The disparity is
    aggregated over the batch, thus to get the individual disparities please use the functional version of this
    metric: ``torchmetrics.functional.shape.procrustes.procrustes_disparity``.

    As input to ``forward`` and ``update`` the metric accepts the following input:

        - ``point_cloud1`` (torch.Tensor): A tensor of shape ``(N, M, D)`` with ``N`` being the batch size,
          ``M`` the number of data points and ``D`` the dimensionality of the data points.
        - ``point_cloud2`` (torch.Tensor): A tensor of shape ``(N, M, D)`` with ``N`` being the batch size,
          ``M`` the number of data points and ``D`` the dimensionality of the data points.


    As output to ``forward`` and ``compute`` the metric returns the following output:

        - ``gds`` (:class:`~torch.Tensor`): A scalar tensor with the Procrustes Disparity.

    Args:
        reduction: Determines whether to return the mean disparity or the sum of the disparities.
            Can be one of ``"mean"`` or ``"sum"``.
        kwargs: Additional keyword arguments, see :ref:`Metric kwargs` for more info.

    Raises:
        ValueError: If ``average`` is not one of ``"mean"`` or ``"sum"``.

    Example:
        >>> from torch import randn
        >>> from torchmetrics.shape import ProcrustesDisparity
        >>> metric = ProcrustesDisparity()
        >>> point_cloud1 = randn(10, 50, 2)
        >>> point_cloud2 = randn(10, 50, 2)
        >>> metric(point_cloud1, point_cloud2)
        tensor(0.9770)

    Ú	disparityÚtotalFÚfull_state_updateÚis_differentiableÚhigher_is_betterç        Úplot_lower_boundg      ð?Úplot_upper_boundÚmeanÚ	reduction©r   ÚsumÚkwargsÚreturnNc                 ó  •—  t          ¦   «         j        d	i |¤Ž |dvrt          d|› �¦  «        ‚|| _        |                      dt          j        d¦  «        d¬¦  «         |                      dt          j        d¦  «        d¬¦  «         d S )
Nr   z9Argument `reduction` must be one of ['mean', 'sum'], got r   r   r   )ÚdefaultÚdist_reduce_fxr   r   © )ÚsuperÚ__init__Ú
ValueErrorr   Ú	add_stateÚtorchÚtensor)Úselfr   r   Ú	__class__s      €úm/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/shape/procrustes.pyr#   zProcrustesDisparity.__init__P   s’   ø€ Ø�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"Ø˜OÐ+Ð+ÝÐdÐYbÐdÐdÑeÔeÐeØ"ˆŒØ�Š�{­E¬L¸Ñ,=Ô,=ÈeˆÑTÔTÐTØ�Š�w­¬°Q©¬ÈˆÑNÔNÐNÐNÐNó    Úpoint_cloud1Úpoint_cloud2c                 ó®   — t          ||¦  «        }| xj        |                     ¦   «         z  c_        | xj        |                     ¦   «         z  c_        dS )z8Update the Procrustes Disparity with the given datasets.N)r
   r   r   r   Únumel)r(   r,   r-   r   s       r*   ÚupdatezProcrustesDisparity.updateX   sG   € å0°¸|ÑLÔLˆ	ØˆŒ˜)Ÿ-š-™/œ/Ñ)ˆŒØˆ
Œ
�i—o’oÑ'Ô'Ñ'ˆ
Œ
ˆ
ˆ
r+   c                 óD   — | j         dk    r| j        | j        z  S | j        S )z"Computes the Procrustes Disparity.r   )r   r   r   )r(   s    r*   ÚcomputezProcrustesDisparity.compute^   s&   € àŒ>˜VÒ#Ð#Ø”> D¤JÑ.Ð.ØŒ~Ðr+   ÚvalÚaxc                 ó.   — |                       ||¦  «        S )a.  Plot a single or multiple values from the metric.

        Args:
            val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
                If no value is provided, will automatically call `metric.compute` and plot that result.
            ax: An matplotlib axis object. If provided will add plot to that axis

        Returns:
            Figure and Axes object

        Raises:
            ModuleNotFoundError:
                If `matplotlib` is not installed

        .. plot::
            :scale: 75

            >>> # Example plotting a single value
            >>> import torch
            >>> from torchmetrics.shape import ProcrustesDisparity
            >>> metric = ProcrustesDisparity()
            >>> metric.update(torch.randn(10, 50, 2), torch.randn(10, 50, 2))
            >>> fig_, ax_ = metric.plot()

        .. plot::
            :scale: 75

            >>> # Example plotting multiple values
            >>> import torch
            >>> from torchmetrics.shape import ProcrustesDisparity
            >>> metric = ProcrustesDisparity()
            >>> values = [ ]
            >>> for _ in range(10):
            ...     values.append(metric(torch.randn(10, 50, 2), torch.randn(10, 50, 2)))
            >>> fig_, ax_ = metric.plot(values)

        )Ú_plot)r(   r3   r4   s      r*   ÚplotzProcrustesDisparity.plotd   s   € ðL �zŠz˜#˜rÑ"Ô"Ð"r+   )r   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   Úboolr   r   r   Úfloatr   r   r   r#   r&   r0   r2   r   r   r   r   r   r7   Ú__classcell__)r)   s   @r*   r   r      sq  ø€ € € € € € ð'ð 'ðR ÐÐÑØ€M€M�MØ#Ð�tÐ#Ð#Ñ#Ø#Ð�tÐ#Ð#Ñ#Ø"Ð�dÐ"Ð"Ñ"Ø!Ð�eÐ!Ð!Ñ!Ø!Ð�eÐ!Ð!Ñ!ðOð O '¨-Ô"8ð OÈSð OÐUYð Oð Oð Oð Oð Oð Oð( 5¤<ð (¸u¼|ð (ÐPTð (ð (ð (ð (ð˜œð ð ð ð ð&#ð &#˜˜f h¨vÔ&6¸Ð<Ô=ð &#È(ÐS[ÔJ\ð &#Ðhvð &#ð &#ð &#ð &#ð &#ð &#ð &#ð &#r+   r   )Úcollections.abcr   Útypingr   r   r   r&   r   Útyping_extensionsr   Útorchmetricsr	   Ú(torchmetrics.functional.shape.procrustesr
   Útorchmetrics.utilities.importsr   Útorchmetrics.utilities.plotr   r   Ú__doctest_skip__r   r!   r+   r*   ú<module>rH      s  ðð %Ð $Ð $Ð $Ð $Ð $Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'à €€€Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à Ð Ð Ð Ð Ð Ø IÐ IÐ IÐ IÐ IÐ IØ @Ð @Ð @Ð @Ð @Ð @Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àð 4Ø2Ð3Ððl#ð l#ð l#ð l#ð l#˜&ñ l#ô l#ð l#ð l#ð l#r+   