+
    åûj?  ã                  ó˜   a € 0 t $ R t^ RIHt ^ RIt^ RIHt ^ RIHtH	t	H
t
Ht ^ RIHt RtR]R&   R	 R
 ltR R ltRR R lltR R ltR# )z0Triangulate 3D points from two views by the DLT.)ÚannotationsN)ÚKORNIA_CHECK_SHAPE)Ú_autocast_disabledÚ _normalize_to_float32_or_float64Ú_torch_svd_castÚis_mps_tensor_safe)Úconvert_points_from_homogeneousi`m  ÚintÚ_CUSOLVER_EIGH_BATCH_LIMITc               ó    € V ^8„  d   QhRRRR/# )é   ÚMútorch.TensorÚreturn© )Úformats   "ÚbC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\epipolar\triangulation.pyÚ__annotate__r   (   s   € ÷ #ñ #˜,ð #¨<ñ #ó    c           	     ó|  € V P                   ^ ,          pV\        8:  d+   \        P                  P	                  V 4      w  r#VR,          # \        ^ V\        4       Uu. uF=  p\        P                  P	                  WV\        ,            4      ^,          R,          NK?  	  pp\        P                  ! V^ R7      # u upi )a  Return the eigenvector for the smallest eigenvalue of each symmetric matrix.

Handles cuSOLVER's batch-size limit by chunking when necessary.

Args:
    M: batch of symmetric PSD matrices, shape ``(N, k, k)``.

Returns:
    Eigenvectors of shape ``(N, k)``.
©Údim).é    )Úshaper
   ÚtorchÚlinalgÚeighÚrangeÚcat)r   ÚNÚ_ÚVÚiÚpartss   &     r   Ú_eigh_smallest_vecr$   (   s¥   € ð 	
�‰��
€AØÔ&Ô&Ü�|‰|× Ñ  Ó#‰ˆØ��yÐô �q˜!Ô7Ô8óá8ˆAô 	�‰×Ñ˜! Ô$>Õ >Ð?Ó@ÀÕCÀF×KÐKÙ8ð 
ð ô �9Š9�U Ô"Ð"ùò	s   ÁAB9c               ó    € V ^8„  d   QhRRRR/# )r   ÚAr   r   r   )r   s   "r   r   r   ?   s   € ÷ #ñ # ð #°ñ #r   c           	     ó‚  aa€ V R,          oV R,          oR VV3R llpV! ^ ^4      V! ^ ^4      V! ^ ^4      V! ^^4      V! ^^4      V! ^^4      3w  r#rErg\         P                  ! V R,          V R,          .RR7      P                  R	4      w  r‰r«\         P                  ! Wy,          Wj,          ,
          W[,          ,           V) V,          WJ,          ,           W;,          ,
          Wh,          WI,          ,
          W+,          ,           V) V,          W9,          ,           W*,          ,
          .R	R7      pVP                  RR
4      # )aÀ  Return the null vectors of the four :math:`3 \times 4` sub-systems of each :math:`4 \times 4` matrix.

Row ``j`` of the result is orthogonal to every row of ``A`` but row ``3 - j`` (sub-systems ``{0, 1, 2}``,
``{0, 1, 3}``, ``{0, 2, 3}``, ``{1, 2, 3}``); up to sign it is the column of the adjugate of ``A`` for the
row left out, the vector of :math:`3 \times 3` minors that :func:`~kornia.geometry.solvers.null_vector_3x4`
returns. The minors are expanded along the ``2 x 2`` minors of the row pairs ``(0, 1)`` and ``(2, 3)``, which
all four share: the Hodge dual of one pair's bivector applied to each row of the other pair. These are the
columns of :func:`kornia.core._small_linalg._adjugate_4x4` in fewer, wider kernels, about half its time for a
million matrices on the CPU and on MPS.

Args:
    A: batch of matrices, shape ``(*, 4, 4)``.

Returns:
    The four null vectors, shape ``(*, 4, 4)``, not normalised: a sub-system of rank below 3 gives zero.
c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úpr	   Úqr   r   r   )r   s   "r   r   Ú._sub_system_null_vectors.<locals>.__annotate__S   s!   € ÷ =ñ =�ð =˜ð = ñ =r   c                óz   <€ SR V 3,          SR V3,          ,          SR V3,          SR V 3,          ,          ,
          # ).r   )r)   r*   ÚPÚQs   &&€€r   ÚminorÚ'_sub_system_null_vectors.<locals>.minorS   s8   ø€ Ø��a��y˜1˜S !˜V�9Õ$ q¨¨a¨¥y°1°S¸!°Vµ9Õ'<Õ<Ð<r   r   ).:r   Nr   NºNNN).:é   Nr   Nr1   ).:r   NNr1   ).:Nr   Nr1   éýÿÿÿéÿÿÿÿéþÿÿÿ)r   ÚstackÚunbindÚflatten)r&   r/   Ús01Ús02Ús03Ús12Ús13Ús23Úx0Úx1Úx2Úx3Úhr-   r.   s   &            @@r   Ú_sub_system_null_vectorsrD   ?   s  ù€ ð" 	
Ð
Õ€AØ	Ð
Õ€A÷=ñ =ñ $)¨¨A£;±°a¸³¹UÀ1Àa»[É%ÐPQÐSTË+ÑW\Ð]^Ð`aÓWbÑdiÐjkÐmnÓdoÐ#oÑ €Cˆc˜ä—[’[ ! J¥-°°:µÐ!?ÀRÔH×OÑOÐPRÓS�N€BˆBÜ�Šà�H�s•xÕ #¥(Õ*ØˆD�2�I˜�Õ  3¥8Õ+Ø�H�s•xÕ #¥(Õ*ØˆD�2�I˜�Õ  3¥8Õ+ð		
ð ô	€Að �9‰9�R˜ÓÐr   c               ó0   € V ^8„  d   QhRRRRRRRRRRRR/# ©	r   ÚP1r   ÚP2Úpoints1Úpoints2ÚsolverÚstrr   r   )r   s   "r   r   r   e   sT   € ÷ [Eñ [EØð[Eàð[Eð ð[Eð ð	[Eð
 ð[Eð ñ[Er   c           	     ó  € \        V . RO4       \        V. RO4       \        V. RO4       \        V. RO4       \        V P                  P                  4      ;_uu_ 4        \	        WW#V4      uuRRR4       #   + '       g   i     R# ; i)uÙ  Triangulate 3D points from their projections in two views by the linear DLT.

``points3d = triangulate_points(P1, P2, points1, points2)`` takes the projection matrices ``(*, 3, 4)`` of two
cameras and matched points ``(*, N, 2)`` in their image coordinates and returns the Euclidean 3D points
``(*, N, 3)`` in the frame that ``P1`` and ``P2`` map from: the world frame for ``P = K [R | t]`` from
:func:`projection_from_KRt`, and the frame of camera 1 for ``P1 = K1 [I | 0]``. Each point is the least-squares
null vector of its four DLT equations (Hartley and Zisserman, 12.2, p. 312) with ``solver="svd"`` or ``"eigh"``,
and its approximation by one step of inverse iteration with ``"cofactor"``. The correspondences are assumed to be
inliers: there is no robust estimation and no cheirality check. For the relative pose of two calibrated cameras
together with the points, use :func:`motion_from_essential_choose_solution`.

Convention:
    - ``P1`` pairs with ``points1`` and ``P2`` with ``points2``. Input and output points are Euclidean;
      :ref:`Two-view geometry <two-view-conventions>` maps this onto OpenCV. The leading
      dimensions of ``P1`` and ``P2`` broadcast against those of the points.
    - Cheirality and baseline are not checked: a point behind a camera is returned with negative depth, and with
      zero baseline the depth is undefined: ``"svd"`` and ``"eigh"`` return an arbitrary point on the line of
      sight, possibly behind the camera or at infinity (NaN), and ``"cofactor"`` returns NaN.
    - A correspondence at infinity, whose homogeneous ``w`` is at the roundoff of the input and compute dtypes,
      returns NaN. In float16 and bfloat16 that roundoff also covers a point a few tens of units away in the
      scale of ``t``. Mask those rows before a loss (``out[~out.isnan().any(-1)]``); the gradients with respect
      to the cameras and the other points stay finite.
    - ``"svd"`` and ``"eigh"`` solve in float64, or in float32 for float16 and bfloat16 input and on MPS;
      ``"cofactor"`` solves in float32, or in float64 for float64 input. All return the input dtype;
      ``solver`` below compares their accuracy.
    - A caller's autocast region does not change the result.

Args:
    P1: The projection matrix for the first camera with shape ``(*, 3, 4)``.
    P2: The projection matrix for the second camera with shape ``(*, 3, 4)``.
    points1: The set of points seen from the first camera, in the image coordinates of ``P1`` (pixels
      for ``P1 = K [R | t]``), with shape ``(*, N, 2)``.
    points2: The set of points seen from the second camera, in the image coordinates of ``P2`` (pixels
      for ``P2 = K [R | t]``), with shape ``(*, N, 2)``.
    solver: Back-end used to find the null vector of the :math:`4 \times 4` DLT
      constraint matrix. One of:

      * ``"svd"`` â€” most numerically stable. Uses a full SVD. Suitable when
        maximum accuracy is required regardless of speed.
      * ``"eigh"`` *(default)* â€” forms :math:`X^\top X` and finds the eigenvector
        for its smallest eigenvalue via :func:`torch.linalg.eigh`. Algebraically
        equivalent to the SVD solution, and equal to it to roundoff on well-conditioned
        input; forming :math:`X^\top X` squares the singular values, so on ill-conditioned
        rows, such as a baseline much shorter than the depth, it loses accuracy that
        ``"svd"`` keeps. Typically **10-26x
        faster** than ``"svd"`` on GPU for large batches.
      * ``"cofactor"`` â€” closed form, no LAPACK call. The null vectors of the four
        :math:`3 \times 4` sub-systems (the cofactors, as in
        :func:`~kornia.geometry.solvers.null_vector_3x4`) form the adjugate of the
        DLT matrix; the longest one, refined by one step of inverse iteration through
        the adjugate, gives the ``"svd"`` point to roundoff without noise and nearly
        the same point with noise, also for rectified and vertical stereo pairs, where
        a sub-system is nearly rank-deficient. When the noise is comparable to the
        parallax, so that the DLT point itself is far off, one step does not converge
        and the two can differ. The point is NaN when every sub-system is
        rank-deficient (zero baseline). Fastest option for large batches.

Returns:
    The reconstructed 3d points in the world frame with shape ``(*, N, 3)``.

See Also:
    - :func:`motion_from_essential_choose_solution`: the relative pose from an essential matrix, with the points
      triangulated in the frame of camera 1.
    - :func:`projection_from_KRt`: the projection matrices to pass, from intrinsics and poses.
    - :func:`~kornia.geometry.solvers.null_vector_3x4`: the cofactor null vector that ``"cofactor"`` builds on.

Example:
    >>> P1 = torch.eye(3, 4)[None]   # 1x3x4
    >>> P2 = torch.eye(3, 4)[None]
    >>> P2[..., 0, 3] = -1.0  # second camera shifted along x
    >>> pts1 = torch.rand(1, 5, 2)
    >>> pts2 = torch.rand(1, 5, 2)
    >>> pts3d = triangulate_points(P1, P2, pts1, pts2)
    >>> pts3d.shape
    torch.Size([1, 5, 3])

N)Ú*Ú3Ú4)rN   r   Ú2)r   r   ÚdeviceÚtypeÚ_triangulate_points)rG   rH   rI   rJ   rK   s   &&&&&r   Útriangulate_pointsrU   e   s]   € ôh �rš?Ô+Ü�rš?Ô+Ü�w¢Ô0Ü�w¢Ô0ô 
˜BŸI™IŸN™N×	+Õ	+Ü" 2¨7¸VÓD÷ 
,×	+×	+Ó	+ús   Á A8Á8B		c               ó0   € V ^8„  d   QhRRRRRRRRRRRR/# rF   r   )r   s   "r   r   r   Ã   sD   € ÷ [ñ [Øð[Ø&ð[Ø1=ð[ØHTð[Ø^að[àñ[r   c           
     ó*  € VR,          V R,          ,          V R,          ,
          pVR,          V R,          ,          V R,          ,
          pVR,          VR,          ,          VR,          ,
          pVR,          VR,          ,          VR,          ,
          p\         P                  ! WVWx4      w  rVrx\        V4      '       d   \         P                  p	MEVP                  \         P                  8X  d   \         P
                  p	M\        VP                  4      p	VR8X  d4   \         P                  ! WVWx.RR7      p
\        V
4      w   r¼VR,          pEMhVR8X  d›   \         P                  ! WVWx.RR7      p
V
P                  RR pV
P                  V	4      pVP                  V,          pVP                  ^ R4      p\        V4      P                  V
P                  4      pVP                  ! . VO^N5!  pEMÇVR8X  Ed±   \        VP                  4      p	\         P                  ! V	4      P                   p\         P                  ! WVWx.RR7      P                  V	4      pVP#                  RR7      pVP%                  RRR7      P'                  V4      pVVR,          ,          VV,          pp\)        V4      pVP#                  RR7      pVP+                  RRR7      VP-                  R4      P'                  V4      ,          pVR\         P                  ! V	4      P.                  ,          V,          8„  P1                  RRR7      pVP3                  RRR7      R,          P4                  ! . VP                  RR O^N^N5!  pVP7                  RV4      P9                  R4      VP%                  RRR7      P'                  V4      ,          pVVR,          ,          P9                  R4      pVVP#                  RRR7      P'                  V4      ,          pVP                  VR,          ,          P9                  R4      pVVP#                  RRR7      P'                  V4      ,          p\         P:                  ! VV\         P<                  ! V\?        R	4      4      4      P                  VP                  4      pM\A        R
V R24      hVR8X  d   RMRpV\         P                  ! V	4      P.                  ,          R\         P                  ! VP                  4      P.                  ,          ,           p VR,          PC                  4       V VP#                  RRR7      ,          8*  p!\         P:                  ! V!\         P<                  ! V\?        R	4      4      V4      p\E        V4      p"V"# ).Úsvdr   r   NÚcofactorT)r   Úkeepdimg       @ÚnanzUnknown solver 'z*'. Choose from: 'svd', 'eigh', 'cofactor'.g      `@g      0@g      @).ºr   r2   N).:r   é   Nr1   ).r\   r1   ).ºr2   r   N).r^   r1   r5   r4   ).r4   r3   ).N).:r]   NN)#r   Úbroadcast_tensorsr   Úfloat32ÚdtypeÚfloat64r   r6   r   r   ÚtoÚmTr8   r$   ÚreshapeÚfinfoÚtinyÚnormÚamaxÚ	clamp_minrD   ÚprodÚflipÚepsÚanyÚargmaxÚexpandÚgatherÚsqueezeÚwhereÚ	full_likeÚfloatÚNotImplementedErrorÚabsr   )#rG   rH   rI   rJ   rK   Úrow0Úrow1Úrow2Úrow3Úcompute_dtypeÚXr    r!   Ú
points3d_hÚbatch_shapeÚX_castÚXTXÚflatÚv_flatrg   r&   Ú	row_normsÚscaleÚHÚh_normsÚsub_row_normsÚ	full_rankÚlongestÚcÚwÚvÚw_scaleÚw_tolÚat_infinityÚpoints3ds#   &&&&&                              r   rT   rT   Ã   sq  € ð
 �8Õ˜r +�Õ.°°KµÕ@€DØ�8Õ˜r +�Õ.°°KµÕ@€DØ�8Õ˜r +�Õ.°°KµÕ@€DØ�8Õ˜r +�Õ.°°KµÕ@€Dä"×4Ò4°TÀÓLÑ€D�ô ˜$×ÒÜŸ™‰Ø	�‰”u—}‘}Ô	$ÜŸ™‰ä8¸¿¹ÓDˆà�„Ü�KŠK˜ TÐ0°bÔ9ˆô
 " !Ó$‰ˆˆ1Ø�w•ZŠ
à	�6Ô	Ü�KŠK˜ TÐ0°bÔ9ˆð —g‘g˜c˜r�lˆØ—‘�mÓ$ˆØ�i‰i˜&Õ ˆØ�{‰{˜1˜bÓ!ˆÜ# DÓ)×,Ñ,¨Q¯W©WÓ5ˆØ—^’^Ð4 [Ð4°!Ó4Š
à	�:Õ	ô 9¸¿¹ÓDˆÜ�{Š{˜=Ó)×.Ñ.ˆÜ�KŠK˜ TÐ0°bÔ9×<Ñ<¸]ÓKˆà—F‘F˜r�F“Nˆ	Ø—‘ 2¨t�Ó4×>Ñ>¸tÓDˆØ˜5 Õ+Õ+¨Y¸Õ->ˆ9ˆÜ$ QÓ'ˆð —&‘&˜R�&“.ˆØ!Ÿ™¨2°t˜Ó<¸y¿~¹~ÈbÓ?Q×?[Ñ?[Ð\`Ó?aÕaˆØ˜s¤U§[¢[°Ó%?×%CÑ%CÕCÀmÕSÑS×XÑXÐ]_ÐimÐXÓnˆ	Ø—.‘. R°�.Ó6°yÕA×HÒHÐ]È!Ï'É'ÐRUÐSUÈ,Ð]ÐXYÐ]Ð[\Ó]ˆØ�H‰H�R˜Ó!×)Ñ)¨"Ó-°·±ÀÈT°Ó0R×0\Ñ0\Ð]aÓ0bÕbˆØ��9•Õ×&Ñ& rÓ*ˆØ�—‘˜2 t�Ó,×6Ñ6°tÓ<Õ<ˆØ�T‰T�A�i•LÕ ×)Ñ)¨"Ó-ˆØ�—‘˜2 t�Ó,×6Ñ6°tÓ<Õ<ˆÜ—[’[ ¨A¬u¯ª¸qÄ%ÈÃ,Ó/OÓP×SÑSÐTX×T^ÑT^Ó_‰
ô "Ð$4°V°HÐ<fÐ"gÓhÐhð
  Ô'‰e¨T€GØ”e—k’k -Ó0×4Ñ4Õ4°s¼U¿[º[È×IYÑIYÓ=Z×=^Ñ=^Õ7^Õ^€EØ˜WÕ%×)Ñ)Ó+¨u°z·±È2ÐW[°Ó7\Õ/\Ñ\€KÜ—’˜[¬%¯/ª/¸*ÄeÈEÃlÓ*SÐU_Ó`€Jä<¸ZÓH€HØ€Or   )r   )Ú__conditional_annotations__Ú__doc__Ú
__future__r   r   Úkornia.core.checkr   Úkornia.core.utilsr   r   r   r   Úkornia.geometry.conversionsr   r
   Ú__annotations__r$   rD   rU   rT   )r’   s   @r   Ú<module>r™      sJ   øðô$ 7å "ã å 0÷ó õ Hð #)Ð ˜CÓ (õ#õ.#÷L[E÷|[r   