
    3j              	           S SK r S SK JrJr  S SKJrJrJr  SS\ R                  S\ R                  S\S\ R                  4S jjr " S	 S
\R                  5      r
\rg)    N)Tensornn)KORNIA_CHECKKORNIA_CHECK_IS_TENSORKORNIA_CHECK_SHAPEinputtarget	reductionreturnc                    [        U 5        [        U5        [        U SS/5        [        USS/5        [        U R                  UR                  :H  SU R                   SUR                   35        U S   US   -
  S-  U S   US   -
  S-  -   R	                  5       nUS:X  a  UR                  5       nU$ US	:X  a  UR                  5       nU$ US
:X  a   U$ [        S5      e)a  Create a function that calculates the average endpoint error (AEPE) between 2 flow maps.

AEPE is the endpoint error between two 2D vectors (e.g., optical flow).
Given a h x w x 2 optical flow map, the AEPE is:

.. math::

    \text{AEPE}=\frac{1}{hw}\sum_{i=1, j=1}^{h, w}\sqrt{(I_{i,j,1}-T_{i,j,1})^{2}+(I_{i,j,2}-T_{i,j,2})^{2}}

Args:
    input: the input flow map with shape :math:`(*, 2)`.
    target: the target flow map with shape :math:`(*, 2)`.
    reduction : Specifies the reduction to apply to the
     output: ``'none'`` | ``'mean'`` | ``'sum'``. ``'none'``: no reduction will be applied,
     ``'mean'``: the sum of the output will be divided by the number of elements
     in the output, ``'sum'``: the output will be summed.

Return:
    the computed AEPE as a scalar.

Examples:
    >>> ones = torch.ones(4, 4, 2)
    >>> aepe(ones, 1.2 * ones)
    tensor(0.2828)

Reference:
    https://link.springer.com/content/pdf/10.1007/s11263-010-0390-2.pdf

*2z/input and target shapes must be the same. Got: z and ).r      ).   meansumnonezInvalid reduction option.)r   r   r   shapesqrtr   r   NotImplementedError)r   r	   r
   epes       W/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/metrics/endpoint_error.pyaeper      s    < 5!6"usCj)vSz*v||#'VW\WbWbVcchioiuiuhv%w &MF6N2q8E&MFSYN<Z_`;``ffhCFhhj J 
e	ggi J 
f	 J ""=>>    c                      ^  \ rS rSrSrSS\SS4U 4S jjjrS\R                  S\R                  S\R                  4S	 jr	S
r
U =r$ )AEPEL   aX  Computes the average endpoint error (AEPE) between 2 flow maps.

EPE is the endpoint error between two 2D vectors (e.g., optical flow).
Given a h x w x 2 optical flow map, the AEPE is:

.. math::

    \text{AEPE}=\frac{1}{hw}\sum_{i=1, j=1}^{h, w}\sqrt{(I_{i,j,1}-T_{i,j,1})^{2}+(I_{i,j,2}-T_{i,j,2})^{2}}

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

Shape:
    - input: :math:`(*, 2)`.
    - target :math:`(*, 2)`.
    - output: :math:`(1)`.

Examples:
    >>> input1 = torch.rand(1, 4, 5, 2)
    >>> input2 = torch.rand(1, 4, 5, 2)
    >>> epe = AEPE(reduction="mean")
    >>> epe = epe(input1, input2)

r
   r   Nc                 .   > [         TU ]  5         Xl        g N)super__init__r
   )selfr
   	__class__s     r   r!   AEPE.__init__i   s    'r   r   r	   c                 .    [        XU R                  5      $ r   )r   r
   )r"   r   r	   s      r   forwardAEPE.forwardm   s    E4>>22r   )r
   r   )__name__
__module____qualname____firstlineno____doc__strr!   torchr   r&   __static_attributes____classcell__)r#   s   @r   r   r   L   sK    8(# (4 ( (3U\\ 35<< 3ELL 3 3r   r   r(   )r/   r   r   kornia.core.checkr   r   r   r.   r   Moduler   average_endpoint_error r   r   <module>r6      s]   $   V V1 1ell 1s 1PUP\P\ 1h"3299 "3J  r   