§
    ’©º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 	 ddededed	ee	         d
e
eeef         f
d„Zdededed
efd„Z	 ddededed	ee	         d
ef
d„ZdS )é    )ÚOptionalN)ÚTensor)Ú_check_same_shape©Ú_safe_divideÚpredsÚtargetÚ	thresholdÚkeep_sequence_dimÚreturnc                 ód  ‡— t          | |¦  «         ‰€d}n[d‰cxk    r| j        k     sn t          d| j        › d‰› �¦  «        ‚t          ˆfd„t	          | j        ¦  «        D ¦   «         ¦  «        }| |k                         ¦   «         }||k                         ¦   «         }‰€‚t          j        ||z  ¦  «                             ¦   «         }t          j        ||z  |z  ¦  «                             ¦   «         }t          j        ||z  |z  ¦  «                             ¦   «         }	n‡t          j        ||z  |¬¦  «                             ¦   «         }t          j        ||z  |z  |¬¦  «                             ¦   «         }t          j        ||z  |z  |¬¦  «                             ¦   «         }	|||	fS )a%  Update and return variables required to compute Critical Success Index. Checks for same shape of tensors.

    Args:
        preds: Predicted tensor
        target: Ground truth tensor
        threshold: Values above or equal to threshold are replaced with 1, below by 0
        keep_sequence_dim: Index of the sequence dimension if the inputs are sequences of images. If specified,
            the score will be calculated separately for each image in the sequence. If ``None``, the score will be
            calculated across all dimensions.

    Nr   z.Expected keep_sequence dim to be in range [0, z
] but got c              3   ó(   •K  — | ]}|‰k    ¯|V — Œd S ©N© )Ú.0Úir   s     €úv/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/regression/csi.pyú	<genexpr>z1_critical_success_index_update.<locals>.<genexpr>,   s.   øè è € ÐPÐP˜q¸Ð>OÒ9OÐ9O˜Ð9OÐ9OÐ9OÐ9OÐPÐPó    )Údim)	r   ÚndimÚ
ValueErrorÚtupleÚrangeÚboolÚtorchÚsumÚint)
r   r	   r
   r   Úsum_dimsÚ	preds_binÚ
target_binÚhitsÚmissesÚfalse_alarmss
      `      r   Ú_critical_success_index_updater%      s¸  ø€ õ �e˜VÑ$Ô$Ð$àÐ ØˆˆØÐ#Ð0Ð0Ò0Ð0 e¤jÒ0Ð0Ð0Ð0ÝÐsÈ%Ì*ÐsÐsÐ`qÐsÐsÑtÔtÐtåÐPÐPÐPÐP¥E¨%¬*Ñ$5Ô$5ÐPÑPÔPÑPÔPˆð ˜)Ò#×)Ò)Ñ+Ô+€IØ˜IÒ%×+Ò+Ñ-Ô-€JàÐ ÝŒy˜ ZÑ/Ñ0Ô0×4Ò4Ñ6Ô6ˆÝ”˜I¨
Ñ2°jÑ@ÑAÔA×EÒEÑGÔGˆÝ”y )¨jÑ"8¸IÑ!EÑFÔF×JÒJÑLÔLˆˆåŒy˜ ZÑ/°XÐ>Ñ>Ô>×BÒBÑDÔDˆÝ”˜I¨
Ñ2°jÑ@ÀhÐOÑOÔO×SÒSÑUÔUˆÝ”y )¨jÑ"8¸IÑ!EÈ8ÐTÑTÔT×XÒXÑZÔZˆØ�˜Ð%Ð%r   r"   r#   r$   c                 ó.   — t          | | |z   |z   ¦  «        S )aÚ  Compute critical success index.

    Args:
        hits: Number of true positives after binarization
        misses: Number of false negatives after binarization
        false_alarms: Number of false positives after binarization

    Returns:
        If input tensors are 5-dimensional and ``keep_sequence_dim=True``, the metric returns a ``(S,)`` vector
        with CSI scores for each image in the sequence. Otherwise, it returns a scalar tensor with the CSI score.

    r   )r"   r#   r$   s      r   Ú_critical_success_index_computer'   =   s   € õ ˜˜d V™m¨lÑ:Ñ;Ô;Ð;r   c                 óP   — t          | |||¦  «        \  }}}t          |||¦  «        S )aY  Compute critical success index.

    Args:
        preds: Predicted tensor
        target: Ground truth tensor
        threshold: Values above or equal to threshold are replaced with 1, below by 0
        keep_sequence_dim: Index of the sequence dimension if the inputs are sequences of images. If specified,
            the score will be calculated separately for each image in the sequence. If ``None``, the score will be
            calculated across all dimensions.

    Returns:
        If ``keep_sequence_dim`` is specified, the metric returns a vector of  with CSI scores for each image
        in the sequence. Otherwise, it returns a scalar tensor with the CSI score.

    Example:
        >>> import torch
        >>> from torchmetrics.functional.regression import critical_success_index
        >>> x = torch.Tensor([[0.2, 0.7], [0.9, 0.3]])
        >>> y = torch.Tensor([[0.4, 0.2], [0.8, 0.6]])
        >>> critical_success_index(x, y, 0.5)
        tensor(0.3333)

    Example:
        >>> import torch
        >>> from torchmetrics.functional.regression import critical_success_index
        >>> x = torch.Tensor([[[0.2, 0.7], [0.9, 0.3]], [[0.2, 0.7], [0.9, 0.3]]])
        >>> y = torch.Tensor([[[0.4, 0.2], [0.8, 0.6]], [[0.4, 0.2], [0.8, 0.6]]])
        >>> critical_success_index(x, y, 0.5, keep_sequence_dim=0)
        tensor([0.3333, 0.3333])

    )r%   r'   )r   r	   r
   r   r"   r#   r$   s          r   Úcritical_success_indexr)   M   s3   € õD "@ÀÀvÈyÐZkÑ!lÔ!lÑ€Dˆ&�,Ý*¨4°¸ÑFÔFÐFr   r   )Útypingr   r   r   Útorchmetrics.utilities.checksr   Útorchmetrics.utilities.computer   Úfloatr   r   r%   r'   r)   r   r   r   ú<module>r.      sG  ðð Ð Ð Ð Ð Ð à €€€Ø Ð Ð Ð Ð Ð à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7ð Y]ð#&ð #&Øð#&Ø!ð#&Ø.3ð#&ØHPÐQTÌð#&à
ˆ6�6˜6Ð!Ô"ð#&ð #&ð #&ð #&ðL<¨&ð <¸&ð <ÐPVð <Ð[að <ð <ð <ð <ð" Y]ð#Gð #GØð#GØ!ð#GØ.3ð#GØHPÐQTÌð#Gàð#Gð #Gð #Gð #Gð #Gð #Gr   