
    3j%                        % S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	  SSK
Jr  SSKJr  SrS	\S
'   SS jr S           SS jjrg)z2Module with the functionalities for triangulation.    )annotationsN)KORNIA_CHECK_SHAPE) _normalize_to_float32_or_float64_torch_svd_castis_mps_tensor_safe)convert_points_from_homogeneous)null_vector_3x4i`m  int_CUSOLVER_EIGH_BATCH_LIMITc           	     N   U R                   S   nU[        ::  a&  [        R                  R	                  U 5      u  p#US   $ [        SU[        5       Vs/ s H1  n[        R                  R	                  XU[        -    5      S   S   PM3     nn[        R                  " USS9$ s  snf )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)``.
r   ).r      dim)shaper   torchlinalgeighrangecat)MN_Vipartss         `/home/wildlama/miniconda3/lib/python3.13/site-packages/kornia/geometry/epipolar/triangulation.py_eigh_smallest_vecr   $   s     	

A&&||  #y q!788A 	!$> >?@CFK8 
  99U""	s   8B"c                   [        U / SQ5        [        U/ SQ5        [        U/ SQ5        [        U/ SQ5        USSS24   U SSS2SS24   -  U SSS2SS24   -
  nUSSS24   U SSS2SS24   -  U SSS2SS24   -
  nUSSS24   USSS2SS24   -  USSS2SS24   -
  nUSSS24   USSS2SS24   -  USSS2SS24   -
  n[        R                  " XVXx5      u  pVpxUS	:X  a,  [        R                  " XVXx/S
S9n	[	        U	5      u    pUS   nGO]US:X  a  [        R                  " XVXx/S
S9n	[        U	5      (       a  [        R                  nODU	R                  [        R                  :X  a  [        R                  nO[        U	R                  5      nU	R                  SS
 nU	R                  U5      nUR                  U-  nUR                  SS5      n[        U5      R                  U	R                  5      nUR                  " / UQSP76 nGO`US:X  GaJ  [        UR                  5      nUR                  U5      nUR                  U5      nUR                  U5      nUR                  U5      n[        R                  " UUU/S
S9n[        R                  " UUU/S
S9n[!        U5      R                  UR                  5      n[!        U5      R                  UR                  5      nUR#                  SSS9R%                  SS9nUR#                  SSS9R%                  SS9nUU-  nUU-  nUU-  R'                  SSS9n[        R(                  " US:  U* U5      nUU-   nO[+        SU S35      e[-        U5      n U $ )u	  Reconstructs a bunch of points by triangulation.

Triangulates the 3d position of 2d correspondences between several images.
Reference: Internally it uses DLT formulation from Hartley/Zisserman 12.2 pag.312

The input points are assumed to be in homogeneous coordinate system and being inliers
correspondences. The method does not perform any robust estimation.

Args:
    P1: The projection matrix for the first camera with shape :math:`(*, 3, 4)`.
    P2: The projection matrix for the second camera with shape :math:`(*, 3, 4)`.
    points1: The set of points seen from the first camera frame in the camera plane
      coordinates with shape :math:`(*, N, 2)`.
    points2: The set of points seen from the second camera frame in the camera plane
      coordinates with shape :math:`(*, 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. Promotes to fp64 and uses a full
        SVD (via :func:`~kornia.core.utils._torch_svd_cast`). 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; slightly less numerically stable because
        forming :math:`X^\top X` squares the singular values. Typically **10-26x
        faster** than ``"svd"`` on GPU for large batches.
      * ``"cofactor"`` — solves two :math:`3 \times 4` sub-systems analytically
        using :func:`~kornia.geometry.solvers.null_vector_3x4` (closed-form
        cofactor expansion, no LAPACK call). The two solutions are averaged after
        normalisation. This matches the full DLT solution when the constraint
        system is exactly consistent, but is only an approximation in the noisy
        inconsistent case. Fastest option for all batch sizes.

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

Example:
    >>> P1 = torch.eye(3, 4)[None]   # 1x3x4
    >>> P2 = torch.eye(3, 4)[None]
    >>> 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])

)*34)r   r   2.r   r         Nsvdr   ).r      cofactorr'   T)r   keepdimg:0yE>)minzUnknown solver 'z*'. Choose from: 'svd', 'eigh', 'cofactor'.)r   r   broadcast_tensorsstackr   r   float32dtypefloat64r   r   tomTflattenr   reshaper	   normclampsumwhereNotImplementedErrorr   )!P1P2points1points2solverrow0row1row2row3Xr   r   
points3d_hcompute_dtypebatch_shapeX_castXTXflatv_flatr0r1r2r3A_012A_123h_012h_123n012n123v012v123dotpoints3ds!                                    r   triangulate_pointsrZ   ;   s   j r?+r?+w0w0 3!8r#qsA+.C1aK@D3!8r#qsA+.C1aK@D3!8r#qsA+.C1aK@D3!8r#qsA+.C1aK@D"44TLDKKT0b9
 "!$1wZ
	6	KKT0b9 a  !MMMWW%!MMM<QWWEMggcrlm$ii& {{1b!#D),,QWW5^^4[4!4
	:	 9DWW]#WW]#WW]#WW]# RRLb1RRLb1&))$**5&))$**5zzb$z/55$5?zzb$z/55$5?t|t|
 d{B5{{37TE40D[
 "$4VH<f"ghh<ZHHO    )r   torch.Tensorreturnr\   )r   )r;   r\   r<   r\   r=   r\   r>   r\   r?   strr]   r\   )__doc__
__future__r   r   kornia.core.checkr   kornia.core.utilsr   r   r   kornia.geometry.conversionsr   kornia.geometry.solversr	   r   __annotations__r   rZ    r[   r   <module>rg      sz   $ 9 "  0 c c G 3 #) C (#8 KKK K 	K
 K Kr[   