§
    ’©ºjf  ã            	       ó²   — 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ededeeef         fd	„Z		 ddededed         defd„Z
	 ddededed         defd„ZdS )é    N)ÚTensor)ÚLiteral)Ú_check_same_shape)ÚreduceÚpredsÚtargetÚreturnc                 ó–  — | j         |j         k    r t          d| j         › d|j         › d�¦  «        ‚t          | |¦  «         t          | j        ¦  «        dk    r t          d| j        › d|j        › d�¦  «        ‚| j        d         dk    s|j        d         dk    r,t          d| j        d         › d|j        d         › d�¦  «        ‚| |fS )zœUpdate and returns variables required to compute Spectral Angle Mapper.

    Args:
        preds: Predicted tensor
        target: Ground truth tensor

    zEExpected `preds` and `target` to have the same data type. Got preds: z and target: ú.é   z@Expected `preds` and `target` to have BxCxHxW shape. Got preds: é   zSExpected channel dimension of `preds` and `target` to be larger than 1. Got preds: )ÚdtypeÚ	TypeErrorr   ÚlenÚshapeÚ
ValueError)r   r   s     úq/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/image/sam.pyÚ_sam_updater      s  € ð „{�f”lÒ"Ð"ÝðEØ œ;ðEð EØ5;´\ðEð Eð Eñ
ô 
ð 	
õ �e˜VÑ$Ô$Ð$Ý
ˆ5Œ;ÑÔ˜1ÒÐÝØxÈuÌ{ÐxÐxÐioÔiuÐxÐxÐxñ
ô 
ð 	
ð 	Œ�AŒ˜!ÒÐ ¤¨a¤°AÒ!5Ð!5ÝðKØ œ; qœ>ðKð KØ8>¼ÀQ¼ðKð Kð Kñ
ô 
ð 	
ð �&ˆ=Ðó    Úelementwise_meanÚ	reduction)r   ÚsumÚnoneNc                 ó  — | |z                        d¬¦  «        }|                      d¬¦  «        }|                     d¬¦  «        }t          j        |||z  z  dd¦  «                             ¦   «         }t          ||¦  «        S )aW  Compute Spectral Angle Mapper.

    Args:
        preds: estimated image
        target: ground truth image
        reduction: a method to reduce metric score over labels.

            - ``'elementwise_mean'``: takes the mean (default)
            - ``'sum'``: takes the sum
            - ``'none'`` or ``None``: no reduction will be applied

    Example:
        >>> from torch import rand
        >>> preds = rand([16, 3, 16, 16])
        >>> target = rand([16, 3, 16, 16])
        >>> preds, target = _sam_update(preds, target)
        >>> _sam_compute(preds, target)
        tensor(0.5914)

    r   )Údiméÿÿÿÿ)r   ÚnormÚtorchÚclampÚacosr   )r   r   r   Údot_productÚ
preds_normÚtarget_normÚ	sam_scores          r   Ú_sam_computer%   1   s}   € ð2 ˜6‘>×&Ò&¨1Ð&Ñ-Ô-€KØ—’ �Ñ"Ô"€JØ—+’+ !�+Ñ$Ô$€KÝ”˜K¨:¸Ñ+CÑDÀbÈ!ÑLÔL×QÒQÑSÔS€IÝ�)˜YÑ'Ô'Ð'r   c                 óJ   — t          | |¦  «        \  } }t          | ||¦  «        S )a£  Universal Spectral Angle Mapper.

    Args:
        preds: estimated image
        target: ground truth image
        reduction: a method to reduce metric score over labels.

            - ``'elementwise_mean'``: takes the mean (default)
            - ``'sum'``: takes the sum
            - ``'none'`` or ``None``: no reduction will be applied

    Return:
        Tensor with Spectral Angle Mapper score

    Raises:
        TypeError:
            If ``preds`` and ``target`` don't have the same data type.
        ValueError:
            If ``preds`` and ``target`` don't have ``BxCxHxW shape``.

    Example:
        >>> from torch import rand
        >>> from torchmetrics.functional.image import spectral_angle_mapper
        >>> preds = rand([16, 3, 16, 16],)
        >>> target = rand([16, 3, 16, 16])
        >>> spectral_angle_mapper(preds, target)
        tensor(0.5914)

    References:
        [1] Roberta H. Yuhas, Alexander F. H. Goetz and Joe W. Boardman, "Discrimination among semi-arid
        landscape endmembers using the Spectral Angle Mapper (SAM) algorithm" in PL, Summaries of the Third Annual JPL
        Airborne Geoscience Workshop, vol. 1, June 1, 1992.

    )r   r%   )r   r   r   s      r   Úspectral_angle_mapperr'   Q   s*   € õN    vÑ.Ô.�M€Eˆ6Ý˜˜v yÑ1Ô1Ð1r   )r   )r   r   Útyping_extensionsr   Útorchmetrics.utilities.checksr   Ú"torchmetrics.utilities.distributedr   Útupler   r%   r'   © r   r   ú<module>r-      s)  ðð €€€Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5ð�vð  vð °%¸À¸Ô2Gð ð ð ð ð: CUð(ð (Øð(àð(ð Ð>Ô?ð(ð ð	(ð (ð (ð (ðF CUð(2ð (2Øð(2àð(2ð Ð>Ô?ð(2ð ð	(2ð (2ð (2ð (2ð (2ð (2r   