+
    åûj»æ  ã                   óò  € R t ^ RIt^ RIHtHtHtHt ^ RIt^ RIH	t	H
t
 ^ RIHt ^ RIHtHtHtHtHtHtHt ^ RIHtHt ^ RIHtHt ^ RIHt R>R	 R
 lltR?R R lltR R ltR R lt R R lt!R R lt"R R lt#^€t$Rt%R R lt&R R lt'R R lt(R R lt)R  R! lt*R" R# lt+R$ R% lt,R& R' lt-R( R) lt.R* R+ lt/R@R, R- llt0RAR. R/ llt1RBR0 R1 llt2R2 R3 lt3R4 R5 lt4R6 R7 lt5R8 R9 lt6R: R; lt7R< R= lt8R# )CzYFundamental matrices: estimate them, convert from other models, work with epipolar lines.N)ÚLiteralÚOptionalÚTupleÚUnion)ÚKORNIA_CHECK_SAME_SHAPEÚKORNIA_CHECK_SHAPE)Ú
ShapeError)Ú_at_least_float32Ú_autocast_disabledÚ_svd_work_dtypeÚ_symmetric_eigenvectorÚ_torch_svd_castÚ_torch_svd_in_work_dtypeÚsafe_inverse_with_mask)Úconvert_points_from_homogeneousÚconvert_points_to_homogeneous)Ú_det3Ú_null_space_lu)Ú_solve_cubic_realc          
      óÐ   € V ^8„  d   QhR\         P                  R\        R\        \         P                  ,          R\        \         P                  \         P                  3,          /# )é   ÚpointsÚepsÚweightsÚreturn)ÚtorchÚTensorÚfloatr   r   )Úformats   "Ú`C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\epipolar\fundamental.pyÚ__annotate__r    )   sQ   € ÷ X"ñ X"Ü�L‰LðX"Ü$ðX"Ü6>¼u¿|¹|Õ6LðX"ä
Œ5�<‰<œŸ™Ð%Õ&ñX"ó    c                óF  € V P                   ^8w  g   V P                  R,          ^8w  d;   \        R\        V P                  4       R2\        V P                  4      . ROR7      hV P                  w  r4pV P                  V P
                  rvVf   V P                  ^RR7      pEMmVP                  V P                  R,          8w  dX   \        R	\        V P                  R,          4       R
\        VP                  4       R2\        VP                  4      RR.R7      h\        P                  ! V\        P                  4      p	VP                  V	4      p
\        P                  ! V
^ 8  RV
4      p
V
P                  ^RR7      p\        P                  ! V^ 8„  V
\        P                  ! V
4      4      pVP                  ^RR7      pV P                  V	4      VR,          ,          P                  ^RR7      pWÛR,          ,          P                  V4      pW,
          pVP                  R^R7      pVf   VP                  RR7      pMMVP                  X	4      X,          P                  RR7      XP                  R4      ,          P                  V4      p\         P"                  ! R4      VV,           ,          pVVP%                  V^^4      ,          p\        P&                  ! V^^3WgR7      pVVR&   VVR&   V) VR,          ,          VR&   V) VR,          ,          VR&   RVR&   VV3# )aÜ  Normalize 2D point sets to zero mean and a mean distance of sqrt(2) from the origin, Hartley's way.

``points_norm, T = normalize_points(points)`` takes point sets ``(B, N, 2)`` and returns them translated to zero
mean and scaled isotropically so that their mean distance to the origin is :math:`\sqrt{2}`, ``(B, N, 2)``,
together with the similarity ``T`` ``(B, 3, 3)`` that maps the input points to them (Hartley and Zisserman,
4.4.4, p. 107). This is an essential step before the DLT, which is otherwise badly conditioned for pixel
coordinates: :func:`find_fundamental` and :func:`~kornia.geometry.homography.find_homography_dlt` normalize both
point sets with it and undo it on their result, as :math:`T_2^\top F T_1` and :math:`T_2^{-1} H T_1`. With
``weights`` the mean and the mean distance are weighted. For the :math:`[-1, 1]` normalization by the image size,
use :func:`~kornia.geometry.conversions.normalize_pixel_coordinates`.

Args:
   points: Tensor containing the points to be normalized with shape ``(B, N, 2)``.
   eps: epsilon value to avoid numerical instabilities.
   weights: Optional nonnegative weights with shape ``(B, N)`` for the centroid and mean radius.
      Zero-weight points do not influence the transform. An all-zero batch element uses unweighted statistics.

Returns:
   tuple containing the normalized points in the shape ``(B, N, 2)`` and the transformation matrix
   in the shape ``(B, 3, 3)`` that maps the input points to them.

See Also:
    - :func:`normalize_transformation`: the other scaling step of the estimators, a unit bottom-right entry.
    - :func:`~kornia.geometry.conversions.normalize_pixel_coordinates`: a fixed normalization to
      :math:`[-1, 1]` by the image size, not by the point statistics.

z&points must have shape (B, N, 2), got Ú.ÚBÚN©Úactual_shapeÚexpected_shapeT©ÚdimÚkeepdimºNr   Nú!weights must have shape (B, N) = ú, got ç        )r*   Úp©r*   ç       @©ÚdeviceÚdtypeç      ð?éÿÿÿÿ©r$   r%   Ú2©.N).é    r;   ).é   r<   ).r;   r   ).r;   r<   ).r<   r   ).r   r   )ÚndimÚshaper   Úlistr4   r5   Úmeanr   Úpromote_typesÚfloat32ÚtoÚwhereÚsumÚ	ones_likeÚnormÚsqueezeÚmathÚsqrtÚviewÚzeros)r   r   r   r$   Ú_NÚ_r4   r5   Úx_meanÚ	acc_dtypeÚpositive_weightsÚtotal_weightÚeffective_weightsÚweighted_sumÚcenteredÚradiiÚmean_radiusÚscaleÚpoints_normÚ	transforms   &&&                 r   Únormalize_pointsr[   )   sÍ  € ð< ‡{�{�aÔ˜6Ÿ<™<¨Õ+¨qÔ0ÜØ4´T¸&¿,¹,Ó5GÐ4HÈÐJÜ˜fŸl™lÓ+Ú*ô
ð 	
ð �|‰|�H€Aˆ1Ø—M‘M 6§<¡<ˆEà‚Ø—‘ ¨D�Ó1Šà�=‰=˜FŸL™L¨Õ,Ô,ÜØ3´D¸¿¹ÀbÕ9IÓ4JÐ3KÈ6ÔRVÐW^×WdÑWdÓReÐQfÐfgÐhÜ! '§-¡-Ó0Ø # S˜zôð ô ×'Ò'¨¬u¯}©}Ó=ˆ	ð #Ÿ:™: iÓ0ÐÜ Ÿ;š;Ð'7¸!Ñ';¸SÐBRÓSÐØ'×+Ñ+°¸4Ð+Ó@ˆä!ŸKšK¨°qÑ(8Ð:JÌEÏOÊOÐ\lÓLmÓnÐØ(×,Ñ,°¸DÐ,ÓAˆØŸ	™	 )Ó,Ð/@ÀÕ/KÕK×PÑPÐUVÐ`dÐPÓeˆØ¨iÕ!8Õ8×<Ñ<¸UÓCˆØ�€Hð �M‰M˜b AˆMÓ&€EØ‚Ø—j‘j R�jÓ(‰àŸ™ Ó+Ð.?Õ?×DÑDÈÐDÓLÈ|×OcÑOcÐdfÓOgÕg×kÑkÐlqÓrˆô �YŠY�s‹^ ¨cÕ 1Õ2€Eð ˜UŸZ™Z¨¨1¨aÓ0Õ0€Kô —’˜Q  1˜I¨fÔB€IØ €IˆiÑØ €IˆiÑØ!˜6 F¨9Õ$5Õ5€IˆiÑØ!˜6 F¨9Õ$5Õ5€IˆiÑØ€IˆiÑà˜	Ð!Ð!r!   c                ód   € V ^8„  d   QhR\         P                  R\        R\         P                  /# )r   ÚMr   r   )r   r   r   )r   s   "r   r    r    „   s)   € ÷ -ñ -¤§¡ð -´5ð -ÄEÇLÁLñ -r!   c                ó‚  € \        V P                  4      ^8  d;   \        R\        V P                  4       R2\        V P                  4      . ROR7      hV RRR1RR13,          pVP	                  4       V8„  p\
        P                  ! W2\
        P                  ! V4      4      p\
        P                  ! W0V,          V 4      # )a­  Scale matrices so that their bottom-right entry is 1, the gauge of a homography or F.

``M_norm = normalize_transformation(M)`` takes matrices ``(*, m, n)`` and divides each by its last entry
``M[..., -1, -1]``, returning the same shape. This gives :func:`find_fundamental` its ``F[2, 2] = 1`` scaling,
and :func:`~kornia.geometry.homography.find_homography_dlt` its ``H[2, 2] = 1``. For the normalization of point
sets before such a fit, use :func:`normalize_points`.

Convention:
    - A matrix whose last entry is within ``eps`` of zero is returned unchanged, at its own scale.

Args:
    M: The transformation to be normalized of any shape with a minimum size of 2x2.
    eps: magnitude of the last entry at or below which ``M`` is returned unchanged.

Returns:
    the normalized transformation matrix with same shape as the input.

See Also:
    - :func:`normalize_points`: the Hartley normalization of the points the estimators fit.

z!M must have shape (*, m, n), got r#   r&   .N)Ú*ÚmÚnr7   )Úlenr>   r   r?   Úabsr   rD   rF   )r]   r   Únorm_valÚmaskÚdivisors   &&   r   Únormalize_transformationrg   „   s—   € ô, ˆ1�7‰7ƒ|�aÔÜØ/´°Q·W±W³¨¸aÐ@Ü˜aŸg™g›Ú*ô
ð 	
ð
 ˜s B¡C¨©˜}Õ-€HØ�<‰<‹>˜CÑ€DÜ�kŠk˜$¬%¯/ª/¸(Ó*CÓD€GÜ�;Š;�t �[¨!Ó,Ð,r!   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   Úx1Úx2r   ©r   r   )r   s   "r   r    r    ¦   s-   € ÷ =ñ =œeŸl™lð =´·±ð =ÄÇÁñ =r!   c                óB  € V P                   R,          ^8X  dƒ   \        P                  ! V R^R7      w  r#\        P                  ! VR^R7      w  rE\        P                  ! WB,          WC,          WEV,          WS,          WRV\        P                  ! V4      .	RR7      # V P
                  P                  R8X  dF   \        P                  ! VR,          V ,          VR,          V ,          VR,          V ,          .RR7      # VR,          V R	,          ,          P                  R
4      # )aÍ  Rows ``vec(x2 x1^T)`` of the epipolar constraint, so that ``row . vec(F) = x2^T F x1`` with ``F`` row-major.

Each entry is one product ``x2_i x1_j``, so the constructions below give the same bits; the cheapest depends on
the device. On CPU the broadcast outer product costs 2.5x the column-wise form (256 samples x 100 points: 402 vs
157 us); on CUDA it is one kernel instead of a dozen (12 vs 51 us).

Args:
    x1: points of the first image, homogeneous ``(..., N, 3)`` or inhomogeneous ``(..., N, 2)`` with ``w = 1``.
    x2: points of the second image, in the same form as ``x1``.

Returns:
    the design matrix ``(..., N, 9)``: ``[x2 x1, x2 y1, x2, y2 x1, y2 y1, y2, x1, y1, 1]`` for inhomogeneous
    points.
©r*   Úchunksr1   Úcpur7   ).ºr;   r<   N).ºr<   r   N).ºr   é   N).ºNNNN).Nrt   éþÿÿÿ)r>   r   ÚchunkÚcatrF   r4   ÚtypeÚflatten)ri   rj   Úu1Úv1Úu2Úv2s   &&    r   Ú_epipolar_design_rowsr~   ¦   sÕ   € ð 
‡x�x�…|�qÔÜ—’˜R R°Ô2‰ˆÜ—’˜R R°Ô2‰ˆÜ�yŠy˜"�' 2¥7¨B°Rµ¸½À"È"ÌeÏoÊoÐ^`ÓNaÐbÐhjÔkÐkØ	‡y�y‡~�~˜ÔÜ�yŠy˜"˜X�,¨Õ+¨R°­\¸BÕ->ÀÀ8ÅÈrÕ@QÐRÐXZÔ[Ð[Øˆ|Õ˜r ,Õ/Õ/×8Ñ8¸Ó<Ð<r!   c                óŽ   € V ^8„  d   QhR\         P                  R\        \         P                  \         P                  3,          /# ©r   ÚAr   ©r   r   r   )r   s   "r   r    r    ¾   s0   € ÷ $ñ $œ%Ÿ,™,ð $¬5´·±¼u¿|¹|Ð1KÕ+Lñ $r!   c                ó"  € \         P                  ! V P                  \         P                  4      p\	        V P                  V4      4      P                  P                  R^^^4      P                  V P                  4      pVR,          VR,          3# )a  The two-dimensional null space of seven epipolar constraints ``(B, 7, 9)`` as two ``(B, 3, 3)`` matrices.

The null space comes from :func:`~kornia.geometry.solvers.homogeneous._null_space_lu`, in at least float32 since
no backend factorizes half precision.
r7   ©rt   r;   ©rt   r<   )r   rA   r5   rB   r   rC   ÚmTÚreshape)r�   Úsolve_dtypeÚbasiss   &  r   Ú_seven_point_basisrŠ   ¾   sj   € ô ×%Ò% a§g¡g¬u¯}©}Ó=€KÜ˜1Ÿ4™4 Ó,Ó-×0Ñ0×8Ñ8¸¸QÀÀ1ÓE×HÑHÈÏÉÓQ€EØ��;˜˜d�Ð#Ð#r!   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   Úf1Úf2r   rk   )r   s   "r   r    r    É   s2   € ÷ fñ f¤§¡ð f´5·<±<ð fÄEÇLÁLñ fr!   c           	     óŒ  € V R,          V R,          V R,          rCpVR,          VR,          VR,          rvp\         P                  P                  \         P                  ! W6W6.^4      \         P                  ! WGWt.^4      4      pVR,          VR,          VR,          VR,          ,           rºp	\         P                  ! W%W"WU.^4      \         P                  ! W™WºWº.^4      ,          P	                  R4      p\         P                  ! VR,          VR,          VR,          ,           VR,          VR,          ,           VR,          .^4      # )züCoefficients ``(B, 4)`` of the cubic :math:`\det(x f_1 + f_2)`, highest degree first.

Expanded by multilinearity in the rows, so neither matrix needs to be invertible: the leading coefficient is
:math:`\det f_1` and the constant one :math:`\det f_2`.
r„   r…   ©rt   r   ©rt   rs   r7   )rt   é   )rt   é   )r   ÚlinalgÚcrossÚstackrE   )rŒ   r�   Úa1Úa2Úa3Úb1Úb2Úb3ÚcrossesÚx_aaÚx_bbÚx_abÚdotss   &&           r   Ú_det_pencil_coefficientsr¡   É   s  € ð �D•˜2˜d�8 R¨¥XˆB€BØ�D•˜2˜d�8 R¨¥XˆB€BÜ�l‰l× Ñ ¤§¢¨b°bÐ-=¸qÓ!AÄ5Ç;Â;ÐPRÐXZÐO_ÐabÓCcÓd€GØ˜t•} g¨d¥m°W¸Tµ]ÀWÈTÅ]Õ5R�€DÜ�KŠK˜ ¨Ð0°!Ó4´u·{²{ÀDÐPTÐ\`ÐCgÐijÓ7kÕk×pÑpÐqsÓt€DÜ�;Š;˜˜T�
 D¨¥J°°dµÕ$;¸TÀ$½ZÈ$ÈtÍ*Õ=TÐVZÐ[_ÕV`ÐaÐcdÓeÐer!   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# )r   r4   r   )r   r4   r5   )r   s   "r   r    r    ×   s&   € ÷ Dñ DœŸ™ð D¬%¯+©+ñ Dr!   c                ód   € V P                   R8X  d   \        P                  # \        P                  # )zQThe dtype of the small closed-form steps: float64, except on MPS, which has none.Úmps)rx   r   rB   Úfloat64)r4   s   &r   Ú_solve_dtyper¦   ×   s    € à"ŸK™K¨5Ô0Œ5�=‰=ÐC´e·m±mÐCr!   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# ©r   ÚFr   rk   )r   s   "r   r    r    Ü   s"   € ÷ .?ñ .?œŸ™ð .?¬%¯,©,ñ .?r!   c                ó°
  € V P                   pV P                  \        V P                  4      4      p \        P
                  ! ^V P                   V P                  R7      pV P                  V ,          pVP                  RRR7      P                  R4      pV^,          pW5R,          V,          ,
          pVP                  4       P                  R	4      ^,          pV^ 8„  p\        P                  ! W‡\        P                  ! V4      4      P                  4       p	\        WiR,          ,          P                  R4      P                  R4      !  ^,          p
V
P!                  4       ^8  p\        P                  ! V
^ 8„  \        P"                  ! V
4      \        P$                  ! V
\&        P(                  4      4      p\        P                  ! V\        P*                  ! \        P                  ! Wº\        P"                  ! V
4      4      4      V4      ^,          pV\        P                  ! V^V	,          \        P,                  ! V^\&        P(                  ,          ^,          ,           4      ,          \        P"                  ! V	4      4      ,           pW>R,          V,          ,
          p\        P.                  P1                  VR. R
O3,          VR. RO3,          4      pVP                  4       P                  R4      pVP3                  ^RR7      pVP5                  ^VR,          P7                  R^^4      4      R,          pVP5                  ^V4      R,          pVP                  4       P                  R4      pVP3                  ^RR7      pVP5                  ^VR,          P7                  R^^4      4      R,          pVP5                  ^V4      R,          p\        P.                  P1                  VVVP!                  4       P9                  ^4      ,          4      p^\        P:                  ! V P                   4      P<                  ,          V,          P                  4       pVVV,          8„  pVV8„  p\        P                  ! VR,          V\        P                  ! VR,          VV^,          P?                  V4      4      4      pVP                  4       P                  R4      pV\        P                  ! V^ 8„  V\        P                  ! V4      4      PA                  4       R,          ,          pW VR,          ,          VR,          ,          ,
          P                  V4      # )a´  The nearest rank-2 matrices ``(B, 3, 3)`` in Frobenius norm, ``F (I - v v^T)`` for a smallest singular vector.

``v`` is an eigenvector of ``F^T F`` for its smallest eigenvalue :math:`\lambda_3`, found without an SVD: the
eigenvalue from the trigonometric solution of the characteristic polynomial, the vector from the best cross
product of two rows of ``F^T F - \lambda_3 I``. When :math:`\lambda_3` is repeated those rows span one direction or
none and every cross product vanishes; any unit vector orthogonal to the rows is then a smallest singular vector:
the cross product of the largest row with the coordinate axis least aligned to it, or ``e_3`` when every row
vanishes. The nearest rank-2 matrix is not unique there, and this returns one of them.

Runs in :func:`_solve_dtype` and returns ``F``'s dtype. ``sqrt``, ``acos`` and the normalizations take safe
substitutes where their derivative is unbounded (#4229), so gradients stay finite.
©r5   r4   )Údim1Údim2rt   T©r+   ru   r7   ©rt   NN©ru   r7   )r;   r;   r<   )r<   r   r   r:   r„   ©rt   N)rt   rt   N©rt   Nrt   )!r5   rC   r¦   r4   r   Úeyer†   ÚdiagonalrE   ÚsquarerD   rF   rJ   r   ry   Úunbindrc   Ú
zeros_likeÚ	full_likerI   ÚpiÚacosÚcosr“   r”   ÚargmaxÚgatherÚexpandÚargminÚfinfor   Ú	expand_asÚrsqrt)r©   r5   r³   r]   ÚtraceÚqÚshiftedÚp2Úspreadr0   ÚrÚinsideÚboundaryÚangleÚsmallestÚrowsrœ   Úcross_normsÚbestr”   Ú
cross_normÚ	row_normsÚtopÚrowÚrow_normÚperpendicularÚnoiseÚtwo_rowsÚone_rowÚvrG   s   &                              r   Ú_rank2_projectionrÚ   Ü   sÝ  € ð �G‰G€EØ	�‰Œ\˜!Ÿ(™(Ó#Ó$€AÜ
�)Š)�A˜QŸW™W¨Q¯X©XÔ
6€CØ	�‰ˆq�€AØ�J‰J˜B RˆJÓ(×,Ñ,¨RÓ0€EØ��	€AØ�MÕ" SÕ(Õ(€GØ	�‰Ó	×	Ñ	˜hÓ	'¨!Õ	+€BØ�!‰V€FÜ�Š�F¤§¢°Ó 3Ó4×9Ñ9Ó;€AÜ�˜MÕ*Õ*×3Ñ3°BÓ7×>Ñ>¸rÓBÑCÀaÕG€AØ�U‰U‹W�q‰[€FÜ�{Š{˜1˜q™5¤%×"2Ò"2°1Ó"5´u·²ÀqÌ$Ï'É'Ó7RÓS€HÜ�KŠK˜¤§
¢
¬5¯;ª;°vÄ%×BRÒBRÐSTÓBUÓ+VÓ WÐYaÓbÐefÕf€EØ”5—;’;˜v q¨1¥u¬u¯yªy¸ÀÄTÇWÁWÅÈqÅÕ9PÓ/QÕ'QÔSX×ScÒScÐdeÓSfÓgÕg€HØ˜Õ&¨Õ,Õ,€DÜ�l‰l× Ñ   aª lÕ!3°T¸!ºY¸,Õ5GÓH€GØ—.‘.Ó"×&Ñ& rÓ*€KØ×Ñ˜a¨ÐÓ.€DØ�N‰N˜1˜d 9�o×4Ñ4°R¸¸AÓ>Ó?ÀÕE€EØ×#Ñ# A tÓ,¨TÕ2€JØ—‘“×!Ñ! "Ó%€IØ
×
Ñ
˜1 dÐ
Ó
+€CØ
�+‰+�a˜˜Y�×.Ñ.¨r°1°aÓ8Ó
9¸$Õ
?€CØ×Ñ  3Ó'¨Õ-€HÜ—L‘L×&Ñ& s¨C°·±³	×0@Ñ0@ÀÓ0CÕ,DÓE€Mà”—’˜QŸW™WÓ%×)Ñ)Õ)¨EÕ1×9Ñ9Ó;€EØ˜E HÕ,Ñ,€HØ˜Ñ€GÜ�Š�H˜WÕ% u¬e¯kªk¸'À'Õ:JÈMÐ[^Ð_`Õ[a×[kÑ[kÐlqÓ[rÓ.sÓt€AØ�8‰8‹:�>‰>˜"Ó€DØ	ŒE�KŠK˜˜q™ $¬¯ª¸Ó(=Ó>×DÑDÓFÀwÕOÕO€AØ�Q�z•]Õ" a¨
¥mÕ3Õ3×7Ñ7¸Ó>Ð>r!   é   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# r¨   rk   )r   s   "r   r    r      s"   € ÷ .ñ .”e—l‘lð .¤u§|¡|ñ .r!   c                ó²  € V P                   P                  R8X  d   \        M\        pV P                  ^ ,          V8¼  d4   \        V P                   4      \        P                  8X  d   \        V 4      # \        V 4      w  r#p\        P                  ! V4      pVRRR13,          VRRR13&   V\        P                  ! V4      ,          VP                  ,          # )aL  Remove the smallest singular value of ``(B, 3, 3)`` matrices.

:func:`_rank2_projection` for large batches, an SVD for small ones, where it is cheaper. Without float64 (MPS) the
closed form would run in float32, where its error grows like ``eps * (sigma_1 / sigma_2)^2`` through ``F^T F``, so
the SVD is kept for every batch there.
ro   .Nr7   )r4   rx   Ú _RANK2_CLOSED_FORM_MIN_BATCH_CPUÚ(_RANK2_CLOSED_FORM_MIN_BATCH_ACCELERATORr>   r¦   r   r¥   rÚ   r   r·   Ú
diag_embedÚmH)r©   Ú	thresholdÚUÚSÚVÚS_news   &     r   Ú_enforce_rank2rç     s¥   € ð 56·H±H·M±MÀUÔ4JÕ0ÔPx€IØ‡w�wˆq…z�YÔ¤<°·±Ó#9¼U¿]¹]Ô#JÜ  Ó#Ð#Ü˜aÓ �G€Aˆ!Ü×Ò˜QÓ€EØ˜˜S˜b˜S˜•k€Eˆ#ˆs�ˆsˆ(�OØŒu×Ò Ó&Õ&¨¯©Õ-Ð-r!   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# r€   rk   )r   s   "r   r    r    $  s"   € ÷ :ñ :¤§¡ð :´·±ñ :r!   c                ó  € \        V P                  \        P                  ! V P                  \        P
                  4      4      4      R,          pWP                  RRR7      ,          P                  V P                  4      # )a�  The unit null vectors ``(B, 9)`` of eight epipolar constraints ``A`` ``(B, 8, 9)``, in ``A``'s dtype.

One batched LU factorization (:func:`~kornia.geometry.solvers.homogeneous._null_space_lu`) finds them much faster
than ``eigh`` of ``A^T A``, which loops over the batch on CPU and squares the condition number; the factorization
runs in at least float32 since no backend factorizes half precision.
Tr)   ©.r;   r7   )r   rC   r   rA   r5   rB   rG   )r�   Úhs   & r   Ú_eight_point_null_vectorrì   $  sV   € ô 	�q—t‘tœE×/Ò/°·±¼¿¹ÓGÓHÓIÈ&ÕQ€AØ—‘˜2 t�Ó,Õ,×0Ñ0°·±Ó9Ð9r!   c                óX   € V ^8„  d   QhR\         P                  R\         P                  /# r€   rk   )r   s   "r   r    r    /  s&   € ÷ Lñ L¤§¡ð L´·±ñ Lr!   c                óL   € \        \        V 4      P                  R^^4      4      # )a>  Rank-2 fundamental matrices ``(B, 3, 3)`` from eight epipolar constraints ``A`` ``(B, 8, 9)``, in ``A``'s dtype.

:func:`_eight_point_null_vector` followed by :func:`_rank2_projection`: RANSAC's eight-point sampler, which passes
rows of points it normalized once per call, in batches large enough for the closed form.
r7   )rÚ   rì   r‡   )r�   s   &r   Ú_eight_point_fundamentalrï   /  s$   € ô Ô5°aÓ8×@Ñ@ÀÀQÈÓJÓKÐKr!   c                óŽ   € V ^8„  d   QhR\         P                  R\        \         P                  \         P                  3,          /# r€   r‚   )r   s   "r   r    r    8  s4   € ÷ "Hñ "HœuŸ|™|ð "H´´e·l±lÄEÇLÁLÐ6PÕ0Qñ "Hr!   c           	     ó  a€ \        V P                  4      oV3R l\        V 4       4       w  r\        W4      pVP	                  ^4      w  rErg\
        P                  ! WE,           V,           V,           V^V,          ,           ^V,          ,           V^V,          ,           V.^4      p\
        P                  ! WE,
          V,           V,
          V^V,          ,
          ^V,          ,           V^V,          ,
          V.^4      p	\
        P                  ! W3P                  ^4      W‰.^4      p
V
R,          P                  4       P                  ^4      pV
P                  ^VR,          P                  R^^4      4      R,          p\
        P                  ! WW,           W,
          .^4      pVP                  ^VR,          P                  R^^^4      4      R,          p\
        P                  ! V^8H  R,          W4      pVR,          ^ 8g  pVP                  . R	O4      p\        \
        P                  ! VR
,          VV4      4      w  ppVVR
,          ,          pVR,          VR
,          ,          VR
,          ,           pVVP                  4       P!                  RRR7      P#                  4       ,          pVP%                  V P&                  4      V\
        P(                  ! V4      P+                  R4      P-                  R4      ,          3# )aÏ  Fundamental matrices through seven correspondences, one per real root of ``det(x f_1 + f_2) = 0``.

The two-dimensional null space ``x f_1 + f_2`` of the constraints ``A`` ``(B, 7, 9)`` (:func:`_epipolar_design_rows`
of normalized points) is completed by the real roots of its determinant (Hartley and Zisserman, section 11.1.2), so
every candidate has rank two. The cubic is solved in :func:`_solve_dtype`, choosing its leading matrix from
``f_1``, ``f_2``, ``f_1 + f_2`` and ``f_1 - f_2`` to maximize the leading determinant. These four evaluations
determine the homogeneous cubic, so both singular basis matrices still give a well-conditioned parametrization.

Returns:
    Candidates ``(B, 3, 3, 3)`` of unit Frobenius norm in ``A``'s dtype, and a mask ``(B, 3)`` of the real roots
    with finite candidates. A cubic with one real root repeats its candidate in the two masked slots rather than
    producing NaN, so that masking them afterwards leaves finite gradients.
c              3   óD   <"  € T F  qP                  S4      x € K  	  R # 5i©N)rC   )Ú.0Úfrˆ   s   & €r   Ú	<genexpr>Ú*_seven_point_candidates.<locals>.<genexpr>G  s   øé € Ð?Ñ)> A�d‰d�;×ÐÓ)>ùs   ƒ Tr®   )rt   rt   r;   r¯   r7   r„   )rt   NNN)r6   r/   r/   r/   r±   )rt   rt   NNru   r°   )r¦   r4   rŠ   r¡   r¶   r   r•   Úfliprc   r¼   r½   r¾   rD   Ú
new_tensorr   rµ   rE   rÂ   rC   r5   Úisfinitery   Úall)r�   rŒ   r�   ÚcoefficientsÚaÚbÚcÚdÚplusÚminusÚchoicesrÏ   Ú
directionsÚleadÚrestÚisolatedÚfallbackÚrootsÚvalidr©   rˆ   s   &                   @r   Ú_seven_point_candidatesr  8  sR  ø€ ô ˜qŸx™xÓ(€KÜ?Ô);¸AÔ)>Ó?�F€BÜ+¨BÓ3€LØ×$Ñ$ QÓ'�J€Aˆ!ä�;Š;˜� �	 A� q¨1¨q­5¥y°1°qµ5Õ'8¸!¸aÀ!½e½)ÀQÐGÈÓK€DÜ�KŠK˜� � Q�¨¨A°­E­	°A¸µEÕ(9¸1¸qÀ1½u½9ÀaÐHÈ!ÓL€EÜ�kŠk˜<×):Ñ):¸1Ó)=¸tÐKÈQÓO€GØ�7Õ×ÑÓ!×(Ñ(¨Ó+€DØ—>‘> ! T¨-Õ%8×%?Ñ%?ÀÀAÀqÓ%IÓJÈ4ÕP€LÜ—’˜b b¥g¨r­wÐ7¸Ó;€JØ×Ñ˜Q Ð%8Õ 9× @Ñ @ÀÀQÈÈ1Ó MÓNÈtÕT€DÜ�;Š;˜ ™	 =Õ1°2Ó:€Dà˜DÕ! QÑ&€HØ×&Ñ&Ò';Ó<€HÜ$¤U§[¢[°¸'Õ1BÀLÐRZÓ%[Ó\�L€Eˆ5Ø�H˜WÕ%Õ%€EØÐÕ $ w¥-Õ/°$°wµ-Õ?€AØ	ˆA�H‰H‹J�N‰N˜8¨TˆNÓ2×8Ñ8Ó:Õ:€AØ�4‰4�—‘‹=˜%¤%§.¢.°Ó"3×";Ñ";¸BÓ"?×"CÑ"CÀBÓ"GÕGÐGÐGr!   c          
      óÜ   € V ^8„  d   QhR\         P                  R\        R\        \        \         P                  3,          R\
        \         P                  \         P                  3,          /# )r   Úr2ÚlossÚscale2r   )r   r   Ústrr   r   r   )r   s   "r   r    r    ]  sY   € ÷ qñ q”U—\‘\ð q¬ð q´e¼EÄ5Ç<Á<Ð<OÕ6Pð qÔUZÔ[`×[gÑ[gÔin×iuÑiuÐ[uÕUvñ qr!   c           
     ó0  € VR8X  d3   RRW,          ,           ,          \         P                  ! W,          4      3# W8  P                  V P                  4      \         P                  ! V \         P
                  ! W P                  V P                  R7      4      3# )z±IRLS weights and costs of a squared residual: Cauchy, or truncated at ``scale2``.

``scale2`` may be a 0-d tensor, which keeps a compiled caller free of a host synchronization.
Úcauchyr6   r«   )r   Úlog1prC   r5   ÚfminÚ	as_tensorr4   )r  r  r  s   &&&r   Ú_robust_lossr  ]  sm   € ð
 ˆxÔØ�c˜B�KÕ'Õ(¬%¯+ª+°bµkÓ*BÐBÐBØ‰K×Ñ˜BŸH™HÓ%¤u§z¢z°"´e·o²oÀf×T\ÑT\Ðeg×enÑenÔ6oÓ'pÐpÐpr!   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   r5   r4   r   )r   r5   r4   r   )r   s   "r   r    r    g  s-   € ÷ 
ñ 
”e—k‘kð 
¬5¯<©<ð 
¼E¿L¹Lñ 
r!   c                óp   € \         P                  ! . RO. RO. RO.. RO. RO. RO.. RO. RO. RO..V VR7      # )	zB``E[a] = [e_a]_x``, the generators of rotations, as ``(3, 3, 3)``.r«   )r/   r/   r/   )r/   r/   ç      ð¿)r/   r6   r/   )r/   r/   r6   )r  r/   r/   )r/   r  r/   )r6   r/   r/   )r   Útensorr«   s   &&r   Ú
_hat_basisr  g  s@   € ä�<Š<âÒ.²Ð@ÚšoÒ/?Ð@Úš²Ð@ð	
ð
 Øôð r!   c                ó  € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        \         P                  ,          R\        R\        \
        \         P                  3,          R\         P                  /# )r   r©   Ú	algebraicÚ	quadraticre   r  r  r   )r   r   r   r  r   r   )r   s   "r   r    r    t  su   € ÷ ñ Ü‡|�|ðä�|‰|ðô �|‰|ðô ”5—<‘<Õ
 ð	ô
 ðô ”%œŸ™Ð%Õ&ðô ‡\�\ñr!   c           	     óÂ  € V R,          P                   V R,          ,          pV R,          V R,          P                   ,          pV P                  ^4      V,          p\        P                  ! Wg.^4      P                  ^4      V,          p	Ve0   \        P                  ! V^ 8g  V	\        P
                  ! V	4      4      p	W‰P                  4       ,          P                  4       p
VR8X  d   \        P                  ! W¥,          4      M@\        P                  ! V
\        P                  ! WZP                  V
P                  R7      4      pVe	   W³,          pVP                  ^4      # )zNRobust Sampson costs without constructing trial Jacobians or normal equations.r  r«   )rt   r,   rt   )rt   rt   r,   )r†   ry   r   rw   rD   rF   rÂ   rµ   r  r  r  r5   r4   rE   )r©   r  r  re   r  r  Úquad1Úquad2Ú	numeratorÚdenominatorr  Úrhos   &&&&&&      r   Ú_sampson_costr%  t  s  € ð ˆh�K�N‰N˜Q˜x�[Õ(€EØˆh�K˜!˜H�+Ÿ.™.Õ(€EØ—	‘	˜!“˜yÕ(€IÜ—)’)˜U˜N¨AÓ.×6Ñ6°qÓ9¸IÕE€KØÒô —k’k $¨!¡)¨[¼%¿/º/È+Ó:VÓWˆØ
×'Ñ'Ó)Õ
)×	1Ñ	1Ó	3€Bð �8Ôô 	�Š�B•KÔ ä�ZŠZ˜œEŸOšO¨F¿(¹(È2Ï9É9ÔUÓVð ð
 ÒØ�jˆØ�7‰7�1‹:Ðr!   c                ór  € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  R\        \         P                  ,          R\        R\        \
        \         P                  3,          R\        \         P                  \         P                  3,          /# )	r   r©   Útangentr  r  re   r  r  r   )r   r   r   r  r   r   r   )r   s   "r   r    r    �  s›   € ÷ "Dñ "DÜ‡|�|ð"Dä�\‰\ð"Dô �|‰|ð"Dô �|‰|ð	"Dô
 ”5—<‘<Õ
 ð"Dô ð"Dô ”%œŸ™Ð%Õ&ð"Dô Œ5�<‰<œŸ™Ð%Õ&ñ"Dr!   c                óÒ  € VP                   R,          w  rx\        P                  ! V R,          V.^4      p	V R,          P                  V	R,          ,          p
V R,          V	R,          P                  ,          pV	P	                  Wx^,           ^	4      V,          p\        P                  ! W«.^4      P	                  Wx^,           ^4      V,          pVR,          pVe0   \        P
                  ! V^ 8g  V\        P                  ! V4      4      pVP                  4       pVR,          V,          pVR,          VV,          R,          VR,          ,          ,
          VR,          ,          p\        VV,          WV4      w  ppVe   VV,          VV,          ppVVR,          ,          p\        P                  ! VVP                  ,          VVR	,          ,          .^4      VP                  ^4      3# )
až  Robust Gauss-Newton normal equations ``[J^T W J | J^T W r]`` ``(K, P, P + 1)`` and costs ``(K,)``.

For the Sampson residuals of ``F`` ``(K, 3, 3)``, whose derivatives along ``P`` parameters are ``tangent``
``(K, P, 3, 3)``. ``algebraic`` ``(9, N)`` and ``quadratic`` ``(18, N)`` are the per-correspondence monomials of
the epipolar constraint and of the squared gradient norm, from :func:`_epipolar_design_rows`.
r,   r±   )rt   Nr,   rt   )rt   rt   r,   rt   )rt   Nrt   r,   )rt   rt   rt   r,   r„   )rt   ºr<   NNr:   )
r>   r   rw   r†   r‡   rD   rF   rÂ   r  rE   )r©   r'  r  r  re   r  r  ÚKÚPÚstackedr   r!  Úout_cÚout_gr#  ÚinvrÈ   ÚJÚwr$  ÚJws   &&&&&&&              r   Ú_sampson_normal_equationsr3  �  sƒ  € ð �=‰=˜Õ�D€AÜ�iŠi˜˜7� WÐ-¨qÓ1€GàˆnÕ× Ñ  7¨;Õ#7Õ7€EØˆnÕ ¨Õ 4× 7Ñ 7Õ7€EØ�O‰O˜A 1�u aÓ(¨9Õ4€EÜ�IŠI�u�n aÓ(×0Ñ0°¸µE¸2Ó>ÀÕJ€EØ˜•+€KØÒô —k’k $¨!¡)¨[¼%¿/º/È+Ó:VÓWˆØ
×
Ñ
Ó
€CØˆd��cÕ€AØ	ˆu�˜˜S� 'Õ*¨U°5­\Õ9Õ	9¸SÀ½\ÕI€AÜ˜!˜a�% Ó.�F€A€sØÒØ�T•˜3 �:ˆ3ˆØ	
ˆQˆw�Z�€BÜ�9Š9�b˜1Ÿ4™4•i  a¨	¥lÕ!2Ð3°QÓ7¸¿¹À»ÐCÐCr!   c                ó(  € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        \         P                  ,          R\        R\        \
        \         P                  3,          R\        R\         P                  /# )	r   r©   ri   rj   re   r  r  Úitersr   )r   r   r   r  r   r   Úint)r   s   "r   r    r    µ  s‰   € ÷ Hñ HÜ‡|�|ðHä�‰ðHô 	�‰ðHô ”5—<‘<Õ
 ð	Hô
 ðHô ”%œŸ™Ð%Õ&ðHô ðHô ‡\�\ñHr!   c           	     ó2
  aaaa$a%a&€ V P                   ^ ,          pV P                  V P                  r˜V^ 8„  ;'       d2    V	P                  R8H  ;'       d    \        P
                  ! 4       '       * p
V
'       dM   V^8X  dF   SeB   SP                  \        P                  8X  d#   VS^ ,          ,          VS^ ,          ,          Ruro\        W‰4      o$\        P                  ! ^W‰R7      p\        P                  ! ^W‰R7      p\        W4      P                  o%\        P                  ! \        W4      \        W"4      .^4      P                  o&\        P                  P                  V 4      w  rÞpVP                  p\        P                  ! VR,          VR,          \        P                  P                  V4      P!                  4       R,          ,          .R4      p\        P                  ! VR,          VR,          \        P                  P                  V4      P!                  4       R,          ,          .R4      p\        P"                  ! VV.^4      pVR,          VR,          P%                  \        P&                  ! V4      P(                  R7      ,          p\        P*                  ! V^^3RW‰R7      pR R lpR V$V%VVV&V3R	 llpV! VV4      p V! V V4      w  pp\-        V4       EF.  p\        P                  P/                  VR,          VV,          ,           VR,          4      ^ ,          R,          ) pVR,          P1                  V^,          ^4      R
,          pVS$P1                  ^^	4      ,          P1                  V^^^4      pRRVP3                  4       P5                  ^4      ,           ,          P1                  V^^^4      pVVVVV,          ,           ,          ,           V,          pVVR,          ,           pV! VV4      pV
'       dE   V^,           V8X  d7   \7        VS%S&SSS4      p V V8  p!\        P8                  ! V!R,          VV 4      u # V! VV4      w  p"p V V8  R,          p#\        P8                  ! V#R,          VV4      p\        P8                  ! V#VV 4      \        P8                  ! V#V"V4      pp \        P8                  ! V#R,          VV4      \        P8                  ! V#R,          V V4      ppV\        P8                  ! V#RR4      ,          pEK1  	  V # )af  Levenberg-Marquardt on the Sampson distance, batched over fundamental matrices ``(K, 3, 3)``.

In the spirit of PoseLib's ``refine_fundamental`` (Larsson and contributors, https://github.com/PoseLib/PoseLib):
``F = U diag(1, s, 0) V^T`` with rotations ``U``, ``V`` updated by Cayley steps, the seven-parameter factorization
of Bartoli and Sturm, "Nonlinear estimation of the fundamental matrix with minimal parameters", TPAMI 2004. Each
iteration takes the residuals and their Jacobian from two matrix products with per-correspondence monomials.
``x1`` and ``x2`` are homogeneous ``(N, 3)`` points, normalized by the caller. ``loss`` is ``"truncated"`` or
``"cauchy"`` with squared scale ``scale2``; ``mask`` (``(K, N)``) restricts each model to its correspondences. A
step is kept only if it lowers the cost. For RANSAC, under ``torch.no_grad``. On CPU with gradients disabled, a
singleton boolean mask compacts its correspondences, and the last trial evaluates only the cost: its Jacobian and
updated optimizer state would not be used. Earlier iterations keep fused residual and Jacobian evaluation for small
model batches.
ro   Nr«   )Úmingü©ñÒMbP?c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   ÚUVÚsigmar   rk   )r   s   "r   r    Ú,_refine_fundamental_lm.<locals>.__annotate__Þ  s-   € ÷ >ñ >”E—L‘Lð >¬¯©ð >¼%¿,¹,ñ >r!   c                 óº   € \         P                  ! \         P                  ! V4      V.^4      R,          pV R,          V,          V R,          P                  ,          # )r<   r²   )rt   r;   rt   r,   )rt   r<   rt   r,   )r   r•   rF   r†   )r:  r;  rX   s   && r   ÚcomposeÚ'_refine_fundamental_lm.<locals>.composeÞ  sC   € Ü—’œUŸ_š_¨UÓ3°UÐ;¸QÓ?À
ÕKˆØ�;• %Õ'¨2¨k­?×+=Ñ+=Õ=Ð=r!   c                ó®   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  \         P                  3,          /# )r   r©   r:  r   r‚   )r   s   "r   r    r<  â  sC   € ÷ _ñ _œEŸL™Lð _¬e¯l©lð _¼uÄUÇ\Á\ÔSX×S_ÑS_ÐE_Õ?`ñ _r!   c           	      óø   <€ \         P                  ! SV R,          ,          V R,          S,          P                  4       VR,          VR,          P                  ,          R,          .^4      p\	        WSSSSS4      # )rt   r±   )rt   r;   rt   rq   )rt   r<   rt   rq   )r   rw   Únegr†   r3  )	r©   r:  r'  ÚEr  r  re   r  r  s	   && €€€€€€r   Únormal_equationsÚ0_refine_fundamental_lm.<locals>.normal_equationsâ  sk   ø€ ä—)’)Ø��7•�^˜a �j¨1�n×1Ñ1Ó3°b¸Õ6FÈÈLÕIY×I\ÑI\Õ6\Ð^eÕ5fÐgÐijó
ˆô )¨°YÀ	È4ÐQUÐW]Ó^Ð^r!   g      à?r2   r6   gš™™™™™¹?g      $@).r,   ).:r   NNr¯   r7   r…   r„   ).:Né   N).:rF  NNrê   )rt   :Né   N)rt   rG  r:   )rt   r;   r;   )r>   r5   r4   rx   r   Úis_grad_enabledÚboolr  r³   r~   ÚTrw   r“   Úsvdr†   ÚdetÚsignr•   ÚclamprÀ   ÚtinyÚfullÚrangeÚsolve_exr‡   rµ   rE   r%  rD   )'r©   ri   rj   re   r  r  r5  r*  r5   r4   ro   Úeye3Úeye7rã   rä   ÚVhrå   r:  r;  Údampingr>  rD  ÚsystemÚcostÚ	iterationÚdeltaÚhalfÚskewÚfactorÚUV_newÚ	sigma_newÚF_newÚcost_newÚacceptedÚ
system_newÚacceptrC  r  r  s'   &&&fff&                             @@@r   Ú_refine_fundamental_lmre  µ  sð  ý€ ð, 	
�‰��
€AØ—G‘G˜QŸX™Xˆ6Ø
ˆa‰%×
HÐ
H�F—K‘K 5Ñ(×
HÐ
H´×1FÒ1FÓ1HÔ-H€Cß
ˆq�AŒv˜$Ò*¨t¯z©z¼U¿Z¹ZÔ/GØ˜$˜q�'•{ B t¨A¥w¥K°ˆˆ�Ü�5Ó!€AÜ�9Š9�Q˜eÔ3€DÜ�9Š9�Q˜eÔ3€DÜ% bÓ-×/Ñ/€IÜ—	’	Ô0°Ó8Ô:OÐPRÓ:WÐXÐZ[Ó\×^Ñ^€IÜ�|‰|×Ñ Ó"�H€Aˆ"Ø
�‰€Aä�	Š	�1�W•:˜q �z¬E¯L©L×,<Ñ,<¸QÓ,?×,DÑ,DÓ,FÀ}Õ,UÕUÐVÐXZÓ[€AÜ�	Š	�1�W•:˜q �z¬E¯L©L×,<Ñ,<¸QÓ,?×,DÑ,DÓ,FÀ}Õ,UÕUÐVÐXZÓ[€AÜ	�Š�a˜�V˜QÓ	€BØˆd�G�a˜•g—m‘m¬¯ª°EÓ(:×(?Ñ(?�mÓ@Õ@€EÜ�jŠj˜!˜Q ˜ D°ÔE€Gõ>÷_õ _ñ 	��EÓ€AÙ# A rÓ*�L€FˆDÜ˜5—\ˆ	Ü—‘×&Ñ& v¨g¥¸À4½Õ'GÈÐPWÍÓYÐZ[Õ\Ð]cÕdÐdˆØ�U�|×#Ñ# A¨¥E¨1Ó-°Õ3ˆØ�q—y‘y  A“Õ&×/Ñ/°°1°a¸Ó;ˆØ˜˜tŸ{™{›}×0Ñ0°Ó3Õ3Õ4×=Ñ=¸aÀÀAÀqÓIˆØ˜ 4¨$°­+Õ#5Õ6Õ6¸"Õ<ˆØ˜E $�KÕ'ˆ	Ù˜ 	Ó*ˆß�9˜q•= EÔ)Ü$ U¨I°yÀ$ÈÈfÓUˆHØ $‘ˆHÜ—;’;˜x¨Õ6¸¸qÓAÒAÙ/°°vÓ>Ñˆ
�HØ˜T‘/ =Õ1ˆÜ�[Š[˜ 	Õ*¨F°BÓ7ˆÜ—K’K ¨¨qÓ1´5·;²;¸vÀzÐSYÓ3Zˆ6ˆÜ—k’k &¨¥/°9¸eÓDÄeÇkÂkÐRXÐY`ÕRaÐckÐmqÓFrˆtˆØœEŸKšK¨°°TÓ:Õ:‹ñ# "ð$ €Hr!   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   Úpoints1Úpoints2r   rk   )r   s   "r   r    r       s2   € ÷ !añ !aœŸ™ð !a¬u¯|©|ð !aÄÇÁñ !ar!   c           	     ó�  € \        V . RO4       \        V. RO4       \        P                  ! V P                  VP                  4      p\	        V 4      \	        V4      r\        V P                  P                  4      ;_uu_ 4        \        V 4      w  r4\        V4      w  rV\        W54      p\        V4      w  r‰\        VR,          P                  V,          VR,          ,          4      p
\        P                  ! V	R,          V
\        P                  ! V
4      4      P                  V4      uuRRR4       #   + '       g   i     R# ; i)að  Compute the fundamental matrix using the 7-point algorithm.

The 7-point algorithm computes the fundamental matrix from exactly 7 point correspondences.
Unlike the 8-point algorithm, this method returns 3 candidate fundamental matrices, one per real root of the
cubic that formulates the rank-2 constraint, padded to three with zero matrices.

Reference: Hartley/Zisserman 11.1.2 pag.281

Args:
    points1: A set of 7 points in the first image with shape ``(B, 7, 2)``.
    points2: A set of 7 points in the second image with shape ``(B, 7, 2)``.

Returns:
    The computed fundamental matrices with shape ``(B, 3, 3, 3)``, always 3 candidates per batch
    element. A cubic with a single real root gives one candidate followed by two zero matrices.

N)r$   Ú7r9   r±   ©.NN)r   r   rA   r5   r	   r
   r4   rx   r[   r~   r  rg   r†   rD   r·   rC   )rg  rh  r5   Úpoints1_normÚ
transform1Úpoints2_normÚ
transform2r�   Ú
candidatesr
  Úfmatrixs   &&         r   Ú
run_7pointrr     sï   € ô$ �w¢Ô0Ü�w¢Ô0Ü×Ò §¡¨w¯}©}Ó=€EÜ(¨Ó1Ô3DÀWÓ3MˆWô 
˜GŸN™N×/Ñ/×	0Õ	0ô $4°GÓ#<Ñ ˆÜ#3°GÓ#<Ñ ˆÜ! ,Ó=ˆÜ3°AÓ6Ñˆ
ä*¨:°gÕ+>×+AÑ+AÀJÕ+NÐQ[Ð\cÕQdÕ+dÓeˆÜ�{Š{˜5 Õ1°7¼E×<LÒ<LÈWÓ<UÓV×YÑYÐZ_Ó`÷ 
1×	0×	0Ó	0ús   ÂB%D4Ä4E	c          
      óº   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        R\         P                  /# )r   rg  rh  r   Úuse_einsum_at_more_than_pointsr   )r   r   r   r6  )r   s   "r   r    r    $  sV   € ÷ U5ñ U5Ü�\‰\ðU5ä�\‰\ðU5ô ”e—l‘lÕ#ðU5ô %(ð	U5ô
 ‡\�\ñU5r!   c           	     ó†  € \        V . RO4       \        V. RO4       \        W4       V P                  ^,          ^8  d;   \        R\	        V P                  4       R2\	        V P                  4      . ROR7      hVeˆ   \        VRR.4       VP                  V P                  R,          8w  dX   \        R\	        V P                  R,          4       R	\	        VP                  4       R2\	        VP                  4      RR.R7      hVe%   \        VP                  V P                  4      4      p\        P                  ! V P                  VP                  4      p\        V 4      \        V4      r\        V P                  P                  4      ;_uu_ 4        \        WR
7      w  rV\        WR
7      w  rx\        WW4      p	V	P                  w  r«pVf   V^8X  d   \        V	4      pMíVfG   W³8  d)   V	P!                  RR4      P#                  4       V	,          pM�\        P$                  ! RW™4      pMx\        P&                  ! V^ 8  RV4      pW³8  d@   WŸP)                  R4      ,          pVP!                  RR4      P#                  4       V	,          pM\        P$                  ! RW™V4      p\        P*                  P-                  V4      w  ppVR,          p\/        VP1                  V
^^4      4      pVP!                  RR4      VV,          ,          p\3        V4      P                  V4      uuRRR4       #   + '       g   i     R# ; i)a>  Compute the fundamental matrix using (weighted) 8-point DLT, optimized.

Args:
    points1: (B, N, 2), N >= 8
    points2: (B, N, 2), N >= 8
    weights: optional (B, N) nonnegative weights
    use_einsum_at_more_than_points: threshold for using einsum vs GEMM for large N

Returns:
    (B, 3, 3) fundamental matrices
r$   r%   z?points1 and points2 must have shape (B, N, 2) with N >= 8, got r#   r&   Nr,   r-   r.   )r   zbni,bnj->bijr/   zbni,bnj,bn->bijr8   )r$   zN >= 8r9   ru   r7   rê   )r   r   r>   r   r?   r	   rC   r5   r   rA   r
   r4   rx   r[   r~   rì   Ú	transposeÚ
contiguousÚeinsumrD   Ú	unsqueezer“   Úeighrç   r‡   rg   )rg  rh  r   rt  r5   Úpts1nÚT1Úpts2nÚT2r�   r$   r%   rN   rë   r]   r1  ÚAwÚ_evalsÚevecsÚF_rank2r©   s   &&&&                 r   Ú
run_8pointrƒ  $  sž  € ô" �w¢Ô0Ü�w¢Ô0Ü˜GÔ-Ø‡}�}�QÕ˜!ÔÜØMÌdÐSZ×S`ÑS`ÓNaÐMbÐbcÐdÜ˜gŸm™mÓ,Ú/ô
ð 	
ð
 ÒÜ˜7 S¨# JÔ/Ø�=‰=˜GŸM™M¨"Õ-Ô-ÜØ3´D¸¿¹ÀrÕ9JÓ4KÐ3LÈFÔSWÐX_×XeÑXeÓSfÐRgÐghÐiÜ! '§-¡-Ó0Ø # S˜zôð ð ÒÜ# G§J¡J¨w¯}©}Ó$=Ó>ˆÜ×Ò §¡¨w¯}©}Ó=€EÜ(¨Ó1Ô3DÀWÓ3MˆWô 
˜GŸN™N×/Ñ/×	0Õ	0ä$ WÔ>‰	ˆÜ$ WÔ>‰	ˆô " %Ó/ˆà—'‘'‰ˆˆaàŠ?˜q Aœvä(¨Ó+‰Að ŠØÔ5àŸ™ B¨Ó+×6Ñ6Ó8¸1Õ<‘Aô Ÿš ^°QÓ:‘Aô —K’K ¨!¡¨S°'Ó:�ØÔ5ð Ÿ[™[¨›_Õ,�BØŸ™ R¨Ó,×7Ñ7Ó9¸AÕ=‘Aô ŸšÐ%6¸¸aÓ@�Aä!ŸL™L×-Ñ-¨aÓ0‰MˆF�EØ�f•ˆAÜ  §¡¨1¨a°Ó!3Ó4ˆØ�L‰L˜˜RÓ  G¨b¥LÕ1ˆä'¨Ó*×-Ñ-¨eÓ4÷Y 
1×	0×	0Ó	0ús   ÆFL/Ì/M 	c                ó®   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\         P                  /# )r   rg  rh  r   r   )r   r   r   )r   s   "r   r    r    |  sF   € ÷ Wñ WœŸ™ð W¬u¯|©|ð WÄhÌuÏ|É|ÕF\ð WÔhm×htÑhtñ Wr!   c                ó2
  € \        V . RO4       \        V. RO4       \        W4       V P                  ^,          ^8  d;   \        R\	        V P                  4       R2\	        V P                  4      . ROR7      hVez   VP                  V P                  R,          8w  dX   \        R\	        V P                  R,          4       R	\	        VP                  4       R2\	        VP                  4      RR.R7      hV P
                  p\        V 4      p\        V P                  P                  4      ;_uu_ 4        \        P                  ! W.RR
7      P                  V4      pVf6   \        P                  ! VP                  R,          VP                  VR7      pM,VP                  V4      p\        P                  ! V^ 8  RV4      pVP                  R4      VP                  R4      ,           P!                  4       p\        P                  ! VP#                  R^^4      VR4      p\        P                  ! VP#                  R^4      VR4      pVR,          V,          P                  ^4      VP                  ^RR7      P%                  \        P&                  ! V4      P(                  4      ,          pWXR,          ,
          p	W–R,          ,          P+                  RR4      V	,          p
V\        P,                  8X  d>   \        P.                  P1                  V
P3                  4       4      w  r¼\5        W«V^ 4      pMr\7        W–R,          P9                  4       ,          P3                  4       RR7      w  rïp\5        W¯P                  V4      P;                  4       VP                  V4      R4      p\        P<                  ! VR,          4      pWØ,          P                  R4      ) p\        P>                  ! VVVR,          VVVR,          VR,          VR,          V.	RR
7      P#                  R^^4      p\A        V4      p\        P                  ! VP#                  R^^4      V\C        R4      4      pV\        PD                  8X  dp   VPG                  4       PI                  RRR7      p\        P                  ! V\        P&                  ! \        PD                  4      PJ                  8„  VV,          V4      pVP                  V4      uuRRR4       #   + '       g   i     R# ; i)aÝ  Compute the affine fundamental matrix of two affine cameras by orthogonal regression.

Two affine cameras (parallel projection, such as weak perspective) have a fundamental matrix of the form
``[[0, 0, a], [0, 0, b], [c, d, e]]``: the epipolar constraint :math:`a x_2 + b y_2 + c x_1 + d y_1 + e = 0` is a
hyperplane in the space of the stacked correspondences :math:`(x_2, y_2, x_1, y_1)`, and the distance of a
correspondence to it is the geometric error, the smallest total displacement of its two points that makes them
correspond. The hyperplane that minimizes the sum of the squared (weighted) distances passes through the
centroid, and its normal is the eigenvector of the smallest eigenvalue of the centred scatter matrix. This is
the Gold Standard (maximum-likelihood) estimate under Gaussian noise, exact for four correspondences. When the
points of one image lie on a line, the minimizer is that line, a rank-one matrix with ``(a, b) = 0`` or
``(c, d) = 0``, which no pair of affine cameras has; ``RANSAC("fundamental_affine")`` rejects such models.

Reference: Hartley and Zisserman, Multiple View Geometry in Computer Vision, 2nd ed., section 14.2, algorithm 14.1.

Args:
    points1: points in the first image ``(B, N, 2)``, :math:`N \ge 4`.
    points2: points in the second image ``(B, N, 2)``.
    weights: optional nonnegative weights ``(B, N)`` of the correspondences' squared distances.

Returns:
    The affine fundamental matrices ``(B, 3, 3)``, scaled so that ``F[2, 2] = 1``.

r$   r%   z?points1 and points2 must have shape (B, N, 2) with N >= 4, got r#   r&   Nr,   r-   r.   r1   r3   r/   r6   Tr®   F)Úfull_matricesÚnanr)   r8   )r$   zN >= 4r9   r7   ru   r°   r:   r±   r„   r…   r�   r�   )&r   r   r>   r   r?   r5   r   r
   r4   rx   r   rw   rC   ÚonesrD   rE   rú   rK   Ú	clamp_minrÀ   rO  rv  r¥   r“   rz  Údetachr   r   rJ   rµ   r·   r•   rg   r   Úfloat16rc   ÚamaxÚmax)rg  rh  r   r5   ÚworkÚXr1  Úfiniter@   ÚcentredÚscatterÚeigenvaluesÚeigenvectorsÚnormalrN   rä   rå   rL   Úlastr©   rX   s   &&&                  r   Ú
run_affiner—  |  s×  € ô0 �w¢Ô0Ü�w¢Ô0Ü˜GÔ-Ø‡}�}�QÕ˜!ÔÜØMÌdÐSZ×S`ÑS`ÓNaÐMbÐbcÐdÜ˜gŸm™mÓ,Ú/ô
ð 	
ð
 Ò˜wŸ}™}°·±¸bÕ0AÔAÜØ/´°W·]±]À2Õ5FÓ0GÐ/HÈÌtÐT[×TaÑTaÓObÐNcÐcdÐeÜ˜gŸm™mÓ,Ø ˜:ô
ð 	
ð
 �M‰M€Eô ˜7Ó#€DÜ	˜GŸN™N×/Ñ/×	0Õ	0Ü�IŠI�wÐ(¨bÔ1×4Ñ4°TÓ:ˆØŠ?Ü—
’
˜1Ÿ7™7 2�;¨q¯x©x¸tÔD‰Að —
‘
˜4Ó ˆAÜ—’˜A ™E 3¨Ó*ˆAð —%‘%˜“/ A§E¡E¨"£IÕ-×7Ñ7Ó9ˆÜ�KŠK˜Ÿ™ B¨¨1Ó-¨q°#Ó6ˆÜ�KŠK˜Ÿ™ B¨Ó*¨A¨sÓ3ˆØ�)•˜qÕ ×%Ñ% aÓ(¨1¯5©5°¸D¨5Ó+A×+KÑ+KÌEÏKÊKÐX\ÓL]×LbÑLbÓ+cÕcˆØ˜7•mÕ#ˆà˜y�\Õ)×4Ñ4°R¸Ó<¸wÕFˆð ”5—=‘=Ô Ü(-¯©×(9Ñ(9¸'¿.¹.Ó:JÓ(KÑ%ˆKÜ+¨GÀ,ÐPQÓR‰Fô /°¸I½,×:KÑ:KÓ:MÕ0M×/UÑ/UÓ/WÐglÔm‰GˆA�!Ü+¨G·T±T¸$³Z×5FÑ5FÓ5HÈ!Ï$É$ÈtË*ÐVXÓYˆFÜ× Ò  ¨¥Ó.ˆØ•×#Ñ# BÓ'Ð'ˆÜ�KŠKØ�E˜6 $�<¨°°v¸dµ|ÀVÈDÅ\ÐSYÐZ^ÕS_ÐaeÐfÐlnô
ç
‰$ˆr�1�a‹.ð 	
ô % QÓ'ˆÜ�KŠK˜Ÿ™ B¨¨1Ó-¨q´%¸³,Ó?ˆØ”E—M‘MÔ!ð —E‘E“G—L‘L X°t�LÓ<ˆEÜ—’˜E¤E§K¢K´·±Ó$>×$BÑ$BÑBÀAÈÅIÈqÓQˆAØ�t‰t�E‹{÷W 
1×	0×	0Ó	0ús   Ä5OTÔT	c          
      óÈ   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  ,          R\        R,          R\         P                  /# )r   rg  rh  r   Úmethodr   )Ú8POINTÚ7POINTÚAFFINE)r   r   r   r   )r   s   "r   r    r    Ö  s\   € ÷ Fñ FÜ�\‰\ðFä�\‰\ðFô ”e—l‘lÕ#ðFô Ð0Õ1ð	Fô
 ‡\�\ñFr!   c                óð   € VP                  4       R8X  d   \        W4      pV# VP                  4       R8X  d   \        WV4      pV# VP                  4       R8X  d   \        WV4      pV# \	        RV R24      h)a)  Estimate the fundamental matrix from pixel correspondences with the 8-, 7-point or affine algorithm.

``F = find_fundamental(points1, points2)`` takes correspondences ``(B, N, 2)``, ``N >= 8``, of the first and the
second image, in pixels or any other image coordinates, and returns the rank-2 matrix ``(B, 3, 3)`` with
:math:`x_2^\top F x_1 = 0` (the second image's point on the left) of the Hartley-normalized, optionally weighted,
8-point least-squares fit. ``method="7POINT"`` takes exactly seven correspondences and returns the three
candidates ``(B, 3, 3, 3)`` of the 7-point algorithm instead. ``method="AFFINE"`` takes ``N >= 4``
correspondences of two affine cameras (parallel projection, such as weak-perspective views of a distant scene)
and returns their affine fundamental matrix ``[[0, 0, a], [0, 0, b], [c, d, e]]``, the Gold Standard
(maximum-likelihood) fit of Hartley and Zisserman's algorithm 14.1. For calibrated cameras and normalized camera
coordinates, use :func:`find_essential`; for a planar scene or a camera that only rotates, where ``F`` is not
determined, :func:`~kornia.geometry.homography.find_homography_dlt`; with outliers,
:class:`~kornia.geometry.ransac.RANSAC`.

Convention:
    - :ref:`Two-view geometry <two-view-conventions>` maps the argument order onto OpenCV.
    - The result is scaled so that ``F[2, 2] = 1`` by :func:`normalize_transformation`, which leaves it at its
      unnormalised scale when ``F[2, 2]`` is numerically zero, as for exactly rectified stereo.
      ``method="7POINT"`` returns three candidates in no particular order.
    - ``weights`` weight each correspondence's equation in the linear system (for ``"AFFINE"``, its squared
      distance): only their ratios matter, a negative weight counts as zero, and ``method="7POINT"`` ignores them.
    - ``"AFFINE"`` fits and returns the affine form exactly; it computes in float64 (float32 on MPS and for
      half-precision input). A float16 result whose entries ``F[2, 2] = 1`` would put above float16's maximum
      (``e`` near 0, as for points centred on the origin) is scaled to its largest entry 1 instead. A batch
      element with a non-finite point or weight gets a NaN matrix, and the others are unaffected.
    - When the 7-point cubic has one real root, the two extra ``"7POINT"`` candidates are zero matrices.
    - A caller's autocast region does not change the fit.

.. note::
    On MPS, ``method="8POINT"`` needs torch 2.14 or later (2.7 for exactly eight correspondences without
    weights), ``"7POINT"`` needs torch 2.7 or later, and ``"AFFINE"`` runs from torch 2.5.1; see
    :ref:`MPS linear algebra <mps-linear-algebra>`.

Args:
    points1: A set of points in the first image with a tensor shape ``(B, N, 2)``: :math:`N \ge 8` for
        ``"8POINT"``, exactly 7 for ``"7POINT"``, :math:`N \ge 4` for ``"AFFINE"``.
    points2: A set of points in the second image with the shape of ``points1``.
    weights: Tensor containing the weights per point correspondence with a shape of ``(B, N)``.
    method: The method to use for computing the fundamental matrix: "8POINT", "7POINT" or "AFFINE".

Returns:
    the computed fundamental matrix with shape ``(B, 3, 3)`` for ``"8POINT"`` and ``"AFFINE"``, and
    ``(B, 3, 3, 3)`` for ``"7POINT"``.

Raises:
    ValueError: If an invalid method is provided.

See Also:
    - :func:`find_essential`: the model of calibrated cameras, from normalized camera coordinates.
    - :func:`~kornia.geometry.homography.find_homography_dlt`: a homography, the model of a plane or of a
      rotating camera.
    - :class:`~kornia.geometry.ransac.RANSAC`: one fundamental matrix, robust to wrong correspondences.
    - :func:`sampson_epipolar_distance`: the residual of correspondences under the result.
    - :func:`fundamental_from_essential`: a fundamental matrix from an essential matrix and both intrinsics.

r›  rš  rœ  zInvalid method: z8. Supported methods are '7POINT', '8POINT' and 'AFFINE'.)Úupperrr  rƒ  r—  Ú
ValueError)rg  rh  r   r™  Úresults   &&&& r   Úfind_fundamentalr¡  Ö  s‚   € ð| ‡|�|ƒ~˜Ô!Ü˜GÓ-ˆð €Mð 
�‰‹˜8Ô	#Ü˜G¨gÓ6ˆð
 €Mð	 
�‰‹˜8Ô	#Ü˜G¨gÓ6ˆð €Mô Ð+¨F¨8Ð3kÐlÓmÐmr!   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   r   ÚF_matr   rk   )r   s   "r   r    r      s2   € ÷ 9Pñ 9P¬¯©ð 9P¼U¿\¹\ð 9PÌeÏlÉlñ 9Pr!   c                ó’  € \        V . RO4       V P                  R	,          ^8X  d   \        V 4      pMUV P                  R	,          ^8X  d   T pM:\        R\	        V P                  4       R2\	        V P                  4      . R
OR7      h\        V. RO4       \
        P                  ! VP                  VP                  4      p\
        P                  ! \        V4      RR	R7      p\        V4      V,          p\
        P                  ! VR^R7      w  rVpWU,          Wf,          ,           p\
        P                  ! VR8„  R\
        P                  ! V4      ,          \
        P                  ! V4      4      pWH,          p	\
        P                  ! V	RR	R7      p	V\
        P                  \
        P                  39   d   V	P!                  V4      # T	# )aë  Compute the epipolar lines of points in the other image, scaled to a unit normal.

``lines = compute_correspond_epilines(points, F_mat)`` takes points ``(*, N, 2)``, or homogeneous
``(*, N, 3)``, and fundamental matrices ``(*, 3, 3)``, and returns the lines :math:`F x` as ``(a, b, c)`` with
:math:`ax + by + c = 0`, ``(*, N, 3)``, scaled to :math:`a^2 + b^2 = 1` so that :math:`|ax + by + c|` is the
distance of a point to them. For first-image points and an ``F`` from :func:`find_fundamental` the lines lie in
the second image; for second-image points pass ``F.transpose(-2, -1)``. For the distance of the matching points
to these lines, use :func:`left_to_right_epipolar_distance`.

Convention:
    - As OpenCV's ``computeCorrespondEpilines`` with ``whichImage=1``; see
      :ref:`two-view geometry <two-view-conventions>`. A line with :math:`a = b = 0` is returned unscaled.

Args:
    points: tensor containing the set of points to project in the shape of ``(*, N, 2)`` or ``(*, N, 3)``.
    F_mat: the fundamental to use for projection the points in the shape of ``(*, 3, 3)``.

Returns:
    a tensor with shape ``(*, N, 3)`` containing the epipolar lines :math:`F x` of the points.
    Each line is described as
    :math:`ax + by + c = 0` and encoding the vectors as :math:`(a, b, c)`.

See Also:
    - :func:`left_to_right_epipolar_distance`: the distance of each second-image point to these lines.
    - :func:`get_closest_point_on_epipolar_line`: the point of each line nearest to the matching point.

z3points must have shape (*, N, 2) or (*, N, 3), got r#   r&   )Údim0r¬   rm   r/   r6   )r_   r%   ÚDIMr7   )r_   r%   ú2 or 3©r_   Ú3r©  ru   )r   r>   r   r   r?   r   rA   r5   rv  r	   rv   rD   rJ   rF   r‹  Úbfloat16rC   )
r   r£  Úpoints_hr5   Úlinesrý   rþ   rN   ÚnuÚlines
   &&        r   Úcompute_correspond_epilinesr¯    sU  € ô8 �vÒ0Ô1Ø‡|�|�BÕ˜1ÔÜ!>¸vÓ!F‰Ø	�‰�bÕ	˜QÔ	Ø‰äØAÄ$ÀvÇ|Á|ÓBTÐAUÐUVÐWÜ˜fŸl™lÓ+Ú/ô
ð 	
ô
 �ušoÔ.ô ×Ò §¡°·±Ó<€Eä�ŠÔ0°Ó:ÀÈ"ÔM€HÜ˜eÓ$ xÕ/€EÜ�kŠk˜% R°Ô2�G€Aˆ!ð •u˜q�u•}€BÜ	�Š�R˜#‘X˜s¤U§Z¢Z°£^Õ3´U·_²_ÀRÓ5HÓ	I€Bð �:€DÜ�?Š?˜4 b¨rÔ2€DØ"¤u§}¡}´e·n±nÐ&EÔEˆ4�7‰7�5‹>ÐOÈ4ÐOr!   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   r¬  r   r   rk   )r   s   "r   r    r    [  s-   € ÷ 'ñ 'œUŸ\™\ð '´5·<±<ð 'ÄEÇLÁLñ 'r!   c                ó  € \        V . RO4       \        V. ROR4       VP                  ^,          ^8X  d   \        V4      pMUVP                  ^,          ^8X  d   TpM:\        R\	        VP                  4       R2\	        VP                  4      . R	OR7      hV \
        P                  ! . R
OV P                  V P                  R7      P                  ^^^4      ,          p\
        P                  P                  W#^R7      pV# )a~  Compute the line through each point that is perpendicular to a given line.

``perp = get_perpendicular(lines, points)`` takes lines ``(B, N, 3)`` as ``(a, b, c)`` with
:math:`ax + by + c = 0` and points ``(B, N, 2)``, or homogeneous ``(B, N, 3)``, paired by index, and returns the
line ``(B, N, 3)`` through each point perpendicular to its line, :math:`(-b, a, bx - ay)` for the point
:math:`(x, y)`. :func:`get_closest_point_on_epipolar_line` intersects it with the epipolar line; for that point
directly, use that function.

Args:
    lines: tensor containing the set of lines ``(B, N, 3)``.
    points:  tensor containing the set of points ``(B, N, 2)``.

Returns:
    a tensor with shape ``(B, N, 3)`` containing a vector of the epipolar
    perpendicular lines. Each line is described as
    :math:`ax + by + c = 0` and encoding the vectors as :math:`(a, b, c)`; the normal :math:`(a, b)` has the
    norm of the input line's and is not rescaled.

See Also:
    - :func:`get_closest_point_on_epipolar_line`: the foot of this perpendicular on an epipolar line.
    - :func:`compute_correspond_epilines`: the epipolar lines to pass as ``lines``.

z.points must have shape (B, N, 2) or (B, N, 3).z3points must have shape (B, N, 2) or (B, N, 3), got r#   r&   r«   r1   )r_   r%   r©  ©r$   r%   ÚD©r$   r%   r§  )r<   r<   r;   )r   r>   r   r   r?   r   r  r5   r4   rK   r“   r”   )r¬  r   r«  Úinfinity_pointÚperps   &&   r   Úget_perpendicularr·  [  sÎ   € ô0 �ušoÔ.ä�všÐ0`ÔaØ‡|�|�A…˜!ÔÜ!>¸vÓ!F‰Ø	�‰�a�˜AÔ	Ø‰äØAÄ$ÀvÇ|Á|ÓBTÐAUÐUVÐWÜ˜fŸl™lÓ+Ú/ô
ð 	
ð
 œUŸ\š\ª)¸5¿;¹;ÈuÏ|É|Ô\×aÑaÐbcÐefÐhiÓjÕj€NÜŸ™×+Ñ+¨HÈ!Ð+ÓL€DØ€Kr!   c                ó˜   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  /# ©r   Úpts1Úpts2ÚFmr   rk   )r   s   "r   r    r    …  sD   € ÷ /Cñ /C¬U¯\©\ð /CÄÇÁð /CÔSX×S_ÑS_ð /CÔdi×dpÑdpñ /Cr!   c                óÂ  € \        V\        P                  4      '       g   \        R\	        V4       24      h\        VP                  4      ^8  g   VP                  RR R	8X  g   \        RVP                   24      h\        V. R
OR4       VP                  ^,          R9  d;   \        R\        VP                  4       R2\        VP                  4      . ROR7      h\        P                  P                  4       '       d   \        WV4      # \        VP                  P                  4      ;_uu_ 4        \        WV4      uuRRR4       #   + '       g   i     R# ; i)a÷  Move each second-image point to the nearest point of the epipolar line of its first-image match.

``points = get_closest_point_on_epipolar_line(pts1, pts2, Fm)`` takes first- and second-image points
``(B, N, 2)``, or homogeneous ``(B, N, 3)``, and fundamental matrices ``(B, 3, 3)`` in the
:math:`x_2^\top F x_1 = 0` order of :func:`find_fundamental`, and returns, in the second image, the orthogonal
projection ``(B, N, 2)`` of each ``pts2`` onto the epipolar line :math:`F x_1` of its ``pts1``. Only the
second-image points move. For the distance between the two, use :func:`left_to_right_epipolar_distance`.

Convention:
    - ``Fm`` and ``pts2`` take the dtype of ``pts1``. A caller's autocast region does not change the result,
      outside TorchScript.

Args:
    pts1: points in the first image with shape ``(B, N, 2)`` or ``(B, N, 3)``. If they are not
          homogeneous, converted automatically.
    pts2: points in the second image with shape ``(B, N, 2)`` or ``(B, N, 3)``. If they are not
          homogeneous, converted automatically.
    Fm: Fundamental matrices with shape ``(B, 3, 3)``. Called Fm to avoid ambiguity with torch.nn.functional.

Returns:
    point on epipolar line ``(B, N, 2)``.

See Also:
    - :func:`left_to_right_epipolar_distance`: the distance from each ``pts2`` to the returned point.
    - :func:`compute_correspond_epilines`: the epipolar lines the points are projected onto.
    - :func:`get_perpendicular`: the perpendicular through ``pts2`` that this intersects with the line.

z#Fm type is not a torch.Tensor. Got Nz#Fm must be a (*, 3, 3) tensor. Got z,pts2 must have shape (B, N, 2) or (B, N, 3).z1pts2 must have shape (B, N, 2) or (B, N, 3), got r#   r&   ru   )rs   rs   r²  )r   rs   r´  )Ú
isinstancer   r   Ú	TypeErrorrx   rb   r>   rŸ  r   r   r?   ÚjitÚis_scriptingÚ#_get_closest_point_on_epipolar_liner
   r4   )rº  r»  r¼  s   &&&r   Ú"get_closest_point_on_epipolar_linerÃ  …  s  € ô: �bœ%Ÿ,™,×'Ò'ÜÐ=¼dÀ2»h¸ZÐHÓIÐIÜˆB�H‰H‹˜Ô "§(¡(¨2¨3 -°6Ô"9ÜÐ>¸r¿x¹x¸jÐIÓJÐJä�tš_Ð.\Ô]Ø‡z�z�!…}˜FÔ"ÜØ?ÄÀTÇZÁZÓ@PÐ?QÐQRÐSÜ˜dŸj™jÓ)Ú/ô
ð 	
ô ‡y�y×Ñ×ÒÜ2°4¸rÓBÐBÜ	˜BŸI™IŸN™N×	+Õ	+Ü2°4¸rÓB÷ 
,×	+×	+Ó	+ús   Ä6EÅE	c                ó˜   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  /# r¹  rk   )r   s   "r   r    r    ·  sD   € ÷ Vñ V¬e¯l©lð VÄ%Ç,Á,ð VÔTY×T`ÑT`ð VÔej×eqÑeqñ Vr!   c                 óz  € VP                  V P                  4      pVP                  V P                  4      pV P                  R,          ^8X  d   \        V 4      p VP                  R,          ^8X  d   \        V4      p\	        W4      p\        W14      p\        \        P                  P                  W4^R7      4      # )r<   r1   r7   )
rC   r5   r>   r   r¯  r·  r   r   r“   r”   )rº  r»  r¼  Úline1in2r¶  s   &&&  r   rÂ  rÂ  ·  s�   € ð 
�‰ˆt�z‰zÓ	€BØ�7‰7�4—:‘:Ó€DØ‡z�z�"…~˜ÔÜ,¨TÓ2ˆØ‡z�z�"…~˜ÔÜ,¨TÓ2ˆÜ*¨4Ó4€HÜ˜XÓ,€DÜ*¬5¯<©<×+=Ñ+=¸hÐRSÐ+=Ó+TÓUÐUr!   c                ó˜   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  /# )r   ÚE_matÚK1ÚK2r   rk   )r   s   "r   r    r    Å  sA   € ÷ /Rñ /R¤e§l¡lð /R¼¿¹ð /RÌ%Ï,É,ð /RÔ[`×[gÑ[gñ /Rr!   c           
     óR  € \        V . RO4       \        V. RO4       \        V. RO4       \        V P                  RR 4      \        VP                  RR 4      u;8X  d   \        VP                  RR 4      8X  gQ   M \        R\	        V P                  4       R\	        VP                  4       R\	        VP                  4       R24      hV P
                  p\        \        V4      4      w  rE\        \        V4      4      w  rgVP                  RR	4      \        V 4      ,          V,          pWW,          R
,          p	\        P                  ! W˜\        P                  ! V\        R4      4      4      pV\        P                  \        P                  39   d   VP                  V4      # T# )a˜  Convert an essential matrix and the intrinsics of its two cameras to their fundamental matrix.

``F = fundamental_from_essential(E_mat, K1, K2)`` takes an essential matrix ``(*, 3, 3)`` with
:math:`x_2^\top E x_1 = 0` in normalized camera coordinates and the pixel intrinsics ``(*, 3, 3)`` of the
first and the second camera, all with the same number of dimensions, and returns
:math:`F = K_2^{-\top} E K_1^{-1}`, ``(*, 3, 3)``, for which :math:`x_2^\top F x_1 = 0` in pixels (Hartley and
Zisserman, 9.6, p. 257, eq. 9.12). A batch element with a singular camera matrix is NaN. For the reverse, use
:func:`essential_from_fundamental`.

Convention:
    - ``K1`` is the camera of the first image, so ``F`` follows the :math:`x_2^\top F x_1 = 0` order of
      :func:`find_fundamental`; it keeps the scale of ``E_mat``, with no ``F[2, 2] = 1`` normalisation.

Args:
    E_mat: The essential matrix with shape of ``(*, 3, 3)``.
    K1: The camera matrix from first camera with shape ``(*, 3, 3)``.
    K2: The camera matrix from second camera with shape ``(*, 3, 3)``.

Returns:
    The fundamental matrix with shape ``(*, 3, 3)``.

See Also:
    - :func:`essential_from_fundamental`: the reverse conversion, :math:`E = K_2^\top F K_1`.
    - :func:`fundamental_from_projections`: a fundamental matrix from two projection matrices instead.
    - :func:`find_fundamental`: a fundamental matrix fitted to pixel correspondences directly.

NzSE_mat, K1 and K2 must have shape (*, 3, 3) with the same number of dimensions, got z, ú and r#   r‡  r¨  ru   r7   rk  )r   rb   r>   r   r?   r5   r   r	   rv  r   rD   r¸   r   r‹  rª  rC   )
rÈ  rÉ  rÊ  r5   ÚK1_invÚvalid1ÚK2_invÚvalid2r£  r
  s
   &&&       r   Úfundamental_from_essentialrÑ  Å  sI  € ô8 �ušoÔ.Ü�rš?Ô+Ü�rš?Ô+Üˆu�{‰{˜3˜BÐÓ ¤C¨¯©°°"¨Ó$6ÖL¼#¸b¿h¹hÀsÈ¸mÓ:LÖLÜðÜ˜Ÿ™Ó$Ð% R¬¨R¯X©X«Ð'7°u¼TÀ"Ç(Á(»^Ð<LÈAðOó
ð 	
ð �K‰K€EÜ+Ô,=¸bÓ,AÓB�N€FÜ+Ô,=¸bÓ,AÓB�N€FØ×Ñ˜R Ó$Ô'8¸Ó'?Õ?À&ÕH€Eð �_˜oÕ.€EÜ�KŠK˜¤e§o¢o°e¼UÀ5»\Ó&JÓK€EØ#¬¯©´u·~±~Ð'FÔFˆ5�8‰8�E‹?ÐQÈEÐQr!   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   ÚP1ÚP2r   rk   )r   s   "r   r    r    ü  s2   € ÷ Pñ P¤U§\¡\ð P´u·|±|ð PÌÏÉñ Pr!   c                ó¦  € \        V . R
O4       \        V. R
O4       V P                  RR VP                  RR 8w  d9   \        R\        V P                  4       R\        VP                  4       R24      hR R lpV P                  pV\
        P                  \
        P                  39  d?   V P                  \
        P                  4      p VP                  \
        P                  4      pV R,          pV! V R,          V R,          4      pV R,          pVR,          pV! VR,          VR,          4      pVR,          p	V! WG4      V! WW4      V! Wg4      rËp
V! WH4      V! WX4      V! Wh4      rþpV! WI4      V! WY4      V! Wi4      ppp\
        P                  ! V
P                  4       P                  R^4      VP                  4       P                  R^4      VP                  4       P                  R^4      VP                  4       P                  R^4      VP                  4       P                  R^4      VP                  4       P                  R^4      VP                  4       P                  R^4      VP                  4       P                  R^4      VP                  4       P                  R^4      .	^R7      pVP                  ! . V P                  RR O^N^N5!  pV\
        P                  8X  dX   VP                  4       P                  RRR	7      pV\
        P                   ! V^ 8„  V\
        P"                  ! V4      4      ,          pVP                  V4      # )aû  Compute the fundamental matrix of two cameras from their 3x4 projection matrices.

``F = fundamental_from_projections(P1, P2)`` takes the projection matrices ``(*, 3, 4)`` of the first and the
second camera, with the same leading dimensions, and returns their fundamental matrix ``(*, 3, 3)``, for which
:math:`x_2^\top F x_1 = 0` in the image coordinates of ``P1`` and ``P2``: the order of :func:`find_fundamental`.
Each entry is a 4x4 determinant of two rows of each matrix. For a canonical camera pair of a fundamental matrix,
the other way round, use :func:`projections_from_fundamental`; for calibrated cameras given by their poses,
:func:`essential_from_Rt`.

Convention:
    - It is not normalised, and for ``P1 = [I | 0]``, ``P2 = [R | t]`` it is the negative of
      :func:`essential_from_Rt` for the same motion.
    - float16 and bfloat16 inputs are computed in float32. A float16 ``F`` is then divided by its largest
      absolute entry before the cast back, because pixel-unit projection matrices give entries of order ``1e10``,
      above float16's maximum of 65504; an all-zero ``F`` (coincident camera centres) stays zero. bfloat16 has
      float32's exponent range and is cast back unnormalised.

Args:
    P1: The projection matrix from first camera with shape ``(*, 3, 4)``.
    P2: The projection matrix from second camera with shape ``(*, 3, 4)``.

Returns:
     The fundamental matrix with shape ``(*, 3, 3)``.

See Also:
    - :func:`projections_from_fundamental`: a canonical camera pair of a fundamental matrix, the reverse up to
      a projective transformation.
    - :func:`essential_from_Rt`: the calibrated counterpart, from two camera poses.
    - :func:`fundamental_from_essential`: a fundamental matrix from an essential matrix and both intrinsics.
NzCP1 and P2 must have shape (*, 3, 4) with the same batch shape, got rÌ  r#   c                óx   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  /# )r   ÚxÚyr   rk   )r   s   "r   r    Ú2fundamental_from_projections.<locals>.__annotate__"  s-   € ÷ )ñ )”%—,‘,ð )¤5§<¡<ð )´E·L±Lñ )r!   c                 ó4   € \         P                  ! W.RR7      # )r   r1   ru   )r   rw   )r×  rØ  s   &&r   ÚvstackÚ,fundamental_from_projections.<locals>.vstack"  s   € Ü�yŠy˜!˜ RÔ(Ð(r!   r1   Tr)   )r_   r©  Ú4ru   ).r)  rt   ).rr   rt   ).rp   rt   ).r,   rt   r7   r°   )r   r>   r   r?   r5   r   rB   r¥   rC   rw   rL  r‡   rK   r‹  rc   rŒ  rD   rF   )rÓ  rÔ  rÛ  Úinput_dtypeÚX1ÚX2ÚX3ÚY1ÚY2ÚY3ÚX1Y1ÚX2Y1ÚX3Y1ÚX1Y2ÚX2Y2ÚX3Y2ÚX1Y3ÚX2Y3ÚX3Y3ÚF_vecr©   rX   s   &&                    r   Úfundamental_from_projectionsrï  ü  s©  € ô> �rš?Ô+Ü�rš?Ô+Ø	‡x�x��€}˜Ÿ™  "˜Ô%ÜØQÔRVÐWY×W_ÑW_ÓR`ÐQaÐafÔgkÐln×ltÑltÓguÐfvÐvwÐxó
ð 	
õ)ð —(‘(€KØœ5Ÿ=™=¬%¯-©-Ð8Ô8Ø�U‰U”5—=‘=Ó!ˆØ�U‰U”5—=‘=Ó!ˆà	ˆJ�€BÙ	��;•  K¥Ó	1€BØ	ˆJ�€Bà	ˆJ�€BÙ	��;•  K¥Ó	1€BØ	ˆJ�€Bá˜b“~¡v¨b£~±v¸b³~�€DÙ˜b“~¡v¨b£~±v¸b³~�€DÙ˜b“~¡v¨b£~±v¸b³~�ˆ$€Dä�IŠIà�H‰H‹J×Ñ˜r 1Ó%Ø�H‰H‹J×Ñ˜r 1Ó%Ø�H‰H‹J×Ñ˜r 1Ó%Ø�H‰H‹J×Ñ˜r 1Ó%Ø�H‰H‹J×Ñ˜r 1Ó%Ø�H‰H‹J×Ñ˜r 1Ó%Ø�H‰H‹J×Ñ˜r 1Ó%Ø�H‰H‹J×Ñ˜r 1Ó%Ø�H‰H‹J×Ñ˜r 1Ó%ð
	
ð ô€Eð 	�
Š
Ð(�B—H‘H˜S˜b�MÐ( 1Ð( aÓ(€Aà”e—m‘mÔ#à—‘“—‘ °4�Ó8ˆØ”—’˜E A™I u¬e¯oªo¸eÓ.DÓEÕEˆà�4‰4�ÓÐr!   )ç:Œ0âŽyE>N)rð  )NrÛ   ró   )Nrš  )9Ú__doc__rI   Útypingr   r   r   r   r   Úkornia.core.checkr   r   Úkornia.core.exceptionsr   Úkornia.core.utilsr	   r
   r   r   r   r   r   Úkornia.geometry.conversionsr   r   Ú#kornia.geometry.solvers.homogeneousr   r   Ú)kornia.geometry.solvers.polynomial_solverr   r[   rg   r~   rŠ   r¡   r¦   rÚ   rÞ   rß   rç   rì   rï   r  r  r  r%  r3  re  rr  rƒ  r—  r¡  r¯  r·  rÃ  rÂ  rÑ  rï  © r!   r   Ú<module>rú     sç   ðñ$ `ã ß 2Ó 2ã ç IÝ -÷÷ ñ ÷ gß EÝ G÷X"÷v-õD=õ0$õfõDõ
.?ðh $'Ð  Ø+.Ð (õ.õ :õLõ"HõJqõ
õõ8"DõJHõV!a÷HU5÷pW÷tFõR9Põx'õT/CõdVõ/R÷nPr!   