Ë
    þÍ: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y)é    N)ÚTensor)ÚLiteral)Ú_check_same_shape)ÚreduceÚpredsÚtargetÚreturnc                 ó¼  — | j                   |j                   k7  r&t        d| j                   › d|j                   › d�«      ‚t        | |«       t        | j                  «      dk7  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     úv/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torchmetrics/functional/image/sam.pyÚ_sam_updater      sï   € ð ‡{�{�f—l‘lÒ"ÜðØ Ÿ;™;˜- }°V·\±\°NÀ!ðEó
ð 	
ô �e˜VÔ$Ü
ˆ5�;‰;Ó˜1ÒÜØNÈuÏ{É{ÈmÐ[hÐio×iuÑiuÐhvÐvwÐxó
ð 	
ð 	�‰�A‰˜!Ò §¡¨a¡°AÒ!5ÜðØ Ÿ;™; q™>Ð*¨-¸¿¹ÀQ¹Ð7HÈðKó
ð 	
ð �&ˆ=Ðó    Ú	reduction)Úelementwise_meanÚsumÚnoneNc                 óâ   — | |z  j                  d¬«      }| j                  d¬«      }|j                  d¬«      }t        j                  |||z  z  dd«      j	                  «       }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   sm   € ð2 ˜6‘>×&Ñ&¨1Ð&Ó-€KØ—‘ �Ó"€JØ—+‘+ !�+Ó$€KÜ—‘˜K¨:¸Ñ+CÑDÀbÈ!ÓL×QÑQÓS€IÜ�)˜YÓ'Ð'r   c                 ó:   — 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Ð1r   )r   )r   r   Útyping_extensionsr   Útorchmetrics.utilities.checksr   Ú"torchmetrics.utilities.distributedr   Útupler   r%   r'   © r   r   ú<module>r-      s¦   ðó Ý Ý %å ;Ý 5ð�vð  vð °%¸À¸Ñ2Gó ð: CUñ(Øð(àð(ð Ð>Ñ?ð(ð ó	(ðF CUñ(2Øð(2àð(2ð Ð>Ñ?ð(2ð ô	(2r   