+
    åûj¥“ ã                  óJ  € R t ^ RIHt ^ RIt^ RIt^ RIHtHt ^ RI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 ^ RIHt ^ R	IHtHtHtHtHtHt ^ R
IHt ^ RIH t H!t!H"t"H#t# ^ RI$H%t%H&t& ^ RI'H(t(H)t) ^ RI*H+t+H,t,H-t-H.t.H/t/H0t0H1t1 ^ RI2H3t3H4t4H5t5H6t6H7t7H8t8H9t9H:t:H;t;H<t<H=t=H>t> ^ RI?H@t@HAtA R.tBRtCR.tD^tER/tFR0tGRtHR1tIRtJRtKR R ltLR R ltMR R ltNR R ltOR R ltPR  R! ltQ]! ^ R"7      R# R$ l4       tRR% R& ltSR' R( ltTR) R* ltUR+ R, ltV ! R- R]P®                  4      tXR# )2a  Estimate geometric models robustly from correspondences that contain outliers, with RANSAC.

:class:`RANSAC` fits one model to one set of ``(N, 2)`` correspondences (``(N, 2, 2)`` segments for
``"homography_from_linesegments"``), with the first image's points first: a homography or an affine map from the first
image to the second, a fundamental matrix with :math:`x_2^\top F x_1 = 0` from pixels (a general one, or the affine
fundamental matrix of two affine cameras), or an essential matrix from normalized camera coordinates. Its threshold
``inl_th`` is a distance in the units of the correspondences.
:ref:`Two-view geometry <two-view-conventions>` compares this with OpenCV.

Which class to use:

- One model from correspondences with outliers: :class:`RANSAC`, with ``model_type`` one of ``"homography"``,
  ``"homography_from_linesegments"``, ``"affine"``, ``"fundamental"`` (seven-point samples),
  ``"fundamental_7pt"``, ``"fundamental_8pt"``, ``"fundamental_affine"`` or ``"essential"``.
- A model from correspondences known to be inliers, without sampling: the estimators it wraps,
  :func:`~kornia.geometry.homography.find_homography_dlt`, :func:`~kornia.geometry.solvers.find_affine`,
  :func:`~kornia.geometry.epipolar.find_fundamental` and :func:`~kornia.geometry.epipolar.find_essential`.
)ÚannotationsN)Ú	lru_cacheÚpartial)ÚCallableÚListÚOptionalÚTupleÚUnion)Únn)Útorch_version_lt)ÚKORNIA_CHECK_SHAPE)Ú_autocast_disabled)Ú_h_degenerate_sampleÚ_h_degenerate_samplesÚ_inner_homographyÚ_inside_planeÚ_plane_parallax_searchÚ_repeats_plane)Úconvert_points_to_homogeneous)Úfind_essentialÚfind_fundamentalÚproject_to_essentialÚsampson_epipolar_distance)Ú_sampson_from_quadratic_basisÚ_sampson_quadratic_basis)Ú_five_point_candidatesÚ_refine_essential_lm)Ú_eight_point_fundamentalÚ_epipolar_design_rowsÚ_refine_fundamental_lmÚ_seven_point_candidatesÚnormalize_pointsÚnormalize_transformationÚ
run_affine)Ú_four_point_homographyÚ&_line_segment_squared_distance_one_wayÚ_refine_homography_lmÚ_transfer_basisÚ_transfer_from_basisÚfind_homography_dltÚfind_homography_dlt_iteratedÚfind_homography_lines_dltÚ"find_homography_lines_dlt_iteratedÚoneway_transfer_errorÚsample_is_valid_for_homographyÚsampson_homography_distance)Ú_find_affine_tripletÚfind_affineÚRANSACé   ç       @g      @gš™™™™™¹?c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )é   Úkp1útorch.TensorÚkp2ÚmodelsÚinl_thÚfloatÚreturn© )Úformats   "ÚRC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\ransac.pyÚ__annotate__rA   v   s;   € ÷ yñ yØ	ðyØ(ðyØ2>ðyØHMðyàñyó    c           	     ó~  € \        V P                  P                  4      ;_uu_ 4        \        P                  ! \        P                  ! V P
                  VP
                  4      \        P                  4      pVR. RO. RO3,          P                  V4      p\        P                  ! VP                  R^4      V P                  R^4      .R4      P                  V4      pVP                  RRR7      P                  4       pVP                  4       P                  ^4      p\        P                  ! WvR4      p\        P                  ! WvVP                  ^ 4      V,          ,
          R4      p	V	P                  V	,          V,          p
\        V,          ^,          VP!                  4       P                  R4      ,          pVR	,          VR
,          rÜWÊR,          ,          V,          P                  R4      V8¬  WÚR,          ,          V,          P                  R4      V8¬  ,          uuRRR4       #   + '       g   i     R# ; i)a/  Return which affine fundamental matrices ``(B, 3, 3)`` depend on both images' points, ``(B,)``.

``F = [[0, 0, a], [0, 0, b], [c, d, e]]`` puts a correspondence at the geometric distance
``(a x2 + b y2 + c x1 + d y1 + e) / |(a, b, c, d)|``. With ``(c, d) = 0`` that is the distance of ``x2`` to one
line, whatever ``x1`` is, so mismatches whose second points lie along a line all fit it and can outvote the true
geometry; with ``(a, b) = 0`` the same holds in the first image. Points near a line give small terms rather than
zero ones, and what counts as small depends on the images' extent and the threshold. So each image's term,
``(c x1 + d y1)`` over ``kp1`` and ``(a x2 + b y2)`` over ``kp2``, divided by ``|(a, b, c, d)|``, must have a
standard deviation of at least ``_AFFINE_FUNDAMENTAL_MIN_SPREAD`` times the inlier threshold ``inl_th`` (not
squared). For the true geometry the first image's term is the spread of the matched points across the epipolar
lines, seen in the second image. Correspondences with a non-finite point, which no model fits, are left out.
ºNNNT)Úkeepdimç        N)é    é   r6   r6   )r6   r6   rG   rH   éÿÿÿÿ©rD   ºNr6   N©rD   ºr6   NN©rK   rK   )rM   rM   )r   ÚdeviceÚtypeÚtorchÚpromote_typesÚdtypeÚfloat32ÚtoÚcatÚreshapeÚsumÚisfiniteÚ	clamp_minÚwhereÚmTÚ_AFFINE_FUNDAMENTAL_MIN_SPREADÚsquare)r7   r9   r:   r;   ÚworkÚnormalÚpointsÚfiniteÚcountÚcentredÚ
covarianceÚfloorÚn2Ún1s   &&&&          r@   Ú$_affine_fundamental_ties_both_imagesri   v   s—  € ô 
˜CŸJ™JŸO™O×	,Õ	,Ü×"Ò"¤5×#6Ò#6°s·y±yÀ&Ç,Á,Ó#OÔQV×Q^ÑQ^Ó_ˆØ˜š<ªÐ5Õ6×9Ñ9¸$Ó?ˆä—’˜CŸK™K¨¨AÓ.°·±¸BÀÓ0BÐCÀRÓH×KÑKÈDÓQˆØ—‘˜B¨�Ó-×6Ñ6Ó8ˆØ—
‘
“×&Ñ& qÓ)ˆÜ—’˜V¨SÓ1ˆÜ—+’+˜f¨v¯z©z¸!«}¸uÕ/DÕ&DÀcÓJˆØ—Z‘Z 'Õ)¨EÕ1ˆ
ä/°&Õ8¸QÕ>ÀÇÁÃ×ATÑATÐUWÓAXÕXˆØ˜•  u¥ˆBØ &Õ)Õ)¨RÕ/×4Ñ4°RÓ8¸EÑAÈÐX^ÕM_ÕH_ÐceÕGe×FjÑFjÐkmÓFnÐrwÑFwÕx÷ 
-×	,×	,Ó	,ús   ¨G8H+È+H<	c               ó$   € V ^8„  d   QhRRRRRR/# )r6   r:   r8   Ú	thresholdzUnion[float, torch.Tensor]r=   r>   )r?   s   "r@   rA   rA   •   s(   € ÷ Dñ D |ð DÐ@Zð DÐ_kñ DrB   c                ó,  € \         ^,          V,          p\        ^,          p\        V\        P                  4      '       d   VP                  V4      M
\        W#4      p\        P                  P                  V \        P                  ! V R,          V R,          .R4      RR7      pV P                  4       P                  R4      V R,          P                  4       ,
          pVP                  4       P                  R4      W%P                  4       ,          8  # )a„  Return which fundamental matrices ``(M, 3, 3)`` of Hartley-normalized points are nearly of rank one, ``(M,)``.

``F = l m^T`` gives ``x2^T F x1 = (l^T x2) (m^T x1) = 0`` for every ``x2`` on the line ``l`` whatever ``x1`` is, and
for every ``x1`` on ``m`` whatever ``x2`` is, so mismatches along a line in either image all fit it and can outvote
the true geometry. With singular values ``s1 >= s2`` and ``s3 = 0``, what ties the two images together moves a
correspondence's distance by about ``s2 / s1`` over keypoints of about unit radius. The test compares
``|cof F|_F / (|F|_F^2 - F_33^2)`` with ``_FUNDAMENTAL_MIN_RANK_SPREAD`` inlier thresholds of the frame
(``threshold`` is the squared one), or with ``_FUNDAMENTAL_RANK_FLOOR_LIMIT`` if that is smaller: a threshold as
wide as the keypoints fits nearly everything, and without the limit it would reject every model. Pixel coordinates
would not do, as the true geometry can have ``s2 / s1 < 0.01`` there.

No SVD is needed: at rank two ``|cof F|_F = s1 s2`` and ``|F|_F^2 = s1^2 + s2^2``, whose ratio is ``r / (1 + r^2)``
for ``r = s2 / s1``. ``F_33`` is left out of the denominator because it is the epipolar residual of the frame's two
origins, the keypoints' centroids, and not a sign of rank: mismatches that pull the centroids away from the true
matches would otherwise lower the value of the true geometry. The compared value is then at least
``r / (1 + r^2)``, and a rank-one matrix still has zero cofactors. The one rank-one matrix it does not flag, with
only ``F_33`` non-zero, compares ``0 < 0`` but fits no point. Both sides are compared squared. A NaN model compares
False, and has no inliers anyway.
©Údim)rD   rD   :rH   NN)rD   rD   ºNrH   NrI   éþÿÿÿ©rp   rI   )rD   r6   r6   )Ú_FUNDAMENTAL_MIN_RANK_SPREADÚ_FUNDAMENTAL_RANK_FLOOR_LIMITÚ
isinstancerQ   ÚTensorÚ	clamp_maxÚminÚlinalgÚcrossrV   r^   rX   )r:   rk   rf   ÚlimitÚ	cofactorsÚnorms   &&    r@   Ú_fundamental_near_rank_oner}   •   sÉ   € ô( )¨!Õ+¨iÕ7€EÜ)¨1Õ,€Eä&0°¼¿¹×&EÒ&EˆE�O‰O˜EÔ"Ì3ÈuÓK\€Eä—‘×"Ñ" 6¬5¯9ª9°f¸XÕ6FÈÈxÕHXÐ5YÐ[]Ó+^ÐdfÐ"Óg€IØ�=‰=‹?×Ñ˜xÓ(¨6°'­?×+AÑ+AÓ+CÕC€DØ×ÑÓ×!Ñ! (Ó+¨e·k±k³mÕ.CÑCÐCrB   c               ó    € V ^8„  d   QhRRRR/# )r6   Ú	transformr8   r=   r>   )r?   s   "r@   rA   rA   ³   s   € ÷ ñ ˜\ð ¨lñ rB   c                ó¬   € V P                  4       pV R,          V R,          P                  4       ,          VR&   V R,          ) V R,          ,          VR&   V# )z_The inverse of a Hartley normalization ``[[a, 0, b], [0, a, c], [0, 0, 1]]``, without a solver.rN   )rG   rG   )rK   r6   )Úcloner^   )r   Úinverses   & r@   Ú_unnormalizerrƒ   ³   sM   € à�o‰oÓ€GØ Õ'¨)°D­/×*@Ñ*@Ó*BÕB€GˆF�OØ Õ&Ð&¨°4­Õ8€GˆE�NØ€NrB   c               ó$   € V ^8„  d   QhRRRRRR/# )r6   r7   r8   r9   r=   ú/Tuple[torch.Tensor, torch.Tensor, torch.Tensor]r>   )r?   s   "r@   rA   rA   »   s"   € ÷ ?ñ ?˜,ð ?¨\ð ?Ð>mñ ?rB   c                ó†  € \        V P                  P                  4      ;_uu_ 4        \        P                  ! V P
                  \        P                  4      p\        V P                  V4      VP                  V4      R4      w   r4rV\        V4      \        V4      V^ ,          3uuRRR4       #   + '       g   i     R# ; i)zØThe inverse normalizations and the scale of :func:`_pixel_fundamental_near_rank_one`, for ``(N, 2)`` keypoints.

The frame is the shared-scale one of ``local_optimization="lm"``, whose models the test sees directly.
TN)
r   rO   rP   rQ   rR   rS   rT   Ú_normalize_correspondences_corerU   rƒ   )r7   r9   r_   Ú_Út1Út2Úscaless   &&     r@   Ú_rank_test_framerŒ   »   s   € ô
 
˜CŸJ™JŸO™O×	,Õ	,Ü×"Ò" 3§9¡9¬e¯m©mÓ<ˆÜ>¸s¿v¹vÀd»|ÈSÏVÉVÐTXË\Ð[_Ó`Ñˆˆ1�"Ü˜RÓ ¤-°Ó"3°V¸AµYÐ>÷ 
-×	,×	,Ó	,ús   ¨A<B/Â/C 	c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   Úframer…   r:   r8   r;   r<   r=   r>   )r?   s   "r@   rA   rA   Æ   s2   € ÷ Xñ XØ:ðXØDPðXØZ_ðXàñXrB   c           	     ó   € V w  r4p\        VP                  P                  4      ;_uu_ 4        \        P                  ! \        P                  ! VP
                  VP
                  4      \        P                  4      pVP                  V4      P                  VP                  V4      ,          VP                  V4      ,          p\        WrVP                  V4      P                  4       ,          4      uuRRR4       #   + '       g   i     R# ; i)zl:func:`_fundamental_near_rank_one` of pixel models, in a :func:`_rank_test_frame`, for a squared ``inl_th``.N)r   rO   rP   rQ   rR   rS   rT   rU   r\   r}   r^   )rŽ   r:   r;   Úunnormalizer1Úunnormalizer2Úscaler_   Ú
normalizeds   &&&     r@   Ú _pixel_fundamental_near_rank_oner”   Æ   s²   € ð +0Ñ'€M %Ü	˜FŸM™M×.Ñ.×	/Õ	/Ü×"Ò"¤5×#6Ò#6°u·{±{ÀFÇLÁLÓ#QÔSX×S`ÑS`ÓaˆØ"×%Ñ% dÓ+×.Ñ.°·±¸4³Õ@À=×CSÑCSÐTXÓCYÕYˆ
Ü)¨*¸u¿x¹xÈ»~×?TÑ?TÓ?VÕ6VÓW÷ 
0×	/×	/Ó	/ús   ­CC<Ã<D	c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   Úpts1r8   Úpts2r:   r=   r>   )r?   s   "r@   rA   rA   Ñ   s/   € ÷ iñ i ð i°\ð iÈ<ð iÐ\hñ irB   c                ó¢  € \        V P                  P                  4      ;_uu_ 4        V P                  R,          p\        P
                  ! \        P
                  ! V P                  VP                  4      VP                  4      p\        P
                  ! V\        P                  4      pV P                  V^4      P                  V4      pVP                  V^4      P                  V4      pVR,          P                  V4      P                  R^4      pW†P                  ,          P                  R^V4      VR,          P                  V4      ,           p	V	R,          VR,          ,
          P                  4       V	R,          VR,          ,
          P                  4       ,           P                  V4      uuRRR4       #   + '       g   i     R# ; i)a  Squared one-way transfer errors ``(B, N)`` of affine models ``(B, 3, 3)`` on one set of correspondences.

``pts1`` and ``pts2`` are ``(1, N, 2)``, as RANSAC scores them. This is :func:`oneway_transfer_error` without its
projective division and ``w' = 0`` guard, which an affine model's ``[0, 0, 1]`` bottom row makes unnecessary; like
that function, it computes in at least float32.
Nrp   )rD   rK   rK   rI   )rD   rK   rM   )rD   rG   )rD   rH   )r   rO   rP   ÚshaperQ   rR   rS   rT   rW   rU   ÚTÚviewr^   )
r–   r—   r:   Ú
num_pointsrS   r_   Úx1Úx2ÚlinearÚ	projecteds
   &&&       r@   Ú_affine_transfer_errorr¡   Ñ   sA  € ô 
˜DŸK™K×,Ñ,×	-Õ	-Ø—Z‘Z •^ˆ
Ü×#Ò#¤E×$7Ò$7¸¿
¹
ÀDÇJÁJÓ$OÐQW×Q]ÑQ]Ó^ˆÜ×"Ò" 5¬%¯-©-Ó8ˆØ�\‰\˜* aÓ(×+Ñ+¨DÓ1ˆØ�\‰\˜* aÓ(×+Ñ+¨DÓ1ˆØ˜	Õ"×%Ñ% dÓ+×3Ñ3°B¸Ó:ˆØŸd™d•]×(Ñ(¨¨Q°
Ó;¸fÀYÕ>O×>RÑ>RÐSWÓ>XÕXˆ	Ø˜4• 2 d¥8Õ+×3Ñ3Ó5¸À4½È2ÈdÍ8Õ9S×8[Ñ8[Ó8]Õ]×aÑaÐbgÓh÷ 
.×	-×	-Ó	-ús   ¨F
F=Æ=G	)Úmaxsizec               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   Úsample_sizeÚintÚpop_sizeÚbudgetr=   zTuple[int, ...]r>   )r?   s   "r@   rA   rA   å   s(   € ÷ 
ñ 
 ð 
¨sð 
¸Cð 
ÀOñ 
rB   c                ó†  € \        V4      p\        V 4       F  pW0V,
          W,
          ,          ,          pK!  	  ^.p\        V ^,           V^,           4       F]  pW6,          W`,
          ,          pVP                  VR,          \        ^\        P
                  ! Ws,
          4      4      ,           4       TpK_  	  \        V4      # )zACumulative draw counts T'_n (Chum & Matas, CVPR 2005, eqs. 3--4).rI   )r<   ÚrangeÚappendÚmaxÚmathÚceilÚtuple)r¤   r¦   r§   ÚexpectedÚiÚendsÚnÚnext_expecteds   &&&     r@   Ú_prosac_growthr´   ä   s–   € ô �V‹}€HÜ�;ÖˆØ 1•_¨­Õ6Õ6Šñ  àˆ3€DÜ�; •? H¨q¥LÖ1ˆØ �¨­Õ8ˆØ�‰�D˜•Hœs 1¤d§i¢i°Õ0HÓ&IÓJÕJÔKØ Šñ 2ô �‹;ÐrB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   ÚdegensacúOptional[bool]Ú
model_typeÚstrÚlocal_optimizationr=   Úboolr>   )r?   s   "r@   rA   rA   ò   s*   € ÷ 	3ñ 	3 ð 	3¸Cð 	3ÐUXð 	3Ð]añ 	3rB   c                óÆ   € V e&   \        V \        4      '       g   \        RV : 24      hV\        9   ;'       d    VR8H  pV '       d   V'       g   \        R4      hV f   R# T # )zWThe ``degensac`` setting of :class:`RANSAC`: None leaves it off; True requires support.z*degensac must be None, True or False, got Úlmzadegensac=True requires model_type "fundamental" or "fundamental_7pt" with local_optimization="lm"F)rt   r»   Ú
ValueErrorÚ_DEGENSAC_MODELS)r¶   r¸   rº   Ú	supporteds   &&& r@   Ú_resolve_degensacrÁ   ò   sg   € àÒ¤J¨x¼×$>Ò$>ÜÐEÀhÁ\ÐRÓSÐSØÔ.Ñ.×MÐMÐ3EÈÑ3M€IßŸ	ÜØoó
ð 	
ð Ò$ˆ5Ð2¨(Ð2rB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   r7   r8   r9   Úshared_scaler»   r=   zKTuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]r>   )r?   s   "r@   rA   rA   þ   s2   € ÷ Yñ YØ	ðYØ(ðYØ8<ðYàPñYrB   c           
     óˆ  € \         P                  ! V 4      P                  ^4      \         P                  ! V4      P                  ^4      ,          p\         P                  ! W.4      p\         P                  ! VR,          V\         P
                  ! V4      4      p\        WSP                  V P                  4      P                  ^R4      R7      w  rgV'       ds   VR,          pRRV,          P                  4       ,          V,          p	WiR,          ,          p\         P                  ! VR	,          V	R,          ,          VR
,          .^4      p\         P                  ! VR,          V\         P                  ! V\        R4      4      4      p\        V4      pV^ ,          V^,          V^ ,          V^,          RVR,          ,          3# )zl:func:`_normalize_correspondences` with the two scales as a ``(2,)`` tensor, without a host synchronization.)Úweightsr4   ç      ð?Únan)NrD   NrI   )rD   rG   rG   ©rD   NNrJ   rL   )rQ   rY   ÚallÚstackr[   Ú
zeros_liker!   rU   rS   ÚexpandrX   rV   Ú	full_liker<   r   )
r7   r9   rÃ   rb   ÚstackedÚplaceholdersra   Ú
transformsr’   Úratios
   &&&       r@   r‡   r‡   þ   sR  € ô �^Š^˜CÓ ×$Ñ$ QÓ'¬%¯.ª.¸Ó*=×*AÑ*AÀ!Ó*DÕD€FÜ�kŠk˜3˜*Ó%€GÜ—;’;˜v mÕ4°g¼u×?OÒ?OÐPWÓ?XÓY€LÜ)¨,Ç	Á	È#Ï)É)Ó@T×@[Ñ@[Ð\]Ð_aÓ@bÔcÑ€FßØ˜7Õ#ˆØ˜˜e�×(Ñ(Ó*Õ*¨eÕ3ˆØ Õ.Õ.ˆÜ—Y’Y 
¨5Õ 1°E¸-Õ4HÕ HÈ*ÐUZÕJ[Ð\Ð^_Ó`ˆ
Ü�[Š[˜ Õ.°¼¿ºÈÔPUÐV[ÓP\Ó8]Ó^€FÜ*¨6Ó2€FØ�!�9�f˜Q•i ¨A¥°
¸1µ¸sÀZÐPWÕEXÕ?XÐXÐXrB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   r7   r8   r9   rÃ   r»   r=   zKTuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, float, float]r>   )r?   s   "r@   rA   rA     s,   € ÷ "ñ "Ø	ð"Ø(ð"Ø8<ð"àPñ"rB   c                óP   € \        WV4      w  r4rVpVP                  4       w  r‰W4WVW‰3# )a&  Hartley-normalize both images' correspondences with :func:`normalize_points`, once per RANSAC call.

Statistics use the correspondences finite in both images: the others enter :func:`normalize_points` as zero-weight
placeholders, since a weight of 0 does not remove a NaN from its weighted sums, and come out as NaN in both images,
so they are never counted as inliers. ``shared_scale`` gives both images the scale of the mean of their two mean
radii, which keeps the Sampson distance a multiple of the pixel one: :func:`normalize_points` scales by
:math:`\sqrt{2} / (r + \epsilon)`, so that scale is the harmonic mean of the two.

Returns:
    Homogeneous normalized points ``(N, 3)`` of each image, the ``(3, 3)`` transforms that map pixels to them, and
    the two scales in pixels per normalized unit.
)r‡   Útolist)
r7   r9   rÃ   r�   rž   r‰   rŠ   r‹   Ús1Ús2s
   &&&       r@   Ú_normalize_correspondencesr×     s1   € ô =¸SÀ|ÓTÑ€BˆB�FØ�]‰]‹_�F€BØ�2˜2Ð!Ð!rB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   rº   r¹   Úprosac_samplingr»   r¶   r=   ÚNoner>   )r?   s   "r@   rA   rA   $  s0   € ÷ 	Cñ 	C¨cð 	CÀDð 	CÐTXð 	CÐ]añ 	CrB   c                ó²   € \        ^^^ 4      '       d   \        R4      hV R8w  d   \        R4      hV'       d   \        R4      hV'       d   \        R4      hR# )zGReject the configurations that ``RANSAC(compile=True)`` does not cover.z&compile=True needs torch 2.14 or laterr½   z2compile=True supports local_optimization="lm" onlyz-compile=True does not support prosac_samplingz&compile=True does not support degensacN)r   r¾   )rº   rÙ   r¶   s   &&&r@   Ú_check_compile_configrÜ   $  sT   € ä˜˜2˜q×!Ò!ÜÐAÓBÐBØ˜TÔ!ÜÐMÓNÐNßÜÐHÓIÐIßÜÐAÓBÐBñ rB   c                  ó
  a € ] tR tRt$ RtRIR V 3R llltR R ltRJR R	 llt]R
 R l4       t	R R lt
R R ltR R ltR R ltR R lt]R R l4       tR R ltRtR]R&   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RKR* R+ lltRKR, R- lltR. R/ ltR0 R1 ltRLR2 R3 llt]R4 R5 l4       t R6 R7 lt!R8 R9 lt"RMR: R; llt#R< R= lt$RJR> R? llt%]R@ RA l4       t&RB RC lt'RKRD RE llt(RF RG lt)RHt*V ;t+# )Nr2   i0  a@5  Estimate a homography, affine, fundamental or essential matrix robustly despite outliers.

``estimator = RANSAC(model_type, inl_th=2.0)`` builds the estimator, and ``model, inliers = estimator(kp1, kp2)``
takes one set of correspondences ``(N, 2)`` of the first and the second image, or segments ``(N, 2, 2)`` for
``"homography_from_linesegments"``, and returns the best-scoring ``(3, 3)`` model and its ``(N,)`` bool inlier
mask, or an all-zero model and an all-False mask when no model has enough support. A correspondence is an inlier
when its error under the model is at most ``inl_th``, in the units of the keypoints. The model follows the
estimator of its type: a homography or affine map from ``kp1`` to ``kp2``
(:func:`~kornia.geometry.homography.find_homography_dlt`, :func:`~kornia.geometry.solvers.find_affine`), a
fundamental matrix with :math:`x_2^\top F x_1 = 0` (:func:`~kornia.geometry.epipolar.find_fundamental`; for
``"fundamental_affine"`` its ``method="AFFINE"``, the matrix of two affine cameras), or an
essential matrix for camera-normalized keypoints (:func:`~kornia.geometry.epipolar.find_essential`). Each call
estimates one model, since ``batch_size`` batches hypotheses rather than problems; for correspondences known to be
inliers, call those estimators directly (see also https://en.wikipedia.org/wiki/Random_sample_consensus).

Convention:
    - ``kp1`` and ``kp2`` are passed as the first- and second-image arguments of the estimator selected by
      ``model_type``. ``forward`` returns an all-zero model and no inliers when no candidate has more inliers
      than its minimal sample (three correspondences for affine transforms, four for homographies and
      ``"fundamental_affine"``, five for ``"essential"``, seven for ``"fundamental"`` and ``"fundamental_7pt"``,
      eight for ``"fundamental_8pt"``).
    - ``"fundamental"`` draws seven-point samples, like ``"fundamental_7pt"``; ``"fundamental_8pt"`` draws
      eight-point ones.
    - ``inl_th`` is in the keypoints' own units (pixels, or calibrated units for ``"essential"``): a
      correspondence is an inlier when its one-way transfer error for ``"homography"`` or ``"affine"``,
      its Sampson distance for the fundamental models and ``"essential"`` (for ``"fundamental_affine"`` the
      exact geometric distance: the smallest total displacement of the two points that makes them correspond),
      or the mean distance of its transferred endpoints from the image-2 segment's line for
      ``"homography_from_linesegments"`` is at most ``inl_th``.
      :ref:`two-view-conventions` compares this with OpenCV.
    - ``score_type="msac"`` (the default) ranks candidates by ``sum(1 - min(e / inl_th**2, 1))`` over the
      squared errors ``e``; acceptance and early stopping count inliers for either score.
    - ``local_optimization="lm"``, the default for homographies, fundamental and essential matrices, keeps the
      eight best-scoring minimal models of the whole run. After sampling, it refines them together with
      ``max_lo_iters`` Levenberg-Marquardt iterations on all correspondences with the squared error truncated
      at ``inl_th``, keeps the best-scoring refit or minimal model, and refines that one on its inliers with
      ``refine_iters`` iterations of a Cauchy loss of scale ``inl_th / 3``. The returned mask holds the inliers
      of the returned model after conversion to the input dtype; if that conversion loses sufficient support,
      the call returns the all-zero failure result. Early stopping follows the support of the best minimal model.
      The refinements run on the CPU in float64 whatever the device of the correspondences: they are a few dozen
      small operations per iteration, which launch latency makes slower on an accelerator. Homographies and
      fundamental matrices are estimated on Hartley-normalized correspondences; essential matrices in the
      caller's calibrated coordinates, which a normalization would take off the essential manifold, refined on
      that manifold and returned with unit Frobenius norm.
    - ``local_optimization="dlt"``, the only choice for ``"affine"``, ``"fundamental_affine"`` and line
      segments, refits each new best model from its inliers: with the default ``lo_sample_size=32``,
      ``max_lo_iters`` randomized refits on 32-inlier subsets followed by one full-inlier refit;
      ``lo_sample_size=None`` refits all inliers iteratively. Affine models use a linear least-squares refit
      with free translation and return a homogeneous matrix with bottom row ``[0, 0, 1]``; their minimal
      samples need three non-collinear source points. ``"fundamental_affine"`` solves its four-point samples
      and refits its inliers by orthogonal regression, the Gold Standard estimate (Hartley and Zisserman,
      algorithm 14.1). It counts no inliers for a matrix that (nearly) ignores one image, ``(a, b)`` or
      ``(c, d)`` near 0: that matrix is a line in the other image, which mismatches along a line fit. Each
      image's term of the distance must vary over the keypoints by at least two inlier thresholds (a standard
      deviation). A true geometry whose keypoints spread less across its epipolar lines, such as a 15 px patch
      at ``inl_th=2``, is rejected too, and RANSAC returns zeros.
    - ``"fundamental"``, ``"fundamental_7pt"`` and ``"fundamental_8pt"`` count no inliers for a matrix of nearly
      rank one. ``F = l m^T`` is the pair of lines ``l`` and ``m``, and fits every mismatch along either of them
      whatever its point in the other image. With both images' points Hartley-normalized at a shared scale,
      ``|cof F| / (|F|^2 - F_33^2)``, about the ratio of ``F``'s singular values, must reach five inlier
      thresholds of that frame, at most ``0.1``; ``F_33``, the epipolar residual of the keypoint centroids, says
      nothing about rank. A true geometry whose keypoints differ in scale between the views by five times or more
      can fall below it, and RANSAC then keeps another model.
    - ``degensac=True``, an opt-in for ``"fundamental"`` and ``"fundamental_7pt"`` with
      ``local_optimization="lm"``, runs DEGENSAC (Chum, Werner and Matas, CVPR 2005). Every seven-point model that
      sets a new record among the raw scores is tested for an H-degenerate sample: five or more of its seven
      correspondences related by one homography. Such a model fits the dominant plane and whatever happens to
      agree with it off the plane, so the homography is refined, and fundamental matrices are drawn from it and
      pairs of correspondences off the plane (plane and parallax). The best of them, refined, joins the
      eight-model pool and, when it outscores the incumbent, sets the stopping bound. Thresholds and iteration
      counts follow Chum's implementation in pydegensac; the draws come from a private host generator. A plane
      already searched in the call is not searched again: a sample whose homography's inliers lie 95% or more
      inside it is skipped before refinement, and a refined plane whose inliers match it (Jaccard index 0.95 or
      more) before the search. The default, ``degensac=False``, keeps the plain seven-point loop.
      Explicit recovery reproduces that result exactly when no record-setting sample is degenerate.
      Chum's tolerance, three times the squared threshold for five of the seven correspondences, also flags
      samples in many scenes without a dominant plane; there the recovered models only join the competition.
    - ``prosac_sampling=True`` expects correspondences sorted best-first and stops with PROSAC's
      termination-length test; ``confidence=1`` runs the whole ``batch_size * max_iter`` budget.
    - A seeded call uses a private generator and leaves torch's global RNG state unchanged; ``seed=None``
      draws the minimal samples from the global generator. DEGENSAC's recovery draws always come from a private
      host generator, which an unseeded call seeds from the sample that triggers the recovery.
    - ``compile=True`` runs the whole ``local_optimization="lm"`` estimation as one ``torch.compile`` graph
      (torch 2.14 or later, CPU and CUDA). The graph is traced once per configuration and does not
      depend on the number of correspondences, the threshold, the confidence or the budget; it is also saved next
      to inductor's cache (``TORCHINDUCTOR_CACHE_DIR``), so a later process loads it instead of compiling. It
      runs the same algorithm with its own random stream: a seeded call is reproducible and leaves every global
      generator unchanged, while an unseeded call consumes one global random seed. Its result is not the eager
      one. PROSAC sampling and DEGENSAC are not supported.
    - PyTorch before 2.15: after compiled estimation on the CPU, a later CUDA process sharing the same inductor
      cache can save a CPU program as its CUDA artifact, and every CUDA process that loads it then crashes with a
      segmentation fault on its first call. Reproduced on 2.14.0; PyTorch 2.15.0 saves a separate CUDA
      program. On an older PyTorch, use a separate ``TORCHINDUCTOR_CACHE_DIR`` per device, or set
      ``KORNIA_RANSAC_AOT=0`` to skip the artifact. Deleting only ``<TORCHINDUCTOR_CACHE_DIR>/kornia_ransac/``
      does not help: the next CUDA compile reads the same inductor cache and saves the CPU program again
      (`#6278 <https://github.com/kornia/kornia/issues/6278>`_).
    - A caller's autocast region does not change the estimate.
    - On MPS with the default ``local_optimization="lm"``, ``"homography"``, ``"fundamental"``,
      ``"fundamental_7pt"`` and ``"fundamental_8pt"`` need torch 2.7 or later. With ``local_optimization="dlt"``,
      ``"homography"`` needs torch 2.10 or later, and ``"fundamental"``, ``"fundamental_7pt"``,
      ``"fundamental_8pt"`` and ``"essential"`` need torch 2.14 or later, because their inlier refits use the
      weighted eight-point solver. On an older torch, set ``PYTORCH_ENABLE_MPS_FALLBACK=1``; see
      :ref:`MPS linear algebra <mps-linear-algebra>`.

Args:
    model_type: "affine", "homography", "fundamental", "fundamental_7pt", "fundamental_8pt",
        "fundamental_affine", "essential", or "homography_from_linesegments".
    inl_th: positive inlier threshold, in the units given above.
    batch_size: hypotheses generated and verified at once, or ``"auto"`` to pick the batches per call from
        the device and the number of correspondences (see :meth:`resolve_batch_size`).
    max_iter: with an integer ``batch_size``, the maximum number of batches, for a budget of
        ``batch_size * max_iter`` minimal samples; with ``"auto"``, the budget is ``2048 * max_iter``. The
        seven- and five-point solvers can return multiple models per sample.
    confidence: stopping confidence in ``(0, 1]``; 1 disables early stopping.
    max_lo_iters: local optimization iterations: Levenberg-Marquardt iterations with
        ``local_optimization="lm"``, refits with ``"dlt"``; zero disables local optimization.
    score_type: "msac" (default) for truncated squared residuals, or "ransac" for support count.
    prosac_sampling: use PROSAC sampling on best-first ordered correspondences. The growth schedule
        advances per sampled set within each batch; stopping tests the incumbent's support within ranked
        prefixes (Chum and Matas, 2005, section 2.2) as well as within the whole set. It pays off when the
        ranking tracks inlier-ness and the inlier ratio is low (ratio-tested SIFT). On learned matches with
        85% or more inliers it can certify a model fitted to a spatially clustered top-ranked prefix after
        one batch and score below uniform sampling; use uniform sampling or ``confidence=1`` there.
    seed: optional seed, reset on each call for reproducible estimation on the same device.
    lo_sample_size: with ``local_optimization="dlt"``, the inlier-subset size for a batch of ``max_lo_iters``
        randomized local refits followed by a full-inlier refit (default 32). None uses iterative full-inlier
        refitting. Unused with ``"lm"``.
    max_samples: optional budget of minimal samples that overrides the one implied by ``batch_size`` and
        ``max_iter``; the last batch is truncated to it.
    local_optimization: ``"lm"`` or ``"dlt"``, as described above; None picks ``"lm"`` for homographies,
        fundamental and essential matrices and ``"dlt"`` for affine transforms and line segments.
    refine_iters: Levenberg-Marquardt iterations of the final refinement with ``local_optimization="lm"``;
        zero disables it.
    compile: run ``local_optimization="lm"`` as one compiled graph, as described above.
    degensac: run DEGENSAC's dominant-plane recovery, as described above. Defaults to False; None also leaves
        it off. True enables it for ``"fundamental"`` and ``"fundamental_7pt"`` with ``local_optimization="lm"``,
        the only supported combinations; True with any other raises ``ValueError``.

See Also:
    - :func:`~kornia.geometry.homography.find_homography_dlt`: the homography of correspondences known to be
      inliers.
    - :func:`~kornia.geometry.epipolar.find_fundamental`: the fundamental matrix of inlier correspondences.
    - :func:`~kornia.geometry.epipolar.find_essential`: the essential matrix candidates of inlier
      correspondences in normalized camera coordinates.
    - :func:`~kornia.geometry.solvers.find_affine`: the affine map of inlier correspondences.
    - :func:`~kornia.geometry.homography.find_homography_lines_dlt`: the homography of inlier line segments.

Nc                óX   € V ^8„  d   QhRRRRRRRRR	RR
RRRRRRRRRRRRRRRRRRRRR/# )r6   r¸   r¹   r;   r<   Ú
batch_sizezUnion[int, str]Úmax_iterr¥   Ú
confidenceÚmax_lo_itersÚ
score_typerÙ   r»   ÚseedúOptional[int]Úlo_sample_sizeÚmax_samplesrº   zOptional[str]Úrefine_itersr¶   r·   Úcompiler=   rÚ   r>   )r?   s   "r@   rA   ÚRANSAC.__annotate__Æ  sÎ   € ÷ s]ñ s]àðs]ð ðs]ð $ð	s]ð
 ðs]ð ðs]ð ðs]ð ðs]ð ðs]ð ðs]ð &ðs]ð #ðs]ð *ðs]ð ðs]ð !ðs]ð  ð!s]ð" 
ñ#s]rB   c                ó–  <€ \         SV `  4        . ROV n        RR.V n        WpP                  9  d   \	        RV 24      h\
        P                  ! W",          4      '       d   V^ 8:  g   W",          ^ 8X  d   \	        R4      h\        V\        4      '       d   VR8w  d   \	        R4      hM>\        V\        4      '       g   \        V\        4      '       d   V^ 8:  d   \	        R4      hV^ 8:  g   V^ 8  d   \	        R4      hVe?   \        V\        4      '       g   \        V\        4      '       d   V^ 8:  d   \	        R	4      h^ Tu;8  d   ^8:  g   M \	        R
4      h\        V\        4      '       g   \        V\        4      '       d   V^ 8  d   \	        R4      hVf   V\        9   d   RMRpVR9  d   \	        RV: 24      hVR8X  d1   V\        9  d&   \	        RRP                  \        4       RV: 24      h\        WáV4      pWpn        W n        W@n        W0n        W°n        Wn        WPn        W`n        Wn        W€n        W�n        W n        WÀn        WÐn        V'       d   \7        WÈV4       Wðn        Wàn        RV n        V  V  V  V P?                  W4       V
e+   W P@                  8  d   \	        RV P@                   24      hR# R# )a˜	  Initialize the RANSAC estimator.

Args:
    model_type: type of model to estimate: "affine", "homography", "fundamental", "fundamental_7pt",
        "fundamental_8pt", "fundamental_affine", "essential", "homography_from_linesegments".
    inl_th: inlier threshold; the class docstring gives its unit per ``model_type``.
    batch_size: number of generated samples at once, or ``"auto"`` (see :meth:`resolve_batch_size`).
    max_iter: maximum batches to generate. At most ``batch_size * max_iter`` minimal samples are drawn
        (``2048 * max_iter`` with ``batch_size="auto"``) unless ``max_samples`` is given.
    confidence: desired confidence of the result, used for the early stopping. 1 runs the full budget.
    max_lo_iters: number of local optimization iterations.
    score_type: scoring method to use: "msac" (default) or "ransac".
    prosac_sampling: use PROSAC's progressive sampling schedule. Inputs must be sorted best-first
        by match quality. The schedule advances for every sampled set, including within batches.
        Stops when a ranked prefix, or the whole set, certifies the incumbent with ``confidence``.
    seed: optional random seed for reproducible results. If None, uses global random state.
    lo_sample_size: with ``local_optimization="dlt"``, the cap on the number of inliers used by each
        randomized local refit (default 32). Fits ``max_lo_iters`` independent subsets in one batch,
        followed by one full-inlier refit. None uses iterative full-inlier refitting. Subset refits must
        raise the score; a full-inlier refit may also tie it, since it is more precise than the
        minimal-sample model.
    max_samples: optional budget of minimal samples, overriding ``batch_size * max_iter``.
    local_optimization: ``"lm"`` (batched Levenberg-Marquardt refinement of the best minimal models and a
        final robust refinement) or ``"dlt"`` (refits of each new best model); None picks ``"lm"`` where it
        is supported, for homographies, fundamental and essential matrices.
    refine_iters: Levenberg-Marquardt iterations of the final refinement on the inliers with ``"lm"``.
    compile: run ``local_optimization="lm"`` as one compiled graph (torch 2.14 or later).
    degensac: opt-in DEGENSAC dominant-plane recovery for seven-point fundamental matrices.
        Defaults to False; None also leaves it off. True requires seven-point matrices with
        local_optimization="lm".

ÚmsacÚransacúUnsupported score type: z1inl_th and its square must be positive and finiteÚautoz/batch_size must be a positive integer or "auto"z;max_iter must be positive; max_lo_iters must be nonnegativeNz&max_samples must be a positive integerzconfidence must lie in (0, 1]z*refine_iters must be a nonnegative integerr½   Údltz.local_optimization must be "lm" or "dlt", got z!local_optimization="lm" supports ú, z, not z lo_sample_size must be at least )ÚaffineÚ
homographyÚfundamentalÚfundamental_7ptÚfundamental_8ptÚfundamental_affineÚhomography_from_linesegmentsÚ	essential)r½   rð   )!ÚsuperÚ__init__Úsupported_modelsÚsupported_scoresr¾   r¬   rY   rt   r¹   r»   r¥   Ú
_LM_MODELSÚjoinrÁ   rã   r;   rà   rß   rç   r¸   rá   râ   rÙ   rä   ræ   rº   rè   rÜ   Úcompiledr¶   Ú_prosac_endsÚ
_set_modelÚpolisher_sample_size)Úselfr¸   r;   rß   rà   rá   râ   rã   rÙ   rä   ræ   rç   rº   rè   r¶   ré   Ú	__class__s   &&&&&&&&&&&&&&&&€r@   rû   ÚRANSAC.__init__Æ  sˆ  ø€ ôd 	‰ÑÔò	!
ˆÔð "(¨Ð 2ˆÔØ×2Ñ2Ô2ÜÐ7¸
°|ÐDÓEÐEÜ�}Š}˜V�_×-Ò-°¸1´ÀÅÐSTÔ@TÜÐPÓQÐQÜ�j¤#×&Ò&Ø˜VÔ#Ü Ð!RÓSÐSð $ä˜
¤D×)Ò)´¸JÌ×1LÒ1LÐPZÐ^_ÔP_ÜÐNÓOÐOØ�qŒ=˜L¨1Ô,ÜÐZÓ[Ð[ØÒ"Ü�{¤D×)Ò)´¸KÌ×1MÒ1MÐQ\Ð`aÔQaäÐEÓFÐFØ�:Ö" Ö"ÜÐ<Ó=Ð=Ü�l¤D×)Ò)´¸LÌ#×1NÒ1NÐR^ÐabÔRbÜÐIÓJÐJØÒ%Ø)3´zÔ)A¡ÀuÐØ ]Ô2ÜÐMÐN`ÑMcÐdÓeÐeØ Ô%¨*¼JÔ*FÜÐ@ÀÇÁÌ:ÓAVÐ@WÐW]Ð^hÑ]kÐlÓmÐmÜ$ XÐ;MÓNˆØ$ŒØŒØ ŒØ$ŒØ&ÔØ$ŒØ$ŒØ(ÔØ$ŒØ.ÔØŒ	Ø,ÔØ"4ÔØ(ÔßÜ!Ð"4ÀxÔPØŒØ Œà_cˆÔáÙÙà�‰˜
Ô+ØÒ%¨.×;TÑ;TÔ*TÜÐ?À×@YÑ@YÐ?ZÐ[Ó\Ð\ñ +UÑ%rB   c               ó$   € V ^8„  d   QhRRRRRR/# )r6   r¸   r¹   r;   r<   r=   rÚ   r>   )r?   s   "r@   rA   rê   ;  s&   € ÷ 0fñ 0f Sð 0f°%ð 0f¸Dñ 0frB   c                óˆ  € VR8X  d2   \         V n        \        V n        \        V n        ^V n        ^V n        R# VR8X  d=   \        V n        \        V n        \        \        VR7      V n        ^V n        ^V n        R# VR8X  d=   \        V n        \        V n        \        \        VR7      V n        ^V n        ^V n        R# VR8X  d2   \        V n        \         V n        ^V n        \         V n        ^V n        R# VR9   d=   \        V n        \        \         RR7      V n        ^V n        \         V n        ^V n        R# VR8X  d2   \        V n        \"        V n        ^V n        \"        V n        ^V n        R# VR	8X  d2   \        V n        \$        V n        ^V n        \         V n        ^V n        R# \'        V R
V P(                   24      h)zFSelect the model's residual, fitting methods and sample cardinalities.rò   ró   )Úsoft_inl_thrø   rö   Ú7POINT)Úmethodr÷   rù   z is unknown. Try one of N©rô   rõ   )r¡   Úerror_fnr0   Úminimal_solverr1   Úpolisher_solverÚminimal_sample_sizer  r-   r)   r   r*   r%   r+   r,   r   r   r#   r   ÚNotImplementedErrorrü   )r  r¸   r;   s   &&&r@   r  ÚRANSAC._set_model;  s‡  € à˜Ô!Ü2ˆDŒMä"6ˆDÔÜ#.ˆDÔ Ø'(ˆDÔ$Ø()ˆDÖ%Ø˜<Ô'Ü1ˆDŒMÜ"5ˆDÔä#*Ô+GÐU[Ô#\ˆDÔ Ø'(ˆDÔ$Ø()ˆDÖ%ØÐ9Ô9ÜBˆDŒMÜ";ˆDÔä#*Ô+MÐ[aÔ#bˆDÔ Ø'(ˆDÔ$Ø()ˆDÖ%ØÐ,Ô,Ü5ˆDŒMÜ"2ˆDÔØ'(ˆDÔ$Ü#3ˆDÔ Ø()ˆDÖ%ØÐ=Ô=Ü5ˆDŒMÜ")Ô*:À8Ô"LˆDÔØ'(ˆDÔ$Ü#3ˆDÔ Ø()ˆDÖ%ØÐ/Ô/Ü5ˆDŒMÜ",ˆDÔØ'(ˆDÔ$Ü#-ˆDÔ Ø()ˆDÖ%Ø˜;Ô&Ü5ˆDŒMÜ"0ˆDÔØ'(ˆDÔ$Ü#3ˆDÔ Ø()ˆDÖ%ä%¨¨Ð4LÈT×MbÑMbÐLcÐ&dÓeÐerB   c               ó4   € V ^8„  d   QhRRRRRRRRRRRR	R
R/# )r6   r¤   r¥   r¦   rß   Ú	iterationrO   z"Optional[Union[torch.device, str]]Úoffsetrå   r=   r8   r>   )r?   s   "r@   rA   rê   m  sb   € ÷ KEñ KEàðKEð ðKEð ð	KEð
 ðKEð 3ðKEð ðKEð 
ñKErB   c                ón  € Vf   \         P                  ! R4      M\         P                  ! V4      p^ Tu;8  d   V8:  g   M \        R4      hRpV P                  e:   \         P                  ! VR7      pVP                  V P                  V,           4       VP                  R8w  dG   V P                  '       g5   \         P                  ! W2WWR7      P                  V^RR7      P                  # \         P                  ! V3W%\         P                  R7      p\         P                  ! W5\         P                  R7      p	V P                  '       d~   V P                  WV4      p
Vf	   WC,          MTp\         P                   ! W5R7      V,           ^,           p\         P"                  ! W¬4      V,           P%                  VR	7      pWÊR,          8*  p	VP                  R8X  Ed   \         P                  ! W1V\         P&                  VR
7      p\         P(                  ! W1V\         P                  R7      p\+        V4       F«  pW�,
          V,           pVRV3,          V^,           ,          P                  4       pV^ 8”  d@   VRRV13,          VR,          8H  P-                  ^R7      p\         P.                  ! VVV4      pWñ^,
          8X  d   \         P.                  ! V	VV4      pVVRV3&   K­  	  V# \         P                  ! W2WWR7      pV P                  '       d‰   VP1                  \         P                   ! W%R7      R,          VR,          8¬  R4       VR,          ^,
          pVP3                  ^V\         P.                  ! V	R,          RVP5                  ^V4      4      4       VP                  V^RR7      P                  # )aÔ  Minimal sampler, but unlike traditional RANSAC we sample in batches.

Yields the benefit of the parallel processing, esp. on GPU.

Args:
    sample_size: number of samples to draw from the population.
    pop_size: size of the population to sample from.
    batch_size: number of sample sets to generate.
    iteration: zero-based batch index (used for the random seed and, without ``offset``, for PROSAC
        scheduling).
    device: device to place the samples on.
    offset: number of sets drawn by the previous batches, for PROSAC scheduling when batches differ in
        size; None assumes ``iteration`` batches of ``batch_size``.

Returns:
    Tensor of sampled indices with shape ``(batch_size, sample_size)``.

NÚcpuz8sample_size must be positive and no larger than pop_size©rO   ©rO   Ú	generatorF)Úkrn   Úsorted©rO   rS   )r«   )rO   rS   r  rD   rm   r4   rI   ©rD   Nç      ð¿)rQ   rO   r¾   rä   Ú	GeneratorÚmanual_seedrP   rÙ   ÚrandÚtopkÚindicesÚfullÚlongÚzerosr»   Ú_prosac_scheduleÚarangeÚsearchsortedÚclampÚfloat64Úemptyr©   Úanyr[   Úmasked_fill_Úscatter_Úgather)r  r¤   r¦   rß   r  rO   r  r  Ú
populationÚforce_newestr±   ÚstartÚdrawsr"  Úoutr°   ÚlastÚ	candidateÚ	duplicateÚnewests   &&&&&&&             r@   ÚsampleÚRANSAC.samplem  sÚ  € ð6 )/ª”—’˜eÔ$¼E¿LºLÈÓ<PˆØ�;Ö* (Ö*ÜÐWÓXÐXØˆ	Ø�9‰9Ò ÜŸš¨vÔ6ˆIØ×!Ñ! $§)¡)¨iÕ"7Ô8Ø�;‰;˜%Ô¨×(<×(<Ð(<ä—
’
˜:¸ÔTß‘˜¨°5�Ó9ß‘ðô —Z’Z  ¨xÌeÏjÉjÔYˆ
Ü—{’{ :ÄEÇJÁJÔOˆØ××ÐØ×(Ñ(¨ÀÓGˆDØ.4ªn�IÖ*À&ˆEÜ—L’L Ô;¸eÕCÀaÕGˆEÜ×,Ò,¨TÓ9¸KÕG×NÑNÐS[ÐNÓ\ˆJØ ¨¥HÑ,ˆLà�;‰;˜%Õô —:’:˜j¸fÌEÏMÉMÐenÔoˆDÜ—+’+˜j¸fÌEÏJÉJÔWˆCÜ˜;Ö'�Ø!Õ/°!Õ3�Ø! ! Q $�Z¨4°!­8Õ4×:Ñ:Ó<�	Ø�q”5Ø!$ Q¨¨¨ U¥¨y¸Õ/AÑ!A× FÑ FÈ1Ð FÓ M�IÜ %§¢¨I°t¸YÓ G�IØ a�Ô'Ü %§¢¨L¸$À	Ó J�IØ%��A�q�D“	ñ (ð ˆJä�zŠz˜*°vÔSˆØ××ÐØ×ÑœeŸlšl¨8ÔCÀDÕIÈZÐX_ÕM`Ñ`ÐbfÔgð   Õ(¨1Õ,ˆFØ�M‰M˜!˜V¤U§[¢[°¸gÕ1FÈÈTÏ[É[ÐYZÐ\bÓMcÓ%dÔeØ�y‰y˜;¨A°eˆyÓ<×DÑDÐDrB   c               ó   € V ^8„  d   QhRR/# )r6   r=   r¥   r>   )r?   s   "r@   rA   rê   »  s   € ÷ 
.ñ 
.˜sñ 
.rB   c                óÞ   € V P                   e   V P                   # \        V P                  \        4      '       d   V P                  V P                  ,          # \
        V P                  ,          # )a.  Minimal samples drawn per call: ``max_samples`` if given, else ``batch_size * max_iter``.

``batch_size="auto"`` counts ``max_iter`` in batches of 2048, the historical batch, whatever batch the
call resolves. Read at call time, like ``confidence``, so the attributes can be changed after construction.
)rç   rt   rß   r¥   rà   Ú_DEFAULT_BATCH)r  s   &r@   Úsample_budgetÚRANSAC.sample_budgetº  sO   € ð ×ÑÒ'Ø×#Ñ#Ð#Ü�d—o‘o¤s×+Ò+Ø—?‘? T§]¡]Õ2Ð2Ü §¡Õ-Ð-rB   c               ó$   € V ^8„  d   QhRRRRRR/# )r6   Únum_tcr¥   rO   útorch.devicer=   r>   )r?   s   "r@   rA   rê   Ç  s!   € ÷ '.ñ '.¨ð '.°lð '.Àsñ '.rB   c           	     óÊ  € \        V P                  \        4      '       d   V P                  # V P                  R9   pVP                  R8X  d   V'       d   RMRw  rEpMLVP                  R9   d"   R	RV'       g   V P                  R8X  d   RMRrepM\        \        V P                  4      # \        \        V\        V^4      ,          V4      V4      p\        WpP                  4      # )
aµ	  Return the batch size of a ``local_optimization="dlt"`` call: configured or ``"auto"``.

On CUDA and MPS a homography or affine batch costs about the same from a few hundred up to 8192 hypotheses
(the four- and three-point solves are launch-bound), so the whole ``sample_budget`` is drawn in batches
of up to 8192; the epipolar solvers are compute-bound past 2048 hypotheses, so their batches stop there
and early stopping is checked in between. The verification holds a ``batch x N`` residual matrix and a
few temporaries of that size, so past ``2**27`` entries (about 1 GiB at peak in float32) the batch
shrinks with ``N``, down to the 2048 of the historical fixed batch. On CPU the cost is linear in
``batch * N`` residuals, and the eight-point solver is about ten times a DLT, so the batch aims at a
millisecond or so of work, 256 to 2048 hypotheses for homographies and 128 to 512 for affine and the
epipolar models: a three-point affine sample needs far fewer draws than a four-point one, and the smaller
batches let early stopping act sooner (1.1-4.3x faster at equal recall on 500-8000 synthetic matches with
10-50% inliers). Other devices retain the historical 2048-sample batch.

With ``local_optimization="lm"`` an ``"auto"`` batch instead starts at 256 samples on CPU (512 for
homographies) and doubles after every batch, up to 2048 (4096 for homographies), so that inputs with
many inliers stop after a small first batch while the rest pay the per-batch overhead a few times only.
On CUDA and MPS it is the whole budget up to 8192 samples. Essential matrices start at 64 samples on CPU,
up to 1024, and at 256 on CUDA and MPS, up to 8192: a five-point sample needs few draws at high inlier
ratios, and its host eigenvalue solve costs the same on every device. All shrink, down to 64 samples, when a
batch would score more than ``2**22`` (CPU) or ``2**25`` (accelerators) residuals, counting the three models
of a seven-point sample and the ten candidate slots of a five-point one. On accelerators scoring holds two or
three times that many entries at its peak, about 0.5 GiB in float32; on CPU it scores tiles of about a million
residuals, independently of the batch. An integer ``batch_size`` is kept for every batch, except that
compiled CPU RANSAC splits a batch whose candidate-by-correspondence score matrix would exceed the CPU
memory bound. This preserves the sample budget, though the extra batch boundaries can change when
confidence-based stopping is evaluated.
r  r3   rò   é    )ró   rø   )i   é   r3   )i   é€   é   ©ÚcudaÚmpsi   )	rt   rß   r¥   r¸   rP   rw   r?  r@  r«   )r  rC  rO   Úplanarr_   ÚlowerÚupperÚbatchs   &&&     r@   Úresolve_batch_sizeÚRANSAC.resolve_batch_sizeÇ  s¶   € ô: �d—o‘o¤s×+Ò+Ø—?‘?Ð"Ø—‘Ð$RÑRˆØ�;‰;˜%Ôß9?Ñ!5ÐEXÑˆD™Ø�[‰[˜OÔ+Ø!(¨$¿À$Ç/Á/ÐU]ÔB]±Ðcg˜ˆD˜ä”~ t×'9Ñ'9Ó:Ð:Ü”C˜¤ F¨A£Õ.°Ó6¸Ó>ˆÜ�5×,Ñ,Ó-Ð-rB   c               ó$   € V ^8„  d   QhRRRRRR/# )r6   rC  r¥   rO   rD  r=   zTuple[int, int]r>   )r?   s   "r@   rA   rê   ð  s&   € ÷ Añ A cð A°<ð AÀOñ ArB   c                óh  € V P                   p\        V P                  \        4      '       d-   \	        V P                  V4      \	        V P                  V4      3# ^^^^
/P                  V P                  ^4      pV P                  R8H  pV P                  R8H  pVP                  R8X  d   V'       d   RMV'       d   RMRw  rxp	M.VP                  R	9   d   V'       d   RMRRR
r˜pM\        \        R
r˜p\        \	        W‰V\        V^4      ,          ,          4      ^@4      p
\	        WzV4      \	        W£4      3# )z^First and largest batch of a ``local_optimization="lm"`` call; see :meth:`resolve_batch_size`.ró   rù   r  rG  rF  )rI  i   é  @ )é@   i   rU  )rG  r3   rU  rJ  i   )r@  rt   rß   r¥   rw   Úgetr  r¸   rP   r?  r«   )r  rC  rO   r§   r:   rM  rù   ÚfirstrO  r_   Úlargests   &&&        r@   Ú_lm_batch_rangeÚRANSAC._lm_batch_rangeð  s  € à×#Ñ#ˆÜ�d—o‘o¤s×+Ò+Ü�t—‘¨Ó/´°T·_±_ÀfÓ1MÐMÐMà�Q˜˜2�×"Ñ" 4×#;Ñ#;¸QÓ?ˆØ—‘ LÑ0ˆð —O‘O {Ñ2ˆ	Ø�;‰;˜%Ôç(.Ñ$Ï9Ñ4GÐZnñ ˆE™$ð �[‰[˜OÔ+ß)2¡#¸¸tÀW˜$ˆE˜$ä!/´À˜$ˆEÜ”c˜%¨&´3°v¸q³>Õ*AÕ!BÓCÀRÓHˆÜ�5 6Ó*¬C°Ó,@Ð@Ð@rB   c               ó    € V ^8„  d   QhRRRR/# )r6   Únum_inliersr<   r=   r»   r>   )r?   s   "r@   rA   rê     s   € ÷ 6ñ 6¨ð 6°4ñ 6rB   c                ó   € WP                   8„  # )a  Whether a model has support beyond the minimal sample it may have been fitted to.

A minimal-sample model always fits its own sample, so only further inliers are evidence of a
consensus; without them, input with no consensus returns the all-zero failure matrix.
)r  )r  r]  s   &&r@   Ú_is_supportedÚRANSAC._is_supported  s   € ð ×5Ñ5Ñ5Ð5rB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   r¤   r¥   r¦   rO   rD  r=   r8   r>   )r?   s   "r@   rA   rê     s)   € ÷ $ñ $¨Cð $¸3ð $Èð $ÐYeñ $rB   c                óì   € WV P                   V3pV P                  e   V P                  ^ ,          V8w  d.   V\        P                  ! \	        VR,          !  VR7      3V n        V P                  ^,          # )z_Return the cumulative PROSAC draw counts on ``device``, converting them once per configuration.:Né   Nr  )r@  r  rQ   Útensorr´   )r  r¤   r¦   rO   Úkeys   &&&& r@   r(  ÚRANSAC._prosac_schedule  se   € à d×&8Ñ&8¸&ÐAˆØ×ÑÒ$¨×(9Ñ(9¸!Õ(<ÀÔ(CØ!$¤e§l¢l´>À3ÀrÅ7Ñ3KÐTZÔ&[Ð \ˆDÔØ× Ñ  Õ#Ð#rB   c               ó$   € V ^8„  d   QhRRRRRR/# )r6   Úinliersr8   r]  r¥   r=   r>   )r?   s   "r@   rA   rê     s!   € ÷ (1ñ (1¨<ð (1Àcð (1Ècñ (1rB   c           
     ó  € V P                   pV P                  VP                  4       rTV P                  R8¼  g   WT8:  d   V# \	        W0P                  W%W@P                  4      4      p\        V^,           \	        V^,          ^d4      4      pVP                  P                  R8X  d   \        P                  M\        P                  p\        P                  ! Wu^,           VP                  VR7      p	VP                  ^ 4      V^,
          R P                  V4      p
RpW¤,
          P                  ^ R7      W”,
          ,          p\        P                   P#                  WÌV,          4      \        P                   P#                  ^V,
          ^V,
          ^V,
          ,          4      ,           pWË8„  W”,
          V,          \$        P&                  ! R4      ) 8„  ,          pV
RV,          8¬  p\        P                  ! WAP                  VR7      pV
R	,          V,
          P                  ^ R7      V	R	,          V,
          ,          P)                  ^4      p\        P*                  ! V^ 8„  \$        P,                  ! V P                  ) 4      \        P,                  ! V) 4      ,          P/                  4       P                  ^R7      \        P0                  ! V\3        R4      4      4      pV P5                  WEVP                  4      Wt,
          R P                  V4      pWï,          VV8*  ,          p\        P*                  ! VV\        P0                  ! V\3        V4      4      4      P	                  4       p\	        V\7        VP9                  4       4      4      # )
aN  PROSAC termination length test (Chum and Matas, CVPR 2005, section 2.2).

A ranked prefix ``U_n`` certifies the incumbent when its support ``I_n`` there is non-random and
``k_n = log(1 - confidence) / log(1 - C(I_n, m) / C(n, m))`` draws fit inside the prefix's growth
interval ``T'_n``, so that every counted draw was taken from ``U_n`` or a shorter prefix. The
binomial tail of ``I_n - m`` accidental inliers with per-correspondence probability ``beta = 0.05`` is
bounded by Chernoff's inequality at significance 0.05. As in OpenCV's USAC, prefixes shorter than
``min(N / 2, 100)`` correspondences or supporting fewer than 20% of all correspondences cannot
terminate: a handful of top-ranked inliers to a model fitted to their neighbours is no evidence of a
good model. The whole set is always a candidate, which is the uniform-sampling bound.
rÆ   rL  r  Ngš™™™™™©?)rw   gš™™™™™É?Úinfr  )r@  r  Únumelrá   rw   Úmax_samples_by_confr«   rO   rP   rQ   rT   r,  r)  ÚcumsumrU   r+  ÚspecialÚxlogyr¬   ÚlogÚprodr[   Úlog1pr­   rÍ   r<   r(  r¥   Úitem)r  rh  r]  r§   ÚmÚtotalÚboundÚn_minrS   r²   ÚsupportÚbetaÚqÚ
divergenceÚ
non_randomÚenoughÚoffsetsÚprobabilityÚrequiredr±   Úeligibler8  s   &&&                   r@   Ú_prosac_max_samplesÚRANSAC._prosac_max_samples  s”  € ð ×#Ñ#ˆØ×+Ñ+¨W¯]©]«_ˆ5Ø�?‰?˜cÔ! U¤ZØˆMÜ�F×4Ñ4°[ÈÏOÉOÓ\Ó]ˆÜ�A˜•Eœ3˜u¨�z¨3Ó/Ó0ˆð ")§¡×!4Ñ!4¸Ô!=”—’Ä5Ç=Á=ˆÜ�LŠL˜¨¥	°'·.±.ÈÔNˆØ—.‘. Ó# E¨A¥I KÐ0×3Ñ3°EÓ:ˆàˆØ�[×Ñ AÐÓ&¨!­%Õ0ˆÜ—]‘]×(Ñ(¨°­HÓ5¼¿¹×8KÑ8KÈAÐPQÍEÐTUÐXYÕTYÐ^_ÐbfÕ^fÕSgÓ8hÕhˆ
Ø‘h A¥E¨ZÕ#7¼4¿8º8ÀD»>¸/Ñ#IÕJˆ
Ø˜C %�KÑ'ˆä—,’,˜q¯©¸uÔEˆØ Õ(¨7Õ2×9Ñ9¸aÐ9Ó@ÀAÀgÅJÐQXÕDXÕY×_Ñ_Ð`aÓbˆÜ—;’;Ø˜!‰OÜ�ZŠZ˜Ÿ™Ð(Ó)¬E¯KªK¸¸Ó,EÕE×KÑKÓM×SÑSÐXYÐSÓZÜ�OŠO˜K¬¨u«Ó6ó
ˆð
 ×$Ñ$ Q¨w¯~©~Ó>¸u½y¸{ÐK×NÑNÈuÓUˆØÕ&¨(°dÑ*:Õ;ˆÜ—K’K ¨(´E·O²OÀHÌeÐTZËmÓ4\Ó]×aÑaÓcˆ	Ü�5œ#˜iŸn™nÓ.Ó/Ó0Ð0rB   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )r6   Ún_inlr¥   rC  r¤   Úconfr<   r=   r>   )r?   s   "r@   rA   rê   @  s7   € ÷ Yñ Y 3ð Y°ð YÀ#ð YÈUð YÐWZñ YrB   c           	     ó¶  € VR8:  d   ^# VR8¼  g   W8  g   W8  d   \         P                  # W8¼  d   ^# Rp\        V4       F  pW@V,
          W,
          ,          ,          pK!  	  VR8X  d   \         P                  # \        \         P                  \        P
                  ! \        P                  ! V) 4      \        P                  ! V) 4      ,          4      4      # )a   Update max_iter to stop iterations earlier https://en.wikipedia.org/wiki/Random_sample_consensus.

Args:
    n_inl: number of inliers.
    num_tc: total number of correspondences.
    sample_size: size of minimal sample.
    conf: desired confidence level.

Returns:
    Number of samples needed to achieve the desired confidence, rounded up.
    Returns ``sys.maxsize`` when no finite stopping bound is available.

rF   rÆ   )Úsysr¢   r©   rw   r¬   r­   rr  )r…  rC  r¤   r†  Úprob_inlierr°   s   &&&&  r@   rl  ÚRANSAC.max_samples_by_conf?  s£   € ð �3Œ;Ùà�3Œ;˜&Ô.°%Ô2EÜ—;‘;ÐØŒ?Ùð ˆÜ�{Ö#ˆAØ A�I¨&­*Õ5Õ5ŠKñ $ð ˜#ÔÜ—;‘;ÐÜ”3—;‘;¤§	¢	¬$¯*ª*°d°UÓ*;¼d¿jºjÈ+ÈÓ>VÕ*VÓ WÓXÐXrB   c               ó$   € V ^8„  d   QhRRRRRR/# )r6   r7   r8   r9   r=   r>   )r?   s   "r@   rA   rê   `  s'   € ÷ vñ v°ð vÀLð vÐUañ vrB   c                ó¦   € VP                   R,          w  r4V P                  W\        P                  ! W4VP                  VP
                  R7      4      # )zãEstimate models from minimal samples.

Args:
    kp1: source keypoints with shape ``(batch_size, sample_size, 2)``.
    kp2: target keypoints with shape ``(batch_size, sample_size, 2)``.

Returns:
    Estimated models tensor.

rK   ©rS   rO   )r™   r  rQ   ÚonesrS   rO   )r  r7   r9   rß   r¤   s   &&&  r@   Úestimate_model_from_minsampleÚ$RANSAC.estimate_model_from_minsample`  sB   € ð #&§)¡)¨B¥-Ñˆ
Ø×"Ñ" 3¬U¯ZªZ¸
ÐWZ×W`ÑW`Ðil×isÑisÔ-tÓuÐurB   z\Optional[Tuple[torch.Tensor, torch.Tensor, Tuple[torch.Tensor, torch.Tensor, torch.Tensor]]]Ú_dlt_rank_framec          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r6   r7   r8   r9   r:   r;   r<   r=   z/Tuple[torch.Tensor, torch.Tensor, float, float]r>   )r?   s   "r@   rA   rê   q  sB   € ÷ FGñ FGØðFGØ&2ðFGØ<HðFGØRWðFGà	8ñFGrB   c           	     óô  € \         P                  ! V4      '       d   V^ 8:  d   \        R4      hYre\        VP                  4      ^8X  d
   VR,          p\        VP                  4      ^8X  d
   VR,          pVP                  ^ ,          pV P
                  R8X  d9   V P                  VP                  VR^^4      VP                  VR^^4      V4      pMV P                  WV4      p\        R4      p	VP                  W™V	R7      pW„8*  p
V P
                  R8X  d1   V
\        WV\         P                  ! V4      4      R,          ,          p
M…V P
                  \        9   dq   V P                  pVe$   V^ ,          VJ d   V^,          VJ d
   V^,          MRpVf   \        V^ ,          V^ ,          4      MTpV
\        WÃV4      R,          ( ,          p
V
P!                  ^R7      pV P"                  R8X  d   R	VP%                  R
VR7      V,          ,
          P!                  ^\&        P(                  ! VP*                  \&        P,                  4      R7      pVP/                  WÐP0                  8*  R4      pM,V P"                  R8X  d   TpM\        RV P"                   24      hVP3                  4       pWï,          P5                  4       pWß,          P5                  4       pW?,          P7                  4       pW¯,          pVVVV3# )a‘  Verify models by computing inliers and selecting the best model.

Args:
    kp1: source keypoints.
    kp2: target keypoints.
    models: candidate models to verify.
    inl_th: positive squared inlier threshold.

Returns:
    Tuple containing:
        - Best model
        - Inlier mask for the best model
        - Score of the best model
        - Number of inliers (distinct from the MSAC score)

z8The squared inlier threshold must be positive and finiteNrø   rj  )rÇ   ÚposinfÚneginfr÷   rm   rì   rÆ   rF   )rw   r«   )rn   rS   rí   rî   rI   r  )r¬   rY   r¾   Úlenr™   r¸   r  rÌ   r<   Ú
nan_to_numri   ÚsqrtÚ_RANK_TESTED_MODELSr‘  rŒ   r”   rX   rã   r+  rQ   rR   rS   rT   Úmasked_fillr  Úargmaxrs  r�   )r  r7   r9   r:   r;   Ú	kp1_inputÚ	kp2_inputrß   Úerrorsrj  Úinl_maskÚheldrŽ   Úscore_ransacÚscoreÚbest_model_idxÚbest_model_scorer]  Ú
model_bestÚinliers_bests   &&&&&               r@   ÚverifyÚRANSAC.verifyq  s—  € ô& �}Š}˜V×$Ò$¨°!¬ÜÐWÓXÐXØ"�9Üˆs�y‰y‹>˜QÔØ�d•)ˆCÜˆs�y‰y‹>˜QÔØ�d•)ˆCØ—\‘\ !•_ˆ
Ø�?‰?Ð<Ô<Ø—]‘] 3§:¡:¨j¸"¸aÀÓ#CÀSÇZÁZÐPZÐ\^Ð`aÐcdÓEeÐgmÓn‰Fð —]‘] 3¨VÓ4ˆFô �E‹lˆØ×"Ñ" s¸sÐ"ÓCˆØÑ#ˆØ�?‰?Ð2Ô2àÔ"FÀsÐQWÔY]×YbÒYbÐciÓYjÓ"kÐlsÕ"tÕt‰HØ�_‰_Ô 3Ô3à×'Ñ'ˆDØ#Ò/°D¸µG¸yÓ4HÈTÐRSÍWÐXaÓMa�D˜–GÐgkˆEØ8=ºÔ$ S¨¥V¨S°­VÔ4È5ˆEØÔ#CÀEÐSYÓ#ZÐ[bÕ#cÐ"cÕcˆHØ—|‘|¨�|Ó*ˆØ�?‰?˜fÔ$ð ˜6Ÿ<™<¨C°V˜<Ó<¸vÕEÕE×JÑJØœU×0Ò0°·±¼u¿}¹}ÓMð Kó ˆEð ×%Ñ% l×6NÑ6NÑ&NÐPRÓS‰EØ�_‰_ Ô(ð !‰EäÐ7¸¿¹Ð7HÐIÓJÐJØŸ™›ˆØ Õ0×5Ñ5Ó7ÐØ"Õ2×7Ñ7Ó9ˆØÕ+×1Ñ1Ó3ˆ
ØÕ/ˆØ˜<Ð)9¸;ÐFÐFrB   c               ó$   € V ^8„  d   QhRRRRRR/# ©r6   r7   r8   r9   r=   ú!Tuple[torch.Tensor, torch.Tensor]r>   )r?   s   "r@   rA   rê   ¹  s"   € ÷ ñ  lð ¸ð ÐJkñ rB   c                ó`   € V P                   R8X  d   \        W4      pW,          W#,          3# W3# )z³Remove degenerate samples based on model-specific constraints.

Args:
    kp1: source keypoints.
    kp2: target keypoints.

Returns:
    Tuple of filtered keypoints (kp1, kp2).

ró   )r¸   r.   )r  r7   r9   Úmasks   &&& r@   Úremove_bad_samplesÚRANSAC.remove_bad_samples¹  s0   € ð �?‰?˜lÔ*Ü1°#Ó;ˆDØ•9˜c�iÐ'Ð'ØˆxˆrB   c               ó    € V ^8„  d   QhRRRR/# ©r6   r:   r8   r=   r>   )r?   s   "r@   rA   rê   Ë  s   € ÷ ñ ¨ð ¸ñ rB   c                óÎ   € \         P                  ! V4      P                  RR7      P                  RR7      VP                  4       P	                  RR7      ^ 8„  ,          pW,          # )z‹Remove degenerate models based on simple heuristics.

Args:
    models: candidate models to filter.

Returns:
    Filtered models tensor.

rm   rI   rq   )rQ   rY   rÉ   ÚabsÚamax)r  r:   r­  s   && r@   Úremove_bad_modelsÚRANSAC.remove_bad_modelsË  sV   € ô �~Š~˜fÓ%×)Ñ)¨bÐ)Ó1×5Ñ5¸"Ð5Ó=ÀÇÁÃ×ARÑARÐW_ÐARÓA`ÐcdÑAdÕeˆØ�|ÐrB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   r7   r8   r9   rh  r=   r>   )r?   s   "r@   rA   rê   Ù  s)   € ÷ +ñ + ð +°<ð +È,ð +Ð[gñ +rB   c                óü   € W,          R,          pW#,          R,          pVP                  ^4      pV P                  WE\        P                  ! ^WdP                  VP
                  R7      4      pV P                  V4      # )zÛPolish the model using inliers through local optimization.

Args:
    kp1: source keypoints.
    kp2: target keypoints.
    inliers: boolean mask indicating inlier correspondences.

Returns:
    Polished model tensor.

Nr�  )Úsizer  rQ   rŽ  rS   rO   Ú_project_refits)r  r7   r9   rh  Úkp1_inlÚkp2_inlÚnum_inlÚmodels   &&&&    r@   Úpolish_modelÚRANSAC.polish_modelÙ  si   € ð •,˜tÕ$ˆØ•,˜tÕ$ˆØ—,‘,˜q“/ˆØ×$Ñ$ØœeŸjšj¨¨G¿=¹=ÐQX×Q_ÑQ_Ô`ó
ˆð ×#Ñ# EÓ*Ð*rB   c               ó    € V ^8„  d   QhRRRR/# r±  r>   )r?   s   "r@   rA   rê   ó  s   € ÷ Kñ K lð K°|ñ KrB   c                ó„   € V P                   R8w  d   V# V P                  V4      p\        V4      ^ 8”  d   \        V4      # T# )z^Project essential refits onto the manifold, dropping invalid ones before the projection's SVD.rù   )r¸   rµ  r–  r   )r  r:   s   &&r@   rº  ÚRANSAC._project_refitsó  s>   € à�?‰?˜kÔ)ØˆMØ×'Ñ'¨Ó/ˆÜ/2°6«{¸Q¬Ô# FÓ+ÐJÀFÐJrB   c               ó0   € V ^8„  d   QhRRRRRRRRRRRR/# )	r6   r7   r8   r9   rh  ræ   r¥   r  r=   r>   )r?   s   "r@   rA   rê   ú  s<   € ÷ ,ñ ,Øð,Ø&2ð,Ø=Ið,Ø[^ð,Øknð,à	ñ,rB   c           	     óX  € RpV P                   eU   \        P                  ! VP                  R7      pVP	                  V P                   V P
                  ,           V,           4       VP                  4       P                  4       p\        P                  ! V P                  \        V4      VP                  VR7      pWxP                  V^R7      P                  ,          p	V P                  W,          W),          \        P                  ! W‘P                  R7      4      p
V P!                  V
4      # )a  Fit ``max_lo_iters`` random ``lo_sample_size``-subsets of the inliers in one solver batch.

Randomized non-minimal refits let LO escape a bad consensus. Bounded subsets follow Lebeda et al.,
BMVC 2012 (LO+), but this is not the full LO+ algorithm with threshold scheduling.
Nr  r  rm   ©rS   )rä   rQ   r   rO   r!  r@  ÚnonzeroÚflattenr"  râ   r–  r#  r$  r  Ú	ones_likerS   rº  )r  r7   r9   rh  ræ   r  r  r$  ÚsubsetÚselectedr:   s   &&&&&&     r@   Ú_subset_refitsÚRANSAC._subset_refitsú  sÕ   € ð ˆ	Ø�9‰9Ò ÜŸš¨s¯z©zÔ:ˆIà×!Ñ! $§)¡)¨d×.@Ñ.@Õ"@À9Õ"LÔMØ—/‘/Ó#×+Ñ+Ó-ˆô —’˜D×-Ñ-¬s°7«|ÀCÇJÁJÐZcÔdˆØŸ;™; ~¸1˜;Ó=×EÑEÕFˆØ×%Ñ% c¥m°Sµ]ÄEÇOÂOÐT\×dmÑdmÔDnÓoˆØ×#Ñ# FÓ+Ð+rB   c               ó8   € V ^8„  d   QhRRRRRRRRRRRRR	R
RR/# )r6   r7   r8   r9   r¾  rh  Úmodel_scorer<   r]  r  r¥   r=   z5Tuple[torch.Tensor, torch.Tensor, float, float, bool]r>   )r?   s   "r@   rA   rê     sd   € ÷ 1Mñ 1Màð1Mð ð1Mð ð	1Mð
 ð1Mð ð1Mð ð1Mð ð1Mð 
?ñ1MrB   c                ó   € RpV P                   p	V	RJ;'       d    Wi8„  ;'       d    V P                  ^ 8„  p
\        V
'       d   ^MV P                  4       EF1  pW`P                  8  d    EMT
;'       d    V^ 8H  pV'       d   V	e   V P	                  WWIV4      pMV P                  WV4      pVe"   \        V4      ^ 8”  d   V P                  V4      pVe   \        V4      ^ 8X  d   V'       d   K›   M™V P                  WWÐP                  ^,          4      w  rïppVV8„  pVV8H  ;'       d    V'       * pV'       g	   V'       d0   V P                  V4      '       d   TpVP                  4       pTpTpRpV'       d   EK'  V'       d   EK2   M	  W4WVV3# )zÅRefit a newly accepted model from its inliers.

Returns:
    The refined model, its inlier mask, score and support, and whether the model is still the
    minimal solver's (no refit replaced it).

TNF)ræ   râ   r©   r  rÌ  r¿  r–  rµ  r§  r;   r_  r�   )r  r7   r9   r¾  rh  rÏ  r]  r  Úfrom_minimal_solverræ   Ú
bounded_loÚlo_iterationÚ
use_subsetÚmodel_loÚmodel_lo_bestÚ
inliers_loÚscore_loÚnum_inliers_loÚimprovedÚ
tied_refits   &&&&&&&&            r@   Ú_local_optimizationÚRANSAC._local_optimization  s~  € ð" #ÐØ×,Ñ,ˆØ#¨4Ð/×jÐj°KÑ4P×jÐjÐUY×UfÑUfÐijÑUjˆ
Ü!§z¡!°t×7HÑ7H×IˆLØ×6Ñ6Ô6ÚØ#×9Ð9¨¸Ñ(9ˆJß˜nÒ8Ø×.Ñ.¨s¸ÐR[Ó\‘à×,Ñ,¨S°wÓ?�ØÒ#¬¨H«¸Ô(9Ø×1Ñ1°(Ó;�ØÒ¤3 x£=°AÔ#5÷ ÙÙØBFÇ+Á+ÈcÐX`×bmÑbmÐopÕbpÓBqÑ?ˆM x°Ø +Ñ-ˆHð " [Ñ0×CÐC¸´^ˆJßŸJ¨D×,>Ñ,>¸~×,NÒ,NØ%�Ø$×*Ñ*Ó,�Ø&�Ø,�Ø&+Ð#ß’8§J¢JÙñ9 Jð: ˜{Ð9LÐLÐLrB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   r7   r8   r9   rÅ   úOptional[torch.Tensor]r=   rÚ   r>   )r?   s   "r@   rA   rê   B  s*   € ÷ ñ  <ð °lð ÐMcð Ðosñ rB   c                ó²  € V P                   R8w  dš   \        VRR.4       \        VRR.4       VP                  ^ ,          VP                  ^ ,          8X  d#   VP                  ^ ,          V P                  8  d3   \	        RV P                   RVP                   RVP                   24      hV P                   R8X  dœ   \        V. R	O4       \        V. R	O4       VP                  ^ ,          VP                  ^ ,          8X  d#   VP                  ^ ,          V P                  8  d3   \	        RV P                   RVP                   RVP                   24      hR# R# )
ai  Validate input tensors for shape and size requirements.

Args:
    kp1: source keypoints.
    kp2: target keypoints.
    weights: optional correspondence weights (not used currently).

Raises:
    ValueError: if ``kp1`` and ``kp2`` differ in length or hold fewer correspondences than the minimal
        sample.
    ShapeError: if the keypoint shape is wrong.

rø   ÚNÚ2z,kp1 and kp2 should be equal shape at least [z
, 2], got rñ   z, 2, 2], got N)rá  râ  râ  )r¸   r   r™   r  r¾   ©r  r7   r9   rÅ   s   &&&&r@   Úvalidate_inputsÚRANSAC.validate_inputsB  s'  € ð �?‰?Ð<Ô<Ü˜s S¨# JÔ/Ü˜s S¨# JÔ/Ø—I‘I˜a•L C§I¡I¨a¥LÔ0°c·i±iÀµlÀT×E]ÑE]Ô6]Ü ØBÀ4×C[ÑC[ÐB\ð ]ØŸI™I˜; b¨¯©¨ð5óð ð �?‰?Ð<Ô<Ü˜s¢OÔ4Ü˜s¢OÔ4Ø—I‘I˜a•L C§I¡I¨a¥LÔ0°c·i±iÀµlÀT×E]ÑE]Ô6]Ü ØBÀ4×C[ÑC[ÐB\ð ]ØŸI™I˜; b¨¯©¨ð5óð ñ 7^ñ =rB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   r7   r8   r9   rÅ   rß  r=   r«  r>   )r?   s   "r@   rA   rê   a  s,   € ÷ %,ñ %,Øð%,Ø&2ð%,Ø=Sð%,à	*ñ%,rB   c                ó¾  € V P                  WV4       \        VP                  P                  4      ;_uu_ 4        V P                  R8X  dÌ   \
        P                  ! 4       ;_uu_ 4        V P                  '       dw   \
        P                  ! R4      ;_uu_ 4        \
        P                  ! 4       ;_uu_ 4        V P                  W4      uuRRR4       uuRRR4       uuRRR4       uuRRR4       # V P                  W4      uuRRR4       uuRRR4       # V P                  \        9  d   V P                  W4      uuRRR4       # W\        W4      3V n         V P                  W4      RV n        uuRRR4       #   + '       g   i     M; iRRR4       K§    + '       g   i     L·; i  + '       g   i     L¥; i  RT n        i ; i  + '       g   i     R# ; i)aç  Call main forward method to execute the RANSAC algorithm.

Args:
    kp1: source image keypoints ``(N, 2)`` (or line segments ``(N, 2, 2)``).
    kp2: target image keypoints with the same shape. For PROSAC, both inputs must be sorted
        best-first using the same correspondence-quality ordering. Essential estimation uses
        camera-normalized coordinates and a threshold in those units.
    weights: optional correspondences weights. Not used now.

Returns:
    - Estimated model, shape of ``(3, 3)``, or zeros if no valid model is found. A model needs
      more inliers than its minimal sample, since a model fitted to a sample fits that sample.
    - Boolean inlier mask, shape of ``(N,)``, in the supplied correspondence order.

r½   FN)rä  r   rO   rP   rº   rQ   Úno_gradr   Úinference_modeÚ_forward_compiledÚ_forward_lmr¸   r™  Ú_forward_dltrŒ   r‘  rã  s   &&&&r@   ÚforwardÚRANSAC.forwarda  sB  € ð$ 	×Ñ˜S wÔ/ô   §
¡
§¡×0Õ0Ø×&Ñ&¨$Ô.Ü—]’]—_•_Ø—}—}�}Ü"×1Ò1°%×8Õ8¼%¿-º-¿/½/Ø#'×#9Ñ#9¸#Ó#C÷ ;J¹/×8Ñ8÷ %‘_÷ 1Ò0ð  ×+Ñ+¨CÓ5÷	 %‘_÷ 1Ò0ð �‰Ô&9Ô9Ø×(Ñ(¨Ó2÷ 1Ò0ð %(Ô.>¸sÓ.HÐ#IˆDÔ ð,Ø×(Ñ(¨Ó2à'+�Ô$÷! 1Ò0÷ ;J¿/ú×8×8×8Ñ8ú÷ %—_ûð (,�Õ$ú÷! 1×0Ð0ús‰   º/GÁ)1F,	ÂFÂ8E<Ã	
FÃ
F,	Ã
GÃ2F,	Ä
GÄ%GÅGÅF?Å*GÅ<FÆFÆ
F,	ÆF)Æ$F,	Æ,F<Æ7GÆ?	GÇGÇG	c               ó$   € V ^8„  d   QhRRRRRR/# rª  r>   )r?   s   "r@   rA   rê   ˆ  s'   € ÷ C4ñ C4 ð C4°<ð C4ÐDeñ C4rB   c           
     ó€  € \        R4      ) p\        V4      pV P                  pV P                  WAP                  4      pTp\
        P                  ! ^^VP                  VP                  R7      p\
        P                  ! WAP                  \
        P                  R7      p	Rp
\        V) V,          ) 4       EFÞ  pW¶,          V8¼  d    EMÏ\        WeW¶,          ,
          4      pV P                  V P                  WFW±P                  4      RV pW,          pW-,          pV P                  Wï4      w  rï\        V4      ^ 8X  d   K‹  V P                  Wï4      pV P                  R9   d   VP!                  R^^4      pV P#                  V4      pVe   \        V4      ^ 8X  d   Kç  V P%                  WVV P&                  ^,          4      w  ppppVV8”  g   EK  V P)                  V4      '       g   EK4  V P+                  WVVVVV4      w  pppppVP-                  4       pVP-                  4       p	TpTp
V P.                  '       d   V P1                  V\3        V4      4      pEK¤  \        VV P5                  \3        V4      W@P                  V P6                  4      4      pEKá  	  V P                  R8X  d•   V
'       d�   \9        VR,          4      ^ ,          pV P%                  WVR,          V P&                  ^,          4      w  pp	ppV P)                  V4      '       g-   \
        P:                  ! V4      p\
        P:                  ! V	4      p	W‰3# )	z2:meth:`forward` with ``local_optimization="dlt"``.rj  r�  r  FNrù   )rù   rô   rõ   rI   )r<   r–  r@  rQ  rO   rQ   r'  rS   r»   r©   rw   r;  r  r®  r�  r¸   rW   rµ  r§  r;   r_  rÜ  r�   rÙ   r‚  r¥   rl  rá   r   rË   )r  r7   r9   Úbest_score_totalrC  r§   rß   rç   Úbest_model_totalÚinliers_best_totalÚbest_needs_projectionr°   ÚcurrentÚidxsÚkp1_sampledÚkp2_sampledr:   r¾  rh  rÏ  r]  rÑ  rˆ   rx  s   &&&                     r@   rì  ÚRANSAC._forward_dltˆ  sÛ  € ä! %›L˜=ÐÜ˜#“hˆØ×#Ñ#ˆØ×,Ñ,¨V·Z±ZÓ@ˆ
ØˆÜ Ÿ;š; q¨!°3·9±9ÀSÇZÁZÔPÐÜ+0¯;ª;°vÇjÁjÔX]×XbÑXbÔ+cÐà %ÐÜ˜&˜ JÕ.Ð/×0ˆAØ�~ Ô,Úô ˜*¨q­~Õ&=Ó>ˆGØ—;‘;˜t×7Ñ7¸ÈQ×PZÑPZÓ[Ð\dÐ]dÐeˆDØ�)ˆKØ�)ˆKØ'+×'>Ñ'>¸{Ó'XÑ$ˆKÜ�;Ó 1Ô$Ùà×7Ñ7¸ÓQˆFØ�‰Ð"QÔQØŸ™¨¨A¨qÓ1�Ø×+Ñ+¨FÓ3ˆFØ’¤C¨£K°1Ô$4Ùà7;·{±{À3ÈVÐUY×U`ÑU`ÐbcÕUcÓ7dÑ4ˆE�7˜K¨àÐ.×.°D×4FÑ4FÀ{×4SÕ4SØPT×PhÑPhØ˜e W¨k¸;ÈóQÑM��w ¨[Ð:Mð $)§;¡;£=Ð Ø%,§]¡]£_Ð"Ø#.Ð Ø(;Ð%ð ×'×'Ð'Ø"&×":Ñ":¸7ÄCÈÓDTÓ"U“Kä"%ØØ×0Ñ0´°[Ó1AÀ6×KcÑKcÐei×etÑetÓuó#“KñS 1ðb �?‰?˜kÔ)×.CÜ3Ð4DÀTÕ4JÓKÈAÕNÐØ04·±¸CÐFVÐW[ÕF\Ð^b×^iÑ^iÐklÕ^lÓ0mÑ-ˆAÐ! 1 gà×%Ñ% g×.Ò.Ü#(×#3Ò#3Ð4DÓ#EÐ Ü%*×%5Ò%5Ð6HÓ%IÐ"ØÐ3Ð3rB   c               ó$   € V ^8„  d   QhRRRRRR/# rª  r>   )r?   s   "r@   rA   rê   Í  s"   € ÷ 7 ñ 7  \ð 7 ¸ð 7 ÐIjñ 7 rB   c                óz  € ^ RI HpHp VP                  P                  R9  d#   \        RVP                  P                   24      hR W3 4       w  r\        V4      pV P                  WQP                  4      w  rgWs8”  d   \        RV R24      hVP                  P                  R8X  df   V P                  R8X  d   ^
MV P                  ^8X  d   ^M^p\        ^\        V\        V^4      ,          ,          4      p	\        Wi4      \        Wy4      rv\        P                  ! R4      p
V P                  V P                  3 Uu. uF+  p\        P                   ! V.\        P"                  V
R7      NK-  	  ppTV P$                  Wg3 Uu. uF*  p\        P                   ! V\        P&                  V
R7      NK,  	  up,          pV P(                  fr   \        P*                  ! ^ \        P,                  ! \        P&                  4      P                  R\        P&                  VP                  R7      pVP/                  V
4      pMÀ\1        V P(                  \2        4      '       g!   \1        V P(                  \4        4      '       g   \7        R	4      hV P(                  R8  g   V P(                  R8”  d   \        R
4      hV P(                  R,           R,          R,
          p\        P                   ! V\        P&                  V
R7      pVP9                  V4       W.VO5pV P                  V P:                  V P<                  V P>                  VP@                  \C        VP                  4      \        PD                  ! 4       \        PF                  ! 4       \C        \        PH                  ! 4       4      3	pV! VV4      pV! V!  # u upi u upi )zV:meth:`_forward_lm` as the compiled program of :mod:`kornia.geometry._ransac_program`.)Ú	MAX_BATCHÚload_programr  z'compile=True runs on CPU and CUDA, not c              3  óÊ   "  € T FY  pVP                  4       '       d!   VP                  \        P                  R 7      MVP	                  4       P                  4       x € K[  	  R# 5i))Úmemory_formatN)Úis_inferencer�   rQ   Úcontiguous_formatÚdetachÚ
contiguous)Ú.0Úkps   & r@   Ú	<genexpr>Ú+RANSAC._forward_compiled.<locals>.<genexpr>Õ  sN   é € ð 
á �ð @B¿¹×?PÒ?PˆB�H‰H¤5×#:Ñ#:ˆHÔ;ÐVX×V_ÑV_ÓVa×VlÑVlÓVnÔnÛ ùs   ‚A#�AA#z)compile=True supports batches of at most z samplesrù   r�  zseed must be an integerz'seed must be within [-2**63, 2**64 - 1])r  rK  r>   l            lûÿÿÿ         l            l   ÿÿÿÿ )%Úkornia.geometry._ransac_programrü  rý  rO   rP   r¾   r–  rZ  r¸   r  r«   Ú_COMPILED_CPU_SCORE_RESIDUALSrw   rQ   r;   rá   rd  r,  r@  Úint64rä   ÚrandintÚiinforU   rt   r»   r¥   Ú	TypeErrorrª   rã   râ   rè   rS   r¹   Úget_num_threadsÚget_default_dtypeÚget_default_device)r  r7   r9   rü  rý  rC  rX  rY  ÚslotsÚcapÚhostÚvalueÚscalarsÚrandom_seedÚsigned_seedÚinputsre  Úprograms   &&&               r@   rê  ÚRANSAC._forward_compiledÍ  sÝ  € çKà�:‰:�?‰? /Ô1ÜÐFÀsÇzÁzÇÁÐFWÐXÓYÐYñ
à‘jó
‰ˆô �S“ˆØ×-Ñ-¨f·j±jÓA‰ˆØÔÜÐHÈÈÐS[Ð\Ó]Ð]Ø�:‰:�?‰?˜eÔ#ð Ÿ/™/¨[Ô8‘BÀ4×C[ÑC[Ð_`ÔC`¹aÐfgˆEÜ�aÔ6¸5Ä3ÀvÈqÃ>Õ;QÕRÓSˆCÜ  ›_¬c°'Ó.?�7Ü�|Š|˜EÓ"ˆØY]×YdÑYdÐfj×fuÑfuÑXvÓwÑXvÈu”5—<’<  ¬u¯}©}ÀT×JÑXvˆÐwØØNR×N`ÑN`ÐbgÑMqó
ÙMqÀEŒE�LŠL˜¤e§k¡k¸$×?ÑMqñ
õ 	
ˆð �9‰9Òô  Ÿ-š-¨¬5¯;ª;´u·{±{Ó+C×+GÑ+GÈÔSX×S^ÑS^Ðgj×gqÑgqÔrˆKØ%Ÿ.™.¨Ó.‰Kô ˜$Ÿ)™)¤T×*Ò*´*¸T¿Y¹YÌ×2LÒ2LÜÐ 9Ó:Ð:Ø�y‰y˜:Ô%¨¯©°]Ô)BÜ Ð!JÓKÐKØ ŸI™I¨Õ1°gÕ>À7ÕKˆKÜŸ,š, {¼%¿+¹+ÈdÔSˆKØ�‰�{Ô#ØÐ%˜WÑ%ˆà�O‰OØ�O‰OØ×ÑØ×ÑØ�I‰IÜ�—
‘
‹OÜ×!Ò!Ó#Ü×#Ò#Ó%Ü”×(Ò(Ó*Ó+ð

ˆñ ˜s FÓ+ˆÙ˜ÑÐùò? xùò
s   Ä?1N3Æ0N8c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   r�   r8   rž   Útrack_originsr»   r=   z+Tuple[torch.Tensor, Optional[torch.Tensor]]r>   )r?   s   "r@   rA   rê     s,   € ÷ /ñ /Øð/Ø$0ð/ØAEð/à	4ñ/rB   c                óà  € VP                   P                  R8H  pV'       d4   \        P                  ! VP                  ^ ,          VP                   R7      MRpV P
                  R8X  d    \        VR,          VR,          4      pV'       dN   W,          W&,          r!Ve	   WV,          p\        V4      ^ 8X  d   VP                  ^ ^^4      V3# \        W4      V3# \        W4      pVP                  VR,          ( \        R4      4      V3# \        W4      pV P
                  R8X  du   \        V4      w  ršVe#   VP                  V	P                  ^,          4      pV'       d&   Wš,          Ve   WZP                  4       ,          3# R3# V	P                  ^ ^4      V3# V P                   ^8X  dh   \#        V4      w  ršV	P                  V
R	,          ( \        R4      4      P                  ^ ^4      pVe#   VP                  V	P                  ^,          4      pM\%        V4      pV'       dL   \        P&                  ! V4      P                  ^4      P)                  ^4      pW{,          Ve
   W[,          3# R3# Wu3# )
aé  Minimal models ``(M, 3, 3)`` of normalized (for essential matrices, calibrated) samples ``(B, m, 3)``.

Samples that :func:`~kornia.geometry.homography.sample_is_valid_for_homography` rejects and absent roots of
the seven-point cubic are dropped on CPU; on other devices, where dropping would need a synchronization, they
are NaN models, which score no inliers. The orientation test is unaffected by the normalization, a
translation and a positive scale.

Returns:
    The models and the sample row ``(M,)`` each was solved from, in draw order: sample by sample, and root by
    root within a sample, as DEGENSAC's record setters need them. The sample rows are None unless
    ``track_origins=True``, avoiding this bookkeeping for plain RANSAC.
r  r  Nró   rÇ   rù   ).rK   rÈ   ).NN)rO   rP   rQ   r)  r™   r¸   r.   r–  Ú	new_zerosr$   rš  r<   r   r   Úrepeat_interleaverÈ  r  r    r   rY   rÉ   )r  r�   rž   r  ÚcompactÚrowsÚorientedr:   ÚdesignÚ
candidatesÚvalidÚkeeps   &&&&        r@   Ú_lm_minimal_modelsÚRANSAC._lm_minimal_models  s  € ð —)‘)—.‘. EÑ)ˆß>KŒu�|Š|˜BŸH™H Q�K°·	±	Õ:ÐQUˆØ�?‰?˜lÔ*Ü5°b¸µkÀ2ÀgÅ;ÓOˆHßØ� r¥|�BØÒ#Ø�>�DÜ�r“7˜a”<ØŸ<™<¨¨1¨aÓ0°$Ð6Ð6Ü-¨bÓ5°tÐ;Ð;Ü+¨BÓ3ˆFØ×%Ñ% x°Õ'>Ð&>ÄÀeÃÓMÈtÐSÐSÜ& rÓ.ˆØ�?‰?˜kÔ)ä 6°vÓ >ÑˆJØÒØ×-Ñ-¨j×.>Ñ.>¸qÕ.AÓB�ßØ!Õ(À4ÒCS¨$¯}©}«Õ*?Ð]Ð]ÐY]Ð]Ð]Ø×%Ñ% a¨Ó+¨TÐ1Ð1Ø×#Ñ# qÔ(Ü 7¸Ó ?ÑˆJØ×+Ñ+¨U°?Õ-CÐ,CÄUÈ5Ã\ÓR×ZÑZÐ[\Ð^_Ó`ˆFØÒØ×-Ñ-¨j×.>Ñ.>¸qÕ.AÓB�øä-¨fÓ5ˆFßÜ—>’> &Ó)×1Ñ1°!Ó4×8Ñ8¸Ó;ˆDØ•<¨tÒ/? ¥ÐIÐIÀTÐIÐIØˆ|ÐrB   c               ó$   € V ^8„  d   QhRRRRRR/# )r6   Úscoresr8   Úpriorr<   r=   z	List[int]r>   )r?   s   "r@   rA   rê   8  s&   € ÷ Pñ P Lð P¸ð PÀ9ñ PrB   c                ó  € \         P                  ! V P                  RV4      \         P                  ! V ^ 4      P                  RR .4      pWP                  V4      8„  P                  4       P                  4       P                  4       # )zûIndices of the models, in draw order, whose score beats ``prior`` and every earlier score of the batch.

The models a sequential loop would find to set a new raw record (Chum's ``maxSs``), found at once with a
running maximum over the CPU ``scores``.
N)rH   rI   )	rQ   rV   Únew_fullÚcummaxÚvaluesrZ   rÇ  rÈ  rÔ   )r*  r+  Úearliers   && r@   Ú_raw_record_settersÚRANSAC._raw_record_setters7  sl   € ô —)’)˜VŸ_™_¨T°5Ó9¼5¿<º<ÈÐPQÓ;R×;YÑ;YÐZ]Ð[]Ð;^Ð_Ó`ˆØ×*Ñ*¨5Ó1Ñ1×:Ñ:Ó<×DÑDÓF×MÑMÓOÐOrB   c               ó(   € V ^8„  d   QhRRRRRRRR/# )r6   r:   r8   r�   rž   r=   r>   )r?   s   "r@   rA   rê   A  s/   € ÷ Wñ W ð W°<ð WÀ\ð WÐVbñ WrB   c                ó†   € V P                   R8X  d   \        V\        W#R,          4      4      # \        V\	        W#4      4      # )zhSquared residuals ``(M, N)`` of normalized models on normalized correspondences (calibrated: essential).ró   rJ   )r¸   r(   r'   r   r   )r  r:   r�   rž   s   &&&&r@   Ú
_lm_errorsÚRANSAC._lm_errorsA  s7   € à�?‰?˜lÔ*Ü'¨´ÀÀuÅIÓ0NÓOÐOÜ,¨VÔ5MÈbÓ5UÓVÐVrB   c               ó$   € V ^8„  d   QhRRRRRR/# )r6   rž  r8   rk   r<   r=   r>   )r?   s   "r@   rA   rê   G  s!   € ÷ =ñ = ð =¸ð =À<ñ =rB   c                óB  € V P                   R8X  dd   \        P                  ! V\        P                  ! VR,          V4      4      pVP	                  V) 4      P                  R4      P                  ^4      # W8*  P                  ^4      P                  VP                  4      # )zfMSAC scores ``sum(1 - min(e / threshold, 1))`` or RANSAC support counts ``(M,)`` of squared residuals.rì   rÆ   )ro   ro   )	rã   rQ   ÚfminrÍ   Údiv_Úadd_rX   rU   rS   )r  rž  rk   Úcontributionss   &&& r@   Ú	_lm_scoreÚRANSAC._lm_scoreG  s{   € à�?‰?˜fÔ$ô "ŸJšJ v¬u¯ª¸vÀf½~ÈyÓ/YÓZˆMØ ×%Ñ% y jÓ1×6Ñ6°sÓ;×?Ñ?ÀÓBÐBØÑ#×(Ñ(¨Ó+×.Ñ.¨v¯|©|Ó<Ð<rB   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR	/# )
r6   r:   r8   Úbasisrk   r<   Úmax_residualsr¥   r=   z9Tuple[torch.Tensor, torch.Tensor, Optional[torch.Tensor]]r>   )r?   s   "r@   rA   rê   P  s;   € ÷ Yñ YØ"ðYØ+7ðYØDIðYØZ]ðYà	BñYrB   c                ó†  € V P                   R8H  pV P                   \        9   pVP                  ^,          V'       d   ^M^,          pVP                  P                  R8X  d   \        ^V\        V^4      ,          4      M\        \        V4      ^4      p. . . rºp	VR8:  d   VP                  M\        P                  pV'       d   \        M\        p\        ^ \        V4      V4       FØ  pV! WWè,            V4      pWó8*  pV'       d$   V\        WWè,            V4      R,          ( ,          pVP                  ^VR7      pV
P                  V4       T	P                  V P                   R8X  d   V P#                  Wó4      MVP%                  VP                  4      4       V P&                  '       g   KÇ  VP                  V4       KÚ  	  \        V	4      ^8X  d&   V	^ ,          V
^ ,          V'       d   V^ ,          3# R3# \        P(                  ! V	4      \        P(                  ! V
4      V'       d   \        P(                  ! V4      3# R3# )al  Score minimal models without retaining the whole model-by-correspondence residual matrix.

CPU hypothesis tiles bound temporary storage independently of the solver batch. Correspondences are never
split, so each score uses the same reduction as full verification. Accelerators keep one tile to amortize
launch overhead. Support counts accumulate in the working dtype while they are exactly representable,
avoiding the default int64 conversion of every entry of the inlier matrix. Only PROSAC retains the boolean
masks: its stopping rule must use the same inlier decisions as the score, including at rounding boundaries.
ró   r  NrÆ  rì   i   r  )r¸   r™  r™   rO   rP   r«   r–  rS   rQ   r
  r(   r   r©   r}   rX   rª   rã   r=  rU   rÙ   rV   )r  r:   r@  rk   rA  rM  Úrank_testedr²   Útiler*  ÚcountsÚmasksÚcount_dtypeÚresidual_fnr4  rž  rh  rx  s   &&&&&             r@   Ú_lm_score_modelsÚRANSAC._lm_score_modelsP  sÄ  € ð —‘ LÑ0ˆØ—o‘oÔ)<Ñ<ˆØ�K‰K˜�N§F™q°Õ2ˆØ5;·]±]×5GÑ5GÈ5Ô5PŒs�1�m¤s¨1¨a£yÕ0Ô1ÔVYÔZ]Ð^dÓZeÐghÓViˆØ " B¨˜ˆØ&'¨7¤l�f—l’l¼¿¹ˆß.4Õ*Ô:WˆÜ˜1œc &›k¨4Ö0ˆEÙ  °µÐ!=¸uÓEˆFØÑ)ˆGßØ!Ô%?ÀÈuÍ|Ð@\Ð^gÓ%hÐipÕ%qÐ$qÕq�Ø—k‘k !¨;�kÓ7ˆGØ�M‰M˜'Ô"Ø�M‰M¸t¿¹ÐRXÔ?X˜$Ÿ.™.¨Ô;Ð^e×^hÑ^hÐio×iuÑiuÓ^vÔwØ×#×#Ò#Ø—‘˜WÖ%ñ 1ô ˆv‹;˜!ÔØ˜!•9˜f Q�i·U¨¨q­ÐDÐDÀÐDÐDÜ�yŠy˜Ó ¤%§)¢)¨FÓ"3Ï´U·Y²Y¸uÓ5EÐXÐXÐTXÐXÐXrB   c               ó8   € V ^8„  d   QhRRRRRRRRRRR	R
RRRR/# )r6   r:   r8   r�   rž   r­  rß  Úlossr¹   Úscale2r<   Úitersr¥   r=   r>   )r?   s   "r@   rA   rê   p  sd   € ÷ Qñ QàðQð ðQð ð	Qð
 %ðQð ðQð ðQð ðQð 
ñQrB   c           	     ó¨   € V P                   R8X  d   \        WVR,          WEWg4      # V P                   R8X  d   \        WW4WVV4      # \        WW4WVV4      # )zcRefine normalized (calibrated: essential) models with Levenberg-Marquardt, on float64 host tensors.ró   rù   rJ   )r¸   r&   r   r   )r  r:   r�   rž   r­  rL  rM  rN  s   &&&&&&&&r@   Ú
_lm_refineÚRANSAC._lm_refinep  sS   € ð �?‰?˜lÔ*Ü(¨°R¸µYÀÈFÓZÐZØ�?‰?˜kÔ)Ü'¨°B¸dÈEÓRÐRÜ% f°"¸DÈ%ÓPÐPrB   c               óH   € V ^8„  d   QhRRRRRRRRRRRRRRR	R
RRRRRRRR/# )r6   r¾  r8   r;  r�   rž   Úx1_hostÚx2_hostr@  rk   r<   r  zOptional[torch.Generator]Úseen_planesúOptional[List[torch.Tensor]]ró   rß  r=   zQOptional[Tuple[torch.Tensor, torch.Tensor, torch.Tensor, Optional[torch.Tensor]]]r>   )r?   s   "r@   rA   rê   �  s‘   € ÷ V.ñ V.àðV.ð ðV.ð ð	V.ð
 ðV.ð ðV.ð ðV.ð ðV.ð ðV.ð -ðV.ð 2ðV.ð +ðV.ð 
[ñV.rB   c           	     ó8  € V P                   pVf\   VP                  4       p\        VP                  4       P                  4       P	                  4       W],          Wm,          ^V,          4      pVf   R# \
        P                  ! V4      P                  ^4      \
        P                  ! V4      P                  ^4      ,          P                  4       P                  4       pW^R3,          WnR3,          pp\        VR,          VR,          VR,          4      ^ ,          pV
f   . MT
p\        V^V,          8  P                  4       4      ^8  g   \        V^V,          8*  V4      '       d   R# \        W¿V^V,          V	4      w  ppV^V,          8*  V^dV,          8„  pp\        VV4      '       d   R# VP!                  V4       \        VP                  4       4      ^8:  g   \        VP                  4       4      ^8  d   R# VV,          P#                  VP$                  4      p\'        VP#                  VP$                  VP(                  4      VV,          VV,          ^V,          VP$                  P*                  R8X  d   RMRV	4      pVf   R# V^ ,          pV P-                  VWx4      w  pppVP/                  VV8*  R4      p\1        VP3                  4       4      ^ 8  d   R# \        VP5                  4       4      pVVV^,            VVV^,            VVV^,            3pVf   RMVVV^,            pV P6                  ^ 8X  d   . VOVN5# V P9                  V^ ,          P                  4       P	                  4       W^,          Wn,          RRW€P6                  4      P#                  VP$                  VP(                  4      pV P-                  VWx4      w  pppVP/                  VV8*  R4      p\1        V^ ,          4      \1        V^,          ^ ,          4      8  d   . VOVN5# VVVV3# )aÜ  DEGENSAC's recovery of a raw record setter (Chum, Werner and Matas, CVPR 2005; Chum's ``exp_ranF.c``).

``model`` ``(3, 3)`` is a seven-point model of ``sample`` ``(7,)``, both on the device of the normalized
correspondences ``x1``, ``x2`` ``(N, 3)``; ``x1_host``, ``x2_host`` are the same correspondences on the host in
float64, NaN where not finite; ``threshold`` is the squared threshold ``t`` of that frame. When the sample is
H-degenerate and its homography has at least 8 inliers at ``3 t``, the homography is refined (``innerH``), and
with more than 6 plane inliers at ``16 t`` and at least 4 correspondences beyond ``100 t``, plane-and-parallax
models are drawn from those (:mod:`kornia.geometry._degensac`), unless ``seen_planes``, the refined planes'
inlier masks of the call's earlier recoveries, already holds the plane (:func:`_repeats_plane`); a new plane
is appended to it. The best-scoring model is refined like the pool, with ``max_lo_iters`` truncated
Levenberg-Marquardt iterations, Chum's ``innerFH`` role, and the better of it and its refinement is returned
alone, as ``rFtH`` returns one model: near-duplicates from one search would crowd the eight-model pool.

``homography``, when supplied, is the result of the batch's degeneracy check in float64 on the host.

Returns:
    The recovered model ``(1, 3, 3)`` with its score, support and, with PROSAC, inlier mask, as
    :meth:`_lm_score_models` returns them; None when the sample is not H-degenerate or nothing is recovered.
NrK   r  rG  r3   Ú	truncatedr  )r  r  r   r  ÚdoublerQ   rY   rÉ   rÇ  rÈ  r/   r¥   rX   r   r   r   rª   rU   rO   r   rS   rP   rI  rš  r<   r«   r›  râ   rP  )r  r¾  r;  r�   rž   rS  rT  r@  rk   r  rU  ró   rt  Úsample_hostr!  Úp1Úp2rž  ÚplanesÚplaneÚ	off_planeÚoff_rowsÚfoundr:   r*  rE  rF  ÚbestÚrawÚraw_maskÚrefineds   &&&&&&&&&&&&                   r@   Ú_degensac_recoverÚRANSAC._degensac_recover�  sŽ  € ðB ×$Ñ$ˆØÒØ Ÿ*™*›,ˆKÜ-Ø—‘“×"Ñ"Ó$×+Ñ+Ó-¨wÕ/CÀWÕEYÐ[\Ð_hÕ[hóˆJð ÒÙÜ—’˜wÓ'×+Ñ+¨AÓ.´·²ÀÓ1H×1LÑ1LÈQÓ1OÕO×XÑXÓZ×bÑbÓdˆØ˜r˜Õ" G°"¨HÕ$5ˆBˆÜ,¨R°­X°r¸$µxÀÈDÕAQÓRÐSTÕUˆØ"Ò*‘°ˆô �˜˜Y�Ñ&×+Ñ+Ó-Ó.°Ô2´mÀFÈbÐS\ÍnÑD\Ð^d×6eÒ6eÙÜ.¨z¸rÀ2È	Å>ÐS\Ó]Ñˆ
�FØ! R¨)¥^Ñ3°V¸cÀI½oÑ5MˆyˆÜ˜% ×(Ò(ÙØ�‰�eÔÜˆu�y‰y‹{Ó˜qÔ ¤C¨	¯©«Ó$8¸1Ô$<ÙØ˜	•?×%Ñ% b§i¡iÓ0ˆÜ&Ø�M‰M˜"Ÿ)™) R§X¡XÓ.Øˆx�LØˆx�LØ�	�MØ—9‘9—>‘> UÔ*‰C°Øó
ˆð Š=ÙØ�q•ˆØ $× 5Ñ 5°f¸eÓ OÑˆ�˜Ø×#Ñ# F¨a¡K°Ó6ˆÜ�—‘“Ó Ô"ÙÜ�6—=‘=“?Ó#ˆØ�T˜D 1�HÐ% v¨d°T¸AµXÐ'>ÀÀtÈdÐUVÍhÐ@WÐWˆØ š=‘4¨e°D¸4À!½8Ð.DˆØ×Ñ Ô!Ø#�SÐ#˜(Ñ#Ð#Ø—/‘/Ø��F�J‰J‹L×ÑÓ! 7¥=°'µ-ÀÀ{ÐT]×_pÑ_pó
ç
‰"ˆR�Y‰Y˜Ÿ™Ó
!ð 	ð !%× 5Ñ 5°g¸uÓ PÑˆ�˜Ø×#Ñ# F¨a¡K°Ó6ˆô �˜•Óœe C¨¥F¨1¥IÓ.Ô.Ø#�SÐ#˜(Ñ#Ð#Ø˜ ¨Ð-Ð-rB   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )r6   r$  r8   Úcandidate_scoresr:   r*  r=   r«  r>   )r?   s   "r@   rA   rê   Ú  s;   € ÷ Hñ HØ ðHØ4@ðHØJVðHØ`lðHà	*ñHrB   c           	     óà   € \         P                  ! W1.4      P                  \        \        \        V4      \        V4      ,           4      4      w  r\         P                  ! W .4      V,          V3# )zdThe pool's ``_LM_CANDIDATES`` best models and scores after adding ``models``, placed first for ties.)rQ   rV   r#  rw   Ú_LM_CANDIDATESr–  )r$  ri  r:   r*  Úorders   &&&& r@   Ú_lm_poolÚRANSAC._lm_poolÙ  s\   € ô
 #(§)¢)¨VÐ,FÓ"G×"LÑ"LÜ”¤ F£¬cÐ2BÓ.CÕ CÓDó#
ÑÐô �yŠy˜&Ð-Ó.¨uÕ5Ð7GÐGÐGrB   c          
     ó,   € V ^8„  d   QhRRRRRRRRRR/# )	r6   rF  rß  ÚrowzUnion[int, torch.Tensor]rx  r¥   rC  r=   r>   )r?   s   "r@   rA   rê   ã  s4   € ÷ 
ñ 
Ø+ð
Ø2Jð
ØUXð
Øbeð
à	ñ
rB   c           	     ó°   € Ve   V P                  W,          V4      # \        V P                  V P                  W4V P                  V P
                  4      4      # )z®Samples to draw for an incumbent with ``support`` inliers, as in OpenCV's USAC.

PROSAC's termination test on ``masks[row]`` when PROSAC keeps masks, else the classic bound.
)r‚  rw   r@  rl  r  rá   )r  rF  rp  rx  rC  s   &&&&&r@   Ú_lm_stopping_boundÚRANSAC._lm_stopping_boundã  sS   € ð ÒØ×+Ñ+¨E­J¸Ó@Ð@ÜØ×Ñ × 8Ñ 8¸È$×JbÑJbÐdh×dsÑdsÓ tó
ð 	
rB   c               óL   € V ^8„  d   QhRRRRRRRRRRRRR	RR
RRRRRRRRRRR/# )r6   r:   r8   Úsamplesr*  r+  r<   r�   rž   rS  rT  r@  rk   r  r¥   rU  rV  r=   zMList[Tuple[torch.Tensor, torch.Tensor, torch.Tensor, Optional[torch.Tensor]]]r>   )r?   s   "r@   rA   rê   ð  s�   € ÷ :ñ :àð:ð ð:ð ð	:ð
 ð:ð ð:ð ð:ð ð:ð ð:ð ð:ð ð:ð ð:ð 2ð:ð 
Wñ:rB   c                ó>  € V P                  VP                  4       V4      pV'       g   . # \        P                  ! 4       pV P                  e<   VP                  V P                  ^V P                  ,          ,           V,           4       MEVP                  \        \        W-^ ,          ,          P                  4       4      4      R,          4       Vf   . MTp. pW-,          P                  4       p\        W,          P                  4       P                  4       P                  4       VV,          VV,          ^V
,          4      p\        VV4       FL  w  ppVf   K  V P                  VV,          VV,          VVVVV	V
VVV4      pVf   K;  VP                  V4       KN  	  V# )aÅ  DEGENSAC's recoveries of a batch's raw record setters, in draw order (:meth:`_raw_record_setters`).

``models`` ``(M, 3, 3)`` were solved from ``samples`` ``(M, 7)`` and scored ``scores``; ``prior`` is the raw
record before the batch. Every recovery draw comes from one private host generator per batch: a device
generator cannot draw on the host, and the global one, which an unseeded call's minimal samples come from,
must not advance, or every later sample of the call would differ from ``degensac=False``. A seeded call seeds
it ``seed + 2 * sample_budget + iteration``; an unseeded one from the first record setter's sample, drawn from
the global generator, so that its draws still differ between calls.
l   ÿÿÿÿ )r1  r  rQ   r   rä   r!  r@  Úhashr®   rÔ   r   r  rY  Úziprf  rª   )r  r:   ru  r*  r+  r�   rž   rS  rT  r@  rk   r  rU  Úrecordsr  r]  Ú
recoveriesÚsamples_hostÚhomographiesÚrecordró   Ú	recovereds   &&&&&&&&&&&&&         r@   Ú_degensac_batchÚRANSAC._degensac_batchð  sm  € ð2 ×*Ñ*¨6¯:©:«<¸Ó?ˆßØˆIÜ—O’OÓ%ˆ	Ø�9‰9Ò Ø×!Ñ! $§)¡)¨a°$×2DÑ2DÕ.DÕ"DÀyÕ"PÕQð ×!Ñ!¤$¤u¨W¸QµZÕ-@×-GÑ-GÓ-IÓ'JÓ"KÐN`Õ"`ÔaØ"Ò*‘°ˆØˆ
ØÕ'×+Ñ+Ó-ˆÜ,Ø�O×"Ñ"Ó$×(Ñ(Ó*×1Ñ1Ó3°W¸\Õ5JÈGÐT`ÕLaÐcdÐgpÕcpó
ˆô #& g¨|Ö"<ÑˆF�JØÒ!ÙØ×.Ñ.Ø�v•Ø˜•ØØØØØØØØØóˆIð Ô$Ø×!Ñ! )Ö,ñ# #=ð$ ÐrB   c               ó$   € V ^8„  d   QhRRRRRR/# rª  r>   )r?   s   "r@   rA   rê   ,  s'   € ÷ S1ñ S1˜|ð S1°,ð S1ÐCdñ S1rB   c                ó  aA€ VP                   VP                  rCV\        P                  8X  d   \        P                  M\        P                  p\        V4      V P                  rvV P                  R8H  pV P                  R8H  p	\        P                  ! ^^WCR7      \        P                  ! V\        P                  VR7      3p
\        P                   ! R4      pVP                  4       P                  V4      P                  4       VP                  4       P                  V4      P                  4       rÜ\        P                  ! V4      P                  ^4      \        P                  ! V4      P                  ^4      ,          oA\        SAP                  4       4      '       g   V
# V	'       dL   VA3R lWÍ3 4       w  rï\        P                   ! ^\        P                  R7      ;ppV P"                  ^,          pM;\%        WÍV'       * 4      w  rïppppV P"                  V'       d   TMT,          ^,          pVP                  W54      VP                  W54      ppV'       d   \'        VVR,          4      M\)        VV4      pV P*                  pV P-                  Wc4      w  pp\/        V P0                  \2        4      '       * pVP5                  ^ ^^4      VP5                  ^ 4      ppRpV P6                  ;'       d    V^8H  pRp . p!T^ ^ p$p#p"V#V"8  EdŒ   \9        VV"V#,
          4      p%V P;                  WvV%V$VV#R7      p&T$p'V#V%,           V$^,           p$p#V'       d   \9        ^V,          V4      pV P=                  VV&,          VV&,          VR7      w  p(p)\        V(4      ^ 8X  d   K—  V P?                  V(VV4      w  p*p+p,V*PA                  V+V8*  R4      p*V*PC                  \9        \D        \        V(4      4      4      w  p-p.V+V.,          p/V PG                  VVV(V.,          V-4      w  pp\        PH                  ! V-V/P                  V-P                  4      .4      PK                  4       w  p0p1\M        \O        \        V04      4      V0PP                  R	7      p2V0V2,          V8”  d5   V0V2,          pV PS                  V,V.V2,          \3        V1V2,          4      V4      p"V)e   V0V2,          V 8:  d   EK×  V PU                  V(V&V),          V*V VVVVVVV'V!4      p3V0V2,          p V3 F‡  w  p4p5p6p7V PG                  VVV4V54      w  pp\3        V5PW                  4       4      p8\Y        V5V8,          4      V8”  g   KQ  \Y        V5V8,          4      pV PS                  V7V8\3        V6V8,          4      V4      p"K‰  	  EK“  VSA,          VSA,          rþVP                  V4      P                  4       VP                  V4      ^ 8¬  ,          p\        V4      ^ 8X  d   V
# V PZ                  ^ 8”  d9   V P]                  VWïR
RVV PZ                  4      p9\        P^                  ! V9V.4      pV Pa                  VWï4      p:V:V8*  p;V P                  \b        9   p<V<'       d   V;\e        VV4      R,          ( ,          p;V Pg                  V:V4      PA                  V;Pi                  ^4      V8*  R4      p0\3        V0PW                  4       4      p2V0V2,          ^ 8  d   V
# VV2,          V;V2,          p;p=V Pj                  ^ 8”  d°   V;R
,          p>V P]                  V=R
,          WïV>RV^	,          V Pj                  4      p?V Pa                  V?Wï4      ^ ,          V8*  p@V<'       d   X@\e        V?V4      ^ ,          ( ,          p@V Pm                  \3        X@Pi                  4       4      4      '       d   V?^ ,          X@p;p=V	'       d{   \o        V=4      p=V=V=Pq                  4       ,          P                  V4      p=V=V=Ps                  4       V=Pu                  4       PW                  4       ,          Pw                  4       ,          p=MiV'       d.   \        Px                  P{                  V4      V=,          V,          MVP|                  V=,          V,          p=\        V=4      P                  V4      p=\        \        P                  ! V=4      P                  4       4      '       g   V
# V P�                  VR
,          VR
,          V=R
,          P                  \        P                  4      4      ^ ,          p:SAV:V P"                  ^,          8*  ,          p>V Pm                  \3        V>Pi                  4       4      4      '       g   V
# V=P                  V4      V>P                  V4      3# )a¤  RANSAC with batched minimal solvers and Levenberg-Marquardt local optimization and refinement.

Sampling, minimal solving and scoring run on the device of the correspondences; the normalization, the
refinements and the final selection run on the host in float64, which needs a handful of synchronizations
per call instead of one per small operation. What differs from the public solvers is what a sampling loop
needs: correspondences are normalized once per call rather than per sample, models stay in that normalized
frame at unit Frobenius norm instead of ``F[2, 2] = 1``, absent candidates are NaN on accelerators rather than
dropped, and scoring uses the quadratic Sampson and folded transfer bases, which are fast and accurate in that
frame only. Essential matrices skip the normalization: calibrated coordinates are already of unit scale, and
a translation or scaling of them would take the models off the essential manifold.
ró   rù   r�  r  c           	   3  ó|   <"  € T F1  p\        VP                  SR,          ( \        R4      4      4      x € K3  	  R# 5i)rD   NrÇ   r  )r   rš  r<   )r  r  rb   s   & €r@   r  Ú%RANSAC._forward_lm.<locals>.<genexpr>H  s7   øé € ð  á.�Bô .¨b¯n©n¸fÀW½oÐ=MÌuÐUZË|Ó.\×]Ð]Û.ùs   ƒ9<rÆ  )r  )r  )re  NrX  ÚcauchyrJ   r  r  )ArO   rS   rQ   r,  rT   r–  r  r¸   r'  r»   r  rU   rY  rY   rÉ   r.  Úeyer;   r×   r'   r   r@  rZ  rt   rß   r¥   r  r¶   rw   r;  r'  rI  rš  r#  rk  rm  rÊ   rÔ   r«   r©   Ú__getitem__rr  r  r›  r<   râ   rP  rV   r5  r™  r}   r=  rX   rè   r_  r   r|   rÈ  r³  Úsignrx   Úinvr\   r"   r  )Br  r7   r9   rO   rS   r_   rC  rt  rM  rù   Úfailurer  Úkp1_hostÚkp2_hostrS  rT  r‰   rŠ   rk   rÕ   rÖ   r�   rž   r@  r§   rP  rY  Úgrowr$  ri  Ú
best_scorer¶   Úbest_minimal_scorerU  rç   Údrawnr  rõ  r$  Úbatch_iterationr:   ÚoriginÚ
scores_allÚ
counts_allÚ	masks_allÚ
top_scoresÚtopÚ
top_countsr*  rE  rb  rz  Úrecovered_modelsÚrecovered_scoresÚrecovered_countsÚrecovered_masksÚwinnerÚrefitsrž  rh  rC  r¾  r­  re  Úrefined_inliersrb   sB   &&&                                                              @r@   rë  ÚRANSAC._forward_lm,  sæ  ø€ ð Ÿ
™
 C§I¡I�Ø %¬¯©Ô 6Œu�}Š}¼E¿M¹MˆÜ˜“H˜d×6Ñ6�Ø—‘ LÑ0ˆØ—O‘O {Ñ2ˆ	Ü—;’;˜q !¨5Ô@Ä%Ç+Â+ÈfÔ\a×\fÑ\fÐouÔBvÐwˆÜ�|Š|˜EÓ"ˆð !ŸZ™Z›\Ÿ_™_¨TÓ2×9Ñ9Ó;¸S¿Z¹Z»\¿_¹_ÈTÓ=R×=YÑ=YÓ=[�(Ü—’ Ó)×-Ñ-¨aÓ0´5·>²>À(Ó3K×3OÑ3OÐPQÓ3RÕRˆÜ�F—J‘J“L×!Ò!ØˆNßô à#Ñ.ó ÑˆGô —i’i ¬¯©Ô7Ð7ˆB�ØŸ™ Q�‰Iä/IÈ(ÐbhÔ^hÓ/iÑ,ˆG˜b " b¨"ØŸ™¯f©¸"Õ=À!ÕCˆIØ—‘˜FÓ)¨7¯:©:°fÓ+CˆBˆß28”  B u¥IÔ.Ô>VÐWYÐ[]Ó>^ˆØ×#Ñ#ˆØ×-Ñ-¨fÓ=‰ˆˆwÜ˜dŸo™o¬sÓ3Ô3ˆØ')§|¡|°A°q¸!Ó'<¸b¿l¹lÈ1»oÐ$ˆ
Øˆ
ð —=‘=×+Ð+ Q¨!¡VˆØ!ÐØ*,ˆØ(.°°1˜I�UˆØ�kÕ!Ü˜% ¨uÕ!4Ó5ˆGØ—k‘k !¨W°iÀÐPU�kÓVˆGØ'ˆOØ$ w�°	¸Aµ�9ˆEßÜ˜A �I wÓ/�Ø!×4Ñ4°R¸µ[À"ÀWÅ+Ð]eÐ4Óf‰NˆF�FÜ�6‹{˜aÔÙð 15×0EÑ0EÀfÈeÐU^Ó0_Ñ-ˆJ˜
 IØ#×/Ñ/°
¸a±ÀÓFˆJØ(Ÿo™o¬c´.Ä#ÀfÃ+Ó.NÓO‰OˆJ˜Ø# C�ˆJà+/¯=©=¸ÐEUÐW]Ð^aÕWbÐdnÓ+oÑ(ˆJÐ(Ü"Ÿ[š[¨*°j·m±mÀJ×DTÑDTÓ6UÐ)VÓW×^Ñ^Ó`‰NˆF�FÜ”uœS ›[Ó)¨v×/AÑ/AÔBˆDØ�d�|˜jÔ(à# D�\�
Ø"×5Ñ5°iÀÀTÅÌCÐPVÐW[ÕP\ÓL]Ð_eÓf�ØŠ~ ¨¥Ð1CÔ!CÚØ×-Ñ-ØØ˜•ØØ"ØØØØØØØØóˆJð "(¨¥ÐÛYcÑUÐ Ð"2Ð4DÀoØ/3¯}©}ØÐ 0Ð2BÐDTó0Ñ,�
Ð,ô Ð-×4Ñ4Ó6Ó7�ÜÐ)¨&Õ1Ó2°ZÖ?Ü!&Ð'7¸Õ'?Ó!@�JØ"&×"9Ñ"9Ø'¨´Ð5EÀfÕ5MÓ1NÐPVó#’Kô Zdð # 6�?¨G°F­O�Ø—]‘] 4Ó(×/Ñ/Ó1Ð2B×2EÑ2EÀdÓ2KÈqÑ2PÕQˆ
Üˆz‹?˜aÔØˆNØ×Ñ˜qÔ Ø—_‘_ Z°À4ÈÐV_Ðae×arÑarÓsˆFäŸš F¨JÐ#7Ó8ˆJØ—‘ ¨WÓ>ˆØ˜IÑ%ˆà—o‘oÔ)<Ñ<ˆßØÔ!;¸JÈ	Ó!RÐSZÕ![Ð [Õ[ˆGØ—‘ ¨	Ó2×>Ñ>¸w¿{¹{È1»~ÐQRÑ?RÐTXÓYˆÜ�6—=‘=“?Ó#ˆØ�$�<˜!ÔØˆNØ# DÕ)¨7°4­=ˆwˆØ×Ñ˜qÔ à˜4•=ˆDØ—o‘o e¨D¥k°7ÀTÈ8ÐU^ÐabÕUbÐdh×duÑduÓvˆGØ"Ÿo™o¨g°wÓHÈÕKÈyÑXˆOßØ"1Ô5OÐPWÐYbÓ5cÐdeÕ5fÐ4fÕ"f�Ø×!Ñ!¤# o×&9Ñ&9Ó&;Ó"<×=Ò=Ø!(¨¥¨_�w�ßä(¨Ó/ˆEØ˜UŸZ™Z›\Õ)×-Ñ-¨eÓ4ˆEà˜EŸM™M›O¨E¯I©I«K×,>Ñ,>Ó,@ÕA×FÑFÓHÕH‰Eç;A”U—\‘\×%Ñ% bÓ)¨EÕ1°BÖ6ÈÏÉÐPUÍÐXZÕHZˆEÜ,¨UÓ3×6Ñ6°uÓ=ˆEÜ”E—N’N 5Ó)×-Ñ-Ó/×0Ò0ØˆNð —‘˜x¨�~¨x¸­~¸uÀT½{¿~¹~ÌeÏmÉmÓ?\Ó]Ð^_Õ`ˆØ˜ 4§;¡;°¥>Ñ1Õ2ˆØ×!Ñ!¤# d§h¡h£j£/×2Ò2ØˆNØ�x‰x˜Ó §¡¨£Ð0Ð0rB   )r‘  r  rß   r   rá   r¶   r  r;   ræ   rº   rà   râ   rç   r  r  r¸   r  r  rÙ   rè   rã   rä   rü   rý   )ró   r4   rï   é
   g®Gáz®ï?é   rì   FNé    NNrc  FF)NN)N)F)i   ),Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rû   r  r;  Úpropertyr@  rQ  rZ  r_  r(  r‚  Ústaticmethodrl  r�  r‘  Ú__annotations__r§  r®  rµ  r¿  rº  rÌ  rÜ  rä  rí  rì  rê  r'  r1  r5  r=  rI  rP  rf  rm  rr  r  rë  Ú__static_attributes__Ú__classcell__)r  s   @r@   r2   r2   0  s-  ø‡ ñS÷js]ò s]õj0f÷dKEðZ ô
.ó ð
.õ'.õRAõ,6õ$õ(1ðT ôYó ðYõ@vð uy€OÐqÓxõFGõPõ$õ+õ4Kõ,õ*1M÷f÷>%,õNC4õJ7 ÷r/ðb ôPó ðPõWõ=÷Yõ@Q÷"V.ðp ôHó ðHõ
÷:÷xS1ó S1rB   )ró   rô   rõ   rö   rù   r  rU  )rô   rõ   rö   )Yr¨  Ú
__future__r   r¬   rˆ  Ú	functoolsr   r   Útypingr   r   r   r   r	   rQ   r
   Úkornia.core._compatr   Úkornia.core.checkr   Úkornia.core.utilsr   Úkornia.geometry._degensacr   r   r   r   r   r   Úkornia.geometry.conversionsr   Úkornia.geometry.epipolarr   r   r   r   Ú!kornia.geometry.epipolar._metricsr   r   Ú"kornia.geometry.epipolar.essentialr   r   Ú$kornia.geometry.epipolar.fundamentalr   r   r   r    r!   r"   r#   Úkornia.geometry.homographyr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   Úkornia.geometry.solvers.affiner0   r1   Ú__all__r?  rþ   rk  r¿   r	  r]   r™  rr   rs   ri   r}   rƒ   rŒ   r”   r¡   r´   rÁ   r‡   r×   rÜ   ÚModuler2   r>   rB   r@   Ú<module>r¾     s  ðñ$õ& #ã Û 
ß (ß 9Õ 9ã Ý å 0Ý 0Ý 0÷÷ õ Fß vÓ vß eß [÷÷ ñ ÷÷ ÷ ó ÷ Màˆ*€ð €ð ^€
Ø€à5Ð ð !(Ð ð "%Ð ð LÐ Ø"Ð Ø #Ð õyõ>Dõ<õ?õXõiñ& �2Ôô
ó ð
õ	3õYõ$"õ(	CôO1ˆR�Y‰Yö O1rB   