+
    åûjS1  ã                  ór   € R t ^ RIHt ^ RIt^ RIHtHt ^ RIHt R R lt	R R lt
R	R
/R R lltR R ltR# )z3Closed-form solvers for homogeneous linear systems.)ÚannotationsN)ÚKORNIA_CHECK_IS_TENSORÚKORNIA_CHECK_SHAPE)Ú_needs_derivativesc               ó@   € V ^8„  d   QhRRRRRRRRRRRRRRR	RR
RRR/
# )é   Úa0útorch.TensorÚa1Úa2Úb0Úb1Úb2Úc0Úc1Úc2Úreturn© )Úformats   "Ú_C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\solvers\homogeneous.pyÚ__annotate__r      sx   € ÷ #Zñ #ZØð#Zàð#Zð 	ð#Zð 	ð	#Zð
 	ð#Zð 	ð#Zð 	ð#Zð 	ð#Zð 	ð#Zð ñ#Zó    c	                ó¾   € WV,          WW,          ,
          ,          WV,          WV,          ,
          ,          ,
          W#V,          WF,          ,
          ,          ,           # )aº  Compute a batch of 3x3 determinants via Sarrus' rule.

Given three rows (each split into their three scalar components), returns::

    | a0  a1  a2 |
    | b0  b1  b2 |
    | c0  c1  c2 |

All inputs must be broadcastable to the same shape.

Args:
    a0: first element of the first row.
    a1: second element of the first row.
    a2: third element of the first row.
    b0: first element of the second row.
    b1: second element of the second row.
    b2: third element of the second row.
    c0: first element of the third row.
    c1: second element of the third row.
    c2: third element of the third row.

Returns:
    Scalar determinant (or batch of scalars) with the broadcasted shape.
r   )	r   r
   r   r   r   r   r   r   r   s	   &&&&&&&&&r   Ú_det3r      sA   € ðF �b•˜2�7Õ"Õ# b°­G°bµgÕ,=Õ&>Õ>ÀÈBÅwÐQSÕQXÕGXÕAYÕYÐYr   c               ó    € V ^8„  d   QhRRRR/# ©r   ÚAr	   r   r   )r   s   "r   r   r   B   s   € ÷ r1ñ r1�|ð r1¨ñ r1r   c                ó2  € \        V 4       \        V . RO4       V R,          pV R,          pV R,          p\        VR,          VR,          VR,          VR,          VR,          VR,          VR,          VR,          VR,          4	      p\        VR	,          VR,          VR,          VR	,          VR,          VR,          VR	,          VR,          VR,          4	      ) p\        VR	,          VR,          VR,          VR	,          VR,          VR,          VR	,          VR,          VR,          4	      p\        VR	,          VR,          VR,          VR	,          VR,          VR,          VR	,          VR,          VR,          4	      ) p\        P                  ! WEWg.R
R7      # )uª	  Compute the null vector of rank-3 ``(*, 3, 4)`` matrices from cofactors, without an SVD.

``v = null_vector_3x4(A)`` takes matrices ``(*, 3, 4)`` and returns unnormalized vectors ``(*, 4)`` with
:math:`A v = 0`: the last right singular vector up to scale and sign when ``A`` has rank 3, and the zero vector
when its rank is lower. Each component is a signed ``3 x 3`` determinant, so no LAPACK or cuSOLVER call is made.
For a least-squares null vector of a matrix with more rows, use an SVD (:func:`torch.linalg.svd`).

The null vector :math:`\mathbf{v} \in \mathbb{R}^4` satisfies
:math:`A\,\mathbf{v} = \mathbf{0}`.  For a matrix of rank 3 this solution
is unique up to scale.

The computation uses the **4-D cross-product** (cofactor expansion):
each component of :math:`\mathbf{v}` is a :math:`3 \times 3` determinant of
the submatrix obtained by dropping the corresponding column of :math:`A`.
For a rank-3 :math:`A` this gives the last right singular vector up to scale
and sign, but replaces the SVD with 48 scalar multiplications and 20
additions â€” no LAPACK or cuSOLVER call is made. The sign follows the
cofactor formula below (``[I | 0]`` gives ``[0, 0, 0, -1]``), and a lower
rank gives the zero vector rather than a unit vector.

.. math::

    v_j = (-1)^j \det\!\bigl(A_{[0,1,2],\,\widehat{j}}\bigr), \quad j = 0, 1, 2, 3

where :math:`A_{[0,1,2],\,\widehat{j}}` denotes the :math:`3 \times 3`
submatrix formed by deleting column :math:`j`.

.. note::

    The returned vector is **not** normalised.  Divide by its norm if a
    unit null vector is required.

.. note::

    The function is only correct when :math:`A` has rank exactly 3.  For
    rank-deficient inputs (rank < 3) the result is the zero vector.

Args:
    A: matrix of shape ``(*, 3, 4)``.

Returns:
    Null vector of shape ``(*, 4)``.

Raises:
    TypeCheckError: if ``A`` is not a :class:`torch.Tensor`.
    ShapeError: if the last two dimensions of ``A`` are not ``(3, 4)``.

See Also:
    - :func:`~kornia.geometry.epipolar.triangulate_points`: its ``"cofactor"`` solver uses these minors on the
      ``4 x 4`` DLT systems of a triangulation.

Example:
    >>> A = torch.tensor([[[1., 0., 0., 0.],
    ...                    [0., 1., 0., 0.],
    ...                    [0., 0., 1., 0.]]])   # null vector is [0,0,0,-1]
    >>> v = null_vector_3x4(A)                   # shape (1, 4)
    >>> (A @ v.unsqueeze(-1)).squeeze(-1)         # should be near zero
    tensor([[0., 0., 0.]])

)Údim)Ú*Ú3Ú4).é    ºNNN).é   r#   ).r   r#   ).r$   ).r   ).é   ).r"   éÿÿÿÿ)r   r   r   ÚtorchÚstack)r   ÚaÚbÚcÚv0Úv1Úv2Úv3s   &       r   Únull_vector_3x4r0   B   s€  € ôz ˜1ÔÜ�qš/Ô*à	ˆ)�€AØ	ˆ)�€AØ	ˆ)�€Aô 
Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	ó

€Bô Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	ó
ð 

€Bô 
Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	ó

€Bô Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	Ø	ˆ&�	ó
ð 

€Bô �;Š;˜ Ð'¨RÔ0Ð0r   Úrank_deficient_basisFc               ó$   € V ^8„  d   QhRRRRRR/# )r   r   r	   r1   Úboolr   r   )r   s   "r   r   r   ·   s!   € ÷ >ñ >�lð >¸Tð >Èlñ >r   c          	     ó  € V P                   w  r#pRpV P                  P                  R8X  d‰   V'       g�   \        V 4      '       gp   V P	                  W$V4      pV P
                  VRRV13&   \        P                  P                  V4      w  rxp	VRRV13,          VRRV13,          r‡V	^ 8„  W“8  ,          pM,\        P                  P                  V P
                  4      w  rxp
VRRV1RV13,          p\        P                  P                  4       '       d@   V P                  P                  R8X  d%   VP
                  P                  4       P
                  pVRVR1RV13,          pV P                  P                  R8X  d    VP                  4       VP                  4       rË\        P                  P                  W¼RRRR7      p\        P                  ! WC,
          V P                  V P                  R	7      P                  VRR4      p\        P                   ! WxRR
7      w  p p
V\        P"                  ! VP
                  ) V.^4      ,          pVe>   \        P$                  ! VR,          \        P&                  ! V\)        R4      4      V4      pV# )a¹  Right null spaces of a batch of ``(B, m, n)`` matrices, ``m < n``, as ``(B, n, n - m)``.

With ``A^T = P L U`` from a partial-pivoted LU factorization, ``f^T A^T = 0`` exactly when ``y = P^T f`` solves
``y^T L = 0``. Splitting the unit lower trapezoidal ``L`` into its square top ``L_1`` and bottom ``L_2`` rows
gives the basis ``y = [-(L_2 L_1^{-1})^T; I]``. The pivoting chooses the gauge, so no coordinate of the null
vector is assumed non-zero, and the basis is not orthonormal.

Unlike an SVD, a QR or an ``eigh`` of ``A^T A``, a batched LU factorization is one batched kernel on every
backend, and working on ``A`` rather than ``A^T A`` does not square its condition number. ``L_1`` is unit
triangular, so a rank-deficient ``A`` still gives a basis of null vectors, of dimension ``n - m`` only, as long
as the factorization stays finite; callers treat non-finite vectors as degenerate.

On CUDA without a gradient, a matrix whose factorization meets an exactly zero pivot before its last column (an
exactly rank-deficient ``A``, such as one with a zero row above its last) gives NaN instead, unless
``rank_deficient_basis`` asks for that basis on every backend; every other matrix gives the same basis.
NÚcuda.r#   ÚmpsFT)ÚupperÚleftÚunitriangular©ÚdtypeÚdevice)Úunpack_dataÚnanr&   )r#   NN)Úshaper<   Útyper   Ú	new_zerosÚmTr'   ÚlinalgÚlu_factor_exÚcompilerÚis_compilingÚ
contiguousÚsolve_triangularÚeyer;   ÚexpandÚ	lu_unpackÚcatÚwhereÚ	full_likeÚfloat)r   r1   ÚbatchÚmÚnÚstoppedÚpaddedÚluÚpivotsÚinfoÚ_ÚsquareÚrhsÚlowerrI   ÚpermutationÚbasiss   &$               r   Ú_null_space_lur^   ·   s  € ð" —'‘'�K€EˆaØ€GØ‡x�x‡}�}˜Ô×';ÔDVÐWX×DYÒDYð( —‘˜U qÓ)ˆØŸ$™$ˆˆs�B�Q�Bˆw‰Ü Ÿ<™<×4Ñ4°VÓ<Ñˆ�DØ˜˜R˜a˜R˜•[ &¨¨b¨q¨b¨¥/ˆFØ˜!‘8 ¡Õ)‰äŸ™×1Ñ1°!·$±$Ó7‰ˆ�AØ��2�A�2�r˜�r�	�]€FÜ‡~�~×"Ñ"×$Ò$¨¯©¯©¸&Ô)@ð —‘×%Ñ%Ó'×*Ñ*ˆØ
ˆQ�‘�B�Q�BˆY�-€CØ‡x�x‡}�}˜Ôà×'Ñ'Ó)¨3¯>©>Ó+;�Ü�L‰L×)Ñ)¨&¸UÈÐ^bÐ)Óc€EÜ
�)Š)�A•E §¡°·±Ô
:×
AÑ
AÀ%ÈÈRÓ
P€CÜŸš¨ÀÔFÑ€K��AØœ%Ÿ)š) e§h¡h Y°Ð$4°aÓ8Õ8€EØÒÜ—’˜G MÕ2´E·O²OÀEÌ5ÐQVË<Ó4XÐZ_Ó`ˆØ€Lr   c               ó    € V ^8„  d   QhRRRR/# r   r   )r   s   "r   r   r   ø   s   € ÷ ñ ˜|ð °ñ r   c           
     óÚ  € V P                   w  rpV P                  p. p\        V4       Fô  pVR,          pVR,          p\        P                  ! V^ 8¬  \        P
                  ! V4      \        P
                  ! V4      ) 4      p	\        P                  ! W‰VP                  ^RR7      ,          ,           VR,          .^4      p
WªP                  ^RR7      ,          p
VP                  V
4       V^V
R	,          ,          V
R
,          V,          ,          ,
          R,          pKö  	  \        P                  ! W0P                  V P                  R7      RVR13,          P                  WW2,
          4      p\        \        V4      4       Fe  pW\,          VRVR13,          rÚ\        P                  ! VRRV13,          V^V
R	,          ,          V
R
,          V,          ,          ,
          .^4      pKg  	  V# )a5  Orthonormal right null spaces of a batch of ``(B, m, n)`` matrices, ``m < n``, as ``(B, n, n - m)``.

The last ``n - m`` columns of ``Q`` in the QR factorization ``A^T = Q R``, from ``m`` Householder reflections
written as batched tensor operations: ``torch.linalg.qr`` has no batched CUDA kernel and loops over the batch.
Both this and :func:`_null_space_lu` span the null space to rounding, but a solver that parametrizes its solution
in the basis can depend on which basis it gets: on 22000 exact five-point samples, Nister's candidates missed the
true essential matrix by more than 1e-3 nine times with this orthonormal basis, seven times with the SVD's, and 81
times with the LU one. It costs about four times the LU null space. ``A`` must have full rank: at a vanishing
reflector the normalization divides by zero.
r#   T)r   ÚkeepdimNr:   )r#   r#   r"   )r#   :Nr$   N)r#   ºr$   NN)r#   r#   N)r#   Nr#   )r#   rb   rb   )r?   rB   Úranger'   rM   Ú	ones_likerL   ÚnormÚappendrI   r;   r<   rJ   Úreversed)r   rP   rQ   rR   Ú	remainingÚ
reflectorsrX   ÚxÚheadÚsignÚvÚQÚkÚtails   &             r   Ú_null_space_householderrq   ø   s‚  € ð —'‘'�K€EˆaØ—‘€IØ€JÜ�1ŽXˆØ�gÕˆØ��xˆä�{Š{˜4 1™9¤e§o¢o°dÓ&;¼e¿oºoÈdÓ>SÐ=SÓTˆÜ�IŠI�t Q§V¡V°¸4 VÓ%@Õ@Õ@À!ÀEÅ(ÐKÈQÓOˆØ—‘˜1 d�Ó+Õ+ˆØ×Ñ˜!ÔØ  Q z¥]Õ!2°a¸
µmÀiÕ6OÕ!PÕPÐR[Õ\Š	ñ ô 	�	Š	�!Ÿ7™7¨1¯8©8Ô4°Q¸¹°UÕ;×BÑBÀ5ÈQÍUÓS€AÜ”e˜A“hÖˆØ•-  1 a¡b 5¥ˆ4Ü�IŠI�q˜˜B˜Q˜B˜•x ¨¨A¨j­MÕ(9¸Q¸z½]ÈTÕ=QÕ(RÕ!RÐSÐUVÓWŠñ  ð €Hr   )Ú__doc__Ú
__future__r   r'   Úkornia.core.checkr   r   Úkornia.core.utilsr   r   r0   r^   rq   r   r   r   Ú<module>rv      s6   ðñ$ :å "ã ç HÝ 0õ#ZõLr1ðj>ÀE÷ >÷Br   