
    3jG                    t    S SK Jr  S SKrS SKJr  S SKJrJrJrJr  SS	S jjr	 " S S\R                  5      rg)
    )annotationsN)nn)KORNIA_CHECKKORNIA_CHECK_IS_TENSORKORNIA_CHECK_SAME_DEVICEKORNIA_CHECK_SAME_SHAPEc                V   [        U 5        [        U5        [        X5        [        X5        [        US;   SU 35        X-
  n[        R
                  " U5      nSU-  US-   -  nUS:X  a  UR                  5       nU$ US:X  a  UR                  5       nU$ US:X  d  Uc   U$ [        S5      e)	an  Criterion that computes the Geman-McClure loss [2].

According to [1], we compute the Geman-McClure loss as follows:

.. math::

    \text{WL}(x, y) = \frac{2 (x - y)^{2}}{(x - y)^{2} + 4}

Where:
   - :math:`x` is the prediction.
   - :math:`y` is the target to be regressed to.

Reference:
    [1] https://arxiv.org/pdf/1701.03077.pdf
    [2] Bayesian image analysis: An application to single photon emission tomography, Geman and McClure, 1985

Args:
    img1: the predicted torch.Tensor with shape :math:`(*)`.
    img2: the target torch.Tensor with the same shape as img1.
    reduction: Specifies the reduction to apply to the
      output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction
      will be applied (default), ``'mean'``: the sum of the output will be divided
      by the number of elements in the output, ``'sum'``: the output will be
      summed.

Return:
    a scalar with the computed loss.

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

)meansumnoneNz/Given type of reduction is not supported. Got: g       @g      @r
   r   r   zInvalid reduction option.)	r   r   r   r   torchsquarer
   r   NotImplementedError)img1img2	reductiondiffdiff2losss         U/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/losses/geman_mcclure.pygeman_mcclure_lossr      s    H 4 4 D'T(226efoep4q
 ;DLLE;%#+&D Fyy{ K 
e	xxz K 
f		 1 K ""=>>    c                  >   ^  \ rS rSrSrSSU 4S jjjrSS jrSrU =r$ )	GemanMcclureLoss\   al  Criterion that computes the Geman-McClure loss [2].

According to [1], we compute the Geman-McClure loss as follows:

.. math::

    \text{WL}(x, y) = \frac{2 (x - y)^{2}}{(x - y)^{2} + 4}

Where:
   - :math:`x` is the prediction.
   - :math:`y` is the target to be regressed to.

Reference:
    [1] https://arxiv.org/pdf/1701.03077.pdf
    [2] Bayesian image analysis: An application to single photon emission tomography, Geman and McClure, 1985

Args:
    reduction: Specifies the reduction to apply to the
      output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction
      will be applied (default), ``'mean'``: the sum of the output will be divided
      by the number of elements in the output, ``'sum'``: the output will be
      summed.

Shape:
    - img1: the predicted torch.Tensor with shape :math:`(*)`.
    - img2: the target torch.Tensor with the same shape as img1.

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

c                .   > [         TU ]  5         Xl        g )N)super__init__r   )selfr   	__class__s     r   r   GemanMcclureLoss.__init__   s    "r   c                *    [        XU R                  S9$ )N)r   r   r   )r   r   )r   r   r   s      r   forwardGemanMcclureLoss.forward   s    !t$..QQr   )r   r   )r   strreturnNone)r   torch.Tensorr   r)   r'   r)   )	__name__
__module____qualname____firstlineno____doc__r   r#   __static_attributes____classcell__)r    s   @r   r   r   \   s    "H# #R Rr   r   r%   )r   r)   r   r)   r   r&   r'   r)   )
__future__r   r   r   kornia.core.checkr   r   r   r   r   Moduler    r   r   <module>r5      s.   $ #   u u?D*Rryy *Rr   