§
    ’©ºjG  ã                   ó¾   — 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ed         def
d„Z	 	 dde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�¦  «        ‚| |fS )u»   Update and returns variables required to compute Erreur Relative Globale Adimensionnelle de SynthÃ¨se.

    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: )ÚdtypeÚ	TypeErrorr   ÚlenÚshapeÚ
ValueError)r   r   s     ús/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/image/ergas.pyÚ_ergas_updater      s´   € ð „{�f”lÒ"Ð"ÝðEØ œ;ðEð EØ5;´\ðEð Eð Eñ
ô 
ð 	
õ �e˜VÑ$Ô$Ð$Ý
ˆ5Œ;ÑÔ˜1ÒÐÝØxÈuÌ{ÐxÐxÐioÔiuÐxÐxÐxñ
ô 
ð 	
ð �&ˆ=Ðó    r   Úelementwise_meanÚratioÚ	reduction)r   ÚsumÚnoneNc                 ó¬  — | j         \  }}}}|                      ||||z  ¦  «        } |                     ||||z  ¦  «        }| |z
  }t          j        ||z  d¬¦  «        }	t          j        |	||z  z  ¦  «        }
t          j        |d¬¦  «        }d|z  t          j        t          j        |
|z  dz  d¬¦  «        |z  ¦  «        z  }t          ||¦  «        S )u­  Erreur Relative Globale Adimensionnelle de SynthÃ¨se.

    Args:
        preds: estimated image
        target: ground truth image
        ratio: ratio of high resolution to low resolution
        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, 1, 16, 16])
        >>> target = preds * 0.75
        >>> preds, target = _ergas_update(preds, target)
        >>> torch.round(_ergas_compute(preds, target))
        tensor(10.)

    é   )Údiméd   é   )r   ÚreshapeÚtorchr   ÚsqrtÚmeanr   )r   r   r   r   ÚbÚcÚhÚwÚdiffÚsum_squared_errorÚrmse_per_bandÚmean_targetÚergas_scores                r   Ú_ergas_computer,   ,   sÝ   € ð6 ”�J€A€qˆ!ˆQØ�MŠM˜!˜Q  A¡Ñ&Ô&€EØ�^Š^˜A˜q ! a¡%Ñ(Ô(€Fà�6‰>€DÝœ	 $¨¡+°1Ð5Ñ5Ô5ÐÝ”JÐ0°A¸±EÑ:Ñ;Ô;€MÝ”*˜V¨Ð+Ñ+Ô+€Kà˜‘+¥¤
­5¬9°mÀkÑ6QÐVWÑ5WÐ]^Ð+_Ñ+_Ô+_ÐbcÑ+cÑ dÔ dÑd€KÝ�+˜yÑ)Ô)Ð)r   c                 óL   — t          | |¦  «        \  } }t          | |||¦  «        S )aõ  Calculates `Error relative global dimensionless synthesis`_ (ERGAS) metric.

    Args:
        preds: estimated image
        target: ground truth image
        ratio: ratio of high resolution to low resolution
        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 RelativeG 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 error_relative_global_dimensionless_synthesis
        >>> preds = rand([16, 1, 16, 16])
        >>> target = preds * 0.75
        >>> error_relative_global_dimensionless_synthesis(preds, target)
        tensor(9.6193)

    )r   r,   )r   r   r   r   s       r   Ú-error_relative_global_dimensionless_synthesisr.   T   s,   € õH " %¨Ñ0Ô0�M€Eˆ6Ý˜% ¨°	Ñ:Ô:Ð:r   )r   r   )r    r   Útyping_extensionsr   Útorchmetrics.utilities.checksr   Ú"torchmetrics.utilities.distributedr   Útupler   Úfloatr,   r.   © r   r   ú<module>r5      s?  ðð €€€Ø Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5ð˜ð ¨ð °E¸&À&¸.Ô4Ið ð ð ð ð0 ØBTð	%*ð %*Øð%*àð%*ð ð%*ð Ð>Ô?ð	%*ð
 ð%*ð %*ð %*ð %*ðV ØBTð	%;ð %;Øð%;àð%;ð ð%;ð Ð>Ô?ð	%;ð
 ð%;ð %;ð %;ð %;ð %;ð %;r   