Ë
    þÍ: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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�«      ‚| |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     úx/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/torchmetrics/functional/image/ergas.pyÚ_ergas_updater      s—   € ð ‡{�{�f—l‘lÒ"ÜðØ Ÿ;™;˜- }°V·\±\°NÀ!ðEó
ð 	
ô �e˜VÔ$Ü
ˆ5�;‰;Ó˜1ÒÜØNÈuÏ{É{ÈmÐ[hÐio×iuÑiuÐhvÐvwÐxó
ð 	
ð �&ˆ=Ðó    ÚratioÚ	reduction)Úelementwise_meanÚsumÚnoneNc                 ó¨  — | j                   \  }}}}| j                  ||||z  «      } |j                  ||||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ÐÜ—J‘JÐ0°A¸±EÑ:Ó;€MÜ—*‘*˜V¨Ô+€Kà˜‘+¤§
¡
¬5¯9©9°mÀkÑ6QÐVWÑ5WÐ]^Ô+_ÐbcÑ+cÓ dÑd€KÜ�+˜yÓ)Ð)r   c                 ó<   — 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�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ð˜ð ¨ð °E¸&À&¸.Ñ4Ió ð0 ØBTñ	%*Øð%*àð%*ð ð%*ð Ð>Ñ?ð	%*ð
 ó%*ðV ØBTñ	%;Øð%;àð%;ð ð%;ð Ð>Ñ?ð	%;ð
 ô%;r   