ó
    EñiÍ4  ã                   ó¾   • S r SSKJrJrJrJr  SSKJr  SSKr	SSKr	 SSK
JrJr  SrSSKrSSKJrJr  S	S
/rS rS rS rS rS rSS jrg! \ a	    SSKrSr N3f = f)z1Basic linear factorizations needed by the solver.é    )Úblock_arrayÚ	csc_arrayÚ	eye_arrayÚissparse)ÚLinearOperatorN)Úcholesky_AAtÚCholmodTypeConversionWarningTF)ÚwarnÚcatch_warningsÚorthogonalityÚprojectionsc                 óv  • [         R                  R                  U5      n[        U 5      (       a)  [        R
                  R                  R                  U SS9nO[         R                  R                  U SS9nUS:X  d  US:X  a  g[         R                  R                  U R                  U5      5      nXCU-  -  nU$ )a_  Measure orthogonality between a vector and the null space of a matrix.

Compute a measure of orthogonality between the null space
of the (possibly sparse) matrix ``A`` and a given vector ``g``.

The formula is a simplified (and cheaper) version of formula (3.13)
from [1]_.
``orth =  norm(A g, ord=2)/(norm(A, ord='fro')*norm(g, ord=2))``.

References
----------
.. [1] Gould, Nicholas IM, Mary E. Hribar, and Jorge Nocedal.
       "On the solution of equality constrained quadratic
        programming problems arising in optimization."
        SIAM Journal on Scientific Computing 23.4 (2001): 1376-1395.
Úfro)Úordr   )ÚnpÚlinalgÚnormr   ÚscipyÚsparseÚdot)ÚAÚgÚnorm_gÚnorm_AÚnorm_A_gÚorths         Úk/home/mande/repo/quber/.venv/lib/python3.13/site-packages/scipy/optimize/_trustregion_constr/projections.pyr   r      s‘   € ô$ �Y‰Y�^‰^˜AÓ€Fä�‡{�{Ü—‘×$Ñ$×)Ñ)¨!°Ð)Ð7‰ä—‘—‘  u�Ð-ˆð �ƒ{�f “kØä�y‰y�~‰~˜aŸe™e A›hÓ'€Hà˜f‘}Ñ%€DØ€Kó    c                 ó¦   ^ ^^^	• [        S[        S9   [        T 5      m	SSS5        U U	UU4S jnU U	4S jnU U	4S jnXgU4$ ! , (       d  f       N)= f)zLReturn linear operators for matrix A using ``NormalEquation`` approach.
    Úignore)ÚactionÚcategoryNc                 ó@  >• T" TR                  U 5      5      nU TR                  R                  U5      -
  nSn[        TU5      T:”  aU  UT:¼  a   U$ T" TR                  U5      5      nUTR                  R                  U5      -
  nUS-  n[        TU5      T:”  a  MU  U$ ©Nr   é   ©r   ÚTr   )ÚxÚvÚzÚkr   ÚfactorÚ	max_refinÚorth_tols       €€€€r   Ú
null_spaceÚ/normal_equation_projections.<locals>.null_spaceD   s›   ø€ Ù�1—5‘5˜“8ÓˆØ�—‘—‘˜“
‰Nˆð ˆÜ˜A˜qÓ! HÓ,Ø�I‹~Øð ˆñ	 �q—u‘u˜Q“xÓ ˆAØ�A—C‘C—G‘G˜A“J‘ˆAØ�‰FˆAô ˜A˜qÓ! HÕ,ð ˆr   c                 ó2   >• T" TR                  U 5      5      $ ©N©r   ©r(   r   r,   s    €€r   Úleast_squaresÚ2normal_equation_projections.<locals>.least_squaresV   s   ø€ Ù�a—e‘e˜A“hÓÐr   c                 óF   >• TR                   R                  T" U 5      5      $ r2   ©r'   r   r4   s    €€r   Ú	row_spaceÚ.normal_equation_projections.<locals>.row_spaceZ   s   ø€ Ø�s‰s�w‰w‘v˜a“yÓ!Ð!r   )r   r	   r   )
r   ÚmÚnr.   r-   Útolr/   r5   r9   r,   s
   `  ``    @r   Únormal_equation_projectionsr>   9   sJ   û€ ô 
˜xÔ2NÓ	OÜ˜a“ˆ÷ 
P÷ð ö$ ö"ð  iÐ/Ð/÷; 
PÕ	Oús   “AÁ
Ac           	      óX  ^ ^^^^^	^
• [        [        T5      T R                  /T S//SS9m	 [        R                  R
                  R                  T	5      m
U U	UUUUU
4S jnUUU
4S jnUU
4S	 jnXgU4$ ! [         a+    [        SSS9  [        T R                  5       TTTTU5      s $ f = f)
z;Return linear operators for matrix A - ``AugmentedSystem``.NÚcsc)ÚformatzVSingular Jacobian matrix. Using dense SVD decomposition to perform the factorizations.é   ©Ú
stacklevelc                 ó(  >• [         R                  " U [         R                  " T	5      /5      nT" U5      nUS T nSn[        TU5      T:”  aE  UT
:¼  a   U$ UTR	                  U5      -
  nT" U5      nX&-  nUS T nUS-  n[        TU5      T:”  a  ME  U$ r$   )r   ÚhstackÚzerosr   r   )r(   r)   Úlu_solr*   r+   Únew_vÚ	lu_updater   ÚKr;   r-   r<   r.   Úsolves          €€€€€€€r   r/   Ú0augmented_system_projections.<locals>.null_spacev   s²   ø€ ô �IŠI�qœ"Ÿ(š( 1›+Ð&Ó'ˆñ �q“ˆØ�2�AˆJˆð ˆÜ˜A˜qÓ! HÓ,Ø�I‹~Øð ˆð ˜Ÿ™˜f›Ñ%ˆEñ ˜e›ˆIð ÑˆFØ�r˜�
ˆAØ�‰FˆAô ˜A˜qÓ! HÕ,ð  ˆr   c                 ó|   >• [         R                  " U [         R                  " T5      /5      nT" U5      nUTTT-    $ r2   ©r   rF   rG   )r(   r)   rH   r;   r<   rL   s      €€€r   r5   Ú3augmented_system_projections.<locals>.least_squares˜   s;   ø€ ô �IŠI�qœ"Ÿ(š( 1›+Ð&Ó'ˆñ �q“ˆà�a˜˜!™ˆ}Ðr   c                 óv   >• [         R                  " [         R                  " T5      U /5      nT" U5      nUS T $ r2   rO   )r(   r)   rH   r<   rL   s      €€r   r9   Ú/augmented_system_projections.<locals>.row_space¦   s7   ø€ ô �IŠI”r—x’x “{ AÐ&Ó'ˆñ �q“ˆà�b�qˆzÐr   )r   r   r'   r   r   r   Ú
factorizedÚRuntimeErrorr
   Úsvd_factorization_projectionsÚtoarray)r   r;   r<   r.   r-   r=   r/   r5   r9   rK   rL   s   `````    @@r   Úaugmented_system_projectionsrW   `   s­   þ€ ô 	”i “l A§C¡CÐ(¨1¨d¨)Ð4¸UÑC€Að
=Ü—‘×#Ñ#×.Ñ.¨qÓ1ˆ÷ó ÷Döð  iÐ/Ð/øôM ó =Üð +àò	ô -¨Q¯Y©Y«[Ø-.°°8Ø-6¸ó=ò 	=ð	=ús   ¬)A4 Á42B)Â(B)c                 óR  ^ ^^^^	^
^• [         R                  R                  T R                  SSS9u  m
mm	[        R                  R                  TSSS24   [        R                  5      U:  a  [        SSS9  [        T TUTTU5      $ U U	U
UUUU4S	 jnU	U
UU4S
 jnU	U
U4S jnXgU4$ )zMReturn linear operators for matrix A using ``QRFactorization`` approach.
    TÚeconomic)ÚpivotingÚmodeéÿÿÿÿNzPSingular Jacobian matrix. Using SVD decomposition to perform the factorizations.rB   rC   c                 ó  >• TR                   R                  U 5      n[        R                  R	                  T	USS9n[
        R                  " T
5      nX#T'   U TR                   R                  U5      -
  nSn[        TU5      T:”  a|  UT:¼  a   U$ TR                   R                  U5      n[        R                  R	                  T	USS9nX#T'   UTR                   R                  U5      -
  nUS-  n[        TU5      T:”  a  M|  U$ )NF©Úlowerr   r%   )r'   r   r   r   Úsolve_triangularr   rG   r   )r(   Úaux1Úaux2r)   r*   r+   r   ÚPÚQÚRr;   r-   r.   s         €€€€€€€r   r/   Ú0qr_factorization_projections.<locals>.null_spaceÃ   sê   ø€ à�s‰s�w‰w�q‹zˆÜ�|‰|×,Ñ,¨Q°¸EÐ,ÐBˆÜ�HŠH�Q‹KˆØˆ!‰Ø�—‘—‘˜“
‰Nˆð ˆÜ˜A˜qÓ! HÓ,Ø�I‹~Øð ˆð —3‘3—7‘7˜1“:ˆDÜ—<‘<×0Ñ0°°DÀÐ0ÐFˆDØˆa‰Dà�A—C‘C—G‘G˜A“J‘ˆAØ�‰FˆAô ˜A˜qÓ! HÕ,ð ˆr   c                 ó°   >• TR                   R                  U 5      n[        R                  R	                  TUSS9n[
        R                  " T5      nX#T'   U$ )NFr^   )r'   r   r   r   r`   r   rG   )r(   ra   rb   r*   rc   rd   re   r;   s       €€€€r   r5   Ú3qr_factorization_projections.<locals>.least_squaresÜ   sH   ø€ à�s‰s�w‰w�q‹zˆÜ�|‰|×,Ñ,¨Q°¸EÐ,ÐBˆÜ�HŠH�Q‹KˆØˆ!‰Øˆr   c                 ót   >• U T   n[         R                  R                  TUSSS9nTR                  U5      nU$ )NFr'   )r_   Útrans)r   r   r`   r   )r(   ra   rb   r*   rc   rd   re   s       €€€r   r9   Ú/qr_factorization_projections.<locals>.row_spaceå   sC   ø€ à�‰tˆÜ�|‰|×,Ñ,¨Q°Ø38Ø36ð -ð 8ˆð �E‰E�$‹KˆØˆr   )	r   r   Úqrr'   r   r   Úinfr
   rU   )r   r;   r<   r.   r-   r=   r/   r5   r9   rc   rd   re   s   `` ``    @@@r   Úqr_factorization_projectionsrn   ³   sž   þ€ ô �l‰l�o‰o˜aŸc™c¨D°zˆoÐB�G€A€qˆ!ä	‡y�y‡~�~�a˜šA˜‘h¤§¡Ó'¨#Ó-Üð +àò	ô -¨Q°°1Ø-5Ø-6Ø-0ó2ð 	2÷ó ÷2ð ÷ð  iÐ/Ð/r   c                 óÐ   ^ ^^^	^
^• [         R                  R                  T SS9u  m	mm
T	SS2TU:„  4   m	T
TU:„  SS24   m
TTU:„     mU U	U
UUU4S jnU	U
U4S jnU	U
U4S jnXgU4$ )zNReturn linear operators for matrix A using ``SVDFactorization`` approach.
    F)Úfull_matricesNc                 óŒ  >• TR                  U 5      nST-  U-  nTR                  U5      nU TR                  R                  U5      -
  nSn[        TU5      T
:”  ah  UT	:¼  a   U$ TR                  U5      nST-  U-  nTR                  U5      nUTR                  R                  U5      -
  nUS-  n[        TU5      T
:”  a  Mh  U$ )Nr%   r   r&   )r(   ra   rb   r)   r*   r+   r   ÚUÚVtr-   r.   Úss         €€€€€€r   r/   Ú1svd_factorization_projections.<locals>.null_spaceý   sÅ   ø€ à�v‰v�a‹yˆØ�‰s�4‰xˆØ�E‰E�$‹KˆØ�—‘—‘˜“
‰Nˆð ˆÜ˜A˜qÓ! HÓ,Ø�I‹~Øð ˆð —6‘6˜!“9ˆDØ�Q‘3�t‘8ˆDØ—‘�d“ˆAà�A—C‘C—G‘G˜A“J‘ˆAØ�‰FˆAô ˜A˜qÓ! HÕ,ð ˆr   c                 ó\   >• TR                  U 5      nST-  U-  nTR                  U5      nU$ ©Nr%   r3   ©r(   ra   rb   r*   rr   rs   rt   s       €€€r   r5   Ú4svd_factorization_projections.<locals>.least_squares  s/   ø€ à�v‰v�a‹yˆØ�‰s�4‰xˆØ�E‰E�$‹KˆØˆr   c                 ó„   >• TR                   R                  U 5      nST-  U-  nTR                   R                  U5      nU$ rw   r8   rx   s       €€€r   r9   Ú0svd_factorization_projections.<locals>.row_space  s7   ø€ à�s‰s�w‰w�q‹zˆØ�‰s�4‰xˆØ�D‰D�H‰H�T‹NˆØˆr   )r   r   Úsvd)r   r;   r<   r.   r-   r=   r/   r5   r9   rr   rs   rt   s   `  ``    @@@r   rU   rU   ñ   sv   ý€ ô �|‰|×Ñ °ÐÐ7�H€A€qˆ"ð 	
Š!ˆQ�‰Wˆ*‰€AØ	ˆA�‰G’QˆJ‰€BØ	ˆ!ˆc‰'‰
€A÷ò ÷0÷ð  iÐ/Ð/r   c                 ó8  • [         R                  " U 5      u  pVXV-  S:X  a  [        U 5      n [        U 5      (       aD  Uc  SnUS;  a  [	        S5      eUS:X  a'  [
        (       d  [        R                  " S[        SS9  SnOUc  S	nUS
;  a  [	        S5      eUS:X  a  [        XXbX45      u  pxn	ODUS:X  a  [        XXbX45      u  pxn	O-US	:X  a  [        XXbX45      u  pxn	OUS:X  a  [        XXbX45      u  pxn	[        Xf4W5      n
[        XV4W5      n[        Xe4W	5      nX«U4$ )aý	  Return three linear operators related with a given matrix A.

Parameters
----------
A : sparse array (or ndarray), shape (m, n)
    Matrix ``A`` used in the projection.
method : string, optional
    Method used for compute the given linear
    operators. Should be one of:

        - 'NormalEquation': The operators
           will be computed using the
           so-called normal equation approach
           explained in [1]_. In order to do
           so the Cholesky factorization of
           ``(A A.T)`` is computed. Exclusive
           for sparse matrices.
        - 'AugmentedSystem': The operators
           will be computed using the
           so-called augmented system approach
           explained in [1]_. Exclusive
           for sparse matrices.
        - 'QRFactorization': Compute projections
           using QR factorization. Exclusive for
           dense matrices.
        - 'SVDFactorization': Compute projections
           using SVD factorization. Exclusive for
           dense matrices.

orth_tol : float, optional
    Tolerance for iterative refinements.
max_refin : int, optional
    Maximum number of iterative refinements.
tol : float, optional
    Tolerance for singular values.

Returns
-------
Z : LinearOperator, shape (n, n)
    Null-space operator. For a given vector ``x``,
    the null space operator is equivalent to apply
    a projection matrix ``P = I - A.T inv(A A.T) A``
    to the vector. It can be shown that this is
    equivalent to project ``x`` into the null space
    of A.
LS : LinearOperator, shape (m, n)
    Least-squares operator. For a given vector ``x``,
    the least-squares operator is equivalent to apply a
    pseudoinverse matrix ``pinv(A.T) = inv(A A.T) A``
    to the vector. It can be shown that this vector
    ``pinv(A.T) x`` is the least_square solution to
    ``A.T y = x``.
Y : LinearOperator, shape (n, m)
    Row-space operator. For a given vector ``x``,
    the row-space operator is equivalent to apply a
    projection matrix ``Q = A.T inv(A A.T)``
    to the vector.  It can be shown that this
    vector ``y = Q x``  the minimum norm solution
    of ``A y = x``.

Notes
-----
Uses iterative refinements described in [1]
during the computation of ``Z`` in order to
cope with the possibility of large roundoff errors.

References
----------
.. [1] Gould, Nicholas IM, Mary E. Hribar, and Jorge Nocedal.
    "On the solution of equality constrained quadratic
    programming problems arising in optimization."
    SIAM Journal on Scientific Computing 23.4 (2001): 1376-1395.
r   ÚAugmentedSystem)ÚNormalEquationr~   z$Method not allowed for sparse array.r   zmOnly accepts 'NormalEquation' option when scikit-sparse is available. Using 'AugmentedSystem' option instead.rB   rC   ÚQRFactorization)r€   ÚSVDFactorizationz#Method not allowed for dense array.r�   )r   Úshaper   r   Ú
ValueErrorÚsksparse_availableÚwarningsr
   ÚImportWarningr>   rW   rn   rU   r   )r   Úmethodr.   r-   r=   r;   r<   r/   r5   r9   ÚZÚLSÚYs                r   r   r   '  sM  € ôT �8Š8�A‹;�D€Að 	�sˆaƒxÜ�a‹Lˆô �‡{�{Ø‰>Ø&ˆFØÐ>Ó>ÜÐCÓDÐDØÐ%Ó%×.@Ò.@Ü�MŠMð >ô (°Aò7ð 'ˆFøà‰>Ø&ˆFØÐ@Ó@ÜÐBÓCÐCàÐ!Ó!ä)¨!°¸YÓLñ 	-ˆ
¡9à	Ð$Ó	$ä*¨1°¸iÓMñ 	-ˆ
¡9à	Ð$Ó	$ä*¨1°¸iÓMñ 	-ˆ
¡9à	Ð%Ó	%ä+¨A°!¸yÓNñ 	-ˆ
 9ô 	˜�v˜zÓ*€AÜ	˜˜ Ó	.€BÜ˜�v˜yÓ)€Aà�!ˆ8€Or   )Ngê-�™—q=rB   gVçž¯Ò<)Ú__doc__Úscipy.sparser   r   r   r   Úscipy.sparse.linalgr   Úscipy.linalgr   Úsksparse.cholmodr   r	   r„   ÚImportErrorr…   Únumpyr   r
   r   Ú__all__r   r>   rW   rn   rU   r   © r   r   Ú<module>r”      s|   ðÙ 7ç DÓ DÝ .Û Û ðßKØÐó ß )ð Øð€ò òF$0òNP0òf;0ò|30õltøð{ ó ÛØÒðús   ž
A ÁAÁA