+
    åûjé  ã                  óx   € ^ RI Ht ^ RIt^ RIHt ^ RIHtHtHtHt R	R R llt	 ! R R]P                  4      tR# )
é    )ÚannotationsN)Únn)ÚKORNIA_CHECKÚKORNIA_CHECK_IS_TENSORÚKORNIA_CHECK_SAME_DEVICEÚKORNIA_CHECK_SAME_SHAPEc               ó(   € V ^8„  d   QhRRRRRRRR/# )é   Úimg1útorch.TensorÚimg2Ú	reductionÚstrÚreturn© )Úformats   "ÚUC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\losses\charbonnier.pyÚ__annotate__r      s5   € ÷ U^ñ U^˜<ð U^¨|ð U^Èð U^ÐYeñ U^ó    c                ól  € \        V 4       \        V4       \        W4       \        W4       \        VR9   RV 24       \        P
                  ! V P                  VP                  4      pV\        P                  \        P                  39   d&   V P                  4       VP                  4       ,
          MW,
          pV^,          pVR8  p\        P                  ! WeR4      p\        P                  ! VWwR,           P                  4       R,           ,          VR,           P                  4       R,
          4      pVR8X  d   VP                  4       pM/VR8X  d   VP                  4       pMVR8X  g   Vf   M\        R4      hV\        P                  \        P                  39   d   VP                  V4      # T# )	aÿ  Compute the Charbonnier (L1-L2) loss between a prediction and a target.

``loss = charbonnier_loss(img1, img2)`` penalises each residual :math:`x - y` of ``img1`` (:math:`x`) and ``img2``
(:math:`y`) quadratically near 0 and linearly beyond, without bound.

.. math::

    \text{loss}(x, y) = \sqrt{(x - y)^{2} + 1} - 1

Reference:
    [1] https://arxiv.org/pdf/1701.03077.pdf
    [2] Charbonnier: https://ieeexplore.ieee.org/document/413553
    [3] L1-L2: https://hal.inria.fr/inria-00074015/document
    [4] https://arxiv.org/pdf/1712.05927.pdf

Convention:
    - The robust losses are the general loss of Barron [1] on the residual ``img1 - img2`` at scale :math:`c = 1`:
      :math:`\alpha = 1` here, :math:`\alpha = 0` in :func:`~kornia.losses.cauchy_loss`, :math:`\alpha = -2` in
      :func:`~kornia.losses.geman_mcclure_loss` and :math:`\alpha = -\infty` in
      :func:`~kornia.losses.welsch_loss`. Other works use a slightly different Charbonnier form [4].
    - There is no scale argument: the penalty stops being quadratic at residuals of about 1 in the units of the
      data. For a scale :math:`c`, pass ``img1 / c`` and ``img2 / c``.
      :ref:`Losses and metrics <losses-metrics-conventions>` maps the losses onto Barron's code.
    - The losses are symmetric in ``img1`` and ``img2``, which must have the same shape, without broadcasting,
      and the same device.
    - This loss, :func:`~kornia.losses.cauchy_loss`, :func:`~kornia.losses.geman_mcclure_loss` and
      :func:`~kornia.losses.welsch_loss` evaluate float16 and bfloat16 inputs in float32, gradients included, and
      return the input dtype.

Args:
    img1: prediction with shape ``(*)``.
    img2: target with the same shape as ``img1``.
    reduction: ``'none'`` (default) keeps one loss per element, ``'mean'`` averages them, ``'sum'`` adds them.

Returns:
    the loss with the shape of the inputs for ``reduction='none'``, a scalar otherwise.

See Also:
    - :class:`~kornia.losses.CharbonnierLoss`: the module form.
    - :func:`~kornia.losses.cauchy_loss`: grows only logarithmically for large residuals.

Example:
    >>> img1 = torch.randn(2, 3, 32, 32, requires_grad=True)
    >>> img2 = torch.randn(2, 3, 32, 32)
    >>> output = charbonnier_loss(img1, img2, reduction="sum")
    >>> output.backward()

ÚmeanÚsumÚnonez/Given type of reduction is not supported. Got: g      ð?g        zInvalid reduction option.)r   r   r   N)r   r   r   r   ÚtorchÚpromote_typesÚdtypeÚfloat16Úbfloat16ÚfloatÚwhereÚsqrtr   r   ÚNotImplementedErrorÚto)	r   r   r   Úoutput_dtypeÚcompute_diffÚsquaredÚsmallÚsmall_squaredÚlosss	   &&&      r   Úcharbonnier_lossr*      sa  € ôb ˜4Ô ä˜4Ô ä˜DÔ'ä˜TÔ(äØÐ2Ñ2Ð6eÐfoÐepÐ4qôô
 ×&Ò& t§z¡z°4·:±:Ó>€LØ2>Ä5Ç=Á=ÔRW×R`ÑR`ÐBaÔ2a�4—:‘:“< $§*¡*£,Ö.ÐgkÕgr€Lð ˜A�o€GØ�c‰M€EÜ—K’K °Ó4€MÜ�;Š;ØØ¨#Õ-×3Ñ3Ó5¸Õ;Õ<Ø	�3�×ÑÓ Õ$ó€Dð �FÔØ�y‰y‹{‰Ø	�eÔ	Ø�x‰x‹z‰Ø	�fÔ	 	Ò 1Øä!Ð"=Ó>Ð>à$0´U·]±]ÄEÇNÁNÐ4SÔ$Sˆ4�7‰7�<Ó Ð]ÐY]Ð]r   c                  óB   a € ] tR t^stRtRR V 3R llltR R ltRtV ;t# )ÚCharbonnierLossaò  Compute the Charbonnier (L1-L2) loss between a prediction and a target (module form).

``criterion = CharbonnierLoss(reduction)`` stores ``reduction``, and ``loss = criterion(img1, img2)`` is
:func:`~kornia.losses.charbonnier_loss`.

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

Args:
    reduction: ``'none'`` (default), ``'mean'`` or ``'sum'``, as in :func:`~kornia.losses.charbonnier_loss`.

Shape:
    - img1: prediction ``(*)``.
    - img2: target with the same shape as ``img1``.
    - Output: the shape of the inputs for ``reduction='none'``, a scalar otherwise.

See Also:
    - :func:`~kornia.losses.charbonnier_loss`: the one-call form.
    - :class:`~kornia.losses.CauchyLoss`: grows only logarithmically for large residuals.

Example:
    >>> criterion = CharbonnierLoss(reduction="mean")
    >>> img1 = torch.randn(2, 3, 32, 32, requires_grad=True)
    >>> img2 = torch.randn(2, 3, 32, 32)
    >>> output = criterion(img1, img2)
    >>> output.backward()

c               ó    € V ^8„  d   QhRRRR/# )r
   r   r   r   ÚNoner   )r   s   "r   r   ÚCharbonnierLoss.__annotate__‘   s   € ÷ #ñ # #ð #°4ñ #r   c                	ó0   <€ \         SV `  4        Wn        R # )N)ÚsuperÚ__init__r   )Úselfr   Ú	__class__s   &&€r   r2   ÚCharbonnierLoss.__init__‘   s   ø€ Ü‰ÑÔØ"Žr   c               ó$   € V ^8„  d   QhRRRRRR/# )r
   r   r   r   r   r   )r   s   "r   r   r/   •   s&   € ÷ Pñ P˜Lð P°ð PÀñ Pr   c                ó0   € \        WV P                  R7      # )a_  Compute the Charbonnier robust regression loss.

Args:
    img1: Predicted tensor with arbitrary shape.
    img2: Target tensor with the same shape as ``img1``.

Returns:
    Loss tensor reduced according to ``self.reduction``. The
    Charbonnier penalty is a smooth approximation of absolute error and
    remains differentiable near zero residual.
)r   r   r   )r*   r   )r3   r   r   s   &&&r   ÚforwardÚCharbonnierLoss.forward•   s   € ô   TÀÇÁÔOÐOr   )r   ©r   )	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r2   r8   Ú__static_attributes__Ú__classcell__)r4   s   @r   r,   r,   s   s   ø† ñ÷:#ò #÷Pó Pr   r,   r:   )Ú
__future__r   r   r   Úkornia.core.checkr   r   r   r   r*   ÚModuler,   r   r   r   Ú<module>rE      s3   ðõ$ #ã Ý ÷ vÓ u÷U^ôp.P�b—i‘iö .Pr   