§
    ’©ºjï
  ã                   ó¼   — d dl mZmZ d dlmZ d dlmZ dedeeef         fd„Z	dedeeef         d	eed
                  defd„Z
dded	eed
                  defd„ZdS )é    )ÚOptionalÚUnion)ÚTensor)ÚLiteralÚimgÚreturnc                 óŽ  — | j         dk    rt          d| j        › �¦  «        ‚| ddd…dd…f         | ddd…dd…f         z
  }| ddd…dd…f         | ddd…dd…f         z
  }|                     ¦   «                              g d¢¦  «        }|                     ¦   «                              g d¢¦  «        }||z   }|| j        d         fS )	z4Compute total variation statistics on current batch.é   z1Expected input `img` to be an 4D tensor, but got .é   Néÿÿÿÿ)r   é   é   r   )ÚndimÚRuntimeErrorÚshapeÚabsÚsum)r   Údiff1Údiff2Úres1Úres2Úscores         úp/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/torchmetrics/functional/image/tv.pyÚ_total_variation_updater      sØ   € à
„x�1‚}€}ÝÐZÈsÌyÐZÐZÑ[Ô[Ð[Ø��Q�R�R˜˜˜�
ŒO˜c # s¨ s¨A¨A¨A +Ô.Ñ.€EØ��Q�Q�Q˜˜˜�
ŒO˜c # q q q¨#¨2¨# +Ô.Ñ.€Eà�9Š9‰;Œ;�?Š?˜9˜9˜9Ñ%Ô%€DØ�9Š9‰;Œ;�?Š?˜9˜9˜9Ñ%Ô%€DØ�4‰K€EØ�#”)˜A”,ÐÐó    r   Únum_elementsÚ	reduction)Úmeanr   Únonec                 ó¢   — |dk    r|                       ¦   «         |z  S |dk    r|                       ¦   «         S |�|dk    r| S t          d¦  «        ‚)z$Compute final total variation score.r   r   Nr   zHExpected argument `reduction` to either be 'sum', 'mean', 'none' or None)r   Ú
ValueError)r   r   r   s      r   Ú_total_variation_computer"   !   s_   € ð �FÒÐØ�yŠy‰{Œ{˜\Ñ)Ð)Ø�EÒÐØ�yŠy‰{Œ{ÐØÐ˜I¨Ò/Ð/ØˆÝ
Ð_Ñ
`Ô
`Ð`r   r   c                 óH   — t          | ¦  «        \  }}t          |||¦  «        S )a9  Compute total variation loss.

    Args:
        img: A `Tensor` of shape `(N, C, H, W)` consisting of images
        reduction: a method to reduce metric score over samples.

            - ``'mean'``: takes the mean over samples
            - ``'sum'``: takes the sum over samples
            - ``None`` or ``'none'``: return the score per sample

    Returns:
        A loss scalar value containing the total variation

    Raises:
        ValueError:
            If ``reduction`` is not one of ``'sum'``, ``'mean'``, ``'none'`` or ``None``
        RuntimeError:
            If ``img`` is not 4D tensor

    Example:
        >>> from torch import rand
        >>> from torchmetrics.functional.image import total_variation
        >>> img = rand(5, 3, 28, 28)
        >>> total_variation(img)
        tensor(7546.8018)

    )r   r"   )r   r   r   r   s       r   Útotal_variationr$   .   s(   € õ< 2°#Ñ6Ô6Ñ€Eˆ<Ý# E¨<¸ÑCÔCÐCr   N)r   )Útypingr   r   Útorchr   Útyping_extensionsr   ÚtupleÚintr   r"   r$   © r   r   ú<module>r+      s  ðð #Ð "Ð "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %ð
 ð 
¨E°&¸#°+Ô,>ð 
ð 
ð 
ð 
ð
aØð
aØ!& s¨F {Ô!3ð
aØ@HÈÐQfÔIgÔ@hð
aàð
að 
að 
að 
aðDð D˜ð D¨H°WÐ=RÔ5SÔ,Tð DÐagð Dð Dð Dð Dð Dð Dr   