+
    åûjÅû  ã                   ó‚  a € R@ t70 t ^ RIHtHtHtHtHtHt ^ RIt^ RIH	t	 ^ RI
Ht ^ RIHtHt ^ RIHtHtHtHt ^ RIHt ^ RIHt ^R	IHt ]! ^^4      tR
 R ltR R ltRRARRB/t] ^ k RCR R lltR R ltR R lt R R lt!R R lt"R R lt#R R lt$R R lt%RCR  R! llt&R" R# lt'R$ R% lt(RDR& R' llt)RER( R) llt*RCR* R+ llt+RCR, R- llt,R. R/ lt-RFR0 R1 llt.RGR2 R3 llt/RHR4 R5 llt0RIR6 R7 llt1RJR8 R9 llt2 ! R: R;]	Pf                  4      t4 ! R< R=]	Pf                  4      t5 ! R> R?]	Pf                  4      t6R# )Ké    )ÚAnyÚClassVarÚDictÚListÚOptionalÚTupleN)Únn)Útorch_version_ge)ÚKORNIA_CHECK_DM_DESCÚKORNIA_CHECK_SHAPE)Ú_l2_normalizeÚis_autocast_enabledÚis_exportingÚis_mps_tensor_safe)Úget_laf_center)ÚDiscreteSteerer)Úmatch_adalamc                óD   € V ^8„  d   QhR\         P                  R\        /# )é   ÚxÚreturn)ÚtorchÚTensorÚbool)Úformats   "ÚSC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\feature\matching.pyÚ__annotate__r   #   s   € ÷ 9ñ 9œeŸl™lð 9¬tñ 9ó    c                ó²   € \        4       '       d   R# Rp\        P                  P                  4       '       g   \        pT;'       g    \        V 4      '       * # )zgReturn whether ``torch.cdist`` can compute, and differentiate, the distances of descriptors like ``x``.F)r   r   ÚjitÚis_scriptingÚ_MPS_HAS_CDIST_BACKWARDr   )r   Úmps_has_backwards   & r   Ú_torch_cdist_availabler$   #   sB   € ä‡~‚~ÙàÐÜ�9‰9×!Ñ!×#Ò#Ü2ÐØ×8Ð8Ô#5°aÓ#8Ô8Ð8r   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   Úd1Úd2r   ©r   r   )r   s   "r   r   r   .   s-   € ÷ $&ñ $&Œu�|‰|ð $&¤§¡ð $&´%·,±,ñ $&r   c           	     ór  € \         P                  \         P                  3pV P                  p\         P                  P                  4       '       gÁ   V P                  VP                  8w  d¦   \         P                  \         P                  \         P                  3p\        4       '       d#   V P                  V9   d   VP                  V9   g&   \        RV P                   RVP                   24      hV P                  4       VP                  4       rW29   d    V P                  4       VP                  4       r\        V 4      '       d*   \        V4      '       d   \         P                  ! W4      pEM\         P                  ! RRR7      ;_uu_ 4        \         P                  ! RRR7      ;_uu_ 4        V ^,          P                  ^RR7      pV^,          P                  ^RR7      pWgP                  4       ,           R	V ,          VP                  4       ,          ,
          pVP                  R
R7      pVR
8„  p	\         P                   ! W˜R4      p
\         P                   ! WšP#                  4       R
4      pRRR4       RRR4       XP%                  V4      #   + '       g   i     L); i  + '       g   i     L4; i)aò  Compute pairwise L2 distances between rows of d1 and d2.

Uses ``torch.cdist``, except under export, where it has no ONNX lowering, and on
MPS before torch 2.13, where it has no backward. Both fall back to the
matrix-multiplication form of the squared distance. Half-precision inputs are
computed in float32: in half precision the squared norms round away the squared
distance between nearby descriptors, and ``torch.cdist`` has no float16 kernel on
CPU. Distances are returned in the input dtype.
z.The descriptors must have the same dtype, got z and ÚcpuF)Údevice_typeÚenabledÚcudaT)ÚdimÚkeepdimg       @ç        )Úminç      ð?N)r   Úfloat16Úbfloat16Údtyper    r!   Úfloat32r   ÚRuntimeErrorÚfloatr$   ÚcdistÚautocastÚsumÚtÚclampÚwhereÚsqrtÚto)r&   r'   ÚhalfÚoutput_dtypeÚcastableÚ	distancesÚd1_sqÚd2_sqÚdmÚmaskÚsafe_dms   &&         r   Ú_cdistrJ   .   sÕ  € ô �M‰Mœ5Ÿ>™>Ð*€DØ—8‘8€Lä�9‰9×!Ñ!×#Ò#Ø�8‰8�r—x‘xÔô Ÿ™¤u§~¡~´u·}±}ÐEˆHÜ'×)Ò)¨b¯h©h¸(Ô.BÀrÇxÁxÐS[ÔG[Ü"Ð%SÐTV×T\ÑT\ÐS]Ð]bÐce×ckÑckÐblÐ#mÓnÐnØ—X‘X“Z §¡£�ØÔØ—‘“˜RŸX™X›ZˆBÜ˜b×!Ò!Ô&<¸R×&@Ò&@Ü—K’K Ó'Š	ô �^Š^¨°u×=Ö=¼u¿~º~ÐZ`Ðjo×?pÖ?pØ˜•U—K‘K A¨t�KÓ4ˆEØ˜•U—K‘K A¨t�KÓ4ˆEØŸ™›Õ" S¨2¥X°·±³Õ%6Õ6ˆBØ—‘˜c�Ó"ˆBØ˜‘8ˆDÜ—k’k $¨CÓ0ˆGÜŸš D¯,©,«.¸#Ó>ˆI÷ @q×=ð �<‰<˜Ó%Ð%÷ @q×?pú×=×=ús%   Æ!J&Æ1CJ	É2J&ÊJ#ÊJ&Ê&J6	r*   r-   c          	      óÄ   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        \         P                  ,          /# ©r   Údesc1Údesc2rG   r   ©r   r   r   )r   s   "r   r   r   [   sF   € ÷ *&ñ *&Ü�<‰<ð*&Ü %§¡ð*&Ü2:¼5¿<¹<Õ2Hð*&äŒe�l‰lÕñ*&r   c                óV  € Vf5   \        4       '       g%   \        P                  P                  4       '       d   R# \        P                  V P                  P                  4      pVe-   V P                  ^ 4      VP                  ^ 4      ,          V8  d   R# V P                  ^ 4      ^8:  d   VP                  ^ 4      ^8:  d   R# V P                  VP                  8w  g@   V P                  \        P                  \        P                  39  g   \        4       '       d   R# \        P                  ! 4       '       d'   V P                  '       g   VP                  '       d   R# V P                  ^4      P!                  RRR7      pVP                  ^4      P!                  RRR7      p\        P"                  ! V P%                  R4      V\        P&                  ! V4      .R4      p\        P"                  ! V\        P&                  ! V4      V.R4      pVP)                  VP*                  4      # )a  Return the squared L2 distances whose square roots ``torch.cdist`` returns, or ``None``.

For more than 25 rows on either side, ``torch.cdist`` computes the distances by matrix multiplication
(ATen's ``_euclidean_dist``). It appends the squared norms to the descriptors, multiplies, and then takes
``clamp_min(0).sqrt()`` of the whole matrix. This function computes the same product, bit for bit, without the
last two passes. The matchers select on it and take the square root of the selected entries only, which returns
the bits ``torch.cdist`` would have returned for them. The selection is the same too, because the square root
keeps the order, with one difference: two distances that differ only below the precision of their square roots
tie in ``torch.cdist``'s matrix, and are not tied here, so a matcher returns the nearer one.

It returns ``None``, and the matchers use :func:`_get_lazy_distance_matrix`, in these cases:

- ``dm`` is given.
- Either descriptor set needs a gradient: the matchers' in-place selections would break autograd.
- The dtypes differ or are not float32 or float64.
- Autocast is on, where ``torch.cdist`` runs in float32 and a matrix product would not.
- The call is exported or traced.
- The device is neither the CPU nor CUDA. MPS is not measured.
- Neither side has more than 25 rows, the case in which ``torch.cdist`` computes the differences directly.
- The matrix has fewer entries than :data:`_SQUARED_MIN_NUMEL` gives for the device.

Only the matchers' non-scripted path calls it, so TorchScript never compiles it.
NT)r/   éÿÿÿÿéþÿÿÿ)r   r   r    Ú
is_tracingÚ_SQUARED_MIN_NUMELÚgetÚdeviceÚtypeÚsizer5   r6   Úfloat64r   Úis_grad_enabledÚrequires_gradÚpowr;   ÚcatÚmulÚ	ones_likeÚmatmulÚmT)rM   rN   rG   Ú	min_numelÚnorms1Únorms2Úpadded1Úpadded2s   &&&     r   Ú_squared_distancesrg   [   sv  € ð6 
‚~œŸš¬5¯9©9×+?Ñ+?×+AÒ+AÙÜ"×&Ñ& u§|¡|×'8Ñ'8Ó9€IØÒ˜EŸJ™J q›M¨E¯J©J°q«MÕ9¸IÔEÙØ‡z�z�!ƒ}˜Ô˜uŸz™z¨!›}°Ô2ÙØ‡{�{�e—k‘kÔ! U§[¡[¼¿¹ÌÏÉÐ8VÔ%VÔZm×ZoÒZoÙÜ×Ò×Ò E×$7×$7Ð$7¸5×;N×;NÐ;NÙØ�Y‰Y�q‹\×Ñ˜b¨$ÐÓ/€FØ�Y‰Y�q‹\×Ñ˜b¨$ÐÓ/€FÜ�iŠi˜Ÿ™ 2›¨´·²ÀÓ0GÐHÈ"ÓM€GÜ�iŠi˜¤§¢°Ó 7¸Ð@À"ÓE€GØ�>‰>˜'Ÿ*™*Ó%Ð%r   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# ©r   Úsquaredr   r(   )r   s   "r   r   r   ˆ   s"   € ÷ 'ñ '¤E§L¡Lð '´U·\±\ñ 'r   c                ó@   € V P                  ^ 4      P                  4       # )zÆReturn the L2 distance ``torch.cdist`` derives from a squared distance of :func:`_squared_distances`.

No gradient flows here (see :func:`_squared_distances`), so the clamp is not a gradient guard.
)Ú	clamp_minr?   ©rj   s   &r   Ú_distance_from_squaredrn   ˆ   s   € ð
 ×Ñ˜QÓ×$Ñ$Ó&Ð&r   c                óD   € V ^8„  d   QhR\         P                  R\        /# )r   r5   r   )r   r5   r8   )r   s   "r   r   r   �   s"   € ÷ Wñ Wœ5Ÿ;™;ð W¬5ñ Wr   c                ó4   € V \         P                  8X  d   R# R# )z¼Return ``torch.finfo(dtype).max`` for the float32 and float64 of :func:`_squared_distances`.

TorchScript, which compiles the matchers' calls of the helpers below, has no ``torch.finfo``.
g   àÿÿïGgÿÿÿÿÿÿï)r   r6   )r5   s   &r   Ú_largest_finiterq   �   s   € ð
 %*¬U¯]©]Ô$:Ð ÐVÐ@VÐVr   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# ri   r(   )r   s   "r   r   r   ˜   s&   € ÷ nñ nœeŸl™lð n¬u¯|©|ñ nr   c                ót   € V P                  \        R4      \        V P                  4      \        R4      R7      # )a¦  Map ``squared`` in place to a key without nan, which orders as ``torch.topk`` orders it.

``torch.topk`` orders nan after ``+inf``. ``torch.min`` returns the first nan of a row instead. The key keeps the
numbers and ``-inf``, and maps ``+inf`` to the largest finite value and nan to ``+inf``. :func:`_key_to_squared`
maps them back. Only a squared distance of exactly the largest finite value would come back as ``+inf``.
Úinfz-inf©ÚnanÚposinfÚneginf)Únan_to_num_r8   rq   r5   rm   s   &r   Ú_topk_order_key_rz   ˜   s0   € ð ×Ñ¤5¨£<¼ÈÏÉÓ8VÔ_dÐekÓ_lÐÓmÐmr   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )r   Úkeyr   r(   )r   s   "r   r   r   ¢   s&   € ÷ jñ jœŸ™ð j¬%¯,©,ñ jr   c           
     óÈ   € \        V P                  4      p\        P                  ! V \	        R4      8H  \	        R4      \        P                  ! W8H  \	        R4      V 4      4      # )zRInvert :func:`_topk_order_key_` for the few entries a selection took from the key.rt   rv   )rq   r5   r   r>   r8   )r|   Úlargests   & r   Ú_key_to_squaredr   ¢   sG   € ä˜cŸi™iÓ(€GÜ�;Š;�sœe E›lÑ*¬E°%«L¼%¿+º+ÀcÁnÔV[Ð\aÓVbÐdgÓ:hÓiÐir   c          	      ó¸   € V ^8„  d   QhR\         P                  R\        R\        \         P                  \         P                  \         P                  3,          /# )r   r|   r.   r   ©r   r   Úintr   )r   s   "r   r   r   ¨   s@   € ÷  ñ  œŸ™ð  ¬3ð  ´5¼¿¹ÄuÇ|Á|ÔUZ×UaÑUaÐ9aÕ3bñ  r   c                óì   € V P                  V4      w  r#VP                  V4      pV P                  W\        R4      4       V P	                  V4      pV P                  WVP                  V4      4       W%V3# )a¨  Return the two smallest entries of ``key`` along ``dim``, and the index of the smallest.

The values are those of ``torch.topk(key, 2, dim, largest=False)``. The index is the first of tied smallest
entries; ``torch.topk`` orders no ties. The second entry is the minimum after the first is masked in place with
``+inf``. The mask is then undone, so ``key`` keeps its values.

The ratio tests of :func:`match_snn` and :func:`match_smnn` use it on CUDA, where :func:`_squared_distances`
returns a matrix of at least 2,048 x 2,048 entries. There this reads the matrix twice and writes one entry per
row or column, while ``torch.topk`` selects by radix. With 8,192 x 8,192 float32 distances on an RTX 4090
(torch 2.14), it takes 0.6 ms for each direction; ``torch.topk`` takes 1.5 ms for the rows and 3.0 ms for the
columns. On the CPU ``torch.topk`` stays, which is faster there than reductions, see
:func:`_first_to_second_nearest_ratio`.
rt   )r1   Ú	unsqueezeÚscatter_r8   Úamin)r|   r.   ÚfirstÚindexÚpickedÚseconds   &&    r   Ú_two_smallest_r‹   ¨   sb   € ð —7‘7˜3“<�L€EØ�_‰_˜SÓ!€FØ‡L�L�œe E›lÔ+Ø�X‰X�c‹]€FØ‡L�L�˜eŸo™o¨cÓ2Ô3Ø˜%ÐÐr   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   r‡   rŠ   r   r(   )r   s   "r   r   r   ¾   s-   € ÷ 'ñ 'œEŸL™Lð '´%·,±,ð 'Ä5Ç<Á<ñ 'r   c                ó‚   € \        \        \        P                  ! W.4      4      4      pV^ ,          V^,          ,          # )ziReturn the distance ratio of the two smallest keys of :func:`_two_smallest_`, as ``torch.topk`` gives it.)rn   r   r   Ústack)r‡   rŠ   rD   s   && r   Ú_ratio_from_keysr�   ¾   s/   € ä&¤´u·{²{ÀEÀ?Ó7SÓ'TÓU€IØ�Q�<˜) A�,Õ&Ð&r   c                óF   € V ^8„  d   QhR\         \        \        3,          /# )r   r   )r   Ústrr   )r   s   "r   r   r   Ä   s   € ÷ =ñ =¤4¬¬S¨¥>ñ =r   c                  ó   € R RRRRR/# )Úthg333333ë?ÚmutualFÚ
spatial_thç      $@© r—   r   r   Ú_get_default_fginn_paramsr˜   Ä   s   € Ø�$˜ %¨°tÐ<Ð<r   c                ó®   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\         P                  /# )r   rM   rN   Údm_r   rO   )r   s   "r   r   r   È   sA   € ÷ ñ Ü�<‰<ðÜ %§¡ðÜ3;¼E¿L¹LÕ3Iðä
‡\�\ñr   c                óD   € Vf   \        W4      pV# \        WV4       TpV# )ac  Check validity of provided distance matrix, or calculates L2-distance matrix if dm is not provided.

Args:
    desc1: Batch of descriptors of a shape ``(B1, D)``.
    desc2: Batch of descriptors of a shape ``(B2, D)``.
    dm_: torch.Tensor containing the distances from each descriptor in desc1
      to each descriptor in desc2, shape of ``(B1, B2)``.

)rJ   r   )rM   rN   rš   rG   s   &&& r   Ú_get_lazy_distance_matrixrœ   È   s0   € ð ‚{Ü�EÓ!ˆð €Iô 	˜U¨3Ô/ØˆØ€Ir   c                óŽ   € V ^8„  d   QhR\         P                  R\        \         P                  \         P                  3,          /# )r   rG   r   ©r   r   r   )r   s   "r   r   r   Ü   s0   € ÷ 
ñ 
”%—,‘,ð 
¤5¬¯©´u·|±|Ð)CÕ#Dñ 
r   c                óÈ   € \         P                  ! ^ ^V P                  V P                  R7      p\         P                  ! ^ ^V P                  \         P                  R7      pW3# )zÒOutput empty tensors.

Returns:
        - Descriptor distance of matching descriptors, shape of ``(0, 1)``.
        - Long torch.Tensor indexes of matching descriptors in desc1 and desc2, shape of ``(0, 2)``.

)rV   r5   )r   ÚemptyrV   r5   Úlong)rG   ÚdistsÚidxss   &  r   Ú	_no_matchr¤   Ü   sD   € ô �KŠK˜˜1 R§Y¡Y°b·h±hÔ?€EÜ�;Š;�q˜! B§I¡I´U·Z±ZÔ@€DØˆ;Ðr   c                óP   € V ^8„  d   QhR\         P                  R\        R\        /# ©r   Údistance_matrixÚblockr   )r   r   r‚   r   )r   s   "r   r   r   é   s%   € ÷ :ñ :¬e¯l©lð :Ä3ð :Ì4ñ :r   c                óà   € V P                   P                  R8w  g   V P                  ^ 4      ^V,          8:  d   R# \        4       ;'       g    \        P
                  P                  4       '       * # )al  Return whether a reduction over the rows of ``distance_matrix`` runs on blocks of ``block`` rows.

On CPU, ``torch.min`` and ``torch.topk`` over the rows of a row-major ``(B1, B2)`` matrix walk each column with a
stride of ``B2`` elements, which is slow when ``B2`` is a power of two, as keypoint budgets usually are, or when
``B1`` is large. On an Apple M1, the column minimum of a ``(2048, 2048)`` matrix costs 7 times its row minimum and
3 times the distance matrix itself. The same kernels run on blocks of ``block`` rows, then on the few results of
the blocks: 2.4 times faster there, 2.7 times for ``(4096, 4096)`` and 4 times for ``(8000, 8000)``. A matrix of
at most ``2 * block`` rows gains little and keeps one reduction. So do CUDA and MPS, which reduce columns as fast
as rows, and a traced or exported graph, which would record whether the last block is partial.
r*   F)rV   rW   rX   r   r   r    rS   )r§   r¨   s   &&r   Ú_reduces_over_row_blocksrª   é   sQ   € ð ×Ñ×"Ñ" eÔ+¨×/CÑ/CÀAÓ/FÈ!ÈeÍ)Ô/SÙÜ“×8Ð8¤%§)¡)×"6Ñ"6Ó"8Ô9Ð9r   c                óš   € V ^8„  d   QhR\         P                  R\        R\        \         P                  \         P                  3,          /# r¦   r�   )r   s   "r   r   r   ù   s:   € ÷ 6ñ 6¤E§L¡Lð 6¼ð 6ÄuÌUÏ\É\Ô[`×[gÑ[gÐMgÕGhñ 6r   c                óx  € \        W4      '       g   \        P                  ! V ^ R7      # V P                  ^ 4      pW"V,          ,
          pV RV P	                  W1,          VR4      P                  ^R7      w  rEV\        P
                  ! ^ W1V P                  R7      R,          ,           pW28  dY   WR P                  ^ R7      w  rg\        P                  ! WFR,          .4      \        P                  ! WWR,          V,           .4      rTVP                  ^ R7      w  r‰W…P                  ^ V	R,          4      ^ ,          3# )a–  Return each column's minimum and its row, bitwise as ``torch.min(distance_matrix, dim=0)``.

On CPU a matrix of more than ``2 * block`` rows is reduced in blocks of rows, see
:func:`_reduces_over_row_blocks`. ``torch.min`` returns the first of tied minima and the first nan of a column,
and the minimum over the blocks keeps the first block's, so the values, rows and gradients are those of one
reduction.
©r.   N©rV   rQ   ©ºNNNN)	rª   r   r1   rX   ÚreshapeÚarangerV   r]   Úgather)
r§   r¨   ÚrowsÚfullÚvalsr£   Ú	rest_valsÚ	rest_idxsÚbestÚfirst_blocks
   &&        r   Ú_min_over_rowsr»   ù   s
  € ô $ O×;Ò;Ü�yŠy˜¨aÔ0Ð0Ø×Ñ Ó"€DØ˜•,Õ€DØ   $Ð'×/Ñ/°µ¸uÀbÓI×MÑMÐRSÐMÓT�J€DØ”%—,’,˜q $°o×6LÑ6LÔMÈgÕVÕV€DØ„{Ø.¨uÐ5×9Ñ9¸aÐ9Ó@Ñˆ	Ü—Y’Y °¥oÐ6Ó7¼¿ºÀDÐTXÍ/Ð\`ÕJ`ÐCaÓ9bˆdØŸ™ Q˜›Ñ€DØ—‘˜Q ¨DÕ 1Ó2°1Õ5Ð5Ð5r   c          
      ó¦   € V ^8„  d   QhR\         P                  R\        R\        R\        \         P                  \         P                  3,          /# )r   r§   r¨   rj   r   )r   r   r‚   r   r   )r   s   "r   r   r     sB   € ÷ :ñ :Ü—\‘\ð:Ü*-ð:Ü>Bð:ä
Œ5�<‰<œŸ™Ð%Õ&ñ:r   c                ó  € \        W4      '       g   \        V P                  4       V4      # V P                  w  r4W3V,          ,
          pV RV P	                  WQ,          W4      P                  ^^RR7      w  rgV\        P                  ! ^ WQV P                  R7      R,          ,           pVP	                  RV4      VP	                  RV4      rvWS8  d]   WR P                  \        ^W5,
          4      ^ RR7      w  r‰\        P                  ! Wh.4      \        P                  ! WyV,           .4      rvVP                  ^^ RR7      w  r«V'       d   \        V
4      p
V
^ ,          V
^,          ,          VP                  ^ VR,          4      ^ ,          3# )a€  Return :func:`_nearest_neighbour_ratio` of ``distance_matrix.t()``: the ratio test of each column.

With ``squared``, ``distance_matrix`` holds squared distances from :func:`_squared_distances`, and the ratio is
taken of the square roots of the two smallest.

On CPU a matrix of more than ``2 * block`` rows takes the two smallest distances of each block of rows with
``torch.topk``, then the two smallest of those, see :func:`_reduces_over_row_blocks`. The two smallest values
are those of one ``torch.topk``, so the ratios are bitwise the same, apart from the sign of a nan ratio (x86
bfloat16 division gives ``-nan`` in its vectorised kernel and ``+nan`` in the strided one), and so is a unique
nearest row. Of tied nearest rows it may return another one: ``torch.topk`` orders no ties. Such a column's ratio
is 1 or nan, which the ratio test of :func:`match_smnn` rejects for any ``th < 1``.
NF©r.   r~   r®   :Né   N)r°   NNrQ   )rª   Ú_nearest_neighbour_ratior<   Úshaper±   Útopkr   r²   rV   r1   r]   rn   r³   )r§   r¨   rj   r´   Úcolsrµ   r¶   r£   r·   r¸   r¹   Úpicks   &&&         r   Ú"_nearest_neighbour_ratio_over_rowsrÅ     sR  € ô $ O×;Ò;Ü'¨×(9Ñ(9Ó(;¸WÓEÐEØ ×&Ñ&�J€DØ˜•,Õ€DØ   $Ð'×/Ñ/°µ¸uÓK×PÑPÐQRÐXYÐchÐPÓi�J€DØ”%—,’,˜q $°o×6LÑ6LÔMÈmÕ\Õ\€DØ—‘˜b $Ó'¨¯©°b¸$Ó)?ˆ$Ø„{Ø.¨uÐ5×:Ñ:¼3¸qÀ$Å+Ó;NÐTUÐ_dÐ:ÓeÑˆ	Ü—Y’Y Ð0Ó1´5·9²9¸dÐPTÕDTÐ=UÓ3VˆdØ—‘˜1 !¨U�Ó3�J€DßÜ% dÓ+ˆØ��7�T˜!•WÕ˜dŸk™k¨!¨T°"­XÓ6°qÕ9Ð9Ð9r   c          
      óä   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        \         P                  \         P                  3,          /# rL   ©r   r   r   r   )r   s   "r   r   r   -  sU   € ÷ H=ñ H=Ü�<‰<ðH=Ü %§¡ðH=Ü2:¼5¿<¹<Õ2HðH=ä
Œ5�<‰<œŸ™Ð%Õ&ñH=r   c                óˆ  € \        V RR.4       \        VRR.4       \        V 4      ^ 8X  g   \        V4      ^ 8X  d   \        V 4      # Rp\        P                  P                  4       '       g   \        WV4      pVf   \        WV4      MTp\        P                  ! V^R7      w  rVVe   \        V4      p\        P                  ! ^ VP                  ^ 4      VP                  R7      p\        P                  ! VP                  R^4      VP                  R^4      .^4      pVP                  R^4      VP                  R^4      3# )aÒ  Match each descriptor in desc1 to its nearest neighbor in desc2, with no filtering.

``dists, idxs = match_nn(desc1, desc2)`` takes two descriptor sets ``(B1, D)`` and ``(B2, D)`` and returns, for
every row of ``desc1`` in order, the L2 distance ``(B1, 1)`` to its nearest row of ``desc2`` and the index pair
``(B1, 2)`` of the two rows; a precomputed ``dm`` ``(B1, B2)`` replaces the L2 distances. Every row is matched,
however ambiguous its nearest neighbour, and several rows can match the same row of ``desc2``. To keep only the
reliable matches, use :func:`match_mnn` (mutual nearest neighbours), :func:`match_snn` (Lowe's ratio test) or
:func:`match_smnn` (both) instead.

Convention:
    - Every ``match_*`` function returns ``(dists, idxs)``, one row per match. ``idxs`` is an int64
      ``(M, 2)`` tensor of ``(index in desc1, index in desc2)`` rows; :func:`match_smnn_batched` adds the batch
      index as a first column. ``dists`` is ``(M, 1)``. Without ``dm``, it has the descriptor dtype, except that
      :func:`match_adalam` returns float32. Lower values are better, and their meaning depends on the function:

      - :func:`match_nn`, :func:`match_mnn`: the distance, the entry of ``dm`` when it is given.
      - :func:`match_snn`: the ratio of the nearest to the second-nearest distance, not a distance.
      - :func:`match_smnn`, :func:`match_smnn_batched`: the larger of the two ratios, desc1 to desc2 and back.
      - :func:`match_fginn`: the ratio of the nearest distance to that of a second neighbour, taken among the 10
        nearest, whose ``lafs2`` centre lies at least ``spatial_th`` from the nearest one's, and 0 without one;
        see its Convention block.
      - :func:`match_adalam`: the inverse of the local RANSAC confidence; see its Convention block.

      :class:`~kornia.feature.LightGlueMatcher` returns LightGlue's matching score in the place of ``dists``,
      which is higher for better matches, and :class:`~kornia.feature.LocalFeatureMatcher` reports
      ``1 - dists`` as ``confidence``.
    - The ratio tests of :func:`match_snn`, :func:`match_smnn`, :func:`match_smnn_batched` and
      :func:`match_fginn` keep ``ratio <= th``: a ratio equal to ``th`` passes.
    - Without ``dm``, the functions use L2 distances. A given ``dm`` replaces them: :func:`match_nn` and
      :func:`match_mnn` require only that smaller entries are better, while ratio tests require non-negative
      distances. Use ``th ** 2`` for squared distances.
    - Of tied nearest neighbours, :func:`match_nn` and :func:`match_mnn` take the one with the lower index.
    - An empty desc1 or desc2 gives a ``(0, 1)`` and a ``(0, 2)`` tensor (``(0, 3)`` for
      :func:`match_smnn_batched`). The ratio tests need a second neighbour: :func:`match_snn` and
      :func:`match_fginn` return no match unless desc2 has two rows, and :func:`match_smnn`,
      :func:`match_smnn_batched` and :func:`match_adalam`, which scores its putative matches by the same ratio,
      need two rows in both.

Args:
    desc1: Batch of descriptors of a shape ``(B1, D)``.
    desc2: Batch of descriptors of a shape ``(B2, D)``.
    dm: torch.Tensor containing the distances from each descriptor in desc1
      to each descriptor in desc2, shape of ``(B1, B2)``.

Returns:
    - Descriptor distance of matching descriptors, shape of ``(B1, 1)``, or ``(0, 1)`` when desc2 is empty.
    - Long torch.Tensor indexes of matching descriptors in desc1 and desc2, shape of ``(B1, 2)``, or
      ``(0, 2)`` when desc2 is empty.

See Also:
    - :func:`match_mnn`: keeps only the pairs that are each other's nearest neighbours.
    - :func:`match_snn`: keeps only the nearest neighbours that pass Lowe's ratio test.
    - :class:`DescriptorMatcher`: the module form, with ``match_mode="nn"``.

ÚBÚDIMNr­   r®   rQ   )r   Úlenr¤   r   r    r!   rg   rœ   r1   rn   r²   rX   rV   r]   Úview)	rM   rN   rG   rj   r§   Úmatch_distsÚ	idxs_in_2Úidxs_in1Úmatches_idxss	   &&&      r   Úmatch_nnrÑ   -  s  € ôt �u˜s E˜lÔ+Ü�u˜s E˜lÔ+ÜˆE‹
�aŒœS ›Z¨1œ_Ü˜ÓÐØ&*€Gä�9‰9×!Ñ!×#Ò#Ü$ U°2Ó6ˆØELÂ_Ô/°¸bÔAÐZa€OÜ"ŸYšY ¸AÔ>Ñ€KØÒÜ,¨[Ó9ˆÜ�|Š|˜A˜yŸ~™~¨aÓ0¸×9IÑ9IÔJ€HÜ—9’9˜hŸm™m¨B°Ó2°I·N±NÀ2ÀqÓ4IÐJÈAÓN€LØ×Ñ˜B Ó" L×$5Ñ$5°b¸!Ó$<Ð<Ð<r   c          
      óä   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        \         P                  \         P                  3,          /# rL   rÇ   )r   s   "r   r   r   x  sO   € ÷ ;1ñ ;1Ü�<‰<ð;1Ü %§¡ð;1Ü2:¼5¿<¹<Õ2Hð;1ä
Œ5�<‰<œŸ™Ð%Õ&ñ;1r   c                óÎ  € \        V RR.4       \        VRR.4       \        V 4      ^ 8X  g   \        V4      ^ 8X  d   \        V 4      # Rp\        P                  P                  4       '       g   \        WV4      pVf   \        WV4      MTp\        VP                  ^ 4      VP                  ^4      4      p\        P                  ! V^R7      w  rg\        V4      w  r‰\        P                  ! WTP                  R7      p
VP                  ^ 4      VP                  ^4      8:  dR   \        P                  ! W©V,          RV 8H  4      R,          p\        P                  ! W·V,          .^4      pWk,          pMP\        P                  ! W§V	,          RV 8H  4      R,          p\        P                  ! W›,          V.^4      pW‹,          pVe   \        V4      pVP!                  R^4      V3# )a‚  Match the descriptors of desc1 and desc2 that are each other's nearest neighbors.

``dists, idxs = match_mnn(desc1, desc2)`` takes two descriptor sets ``(B1, D)`` and ``(B2, D)`` and returns the
pairs whose two descriptors are each other's nearest neighbour, the mutual nearest neighbours: their L2
distances ``(B3, 1)`` and index pairs ``(B3, 2)``, with ``B3 <= min(B1, B2)``. Each row of either set is matched
at most once, but a distinctive descriptor and an ambiguous one are kept alike; to also require Lowe's ratio
test, use :func:`match_smnn` instead.

Convention:
    See the Convention block on :func:`match_nn`. A pair is kept only when each of the two descriptors is the
    nearest neighbour of the other. Ties go to the lower index in both directions, so of several identical
    rows of desc2 only the first can be matched.

Args:
    desc1: Batch of descriptors of a shape ``(B1, D)``.
    desc2: Batch of descriptors of a shape ``(B2, D)``.
    dm: torch.Tensor containing the distances from each descriptor in desc1
      to each descriptor in desc2, shape of ``(B1, B2)``.

Return:
    - Descriptor distance of matching descriptors, shape of ``(B3, 1)``.
    - Long torch.Tensor indexes of matching descriptors in desc1 and desc2, shape of ``(B3, 2)``,
      where 0 <= B3 <= min(B1, B2)

See Also:
    - :func:`match_nn`: the nearest neighbour of every row of desc1, mutual or not.
    - :func:`match_smnn`: mutual nearest neighbours that also pass the ratio test in both directions.
    - :func:`match_snn`: the ratio test in one direction, without the mutual check.
    - :class:`DescriptorMatcher`: the module form, with ``match_mode="mnn"``.

rÉ   rÊ   Nr­   r®   ©r°   r   rQ   )r   rË   r¤   r   r    r!   rg   rœ   r1   rX   r»   r²   rV   ÚnonzerorŽ   rn   rÌ   )rM   rN   rG   rj   r§   ÚmsrÍ   rÎ   Úmatch_dists2Ú	idxs_in_1Úminsize_idxsr”   rÐ   s   &&&          r   Ú	match_mnnrÚ   x  s›  € ôD �u˜s E˜lÔ+Ü�u˜s E˜lÔ+ÜˆE‹
�aŒœS ›Z¨1œ_Ü˜ÓÐØ&*€Gä�9‰9×!Ñ!×#Ò#Ü$ U°2Ó6ˆØELÂ_Ô/°¸bÔAÐZa€OÜ	ˆ_×!Ñ! !Ó$ o×&:Ñ&:¸1Ó&=Ó	>€BÜ"ŸYšY ¸AÔ>Ñ€KÜ,¨_Ó=Ñ€LÜ—<’< ×+AÑ+AÔB€Lð ×Ñ˜AÓ /×"6Ñ"6°qÓ"9Ô9Ü—’˜|¸Õ/CÀCÀRÐ/HÑHÓIÈ$ÕOˆÜ—{’{ F°fÕ,=Ð#>ÀÓBˆØ!Õ)‰ä—’˜|¸Õ/CÀCÀRÐ/HÑHÓIÈ$ÕOˆÜ—{’{ IÕ$5°vÐ#>ÀÓBˆØ"Õ*ˆØÒÜ,¨[Ó9ˆØ×Ñ˜B Ó" LÐ0Ð0r   c                óŽ   € V ^8„  d   QhR\         P                  R\        \         P                  \         P                  3,          /# )r   r§   r   rž   )r   s   "r   r   r   ¶  s7   € ÷ Mñ M´E·L±Lð MÄUÌ5Ï<É<ÔY^×YeÑYeÐKeÕEfñ Mr   c                óH  € \        R4      pV P                  4       p\        P                  ! V4      p\        P                  ! W!W) R7      pVP                  ^R7      w  rVVR,          pVP                  ^V^ 8H  P                  4       4      pVP                  ^V\        P                  ! W�W) R7      4       VP                  ^VR4      P                  ^R7      p	\        P                  ! V	\        R4      VP                  ^R7      4      p
\        P                  ! V4      \        P                  ! V
4      ,          V
^ 8g  ,          p\        P                  ! Wµ^ 4      \        P                  ! Wº^4      ,          p\        P                  ! W¼WZ,          P                  4       4      V3# )aß  Return each row's ratio of the smallest to the second-smallest distance, and the column of the smallest.

:func:`match_snn` calls this on MPS in place of ``torch.topk(distance_matrix, 2, dim=1, largest=False)``, which
is two to three times slower there. Elsewhere ``torch.topk`` is at least as fast: as fast on CUDA, and two to five
times faster on an x86 CPU, where it reads the matrix about once and these reductions several times. The ratios
are those of ``torch.topk``, which orders nan after ``+inf``. Where a ratio is a number, its column is that of the
smallest distance, the first of tied ones. A row without a finite smallest and a finite, non-zero second-smallest
distance gets no gradient. A row needs at least two columns.
rt   ru   r­   Trv   r¯   )r8   Ú
contiguousr   ÚisnanÚ
nan_to_numr1   r³   r¡   r…   Úallr>   r†   ÚisfiniteÚdetach)r§   rt   rG   Úis_nanÚ	remainingr‡   Ú	first_idxÚidxÚotherÚ	no_secondrŠ   ÚdefinedÚratios   &            r   Ú_first_to_second_nearest_ratiorë   ¶  sA  € ô �‹,€Cà	×	#Ñ	#Ó	%€BÜ�[Š[˜‹_€FÜ× Ò  °SÀÔF€IØ —}‘}¨�}Ó+Ñ€EØ
�GÕ
€Cð �I‰I�a˜# ™(Ÿ™Ó*Ó+€EØ×Ñ�q˜#œu×/Ò/°ÀsÐSWÔXÔYà—‘  3¨Ó-×1Ñ1°aÐ1Ó8€IÜ�[Š[˜¤E¨%£L°)·.±.ÀQ°.Ó2GÓH€Fô �nŠn˜UÓ#¤e§n¢n°VÓ&<Õ<ÀÈ!ÁÕL€GÜ�KŠK˜¨Ó*¬U¯[ª[¸È!Ó-LÕL€EÜ�;Š;�w¨­×'>Ñ'>Ó'@ÓAÀ9ÐLÐLr   c                óš   € V ^8„  d   QhR\         P                  R\        R\        \         P                  \         P                  3,          /# )r   r§   rj   r   )r   r   r   r   )r   s   "r   r   r   Õ  s>   € ÷ /ñ /¬e¯l©lð /ÄTð /ÔV[Ô\a×\hÑ\hÔjo×jvÑjvÐ\vÕVwñ /r   c                óØ   € \        V 4      '       d   \        V 4      # \        P                  ! V ^^RR7      w  r#V'       d   \	        V4      pVR,          VR,          ,          VR,          3# )a¿  Return each row's nearest column and its ratio of the nearest to the second-nearest distance.

The ratio test of :func:`match_snn` and :func:`match_smnn`: :func:`_first_to_second_nearest_ratio` on MPS and
``torch.topk`` elsewhere. A row needs at least two columns. With ``squared``, ``distance_matrix`` holds squared
distances from :func:`_squared_distances`, which is never on MPS, and the ratio is taken of the square roots of
the two smallest.
Fr¾   rÔ   ©r°   r¿   )r   rë   r   rÂ   rn   )r§   rj   r¶   r£   s   &&  r   rÀ   rÀ   Õ  sY   € ô ˜/×*Ò*Ü-¨oÓ>Ð>Ü—’˜O¨Q°A¸uÔE�J€DßÜ% dÓ+ˆØ��:˜˜T�
Õ" D¨¥JÐ.Ð.r   c                óð   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        \         P                  ,          R\        \         P                  \         P                  3,          /# ©r   rM   rN   r“   rG   r   ©r   r   r8   r   r   )r   s   "r   r   r   å  sW   € ÷ =5ñ =5Ü�<‰<ð=5Ü %§¡ð=5Ü27ð=5ÜCKÌEÏLÉLÕCYð=5ä
Œ5�<‰<œŸ™Ð%Õ&ñ=5r   c                ó¾  € \        V RR.4       \        VRR.4       V P                  ^ ,          ^ 8X  g   VP                  ^ ,          ^8  d   \        V 4      # Rp\        P                  P                  4       '       g   \        WV4      pVe9   VP                  '       d'   \        V4      p\        V^4      w  rgp\        Wg4      p	M!Vf   \        WV4      MTp\        WTRJ4      w  r˜\        P                  ! W’8*  4      R,          p
V
P                  4       ^ 8X  d   \        V4      # \        P                  ! W¨V
,          .^4      pWš,          P!                  R^4      V3# )a`  Match each descriptor in desc1 to its nearest neighbor in desc2 if it passes Lowe's ratio test.

``dists, idxs = match_snn(desc1, desc2, th)`` takes two descriptor sets ``(B1, D)`` and ``(B2, D)``, keeps the
rows of ``desc1`` whose nearest neighbour in ``desc2`` is at most ``th`` times as far as the second-nearest, and
returns their ratios ``(B3, 1)``, not distances, and index pairs ``(B3, 2)``, with ``B3 <= B1``, in the order of
the rows of ``desc1``. Several rows of ``desc1`` can match the same row of ``desc2``; to keep only mutual
nearest neighbours that pass the test in both directions, use :func:`match_smnn` instead.

Speed, with the same matches, on 1,024 to 8,192 RootSIFT descriptors: on an x86 CPU this is faster than faiss and
OpenCV's ``BFMatcher``, while faiss's exact k-nearest-neighbour search runs this ratio test up to 2.2x faster on
CUDA and up to 2.0x faster on an Apple M1 CPU. See the `image matching guide
<https://kornia.readthedocs.io/en/latest/applications/image_matching.html#feature-speed-by-device>`_.

Convention:
    See the Convention block on :func:`match_nn`; ``dists`` is the ratio of the nearest to the second-nearest
    distance.

Args:
    desc1: Batch of descriptors of a shape ``(B1, D)``.
    desc2: Batch of descriptors of a shape ``(B2, D)``.
    th: distance ratio threshold.
    dm: torch.Tensor containing the distances from each descriptor in desc1
      to each descriptor in desc2, shape of ``(B1, B2)``.

Return:
    - Ratio of the nearest to the second-nearest distance of each match, shape of ``(B3, 1)``.
    - Long torch.Tensor indexes of matching descriptors in desc1 and desc2. Shape: ``(B3, 2)``,
      where 0 <= B3 <= B1.

See Also:
    - :func:`match_nn`: the nearest neighbour of every row of desc1, without the ratio test.
    - :func:`match_mnn`: mutual nearest neighbours, without the ratio test.
    - :func:`match_smnn`: the ratio test in both directions, on mutual nearest neighbours.
    - :func:`match_fginn`: the same ratio test, with a second neighbour that lies elsewhere in the image.
    - :class:`DescriptorMatcher`: the module form, with ``match_mode="snn"``.

rÉ   rÊ   NrÔ   rQ   )r   rÁ   r¤   r   r    r!   rg   Úis_cudarz   r‹   r�   rœ   rÀ   rÕ   ÚnumelrŽ   rÌ   )rM   rN   r“   rG   rj   r§   r‡   rŠ   rÎ   rê   rÏ   rÐ   s   &&&&        r   Ú	match_snnrõ   å  s*  € ôP �u˜s E˜lÔ+Ü�u˜s E˜lÔ+à‡{�{�1…~˜Ô˜eŸk™k¨!�n¨qÔ0Ü˜ÓÐØ&*€Gä�9‰9×!Ñ!×#Ò#Ü$ U°2Ó6ˆØÒ˜wŸŸ˜Ü*¨7Ó3ˆÜ#1°/À1Ó#EÑ ˆ�yÜ  Ó/‰àIPÊÔ3°EÀ"ÔEÐ^eˆÜ3°OÐTXÐEXÓYÑˆä�}Š}˜U™[Ó)¨$Õ/€HØ‡~�~Ó˜1ÔÜ˜Ó)Ð)Ü—;’; °HÕ*=Ð>ÀÓB€LØ�?×Ñ  AÓ&¨Ð4Ð4r   c                óð   € V ^8„  d   QhR\         P                  R\         P                  R\        R\        \         P                  ,          R\        \         P                  \         P                  3,          /# rð   rñ   )r   s   "r   r   r   %  s^   € ÷ F1ñ F1Ü�<‰<ðF1Ü %§¡ðF1Ü27ðF1ÜDLÌUÏ\É\ÕDZðF1ä
Œ5�<‰<œŸ™Ð%Õ&ñF1r   c                óô  € \        V RR.4       \        VRR.4       V P                  ^ ,          ^8  g   VP                  ^ ,          ^8  d   \        V 4      # Rp\        P                  P                  4       '       g   \        WV4      pVeR   VP                  '       d@   \        V4      p\        V^4      w  rgp\        V^ 4      w  ršp\        Wg4      \        Wš4      rÜM1Vf   \        WV4      MTp\        WTRJ4      w  rÈ\        WTRJR7      w  rÛWØ,          pW¸,          \        P                  ! VP                  ^ 4      VP                   R7      8H  p\        P"                  ! WüV8*  ,          Wâ8*  ,          4      R,          pVP%                  4       ^ 8X  d   \        V4      # \        P&                  ! VVV,          .^4      p\        P(                  ! VV,          VV,          4      pVP+                  R^4      V3# )a>	  Match mutual nearest neighbors that also pass Lowe's ratio test in both directions.

``dists, idxs = match_smnn(desc1, desc2, th)`` takes two descriptor sets ``(B1, D)`` and ``(B2, D)``, keeps the
mutual nearest neighbours whose nearest-to-second-nearest distance ratio is at most ``th`` both from ``desc1``
to ``desc2`` and back, and returns the larger of their two ratios ``(B3, 1)`` and their index pairs ``(B3, 2)``,
with ``B3 <= min(B1, B2)``, in the order of the rows of ``desc1``. For many pairs of descriptor sets, padded to
common sizes, use :func:`match_smnn_batched` instead of a loop.

Speed, with the same matches, on 1,024 to 8,192 RootSIFT descriptors: on an x86 CPU this is faster than faiss and
OpenCV's ``BFMatcher``, while faiss's exact k-nearest-neighbour search, run both ways, is up to 1.6x faster on
CUDA and up to 2.0x faster on an Apple M1 CPU. See the `image matching guide
<https://kornia.readthedocs.io/en/latest/applications/image_matching.html#feature-speed-by-device>`_.

Convention:
    - See the Convention block on :func:`match_nn`. A pair is kept when the two descriptors are mutual nearest
      neighbours and pass the ratio test, ``ratio <= th``, in both directions; ``dists`` is the larger of the
      two ratios.
    - ``th`` defaults to 0.95, where :func:`match_snn` and :func:`match_fginn` default to 0.8.

Args:
    desc1: Batch of descriptors of a shape ``(B1, D)``.
    desc2: Batch of descriptors of a shape ``(B2, D)``.
    th: distance ratio threshold.
    dm: torch.Tensor containing the distances from each descriptor in desc1
      to each descriptor in desc2, shape of ``(B1, B2)``.

Return:
    - The larger of the two distance ratios of each match, shape of ``(B3, 1)``.
    - Long torch.Tensor indexes of matching descriptors in desc1 and desc2,
      shape of ``(B3, 2)`` where 0 <= B3 <= B1.

See Also:
    - :func:`match_snn`: the ratio test from desc1 to desc2 only, without the mutual check.
    - :func:`match_mnn`: mutual nearest neighbours without the ratio test.
    - :func:`match_smnn_batched`: the same matches for a batch of padded descriptor-set pairs, in one call.
    - :class:`DescriptorMatcher`: the module form, with ``match_mode="smnn"`` and a default ``th`` of 0.8.
    - :class:`~kornia.geometry.ransac.RANSAC`: the next step, which keeps the matches one geometric model
      explains.

rÉ   rÊ   Nrm   r®   rÔ   rQ   )r   rÁ   r¤   r   r    r!   rg   ró   rz   r‹   r�   rœ   rÀ   rÅ   r²   rX   rV   rÕ   rô   rŽ   ÚmaximumrÌ   )rM   rN   r“   rG   rj   r§   Úfirst1Úsecond1Únearest2Úfirst2Úsecond2Únearest1Úratio1Úratio2Úreverse_ratior”   rÏ   rÐ   rÍ   s   &&&&               r   Ú
match_smnnr  %  s±  € ôV �u˜s E˜lÔ+Ü�u˜s E˜lÔ+à�‰�A�˜Ô §¡¨A¥°Ô 2Ü˜ÓÐØ&*€Gä�9‰9×!Ñ!×#Ò#Ü$ U°2Ó6ˆØÒ˜wŸŸ˜Ü*¨7Ó3ˆÜ$2°?ÀAÓ$FÑ!ˆ˜Ü$2°?ÀAÓ$FÑ!ˆ˜Ü)¨&Ó:Ô<LÈVÓ<]‘àIPÊÔ3°EÀ"ÔEÐ^eˆÜ3°OÐTXÐEXÓYÑˆÜ=¸oÐfjÐWjÔkÑˆð Õ$€MØÕ¤5§<¢<°×0DÑ0DÀQÓ0GÐP_×PfÑPfÔ#gÑg€FÜ�}Š}˜V°¡|Õ4¸Ñ8KÕLÓMÈdÕS€HØ‡~�~Ó˜1ÔÜ˜Ó)Ð)Ü—;’; ¨(°8Õ*<Ð=¸qÓA€LÜ—-’-  xÕ 0°-ÀÕ2IÓJ€KØ×Ñ˜B Ó" LÐ0Ð0r   c                ó\  € V ^8„  d   QhR\         P                  R\         P                  R\        R\        \         P                  ,          R\        \         P                  ,          R\        \         P                  ,          R\        \         P                  \         P                  3,          /# )r   rM   rN   r“   rG   Úmask1Úmask2r   rñ   )r   s   "r   r   r   n  sŒ   € ÷ Iñ IÜ�<‰<ðIä�<‰<ðIô 	ðIô 	”—‘Õð	Iô
 ”E—L‘LÕ!ðIô ”E—L‘LÕ!ðIô Œ5�<‰<œŸ™Ð%Õ&ñIr   c           	     óv  € \        V . RO4       \        V. RO4       V P                  w  rgpVP                  ^ ,          V8w  g   VP                  ^,          V8w  d   \        R4      hV P                  VP                  8w  g2   V P                  VP                  8w  g   V P                  4       '       g   \        R4      hVP                  ^,          p	VeU   VP                  WgV	38w  g7   VP                  V P                  8w  g   VP                  V P                  8w  d   \        R4      hWFV33WVV	333 Fa  w  r«V
f   K  V
P                  V8w  g=   V
P                  \        P                  8w  g   V
P                  V P                  8w  g   KX  \        R4      h	  V^ 8X  g   V^8  g   V	^8  dC   V P                  R4      \        P                  ! R\        P                  V P                  R7      3# Vf3   \        P                  ! Wg3\        P                  V P                  R7      MTpVf3   \        P                  ! Wi3\        P                  V P                  R7      MTpVRJ;'       g    VRJpVEfô   Ve#   V P                  VP                  R4      ( R4      MT pVe#   VP                  VP                  R4      ( R4      MTpVP                  \        P                  \        P                  39   d   VP!                  4       MTpVP                  \        P                  \        P                  39   d   VP!                  4       MTp\#        V 4      ;'       d    T;'       g    \%        Wy4      ^8*  p\'        V 4      '       d-   V'       g%   \        P(                  ! TTV'       d   RMR	R
7      pM»VP+                  WgV	34      p\-        ^ V^4       FS  pVRRRVV^,           13,          VRRRVV^,           13,          ,
          pVVV,          P/                  R4      ,           pKU  	  V^ 8„  p\        P0                  ! V\        P0                  ! VVR4      P3                  4       R4      pMTpVf   VeB   VP                  VP                  ^4      VP                  ^4      ,          ( \!        R4      4      pVP5                  ^^RR7      w  ppVP7                  ^^4      P5                  ^^RR7      w  pp\        P8                  ! V4      P;                  R4      VR,          ^ 8„  ,          p\        P8                  ! V4      P;                  R4      VR,          ^ 8„  ,          p\        P0                  ! VVR,          R4      \        P0                  ! VVR,          R4      ,          p\        P0                  ! VVR,          R4      \        P0                  ! VVR,          R4      ,          pVR,          pVP=                  ^V4      p VR,          P=                  ^V4      \        P>                  ! WpP                  R7      8H  p!VP/                  ^4      ^8¬  VP/                  ^4      ^8¬  ,          p"VV"P                  ^4      ,          V,          VP=                  ^V4      ,          V!,          VV8*  ,          V V8*  ,          p#V#PA                  RR7      w  p$p%\        PB                  ! V$V%VV$V%3,          3^R7      p&\        PD                  ! VV 4      V$V%3,          P                  ^4      PG                  V P                  4      p'V'V&3# )aÈ  Match a batch of padded descriptor-set pairs in one call, each as match_smnn matches one pair.

``ratios, idxs = match_smnn_batched(desc1, desc2, th)`` takes ``B`` pairs of descriptor sets, ``(B, N, D)`` and
``(B, M, D)``, padded to common sizes, with optional boolean masks ``mask1`` ``(B, N)`` and ``mask2`` ``(B, M)``
of the valid rows, and returns the matches of every pair at once, without a loop over the pairs: the larger of
the two ratios ``(K, 1)`` and index rows ``(K, 3)`` of ``(batch index, index in desc1, index in desc2)``, which
index the padded tensors and come sorted by batch index, then index in desc1. For a single pair, use
:func:`match_smnn`.

Convention:
    See the Convention blocks on :func:`match_nn` and :func:`match_smnn`. For each batch item it returns the
    pairs and ratios that :func:`match_smnn` returns for finite distances between the valid descriptors of that
    item, with the batch index as the first column of the indices. Unlike :func:`match_smnn`, it rejects a match
    when the nearest or second-nearest distance in either direction is non-finite. Without ``dm``, float16 and
    bfloat16 descriptors give the results
    of :func:`match_smnn` on float32 copies, with the ratios rounded back, and a few pairs and ratios can differ
    slightly from those of :func:`match_smnn` on the half-precision descriptors.

Args:
    desc1: First descriptors, shape ``(B, N, D)``.
    desc2: Second descriptors, shape ``(B, M, D)``.
    th: Inclusive distance-ratio threshold.
    dm: Optional precomputed L2 distances, shape ``(B, N, M)``.
    mask1: Optional boolean mask of valid first descriptors, shape ``(B, N)``.
    mask2: Optional boolean mask of valid second descriptors, shape ``(B, M)``.
        Masks allow padding variable-length pairs; padding never becomes a neighbor.

Returns:
    - Ratios, shape ``(K, 1)``, with the input device and dtype.
    - Long indices, shape ``(K, 3)``: ``(batch_index, index_in_desc1, index_in_desc2)``.
      Indices refer to the original padded tensors, sorted by batch and first-descriptor index.
      A pair with fewer than two valid descriptors on either side contributes no matches.

Note:
    Memory for the distance matrix scales as :math:`B N M`. Bucket pairs by
    descriptor counts and limit batch size when matching large collections.
    Half-precision descriptors use float32 distance computation before ratios
    are converted back to the input dtype.
    Masked inputs compute the distances directly, without the matrix-multiplication
    form, which avoids its cancellation but can be slower for large masked descriptor sets.
    As in :func:`match_smnn`, a zero second-neighbor distance produces an
    undefined ratio and that ambiguous match is rejected. Ties follow
    :func:`torch.topk` and do not have a guaranteed cross-device ordering.

See Also:
    - :func:`match_smnn`: the same test for one pair of descriptor sets of any sizes, with no padding.
    - :func:`match_snn`: the ratio test in one direction for one pair, without the mutual check.

Example:
    >>> a = torch.tensor([[[0., 0.], [1., 1.], [2., 2.]]])
    >>> ratios, indices = match_smnn_batched(a, a.flip(1))
    >>> indices
    tensor([[0, 0, 2],
            [0, 1, 1],
            [0, 2, 0]])

z0Descriptor batch sizes and dimensions must matchz8Descriptors must have the same floating dtype and deviceNzIDistance matrix must have shape (B, N, M) and the descriptor dtype/devicezSValidity masks must be boolean tensors with shape (B, N)/(B, M) on the input device)r5   rV   r0   Údonot_use_mm_for_euclid_distÚ#use_mm_for_euclid_dist_if_necessary)Úcompute_moder°   r2   rt   Fr¾   r®   T)Úas_tupler­   )rÉ   ÚNÚD)rÉ   ÚMr  )r   r¿   )r   é   rQ   ).r¿   ).r   )$r   rÁ   Ú
ValueErrorrV   r5   Úis_floating_pointr   r   Ú	new_emptyr    r¡   ÚonesÚmasked_fillr„   r3   r4   r8   r   Úmaxr$   r9   Ú	new_zerosÚranger;   r>   r?   rÂ   Ú	transposerá   rà   r³   r²   rÕ   rŽ   rø   r@   )(rM   rN   r“   rG   r  r  ÚbatchÚnr.   ÚmrH   rÁ   Úvalid1Úvalid2ÚmaskedÚwork1Úwork2Ú
mps_directrD   rj   ÚstartÚ
differenceÚpositiveÚvalues1Ú
neighbors1Úvalues2Ú
neighbors2Údefined1Údefined2Úratios1Úratios2rû   r  r”   ÚenoughÚkeepÚbatch_indexÚindex1ÚindicesÚratioss(   &&&&&&                                  r   Úmatch_smnn_batchedr2  n  sú  € ôB �ušoÔ.Ü�ušoÔ.Ø—K‘K�M€EˆcØ‡{�{�1…~˜Ô %§+¡+¨a¥.°CÔ"7ÜÐKÓLÐLØ‡|�|�u—|‘|Ô# u§{¡{°e·k±kÔ'AÈ×I`ÑI`×IbÒIbÜÐSÓTÐTØ�‰�A�€AØ	‚~˜2Ÿ8™8¨°! }Ô4¸¿	¹	ÀUÇ\Á\Ô8QÐUW×U]ÑU]Ðaf×alÑalÔUlÜÐdÓeÐeØ¨ 
Ð+¨e¸Q°ZÐ-@ÓA‰ˆØÔ §¡¨uÔ!4¸¿
¹
ÄeÇjÁjÔ8PÐTX×T_ÑT_Ðch×coÑcoÖToÜÐrÓsÐsñ Bð �„z�Q˜”U˜a !œeØ�‰˜vÓ&¬¯ª°FÄ%Ç*Á*ÐUZ×UaÑUaÔ(bÐbÐbàNSÊmŒU�ZŠZ˜˜
¬%¯*©*¸U¿\¹\ÕJÐaf€FØNSÊmŒU�ZŠZ˜˜
¬%¯*©*¸U¿\¹\ÕJÐaf€FØ˜$Ð×3Ð3 %¨tÐ"3€FØ	ƒzð BGÒAR�×!Ñ! 6×#3Ñ#3°BÓ#7Ð"7¸Ô=ÐX]ˆØAFÒAR�×!Ñ! 6×#3Ñ#3°BÓ#7Ð"7¸Ô=ÐX]ˆØ!&§¡´·±ÄÇÁÐ0OÔ!O�—‘”ÐUZˆØ!&§¡´·±ÄÇÁÐ0OÔ!O�—‘”ÐUZˆô (¨Ó.×NÐN°F×4MÐ4M¼cÀ!»iÈ2¹oˆ
Ü! %×(Ò(·ÜŸšØØß?EÑ;ÐKpô‰Ið —o‘o u° mÓ4ˆGÜ˜q # rÖ*�Ø" 1 a¨¨u°u¸rµzÐ/AÐ#AÕBÀUÈ1ÈdÐTUÐW\Ð_dÐgiÕ_iÐWiÐKiÕEjÕj�
Ø! Z°*Õ%<×$AÑ$AÀ"Ó$EÕE’ñ +ð  ‘{ˆHÜŸš H¬e¯kªk¸(ÀGÈSÓ.Q×.VÑ.VÓ.XÐZ]Ó^‰Iàˆ	ØÒ˜EÒ-Ø×)Ñ)¨F×,<Ñ,<¸QÓ,?À&×BRÑBRÐSTÓBUÕ,UÐ*VÔX]Ð^cÓXdÓeˆ	Ø#Ÿ.™.¨°¸5˜.ÓAÑ€GˆZØ#×-Ñ-¨a°Ó3×8Ñ8¸ÀÈ5Ð8ÓQÑ€GˆZÜ�~Š~˜gÓ&×*Ñ*¨2Ó.°'¸&µ/ÀAÑ2EÕF€HÜ�~Š~˜gÓ&×*Ñ*¨2Ó.°'¸&µ/ÀAÑ2EÕF€Hô �kŠk˜( G¨F¥O°SÓ9¼E¿KºKÈÐRYÐZ`ÕRaÐcfÓ<gÕg€GÜ�kŠk˜( G¨F¥O°SÓ9¼E¿KºKÈÐRYÐZ`ÕRaÐcfÓ<gÕg€GØ˜&Õ!€HØ—N‘N 1 hÓ/€MØ˜Õ×&Ñ& q¨(Ó3´u·|²|ÀAÏlÉlÔ7[Ñ[€FØ�j‰j˜‹m˜qÑ  V§Z¡Z°£]°aÑ%7Õ8€FàØ
×
Ñ
˜1Ó
õ	à
õ	ð �/‰/˜!˜XÓ
&õ	'ð õ		ð
 �b‰=õ	ð ˜BÑõ	 ð 	ð Ÿ,™,°˜,Ó5Ñ€K�Ü�kŠk˜;¨°¸ÀfÐ9LÕ0MÐNÐTUÔV€GÜ�]Š]˜7 MÓ2°;ÀÐ3FÕG×QÑQÐRSÓT×WÑWÐX]×XcÑXcÓd€FØ�7ˆ?Ðr   c                óH  € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  R\        R\        R\        R\        \         P                  ,          R	\
        \         P                  \         P                  3,          /	# )
r   rM   rN   Úlafs1Úlafs2r“   r•   r”   rG   r   )r   r   r8   r   r   r   )r   s   "r   r   r   ú  s˜   € ÷ `;ñ `;Ü�<‰<ð`;ä�<‰<ð`;ô �<‰<ð`;ô �<‰<ð	`;ô
 	ð`;ô ð`;ô ð`;ô 	”—‘Õð`;ô Œ5�<‰<œŸ™Ð%Õ&ñ`;r   c                óŽ  € \        V RR.4       \        VRR.4       \        WV4      pVP                  ^ ,          ^8  d   \        V4      # \	        ^\        ^
VP                  ^ ,          4      4      p	\        P                  ! W‰^RR7      w  r«V
R	,          p\        V4      P                  R
^4      pWÛ,          p\        P                  ! WîR,          ,
          ^^R7      p\        P                  ! VR,          V8  \        R4      V
R,          4      pVP                  ^R7      w  ppVR	,          pVV,          pVV8*  pVV,          p\        V4      ^ 8X  d   \        V4      # \        P                  ! ^ VP                  ^ 4      VP                   R7      V,          pVV,          p\        P"                  ! VP                  R
^4      VP                  R
^4      .^4      pVP                  R
^4      VP                  R
^4      ppV'       g   VV3# \%        V4      w  ppVR	,          VVR,          ,          8H  pVV,          VV,          3# )a±  Match desc1 to desc2 by a ratio test against the first geometrically inconsistent neighbor (FGINN).

``dists, idxs = match_fginn(desc1, desc2, lafs1, lafs2, th, spatial_th)`` takes two descriptor sets ``(B1, D)``
and ``(B2, D)`` and the LAFs ``(1, B2, 2, 3)`` of ``desc2``, keeps the rows of ``desc1`` whose nearest neighbour
in ``desc2`` passes the ratio test of :func:`match_snn` against the nearest candidate whose ``lafs2`` centre
lies at least ``spatial_th`` from the nearest one's, and returns their ratios ``(B3, 1)`` and index pairs
``(B3, 2)``, in the order of the rows of ``desc1``. Closer candidates are skipped (see :cite:`MODS2015` for more
details), so a near-duplicate detection of the same structure, such as another scale or orientation at one
place, does not reject the match as it can in :func:`match_snn`. ``lafs1`` is not read, and ``mutual=True`` adds
the mutual nearest-neighbour check. To test the local affine consistency of the matches in both images, use
:func:`match_adalam` instead.

Convention:
    - See the Convention block on :func:`match_nn`. ``dists`` is a ratio: the nearest distance over the distance
      of the second neighbour, which is the nearest of the ``min(10, B2)`` nearest candidates, the first one
      excluded, whose ``lafs2`` centre lies at least ``spatial_th`` from the centre of the first one. Candidates
      closer than that count as the same structure, not as competitors, whatever their descriptor distance. When
      all of them are -- a dense cluster of detections on one structure -- the ratio is 0 and the match is
      **accepted**: no distinct competing structure among the candidates means the nearest neighbour is
      unambiguous. A descriptor beyond the ``min(10, B2)`` nearest is never the second neighbour, even when every
      candidate is excluded.
    - Only the centres of ``lafs2`` are read, and ``spatial_th`` is in their units: pixels for LAFs in pixels.

Args:
    desc1: Batch of descriptors of a shape ``(B1, D)``.
    desc2: Batch of descriptors of a shape ``(B2, D)``.
    lafs1: LAFs of a shape ``(1, B1, 2, 3)``. Accepted for API symmetry with
      :func:`~kornia.feature.match_adalam` but not read by this function -- only
      ``lafs2`` feeds the geometric check.
    lafs2: LAFs of a shape ``(1, B2, 2, 3)``.
    th: distance ratio threshold.
    spatial_th: minimal distance between the ``lafs2`` centres of the 1st and the 2nd nearest neighbor, in the
      units of those centres.
    mutual: also perform mutual nearest neighbor check.
    dm: torch.Tensor containing the distances from each descriptor in desc1
      to each descriptor in desc2, shape of ``(B1, B2)``.

Return:
    - Ratio of the nearest to the second-neighbour distance of each match, see the Convention block, shape of
      ``(B3, 1)``.
    - Long torch.Tensor indexes of matching descriptors in desc1 and desc2. Shape: ``(B3, 2)``,
      where 0 <= B3 <= B1.

See Also:
    - :func:`match_snn`: the plain ratio test, whose second neighbour can lie on the same structure.
    - :func:`match_adalam`: keeps the nearest-neighbour matches that local affine models of both images support.
    - :class:`GeometryAwareDescriptorMatcher`: the module form, with ``match_mode="fginn"``.

rÉ   rÊ   Fr¾   )Úpr.   rt   r­   r®   rÔ   rQ   )r°   :r   r¿   N)r°   :r¿   NNrî   )r   rœ   rÁ   r¤   r  r1   r   rÂ   r   rÌ   Únormr>   r8   rË   r²   rX   rV   r]   r»   )rM   rN   r4  r5  r“   r•   r”   rG   r§   Únum_candidatesÚ	vals_candrÎ   r¶   Úxy2Úcandidates_xyÚkdistÚ
fginn_valsÚvals_2ndÚ_rê   rH   rÍ   rÏ   rÐ   Úidxs_in_1_mutÚ	good_masks   &&&&&&&&                  r   Úmatch_fginnrC  ú  sü  € ôv �u˜s E˜lÔ+Ü�u˜s E˜lÔ+ä/°¸bÓA€Oà‡{�{�1…~˜ÔÜ˜Ó)Ð)ä˜œC  E§K¡K°¥NÓ3Ó4€NÜ Ÿ:š: oÈ1ÐV[Ô\Ñ€IØ�T�?€DÜ
˜Ó
×
$Ñ
$ R¨Ó
+€CØ•N€Mô �JŠJ�}°VÕ'<Õ<ÀÀqÔI€Eô —’˜U 5�\¨JÑ6¼¸e»ÀiÐPUÕFVÓW€JØ—.‘. Q�.Ó'�K€HˆaØ˜$•€Ià�8�O€EØ�B‰;€DØ˜•+€KÜ
ˆ;Ó˜1ÔÜ˜Ó)Ð)Ü�|Š|˜A˜yŸ~™~¨aÓ0¸×9OÑ9OÔPÐQUÕV€HØ˜$•€IÜ—9’9˜hŸm™m¨B°Ó2°I·N±NÀ2ÀqÓ4IÐJÈAÓN€LØ +× 0Ñ 0°°QÓ 7¸×9JÑ9JÈ2ÈqÓ9Q�€KçØ˜LÐ(Ð(Ü% oÓ6Ñ€A€}Ø˜TÕ" m°LÀÕ4FÕ&GÑG€IØ�yÕ! <°	Õ#:Ð:Ð:r   c                   óX   a a€ ] tR tRt oRtRV3R lV 3R llltV3R lR ltRtVtV ;t	# )	ÚDescriptorMatcheri]  a˜  Match two descriptor sets by nearest neighbours, mutual ones or a ratio test, as a module.

``matcher = DescriptorMatcher("snn", th=0.8)`` builds the module and ``dists, idxs = matcher(desc1, desc2)``
takes two descriptor sets ``(B1, D)`` and ``(B2, D)`` and returns what :func:`match_nn`, :func:`match_mnn`,
:func:`match_snn` or :func:`match_smnn` returns for them, by ``match_mode``: ``(B3, 1)`` qualities and
``(B3, 2)`` index pairs. It holds no parameters and reads no LAFs, which makes it a matcher for
:class:`LocalFeatureMatcher`. For matchers that also read the LAFs, use :class:`GeometryAwareDescriptorMatcher`
instead, and for a learned one, :class:`LightGlueMatcher`.

Convention:
    See the Convention block on :func:`~kornia.feature.match_nn`. ``forward`` returns what the function of
    ``match_mode`` (case-insensitive) returns for the two descriptor sets, with the module's ``th`` for ``snn``
    and ``smnn``. ``th`` defaults to 0.8 for both, while :func:`~kornia.feature.match_smnn` defaults to 0.95,
    and ``nn`` and ``mnn`` do not read it. There is no ``dm``.

Args:
    match_mode: type of matching, can be `nn`, `snn`, `mnn`, `smnn`.
    th: distance ratio threshold of the `snn` and `smnn` modes.

Raises:
    NotImplementedError: for another ``match_mode``.

See Also:
    - :func:`match_nn`: the function of ``match_mode="nn"``, which also takes a precomputed ``dm``; so do the
      other three.
    - :func:`match_mnn`: the function of ``match_mode="mnn"``.
    - :func:`match_snn`: the function of the default ``match_mode="snn"``.
    - :func:`match_smnn`: the function of ``match_mode="smnn"``, whose own ``th`` defaults to 0.95.
    - :class:`GeometryAwareDescriptorMatcher`: the module form of :func:`match_fginn` and :func:`match_adalam`,
      which also take LAFs.
    - :class:`LocalFeatureMatcher`: detects and describes the features of two images, then matches them with a
      module like this one.

c                ó*   <€ V ^8„  d   QhRS[ RS[RR/# )r   Ú
match_moder“   r   N)r‘   r8   )r   Ú__classdict__s   "€r   r   ÚDescriptorMatcher.__annotate__�  s"   ø€ ÷ ñ ¡3ð ±Eð ÀDñ r   c                óÂ   <€ \         SV `  4        VP                  4       p. ROV n        W0P                  9  d   \	        V RV P                   24      hW0n        W n        R# )r	   ú is not supported. Try one of N©r	   ÚmnnÚsnnÚsmnn)ÚsuperÚ__init__ÚlowerÚknown_modesÚNotImplementedErrorrG  r“   )ÚselfrG  r“   Ú_match_modeÚ	__class__s   &&& €r   rQ  ÚDescriptorMatcher.__init__�  sY   ø€ Ü‰ÑÔØ%×+Ñ+Ó-ˆÚ7ˆÔØ×.Ñ.Ô.Ü%¨¨Ð4RÐSW×ScÑScÐRdÐ&eÓfÐfØ%ŒØŽr   c                ó’   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[S[ P                  S[ P                  3,          /# )r   rM   rN   r   rž   )r   rH  s   "€r   r   rI  Š  s?   ø€ ÷ ñ ™UŸ\™\ð ±%·,±,ð Á5ÉÏÉÑW\×WcÑWcÐIcÕCdñ r   c                ó*  € V P                   R8X  d   \        W4      pV# V P                   R8X  d   \        W4      pV# V P                   R8X  d   \        WV P                  4      pV# V P                   R8X  d   \        WV P                  4      pV# \        h)a{  Run forward.

Args:
    desc1: Batch of descriptors of a shape ``(B1, D)``.
    desc2: Batch of descriptors of a shape ``(B2, D)``.

Returns:
    - ``dists`` of the matching function, see :func:`~kornia.feature.match_nn`, shape of ``(B3, 1)``.
    - Long torch.Tensor indexes of matching descriptors in desc1 and desc2,
        shape of ``(B3, 2)`` where :math:`0 <= B3 <= B1`.

r	   rM  rN  rO  ©rG  rÑ   rÚ   rõ   r“   r  rT  )rU  rM   rN   Úouts   &&& r   ÚforwardÚDescriptorMatcher.forwardŠ  s’   € ð �?‰?˜dÔ"Ü˜5Ó(ˆCð ˆ
ð �_‰_ Ô%Ü˜EÓ)ˆCð ˆ
ð �_‰_ Ô%Ü˜E¨$¯'©'Ó2ˆCð
 ˆ
ð	 �_‰_ Ô&Ü˜U¨4¯7©7Ó3ˆCð ˆ
ô &Ð%r   )rS  rG  r“   )rN  çš™™™™™é?)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rQ  r]  Ú__static_attributes__Ú__classdictcell__Ú__classcell__©rW  rH  s   @@r   rE  rE  ]  s$   ù‡ € ñ!÷Fõ ÷÷ ð r   rE  c                   ór   a a€ ] tR tRt oRtR
V3R lV 3R llltRV3R lR lltRV3R lR lltR	tVt	V ;t
# )ÚDescriptorMatcherWithSteereri¤  a=
  Matching that is invariant under rotations, using Steerers.

Args:
    steerer: An instance of :func:`kornia.feature.steerers.DiscreteSteerer`.
    steerer_order: order of discretisation of rotation angles, e.g. 4 leads to quarter rotations.
    steer_mode: can be `global`, `local`.
        `global` means that the we output matches from the global rotation with most matches.
        `local` means that we output matches from a distance matrix
        where the distance between each descriptor pair is the minimal over rotations.
    match_mode: type of matching, can be `nn`, `snn`, `mnn`, `smnn`.
        WARNING: using steer_mode `global` with match_mode `nn` will lead to bad results
        since `nn` doesn't generate different amount of matches depending on goodness of fit.
    th: threshold on distance ratio, or other quality measure.

Example:
    The example below is deliberately small so that it runs anywhere. A real workload uses
    full-resolution images and many more keypoints, and is worth moving onto an accelerator --
    uncomment the ``device`` lines to do that.

    >>> import kornia.feature as KF
    >>> # import kornia as K
    >>> # device = K.core.utils.get_cuda_or_mps_device_if_available()
    >>> img1 = torch.randn([1, 3, 128, 128])
    >>> img2 = torch.randn([1, 3, 128, 128])
    >>> # img1, img2 = img1.to(device), img2.to(device)
    >>> dedode = KF.DeDoDe.from_pretrained(detector_weights="L-C4-v2", descriptor_weights="B-SO2")
    >>> # dedode = dedode.to(device)
    >>> steerer_order = 8  # discretisation order of rotation angles
    >>> steerer = KF.steerers.DiscreteSteerer.create_dedode_default(
    ... generator_type="SO2", steerer_order=steerer_order
    ... )
    >>> # steerer = steerer.to(device)
    >>> matcher = KF.matching.DescriptorMatcherWithSteerer(
    ... steerer=steerer, steerer_order=steerer_order, steer_mode="global", match_mode="smnn", th=0.98
    ... )
    >>> with torch.inference_mode():
    ...     kps1, scores1, descs1 = dedode(img1, n=1_000)
    ...     kps2, scores2, descs2 = dedode(img2, n=1_000)
    ...     kps1, kps2, descs1, descs2 = kps1[0], kps2[0], descs1[0], descs2[0]
    ...     dists, idxs, num_rot = matcher(
    ...         descs1, descs2, normalize=True, subset_size=500,
    ...     )
    >>> idxs.shape == (dists.shape[0], 2), 0 <= num_rot < steerer_order
    (True, True)
    >>> bool((idxs[:, 0] < len(kps1)).all()), bool((idxs[:, 1] < len(kps2)).all())
    (True, True)
    >>> # print(f"{idxs.shape[0]} tentative matches with steered DeDoDe")
    >>> # print(f"at rotation of {num_rot * 360 / steerer_order} degrees")

c                ó<   <€ V ^8„  d   QhRS[ RS[RS[RS[RS[RR/# )r   ÚsteererÚsteerer_orderÚ
steer_moderG  r“   r   N)r   r‚   r‘   r8   )r   rH  s   "€r   r   Ú)DescriptorMatcherWithSteerer.__annotate__Ø  sG   ø€ ÷ ñ á ðñ ðñ ð	ñ
 ðñ ðð 
ñr   c                ól  <€ \         SV `  4        Wn        W n        VP	                  4       pR R.V n        W`P
                  9  d   \        V RV P
                   24      hW`n        VP	                  4       p. ROV n        WpP                  9  d   \        V RV P                   24      hWpn	        WPn
        R# )ÚglobalÚlocalrK  NrL  )rP  rQ  rl  rm  rR  Úknown_steer_modesrT  rn  rS  rG  r“   )	rU  rl  rm  rn  rG  r“   Ú_steer_moderV  rW  s	   &&&&&&  €r   rQ  Ú%DescriptorMatcherWithSteerer.__init__Ø  s±   ø€ ô 	‰ÑÔØŒØ*Ôà%×+Ñ+Ó-ˆØ"*¨GÐ!4ˆÔØ×4Ñ4Ô4Ü%¨¨Ð4RÐSW×SiÑSiÐRjÐ&kÓlÐlØ%ŒØ%×+Ñ+Ó-ˆÚ7ˆÔØ×.Ñ.Ô.Ü%¨¨Ð4RÐSW×ScÑScÐRdÐ&eÓfÐfØ%ŒØŽr   c          
      ó¼   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[S[ P                  ,          RS[S[ P                  S[ P                  3,          /# )r   r&   r'   rG   r   rÇ   )r   rH  s   "€r   r   ro  ð  sP   ø€ ÷ "ñ "Ù—,‘,ð"Ù$)§L¡Lð"Ù6>¹u¿|¹|Õ6Lð"á	‰u�|‰|™UŸ\™\Ð)Õ	*ñ"r   c                ó*  € V P                   R8X  d   \        WVR7      # V P                   R8X  d   \        WVR7      # V P                   R8X  d   \        WV P                  VR7      # V P                   R8X  d   \        WV P                  VR7      # \        h)aA  Dispatch descriptor matching to the configured matching strategy.

Args:
    d1: Descriptor tensor from the first image with shape `(N1, D)`, where `N1` is descriptor count and `D` is
        descriptor dimension.
    d2: Descriptor tensor from the second image with shape `(N2, D)`, where `N2` is descriptor count and `D` is
        descriptor dimension.
    dm: Optional descriptor-distance matrix used instead of recomputing distances from `d1` and `d2`.

Returns:
    Tuple containing match distances or scores and index pairs selected by the configured matching strategy.
r	   )rG   rM  rN  rO  r[  )rU  r&   r'   rG   s   &&&&r   Úmatching_functionÚ.DescriptorMatcherWithSteerer.matching_functionð  sz   € ð �?‰?˜dÔ"Ü˜B rÔ*Ð*Ø�?‰?˜eÔ#Ü˜R¨Ô+Ð+Ø�?‰?˜eÔ#Ü˜R T§W¡W°Ô4Ð4Ø�?‰?˜fÔ$Ü˜b d§g¡g°"Ô5Ð5Ü!Ð!r   c                óÂ   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[RS[S[,          RS[S[ P                  S[ P                  S[S[,          3,          /# )r   rM   rN   Ú	normalizeÚsubset_sizer   )r   r   r   r   r‚   r   )r   rH  s   "€r   r   ro  	  sh   ø€ ÷ @"ñ @"á�|‰|ð@"ñ �|‰|ð@"ñ ð	@"ñ
 ™c•]ð@"ñ 
‰u�|‰|™UŸ\™\©8±C­=Ð8Õ	9ñ@"r   c                ó  € RpV'       d   \        VRR7      p\        VRR7      pV P                  R8X  Ed<   Ve¥   \        P                  ! VP                  ^ ,          4      RV p\        P                  ! VP                  ^ ,          4      RV pV ! W,          W',          VR7      w   r…V P
                  P                  VVVR7      pV P                  WR4      w  ršWšV3# V P                  WR4      w  rš^ p\        ^V P                  4       Fb  pV P
                  P                  WR7      pV P                  WR4      w  rÍVP                  ^ ,          V
P                  ^ ,          8”  g   K^  YÍTrZp	Kd  	  M‘V P                  R8X  d{   \        W4      p\        ^V P                  4       F@  pV P
                  P                  WR7      p\        W4      p\        P                  ! Wï4      pKB  	  V P                  WV4      w  ršM\        hWšV3# )a  Run forward.

Args:
    desc1: Batch of descriptors of a shape ``(B1, D)``.
    desc2: Batch of descriptors of a shape ``(B2, D)``.
    normalize: bool to decide whether to F.normalize descriptors to unit norm.
    subset_size: If set, the subset size to use for determining optimal
        number of rotations. Smaller subset size leads to faster but less
        accurate matching. Only used when `self.steer_mode` is `"global"`.

Returns:
    - Descriptor distance of matching descriptors, shape of ``(B3, 1)``.
    - Long torch.Tensor indexes of matching descriptors in desc1 and desc2,
        shape of ``(B3, 2)`` where :math:`0 <= B3 <= B1`.
    - Number of global rotations from desc1 to desc2, in terms of `self.steerer_order`
        (will be `None` if `self.steer_mode` is `local`).

Nr­   rq  )r{  )Ústeerer_powerr{  rr  rQ   )r   rn  r   ÚrandpermrÁ   rl  Ústeer_descriptionsrx  r  rm  rJ   ÚminimumrT  )rU  rM   rN   r{  r|  Úrot1to2Ú
subsample1Ú
subsample2r@  Údistræ   ÚrÚdist_newÚidx_newrG   Údm_news   &&&&&           r   r]  Ú$DescriptorMatcherWithSteerer.forward	  sÙ  € ð2 ˆçÜ! %¨RÔ0ˆEÜ! %¨RÔ0ˆEà�?‰?˜hÕ&ØÒ&Ü"Ÿ^š^¨E¯K©K¸­NÓ;¸L¸[ÐI�
Ü"Ÿ^š^¨E¯K©K¸­NÓ;¸L¸[ÐI�
Ù $ØÕ%ØÕ%Ø'ô!‘��1ð
 Ÿ™×7Ñ7ØØ")Ø'ð 8ó �ð
 !×2Ñ2°5ÀÓF‘	�Ø 'Ð)Ð)Ø×.Ñ.¨u¸TÓB‰IˆDØˆGÜ˜1˜d×0Ñ0Ö1�ØŸ™×7Ñ7¸Ð7ÓS�Ø$(×$:Ñ$:¸5ÈÓ$NÑ!�Ø—=‘= Õ# c§i¡i°¥lÖ2Ø)1¸A˜w�D™wò	 2ð
 �_‰_ Ô'Ü˜Ó%ˆBÜ˜1˜d×0Ñ0Ö1�ØŸ™×7Ñ7¸Ð7ÓS�Ü Ó-�Ü—]’] 2Ó.’ñ 2ð ×.Ñ.¨u¸RÓ@‰IˆD�#ä%Ð%à˜'Ð!Ð!r   )rS  rs  rG  rn  rl  rm  r“   )rq  rN  r_  ©N)FN)r`  ra  rb  rc  rd  rQ  rx  r]  re  rf  rg  rh  s   @@r   rj  rj  ¤  s1   ù‡ € ñ1÷fõ ÷0"ò "÷2@"÷ @"ò @"r   rj  c                   ól   a a€ ] tR tRt oRtRR.tRV3R lV 3R llltV3R lR ltV3R	 ltR
t	Vt
V ;t# )ÚGeometryAwareDescriptorMatcheriL  a$  Match two descriptor sets that come with their LAFs, by FGINN or AdaLAM, as a module.

``matcher = GeometryAwareDescriptorMatcher("fginn", params)`` builds the module and
``dists, idxs = matcher(desc1, desc2, lafs1, lafs2)`` takes two descriptor sets ``(B1, D)`` and ``(B2, D)`` and
their LAFs ``(1, B1, 2, 3)`` and ``(1, B2, 2, 3)``, and returns what :func:`match_fginn` or :func:`match_adalam`
returns for them, by ``match_mode``: ``(B3, 1)`` ratios or inverse confidences and ``(B3, 2)`` index pairs. It
passes no ``dm``, and no image sizes to AdaLAM; to give them, call the functions directly. For descriptors
without LAFs, use :class:`DescriptorMatcher` instead.

Convention:
    See the Convention block on :func:`~kornia.feature.match_nn`. ``forward`` returns what the function of
    ``match_mode`` (case-insensitive) returns:

    - ``"fginn"`` reads the keys ``th``, ``spatial_th`` and ``mutual`` of ``params`` and ignores any other key.
      ``th`` defaults to 0.85, while :func:`~kornia.feature.match_fginn` defaults to 0.8.
    - ``"adalam"`` passes ``params`` as the AdaLAM ``config``, and no ``hw1`` or ``hw2``, so AdaLAM takes the
      extent of each image's keypoints as the image size.

Args:
    match_mode: type of matching, can be `fginn` or `adalam`.
    params: dictionary of parameters for the matching function.

Raises:
    NotImplementedError: for another ``match_mode``.

See Also:
    - :func:`match_fginn`: the function of the default ``match_mode="fginn"``, whose own ``th`` defaults to 0.8.
    - :func:`match_adalam`: the function of ``match_mode="adalam"``, which also takes the image sizes.
    - :class:`DescriptorMatcher`: the module form of the matchers that read descriptors only.
    - :class:`LightGlueMatcher`: a learned matcher with the same call, which also takes the image sizes.

ÚfginnÚadalamc                ód   <€ V ^8„  d   QhRS[ RS[S[S[ S[P                  3,          ,          RR/# )r   rG  Úparamsr   N)r‘   r   r   r   r   )r   rH  s   "€r   r   Ú+GeometryAwareDescriptorMatcher.__annotate__p  s6   ø€ ÷ #ñ #¡3ð #¹(Á4ÉÉUÏ\É\ÐHYÕCZÕ:[ð #Ðgkñ #r   c                óÆ   <€ \         SV `  4        VP                  4       pW0P                  9  d   \	        V R V P                   24      hW0n        T;'       g    / V n        R# )rK  N)rP  rQ  rR  rS  rT  rG  r‘  )rU  rG  r‘  rV  rW  s   &&& €r   rQ  Ú'GeometryAwareDescriptorMatcher.__init__p  sY   ø€ Ü‰ÑÔØ%×+Ñ+Ó-ˆØ×.Ñ.Ô.Ü%¨¨Ð4RÐSW×ScÑScÐRdÐ&eÓfÐfØ%ŒØ—l�l ˆŽr   c                óÆ   <€ V ^8„  d   QhRS[ P                  RS[ P                  RS[ P                  RS[ P                  RS[S[ P                  S[ P                  3,          /# )r   rM   rN   r4  r5  r   rž   )r   rH  s   "€r   r   r’  x  sY   ø€ ÷ ñ Ù—\‘\ðÙ*/¯,©,ðÙ?D¿|¹|ðÙTY×T`ÑT`ðá	‰u�|‰|™UŸ\™\Ð)Õ	*ñr   c           
     ó  € V P                   R8X  dL   \        4       pVP                  V P                  4       \	        WW4VR,          VR,          VR,          4      pV# V P                   R8X  d   \        WW4V P                  R7      pV# \        h)a×  Run forward.

Args:
    desc1: Batch of descriptors of a shape ``(B1, D)``.
    desc2: Batch of descriptors of a shape ``(B2, D)``.
    lafs1: LAFs of a shape ``(1, B1, 2, 3)``.
    lafs2: LAFs of a shape ``(1, B2, 2, 3)``.

Returns:
    - ``dists`` of the matching function, see :func:`~kornia.feature.match_nn`, shape of ``(B3, 1)``.
    - Long torch.Tensor indexes of matching descriptors in desc1 and desc2,
        shape of ``(B3, 2)`` where :math:`0 <= B3 <= B1`.

rŽ  r“   r•   r”   r�  )Úconfig)rG  r˜   Úupdater‘  rC  r   rT  )rU  rM   rN   r4  r5  r‘  r\  s   &&&&&  r   r]  Ú&GeometryAwareDescriptorMatcher.forwardx  s€   € ð" �?‰?˜gÔ%Ü.Ó0ˆFØ�M‰M˜$Ÿ+™+Ô&Ü˜e¨E¸&À½,ÈÈ|ÕH\Ð^dÐemÕ^nÓoˆCð
 ˆ
ð	 �_‰_ Ô(Ü˜u¨UÀ$Ç+Á+ÔNˆCð ˆ
ô &Ð%r   c                óF   <€ V ^8„  d   Qh/ S[ S[S[,          ,          ;R&   # )r   rS  )r   r   r‘   )r   rH  s   "€r   r   r’  L  s   ø‡ ‚ ñD ™$™s�)Õ$Ñ:òE r   )rG  r‘  )rŽ  N)r`  ra  rb  rc  rd  rS  rQ  r]  Ú__annotate_func__re  rf  rg  rh  s   @@r   r�  r�  L  s3   ù‡ € ñðB )0°Ð':€K÷#õ #÷ð ÷Y … r   r�  c                ób   € V ^8„  d   Qh/ ^ \         9   d   \        \        \        3,          ;R&   # )r   rT   )Ú__conditional_annotations__r   r‘   r‚   )r   s   "r   r   r      s%   € × =Ñ =÷L MÒ L”Dœœc˜•NÑ LòM >r   i   i  @ r‹  )é   )rž  F)F)r_  N)çffffffî?N)rŸ  NNN)r_  r–   FN)8r�  Útypingr   r   r   r   r   r   r   r	   Úkornia.core._compatr
   Úkornia.core.checkr   r   Úkornia.core.utilsr   r   r   r   Úkornia.feature.lafr   Úkornia.feature.steerersr   r�  r   r"   r$   rJ   rT   rg   rn   rq   rz   r   r‹   r�   r˜   rœ   r¤   rª   r»   rÅ   rÑ   rÚ   rë   rÀ   rõ   r  r2  rC  ÚModulerE  rj  r�  r   )r�  s   @r   Ú<module>r§     s
  øð÷$ >× =Ô =ã Ý å 0ß Fß bÓ bÝ -Ý 3å  ñ +¨1¨bÓ1Ð õ9õ$&ðT ',¨Y¸ÀÐ%LÐ Ó L÷*&õZ'õWõnõjõ õ,'õ=÷õ(
õ:÷ 6÷*:÷>H=÷V;1õ|M÷>/÷ =5÷@F1÷RI÷X`;ôFD˜Ÿ	™	ô DôNe" 2§9¡9ô e"ôPE R§Y¡Yö Er   