+
    åûj  ã                  óp   € ^ RI Ht ^ RIt^ RIHt ^ RIHtHt R	R R llt ! R R]P                  4      t	R# )
é    )ÚannotationsN)Únn)ÚKORNIA_CHECKÚKORNIA_CHECK_SHAPEc               ó$   € V ^8„  d   QhRRRRRR/# )é   Úimgútorch.TensorÚ	reductionÚstrÚreturn© )Úformats   "ÚYC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\losses\total_variation.pyÚ__annotate__r      s&   € ÷ Nñ N˜ð N°#ð NÀ,ñ Nó    c                ó,  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V . RO4       \        VR9   RV R24       V P                  \        P                  \        P                  39   d!   V P                  \        P                  4      p M}V P                  \        P                  8X  d!   V P                  \        P                  4      p M>V P                  \        P                  8X  d    V P                  \        P                  4      p V R,          V RRR1R3,          ,
          pV R,          V RRRR13,          ,
          pVP                  4       P                  R4      pVP                  4       P                  R4      pVR8X  d·   V P!                  4       '       g!   VP#                  4       pVP#                  4       pVP$                  R,          ^ 8”  d   VP'                  RR	7      MVP)                  RR	7      pVP$                  R,          ^ 8”  d   VP'                  RR	7      MVP)                  RR	7      pWE,           # VR8X  d-   VP)                  RR	7      pVP)                  RR	7      pWE,           # \+        R
4      h)au  Compute the total variation of an image.

``tv = total_variation(img)`` adds, for each ``(H, W)`` slice of ``img``, the absolute differences between
vertically and between horizontally adjacent pixels, and returns one value per leading index.

.. math::

    \text{TV}(I) = \sum |\partial_y I| + \sum |\partial_x I|

Convention:
    - The channels are not summed: a ``(B, C, H, W)`` batch gives ``(B, C)``.
    - ``reduction='sum'`` is not normalised by the image size. ``'mean'`` averages each term over its own count,
      :math:`(H - 1) W` vertical and :math:`H (W - 1)` horizontal differences, and adds the two means; it is not
      the sum divided by :math:`H W`. An axis with no adjacent pixels contributes zero. There is no ``'none'``.
      :ref:`Losses and metrics <losses-metrics-conventions>` compares both with torchmetrics.
    - Narrow integer inputs are promoted before the differences, to avoid overflow.

Args:
    img: image with shape ``(*, H, W)``.
    reduction: ``'sum'`` (default) adds the differences, ``'mean'`` averages each term.

Returns:
    the total variation with shape ``(*,)``.

.. note::
   See a working example `here <https://www.kornia.org/tutorials/nbs/total_variation_denoising.html>`__.

See Also:
    - :class:`~kornia.losses.TotalVariation`: the module form, which always sums.
    - :func:`~kornia.losses.inverse_depth_smoothness_loss`: smoothness of a depth map, weighted by image edges.

Examples:
    >>> total_variation(torch.ones(4, 4))
    tensor(0.)
    >>> total_variation(torch.ones(2, 5, 3, 4, 4)).shape
    torch.Size([2, 5, 3])

Reference:
    [1] https://en.wikipedia.org/wiki/Total_variation

zNot a torch.Tensor type. Got: ÚmeanÚsumz7Expected reduction to be one of 'mean'/'sum', but got 'z'..ºNNNN)ÚdimzInvalid reduction option.)Ú*ÚHÚW)r   r   ).ºé   NNr   éÿÿÿÿ).r   r   éþÿÿÿ)Ú
isinstanceÚtorchÚTensorÚ	TypeErrorÚtyper   r   ÚdtypeÚuint8Úint8ÚtoÚint16Úint32Úint64ÚabsÚflattenÚis_floating_pointÚfloatÚshaper   r   ÚNotImplementedError)r	   r   Ú
pixel_dif1Ú
pixel_dif2Úres1Úres2s   &&    r   Útotal_variationr5      sÿ  € ôV �cœ5Ÿ<™<×(Ò(ÜÐ8¼¸c»¸ÐDÓEÐEä�sšOÔ,Ü�˜oÑ-Ð1hÐirÐhsÐsuÐ/vÔwð ‡y�y”U—[‘[¤%§*¡*Ð-Ô-Ø�f‰f”U—[‘[Ó!‰Ø	�‰”e—k‘kÔ	!Ø�f‰f”U—[‘[Ó!‰Ø	�‰”e—k‘kÔ	!Ø�f‰f”U—[‘[Ó!ˆà�Z• 3 s¨C¨R¨C° {Õ#3Õ3€JØ�Z• 3 s¨A¨s°¨s {Õ#3Õ3€Jð �>‰>Ó×#Ñ# BÓ'€DØ�>‰>Ó×#Ñ# BÓ'€Dà�FÔØ×$Ñ$×&Ò&Ø—:‘:“<ˆDØ—:‘:“<ˆDà$(§J¡J¨r¥N°QÔ$6ˆt�y‰y˜RˆyÔ ¸D¿H¹HÈ¸HÓ<LˆØ$(§J¡J¨r¥N°QÔ$6ˆt�y‰y˜RˆyÔ ¸D¿H¹HÈ¸HÓ<Lˆð �;Ðð 
�eÔ	Ø�x‰x˜BˆxÓˆØ�x‰x˜BˆxÓˆð �;Ðô "Ð"=Ó>Ð>r   c                  ó&   € ] tR t^ktRtR R ltRtR# )ÚTotalVariationaË  Compute the total variation of an image (module form).

``tv = TotalVariation()`` takes no arguments, and ``out = tv(img)`` is :func:`~kornia.losses.total_variation`
with ``reduction='sum'``.

Convention:
    See the Convention block of :func:`~kornia.losses.total_variation`.

Shape:
    - Input: ``(*, H, W)``.
    - Output: ``(*,)``.

See Also:
    - :func:`~kornia.losses.total_variation`: the one-call form, with ``reduction='mean'`` too.

Examples:
    >>> tv = TotalVariation()
    >>> output = tv(torch.ones((2, 3, 4, 4), requires_grad=True))
    >>> output.data
    tensor([[0., 0., 0.],
            [0., 0., 0.]])
    >>> output.sum().backward()  # grad can be implicitly created only for scalar outputs

c               ó    € V ^8„  d   QhRRRR/# )r   r	   r
   r   r   )r   s   "r   r   ÚTotalVariation.__annotate__…   s   € ÷ $ñ $˜<ð $¨Lñ $r   c                ó   € \        V4      # )a¤  Compute total variation for an image or image batch.

Args:
    img: Tensor with shape ``(*, H, W)``, where ``*`` represents
        optional leading dimensions such as batch and channels,
        :math:`H` is height, and :math:`W` is width.

Returns:
    Tensor containing the sum of absolute horizontal and vertical
    finite differences for each leading element. Lower values indicate
    spatially smoother images.
)r5   )Úselfr	   s   &&r   ÚforwardÚTotalVariation.forward…   s   € ô ˜sÓ#Ð#r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r<   Ú__static_attributes__r   r   r   r7   r7   k   s   † ñ÷2$ñ $r   r7   )r   )
Ú
__future__r   r    r   Úkornia.core.checkr   r   r5   ÚModuler7   r   r   r   Ú<module>rG      s*   ðõ$ #ã Ý ç >÷Nôb'$�R—Y‘Yö '$r   