+
    åûjY?  ã                  óž   € R t ^ RIHt ^ RIHt ^ RIt^ RIHt ^ RIHtH	t	H
t
Ht R R ltR R	 ltR
 R ltR R ltRR R lltRR R lltR# )a€  Angular pose-error metrics and pose AUC.

The rotation error is the geodesic angle between two rotation matrices; the translation error is the
angle between two translation directions, optionally folded into ``[0, 90]`` degrees to absorb the
sign ambiguity of an essential-matrix translation. :func:`auc_from_errors` summarizes any error array
as the area under its cumulative curve.
)Úannotations)ÚSequenceN)ÚTensor)ÚKORNIA_CHECKÚKORNIA_CHECK_IS_TENSORÚKORNIA_CHECK_SAME_SHAPEÚKORNIA_CHECK_SHAPEc               ó$   € V ^8„  d   QhRRRRRR/# )é   Ú	sin_thetar   Ú	cos_thetaÚreturn© )Úformats   "ÚOC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\metrics\pose.pyÚ__annotate__r   )   s!   € ÷ 5ñ 5˜&ð 5¨Vð 5¸ñ 5ó    c                óÂ   € \         P                  ! \         P                  ! V ) V4      ) 4      pW,           p\         P                  ! \         P                  ! V4      W24      # )zdAngle in degrees from a non-negative sine and a cosine, the same in eager, compiled and ONNX graphs.)ÚtorchÚrad2degÚatan2ÚwhereÚisnan)r   r   ÚthetaÚnans   &&  r   Ú
_angle_degr   )   sD   € ô �MŠMœ5Ÿ;š;¨	 z°9Ó=Ð=Ó>€Eà
Õ
€CÜ�;Š;”u—{’{ 3Ó'¨Ó4Ð4r   c               ó$   € V ^8„  d   QhRRRRRR/# )r
   ÚR1r   ÚR2r   r   )r   s   "r   r   r   3   s!   € ÷ 3,ñ 3,˜ð 3, Fð 3,¨vñ 3,r   c                óæ  € \        V 4       \        V4       \        V . RO4       \        V. RO4       \        W4       V P                  RR4      V,          pVP	                  RRR7      P                  R4      pVR,
          R,          pW"P                  RR4      ,
          pR\        P                  ! VR	,          VR
,          VR,          3RR7      P                  RR7      ,          p\        Wd4      # )a  Compute the geodesic angle, in degrees, between two rotation matrices.

``angle = angle_error_mat(R1, R2)`` takes rotations of shape ``(*, 3, 3)`` and returns the angle of the relative
rotation :math:`R = R_1^\top R_2`, in :math:`[0, 180]` degrees, with shape ``(*,)``.

Convention:
    See the Convention block of :func:`~kornia.metrics.pose_errors`, whose ``"R_err"`` this is: one angle in
    degrees per pair, symmetric in ``R1`` and ``R2``. An unbatched pair gives a 0-d tensor. The inputs are not
    checked to be rotations.

Args:
    R1: a rotation matrix of shape ``(*, 3, 3)``.
    R2: a rotation matrix of shape ``(*, 3, 3)``.

Returns:
    the per-matrix angle in degrees, with shape ``(*,)``.

.. note::
    The trace of :math:`R` is :math:`1 + 2\cos\theta` and its skew part is
    :math:`(R - R^\top) / 2 = \sin\theta\,[\mathbf{n}]_\times` for the unit axis :math:`\mathbf{n}`, so
    :math:`\theta = \operatorname{atan2}(\sin\theta, \cos\theta)`. Reading :math:`\sin\theta` from the skew
    part keeps the digits of small angles that :math:`\arccos\!\big((\mathrm{tr}\,R - 1) / 2\big)` loses next
    to :math:`1`: in float32 the result stays within about :math:`2 \cdot 10^{-5}` degrees of the exact angle
    over the whole range.

.. note::
    The angle has a kink at exactly :math:`0^\circ` and :math:`180^\circ` (identical or opposite
    rotations). The gradient there is the subgradient :math:`0` that ``norm`` returns at a zero
    vector, so backpropagating through a perfect or exactly-opposite match stays finite.

See Also:
    - :func:`~kornia.metrics.angle_error_vec`: the angle between two vectors.
    - :func:`~kornia.metrics.pose_errors`: this rotation error and a translation error for whole poses.

Example:
    >>> angle_error_mat(torch.eye(3), torch.eye(3))
    tensor(0.)
)Údim1Údim2g      ð?g       @g      à?©Údim)Ú*Ú3r%   éþÿÿÿéÿÿÿÿ).r
   é   ).é    r
   ).r(   r)   )
r   r   r   Ú	transposeÚdiagonalÚsumr   ÚstackÚnormr   )r   r   ÚrelativeÚtracer   Úskewr   s   &&     r   Úangle_error_matr2   3   sÌ   € ôN ˜2ÔÜ˜2ÔÜ�rš?Ô+Ü�rš?Ô+Ü˜BÔ#à�|‰|˜B Ó# bÕ(€HØ×Ñ 2¨BÐÓ/×3Ñ3°BÓ7€EØ˜• Õ#€Ià×(Ñ(¨¨RÓ0Õ0€DØ”e—k’k 4¨	¥?°D¸µOÀTÈ)Å_Ð"UÐ[]Ô^×cÑcÐhjÐcÓkÕk€IÜ�iÓ+Ð+r   c               ó$   € V ^8„  d   QhRRRRRR/# )r
   Úv1r   Úv2r   r   )r   s   "r   r   r   i   s!   € ÷ 9,ñ 9,˜ð 9, Fð 9,¨vñ 9,r   c                ó¾  € \        V 4       \        V4       \        V RR.4       \        VRR.4       \        W4       W P                  4       P	                  RRR7      ,          p WP                  4       P	                  RRR7      ,          p\
        P                  P                  WRR7      P                  RR7      pW,          P                  R4      p\        W#4      # )a"  Compute the angle, in degrees, between two vectors.

``angle = angle_error_vec(v1, v2)`` takes 3D vectors of shape ``(*, 3)`` and returns the angle between their
directions in :math:`[0, 180]` degrees, with shape ``(*,)``.

Convention:
    See the Convention block of :func:`~kornia.metrics.pose_errors`, whose ``"t_err"`` is this angle before
    folding: one angle in degrees per pair, symmetric in ``v1`` and ``v2`` up to roundoff. An unbatched pair gives
    a 0-d tensor. Only the directions are compared, so the vectors need not have unit length. The angle is not
    folded: opposite vectors give 180.

Args:
    v1: a vector of shape ``(*, 3)``.
    v2: a vector of shape ``(*, 3)``.

Returns:
    the per-vector angle in degrees, with shape ``(*,)``.

.. note::
    With the unit vectors :math:`\hat v_1` and :math:`\hat v_2`, the angle is
    :math:`\theta = \operatorname{atan2}(\lVert \hat v_1 \times \hat v_2 \rVert, \hat v_1 \cdot \hat v_2)`.
    Reading :math:`\sin\theta` from the cross product keeps the digits of small angles that
    :math:`\arccos(\hat v_1 \cdot \hat v_2)` loses next to :math:`1`: in float32 the result stays within
    about :math:`2 \cdot 10^{-5}` degrees of the exact angle over the whole range.

.. note::
    The angle has a kink at exactly :math:`0^\circ` and :math:`180^\circ` (identical or opposite
    vectors). The gradient there is the subgradient :math:`0` that ``norm`` returns at a zero
    vector, so backpropagating through a perfect or exactly-opposite match stays finite.

.. note::
    A zero-length vector gives ``NaN`` rather than raising, since the angle is undefined there.
    Mask those entries before reducing.

See Also:
    - :func:`~kornia.metrics.angle_error_mat`: the angle between two rotations.
    - :func:`~kornia.metrics.translation_ate`: the distance between two translations, which keeps the magnitude.
    - :func:`~kornia.metrics.pose_errors`: folds this angle into ``"t_err"`` and adds the rotation error.

Example:
    >>> v = torch.tensor([1.0, 0.0, 0.0])
    >>> angle_error_vec(v, v)
    tensor(0.)
r$   r%   T)r#   Úkeepdimr"   r'   )r   r   r   ÚabsÚamaxr   ÚlinalgÚcrossr.   r,   r   )r4   r5   r   r   s   &&  r   Úangle_error_vecr<   i   s³   € ôZ ˜2ÔÜ˜2ÔÜ�r˜C ˜:Ô&Ü�r˜C ˜:Ô&Ü˜BÔ#ð 
�f‰f‹h�m‰m ¨DˆmÓ1Õ	1€BØ	�f‰f‹h�m‰m ¨DˆmÓ1Õ	1€BÜ—‘×"Ñ" 2¨rÐ"Ó2×7Ñ7¸BÐ7Ó?€IØ•—‘˜bÓ!€IÜ�iÓ+Ð+r   c               ó$   € V ^8„  d   QhRRRRRR/# )r
   Útr   Út_gtr   r   )r   s   "r   r   r   ¥   s!   € ÷ (#ñ (#�vð (# Vð (#°ñ (#r   c                ó\  € \        V 4       \        V4       \        V RR.4       \        VRR.4       \        V P                  VP                  8H  RV P                   RVP                   24       V P	                  4       ^8X  d   V R,          VR,          rW,
          P                  RR7      # )aV  Compute the absolute translation error (ATE), the distance between two translations.

``err = translation_ate(t, t_gt)`` takes translations of shape ``(*, 3)`` and returns the Euclidean distance
:math:`\lVert t - t_{gt} \rVert_2`. It keeps the magnitude, so it is meaningful only when both translations share
a metric scale and not for a translation known only up to scale, such as one from an essential matrix: use
:func:`~kornia.metrics.angle_error_vec` there.

Convention:
    The result is one distance per sample, in the units of the translations, with no alignment: a trajectory
    shifted by a constant keeps that offset at every pose.

Args:
    t: an estimated translation of shape ``(*, 3)``.
    t_gt: a ground-truth translation of the same shape as ``t``.

Returns:
    the per-sample distance, with shape ``(*,)``. An unbatched ``(3,)`` input returns shape ``(1,)``.

.. note::
    The gradient stays finite even at zero distance, where ``norm`` returns the subgradient ``0``.

See Also:
    - :func:`~kornia.metrics.angle_error_vec`: the angle between translation directions, which ignores the scale.
    - :func:`~kornia.metrics.pose_errors`: the angular rotation and translation errors of whole poses.

Example:
    >>> t = torch.tensor([0.0, 0.0, 0.0])
    >>> t_gt = torch.tensor([3.0, 4.0, 0.0])
    >>> translation_ate(t, t_gt)
    tensor([5.])
r$   r%   z#t and t_gt shapes must match. Got: ú and Nr"   r'   )r   r   r   Úshaper#   r.   )r>   r?   s   &&r   Útranslation_aterC   ¥   s’   € ô@ ˜1ÔÜ˜4Ô Ü�q˜3 ˜*Ô%Ü�t˜c 3˜ZÔ(Ü�—‘˜DŸJ™JÑ&Ð*MÈaÏgÉgÈYÐV[Ð\`×\fÑ\fÐ[gÐ(hÔià‡u�uƒw�!„|Ø�D•'˜4 �:ˆ4Ø�H�?‰?˜rˆ?Ó"Ð"r   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r
   ÚPr   ÚP_gtÚfold_translationÚboolr   zdict[str, Tensor]r   )r   s   "r   r   r   Ð   s/   € ÷ 8Tñ 8T�6ð 8T ð 8T¸4ð 8TÐK\ñ 8Tr   c           	     ó¬  € \        V 4       \        V4       \        V P                  VP                  8H  RV P                   RVP                   24       \        V P                  4       R	9   ;'       d5    V P                  R
,          R9   ;'       d    V P                  R,          ^8H  RV P                   24       V P                  4       ^8X  d   V R,          VR,          r\	        V R,          VR,          4      p\        V R,          VR,          4      pV'       d   \        P                  ! VRV,
          4      pRVRVR\        P                  ! W44      /# )aS  Compute the rotation and translation angular errors, in degrees, between two relative poses.

``errs = pose_errors(P, P_gt)`` takes poses ``[R | t]`` of shape ``(B, 3, 4)`` or ``(B, 4, 4)`` and returns a
dict of per-pose errors, each in degrees with shape ``(B,)``.

Convention:
    - Every error is one angle per pose, never averaged over the batch; an unbatched pose gives shape ``(1,)``,
      where :func:`~kornia.metrics.angle_error_mat` gives a 0-d tensor.
    - ``"R_err"`` is :func:`~kornia.metrics.angle_error_mat` of the two rotation blocks and is never folded.
      ``"t_err"`` is :func:`~kornia.metrics.angle_error_vec` of the two translations, so it compares their
      directions only, folded as ``fold_translation`` says. ``"max_err"`` is the larger of the two per pose.
    - Only the top three rows are read: the bottom row of a ``(4, 4)`` pose is ignored.

Args:
    P: an estimated relative pose ``[R | t]`` of shape ``(3, 4)``, ``(4, 4)``, or batched
        ``(B, 3, 4)`` / ``(B, 4, 4)``.
    P_gt: a ground-truth relative pose of the same shape.
    fold_translation: if ``True`` (default), fold the translation error into :math:`[0, 90]` via
        :math:`\min(e, 180 - e)` to absorb the sign ambiguity of an essential-matrix translation.

Returns:
    a dict with ``"R_err"`` (rotation), ``"t_err"`` (translation) and ``"max_err"`` (their element-wise max).

.. note::
    A pose with zero translation gives ``NaN`` for ``"t_err"`` and ``"max_err"``, and
    :func:`~kornia.metrics.auc_from_errors` propagates that into the AUC. Mask those entries first.

See Also:
    - :func:`~kornia.metrics.angle_error_mat`: the rotation error alone, from rotation matrices.
    - :func:`~kornia.metrics.angle_error_vec`: the translation error alone, before folding.
    - :func:`~kornia.metrics.auc_from_errors`: summarizes ``"max_err"`` over many pairs.
    - :func:`~kornia.metrics.translation_ate`: the translation distance, which keeps the magnitude.

Example:
    >>> P = torch.eye(4)
    >>> P[0, 3] = 1.0
    >>> errs = pose_errors(P, P)
    >>> errs["R_err"], errs["t_err"]
    (tensor([0.]), tensor([0.]))
z#P and P_gt shapes must match. Got: rA   z)P must be (3, 4)/(4, 4) or batched. Got: Ng     €f@ÚR_errÚt_errÚmax_err)r
   é   r&   )rM   é   r'   ).ºNrM   NrO   ).rO   rM   )	r   r   rB   r#   r2   r<   r   ÚminimumÚmaximum)rE   rF   rG   Úr_errrK   s   &&&  r   Úpose_errorsrS   Ð   s  € ôR ˜1ÔÜ˜4Ô Ü�—‘˜DŸJ™JÑ&Ð*MÈaÏgÉgÈYÐV[Ð\`×\fÑ\fÐ[gÐ(hÔiÜØ	�‰‹�6Ñ×HÐH˜aŸg™g b�k¨VÑ3×HÐH¸¿¹À½ÀqÑ8HØ
3°A·G±G°9Ð=ôð
 	‡u�uƒw�!„|Ø�D•'˜4 �:ˆ4ä˜A˜k�N¨D°Õ,=Ó>€EÜ˜A˜j�M¨4°
Õ+;Ó<€EßÜ—’˜e U¨U¥]Ó3ˆØ�U˜G U¨I´u·}²}ÀUÓ7RÐSÐSr   c               ó$   € V ^8„  d   QhRRRRRR/# )r
   Úerrorsr   Ú
thresholdszfloat | Sequence[float]r   zdict[float, float]r   )r   s   "r   r   r     s(   € ÷ Dñ D˜Fð DÐ0Gð DÐ\nñ Dr   c           	     ó
  € \        V 4       \        V\        \        34      '       d   V.pV Uu. uF  p\        V4      NK  	  pp\	        \        V4      ^ 8„  R4       \	        \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      RV 24       V P                  4       p V P                  \        P                  \        P                  39  d%   V P                  \        P                  ! 4       4      p \	        \        V ^ 8  P                  4       4      '       * R4       \        \        P                   ! V 4      P                  4       4      '       d    \"        P%                  V\        R4      4      # V P'                  4       P(                  p V P+                  4       p\        P,                  ! ^V^,           V P.                  V P                  R7      V,          p\        P0                  ! V P3                  ^4      V .4      p \        P0                  ! VP3                  ^4      V.4      p/ pV FÄ  p\        \        P4                  ! W P7                  V4      4      P9                  4       4      p\        P0                  ! VR	V WF^,
          V .4      p\        P0                  ! V R	V V P7                  V.4      .4      p\        P:                  ! WxR
7      p	W’,          P9                  4       R,          WR&   KÆ  	  V# u upi )a6  Compute the area under the cumulative error curve at one or more thresholds, in percent.

``auc = auc_from_errors(errors, thresholds)`` takes any non-negative errors ``(B,)``, such as the
``"max_err"`` of :func:`~kornia.metrics.pose_errors`, and thresholds in their units, and returns a dict from
each threshold to its AUC.

Convention:
    - All errors are pooled into one curve, whatever their shape. The recall curve rises by :math:`1/n` at each
      of the :math:`n` sorted errors, joined to :math:`(0, 0)` and to each other by straight lines (the trapezoid
      rule), and is held flat from the last error below the threshold out to the threshold. The AUC is its area
      divided by the threshold, times 100: a **percentage**, keyed by the threshold as a Python float. An ``inf``
      error never enters the area, so it counts as a failure. :ref:`Losses and metrics
      <losses-metrics-conventions>` maps the AUC and :func:`~kornia.metrics.pose_errors` onto glue-factory and
      SuperGlue.

Args:
    errors: per-sample error values of shape ``(B,)``. Must be non-negative. Integer and
        half-precision inputs are promoted to the default floating dtype before accumulating.
    thresholds: a single threshold or a sequence of thresholds, in the same units as ``errors``.
        Must be strictly positive. Defaults to ``(1, 3, 5, 10)``.

Returns:
    a dict mapping each threshold to its AUC in :math:`[0, 100]`, or ``NaN`` at every threshold
    if any error is ``NaN``.

.. note::
    An error exactly equal to a threshold contributes no area there, so errors all equal to
    ``thr`` score ``0`` at ``thr``. This follows the reference implementations.

See Also:
    - :func:`~kornia.metrics.pose_errors`: computes the errors to summarize.

Example:
    >>> auc_from_errors(torch.zeros(1), thresholds=5.0)
    {5.0: 100.0}
zthresholds must not be empty.c              3  ó*   "  € T F	  q^ 8„  x € K  	  R# 5i)r)   Nr   )Ú.0Úthrs   & r   Ú	<genexpr>Ú"auc_from_errors.<locals>.<genexpr>5  s   é € Ð3©
 ˜1–W«
ùs   ‚FTz"thresholds must be positive. Got: zerrors must be non-negative.r   )ÚdeviceÚdtypeN)Úxg      Y@)r   Ú
isinstanceÚintÚfloatr   ÚlenÚallÚflattenr^   r   Úfloat32Úfloat64ÚtoÚget_default_dtyperH   Úanyr   ÚdictÚfromkeysÚsortÚvaluesÚnumelÚaranger]   ÚcatÚ	new_zerosÚsearchsortedÚ
new_tensorÚitemÚ	trapezoid)
rU   rV   rZ   ÚnÚrecallÚaucsÚlastÚrecall_belowÚerrors_belowÚareas
   &&        r   Úauc_from_errorsr~     sA  € ôJ ˜6Ô"Ü�*œs¤E˜l×+Ò+Ø �\ˆ
Ù(2Ó3©
 ”%˜–*©
€JÐ3Ü”�Z“ 1Ñ$Ð&EÔFÜ—“Ñ3©
Ó3——’Ñ3©
Ó3Ó3Ð7YÐZdÐYeÐ5fÔgà�^‰^Ó€Fà‡|�|œEŸM™M¬5¯=©=Ð9Ô9Ø—‘œ5×2Ò2Ó4Ó5ˆô ”T˜6 A™:×*Ñ*Ó,Ó-Ô-Ð/MÔNÜŒE�KŠK˜Ó×#Ñ#Ó%×&Ò&Ü�}‰}˜Z¬¨u«Ó6Ð6Ø�[‰[‹]×!Ñ!€FØ�‰‹€AÜ�\Š\˜!˜Q �U¨6¯=©=ÀÇÁÔMÐPQÕQ€FÜ�YŠY˜×(Ñ(¨Ó+¨VÐ4Ó5€FÜ�YŠY˜×(Ñ(¨Ó+¨VÐ4Ó5€Fà!€DÛˆô ”5×%Ò% f×.?Ñ.?ÀÓ.DÓE×JÑJÓLÓMˆÜ—y’y &¨¨$ -°¸q½À4Ð1HÐ!IÓJˆÜ—y’y &¨¨$ -°×1BÑ1BÀCÀ5Ó1IÐ!JÓKˆÜ�Š˜|Ô<ˆØ•Z×%Ñ%Ó'¨%Õ/ˆ‹	ñ ð €Kùò9 4s   ¯L )T))r(   rM   é   é
   )Ú__doc__Ú
__future__r   Úcollections.abcr   r   r   Úkornia.core.checkr   r   r   r   r   r2   r<   rC   rS   r~   r   r   r   Ú<module>r…      sL   ðñ$õ #å $ã Ý ÷ó õ5õ3,õl9,õx(#÷V8T÷vDñ Dr   