Ë
    âQ(hq3  ã                   ó²   — d Z ddlmZmZmZmZ ddlmZ ddlZ	ddlZ		 ddl
mZ dZddlZddlmZ d	d
gZd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zy# e$ r	 ddlZdZY Œ/w xY w)z1Basic linear factorizations needed by the solver.é    )ÚbmatÚ
csc_matrixÚeyeÚissparse)ÚLinearOperatorN©Úcholesky_AAtTF)ÚwarnÚorthogonalityÚprojectionsc                 óv  — t         j                  j                  |«      }t        | «      r,t        j
                  j                  j                  | d¬«      }n!t         j                  j                  | d¬«      }|dk(  s|dk(  ryt         j                  j                  | j                  |«      «      }|||z  z  }|S )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         úl/var/www/skyplay_api_hub/venv/lib/python3.12/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à�v˜f‘}Ñ%€DØ€Kó    c                 óR   ‡ ‡‡‡	— t        ‰ «      Š	ˆ ˆ	ˆˆfd„}ˆ ˆ	fd„}ˆ ˆ	fd„}|||fS )zLReturn linear operators for matrix A using ``NormalEquation`` approach.
    c                 ó8  •—  ‰‰j                  | «      «      }| ‰j                  j                  |«      z
  }d}t        ‰|«      ‰kD  rR|‰k\  r	 |S  ‰‰j                  |«      «      }|‰j                  j                  |«      z
  }|dz  }t        ‰|«      ‰kD  rŒR|S ©Nr   é   ©r   ÚTr   )ÚxÚvÚzÚkr   ÚfactorÚ	max_refinÚorth_tols       €€€€r   Ú
null_spacez/normal_equation_projections.<locals>.null_space@   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   •—  ‰‰j                  | «      «      S ©N©r   ©r$   r   r(   s    €€r   Úleast_squaresz2normal_equation_projections.<locals>.least_squaresR   s   ø€ Ù�a—e‘e˜A“hÓÐr   c                 óF   •— ‰j                   j                   ‰| «      «      S r-   ©r#   r   r/   s    €€r   Ú	row_spacez.normal_equation_projections.<locals>.row_spaceV   s   ø€ Ø�s‰s�w‰w‘v˜a“yÓ!Ð!r   r   )
r   ÚmÚnr*   r)   Útolr+   r0   r3   r(   s
   `  ``    @r   Únormal_equation_projectionsr7   9   s,   û€ ô ˜!‹_€F÷õ$ õ"ð �} iÐ/Ð/r   c           	      ól  ‡ ‡‡‡‡‡	‡
— t        t        t        ‰«      ‰ j                  g‰ dgg«      «      Š		 t        j
                  j                  j                  ‰	«      Š
ˆ ˆ	ˆˆˆˆˆ
fd„}ˆˆˆ
fd„}ˆˆ
fd„}|||fS # t        $ r. t        dd¬«       t        ‰ j                  «       ‰‰‰‰|«      cY S w xY w)z;Return linear operators for matrix A - ``AugmentedSystem``.NzVSingular Jacobian matrix. Using dense SVD decomposition to perform the factorizations.é   ©Ú
stacklevelc                 ó  •— t        j                  | t        j                  ‰	«      g«      } ‰|«      }|d ‰ }d}t        ‰|«      ‰kD  rC|‰
k\  r	 |S |‰j	                  |«      z
  } ‰|«      }||z  }|d ‰ }|dz  }t        ‰|«      ‰kD  rŒC|S r    )r   ÚhstackÚzerosr   r   )r$   r%   Úlu_solr&   r'   Únew_vÚ	lu_updater   ÚKr4   r)   r5   r*   Úsolves          €€€€€€€r   r+   z0augmented_system_projections.<locals>.null_spacer   s´   ø€ ô �I‰I�qœ"Ÿ(™( 1›+Ð&Ó'ˆñ �q“ˆØ�2�AˆJˆð ˆÜ˜A˜qÓ! HÒ,Ø�IŠ~Øð ˆð ˜Ÿ™˜f›Ñ%ˆEñ ˜e›ˆIð �iÑˆFØ�r˜�
ˆAØ�‰FˆAô ˜A˜qÓ! HÓ,ð  ˆr   c                 óx   •— t        j                  | t        j                  ‰«      g«      } ‰|«      }|‰‰‰z    S r-   ©r   r=   r>   )r$   r%   r?   r4   r5   rC   s      €€€r   r0   z3augmented_system_projections.<locals>.least_squares”   s;   ø€ ô �I‰I�qœ"Ÿ(™( 1›+Ð&Ó'ˆñ �q“ˆà�a˜˜!™ˆ}Ðr   c                 ór   •— t        j                  t        j                  ‰«      | g«      } ‰|«      }|d ‰ S r-   rE   )r$   r%   r?   r5   rC   s      €€r   r3   z/augmented_system_projections.<locals>.row_space¢   s7   ø€ ô �I‰I”r—x‘x “{ AÐ&Ó'ˆñ �q“ˆà�b�qˆzÐr   )r   r   r   r#   r   r   r   Ú
factorizedÚRuntimeErrorr
   Úsvd_factorization_projectionsÚtoarray)r   r4   r5   r*   r)   r6   r+   r0   r3   rB   rC   s   `````    @@r   Úaugmented_system_projectionsrK   \   s±   þ€ ô 	”4œ#˜a›& !§#¡#˜¨¨D¨	Ð2Ó3Ó4€Að
=Ü—‘×#Ñ#×.Ñ.¨qÓ1ˆ÷ò öDõð �} iÐ/Ð/øôM ò =Üð +àõ	ô -¨Q¯Y©Y«[Ø-.°°8Ø-6¸ó=ò 	=ð	=ús   ¶)A< Á<4B3Â2B3c                 óX  ‡ ‡‡‡‡	‡
‡— t         j                  j                  ‰ j                  dd¬«      \  Š
ŠŠ	t        j                  j                  ‰ddd…f   t        j                  «      |k  rt        dd¬«       t        ‰ ‰|‰‰|«      S ˆ ˆ	ˆ
ˆˆˆˆfd	„}ˆ	ˆ
ˆˆfd
„}ˆ	ˆ
ˆfd„}|||fS )zMReturn linear operators for matrix A using ``QRFactorization`` approach.
    TÚeconomic)ÚpivotingÚmodeéÿÿÿÿNzPSingular Jacobian matrix. Using SVD decomposition to perform the factorizations.r9   r:   c                 ó  •— ‰j                   j                  | «      }t        j                  j	                  ‰	|d¬«      }t        j                  ‰
«      }||‰<   | ‰j                   j                  |«      z
  }d}t        ‰|«      ‰kD  r}|‰k\  r	 |S ‰j                   j                  |«      }t        j                  j	                  ‰	|d¬«      }||‰<   |‰j                   j                  |«      z
  }|dz  }t        ‰|«      ‰kD  rŒ}|S )NF©Úlowerr   r!   )r#   r   r   r   Úsolve_triangularr   r>   r   )r$   Úaux1Úaux2r%   r&   r'   r   ÚPÚQÚRr4   r)   r*   s         €€€€€€€r   r+   z0qr_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ˆa‰Dà�A—C‘C—G‘G˜A“J‘ˆAØ�‰FˆAô ˜A˜qÓ! HÓ,ð ˆr   c                 ó¶   •— ‰j                   j                  | «      }t        j                  j	                  ‰|d¬«      }t        j                  ‰«      }||‰<   |S )NFrR   )r#   r   r   r   rT   r   r>   )r$   rU   rV   r&   rW   rX   rY   r4   s       €€€€r   r0   z3qr_factorization_projections.<locals>.least_squaresØ   sJ   ø€ à�s‰s�w‰w�q‹zˆÜ�|‰|×,Ñ,¨Q°¸EÐ,ÓBˆÜ�H‰H�Q‹KˆØˆˆ!‰Øˆr   c                 óz   •— | ‰   }t         j                  j                  ‰|dd¬«      }‰j                  |«      }|S )NFr#   )rS   Útrans)r   r   rT   r   )r$   rU   rV   r&   rW   rX   rY   s       €€€r   r3   z/qr_factorization_projections.<locals>.row_spaceá   sC   ø€ à�‰tˆÜ�|‰|×,Ñ,¨Q°Ø38Ø36ð -ó 8ˆð �E‰E�$‹KˆØˆr   )	r   r   Úqrr#   r   r   Úinfr
   rI   )r   r4   r5   r*   r)   r6   r+   r0   r3   rW   rX   rY   s   `` ``    @@@r   Úqr_factorization_projectionsr_   ¯   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                 óÒ   ‡ ‡‡‡	‡
‡— t         j                  j                  ‰ d¬«      \  Š	ŠŠ
‰	dd…‰|kD  f   Š	‰
‰|kD  dd…f   Š
‰‰|kD     Šˆ ˆ	ˆ
ˆˆˆfd„}ˆ	ˆ
ˆfd„}ˆ	ˆ
ˆfd„}|||fS )zNReturn linear operators for matrix A using ``SVDFactorization`` approach.
    F)Úfull_matricesNc                 ó„  •— ‰j                  | «      }d‰z  |z  }‰j                  |«      }| ‰j                  j                  |«      z
  }d}t        ‰|«      ‰
kD  re|‰	k\  r	 |S ‰j                  |«      }d‰z  |z  }‰j                  |«      }|‰j                  j                  |«      z
  }|dz  }t        ‰|«      ‰
kD  rŒe|S )Nr!   r   r"   )r$   rU   rV   r%   r&   r'   r   ÚUÚVtr)   r*   Úss         €€€€€€r   r+   z1svd_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                 ó\   •— ‰j                  | «      }d‰z  |z  }‰j                  |«      }|S ©Nr!   r.   ©r$   rU   rV   r&   rc   rd   re   s       €€€r   r0   z4svd_factorization_projections.<locals>.least_squares  s/   ø€ à�v‰v�a‹yˆØ�‰s�4‰xˆØ�E‰E�$‹KˆØˆr   c                 ó„   •— ‰j                   j                  | «      }d‰z  |z  }‰j                   j                  |«      }|S rg   r2   rh   s       €€€r   r3   z0svd_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   r4   r5   r*   r)   r6   r+   r0   r3   rc   rd   re   s   `  ``    @@@r   rI   rI   í   sx   ý€ ô �|‰|×Ñ °ÐÓ7�H€A€qˆ"ð 	
Š!ˆQ�‰Wˆ*‰€AØ	ˆA�‰G’QˆJ‰€BØ	ˆ!ˆc‰'‰
€A÷ñ ö0öð �} iÐ/Ð/r   c                 ó:  — t        j                  | «      \  }}||z  dk(  rt        | «      } t        | «      r=|€d}|dvrt	        d«      ‚|dk(  r8t
        s2t        j                  dt        d¬«       d}n|€d	}|d
vrt	        d«      ‚|dk(  rt        | |||||«      \  }}}	nM|dk(  rt        | |||||«      \  }}}	n3|d	k(  rt        | |||||«      \  }}}	n|dk(  rt        | |||||«      \  }}}	t        ||f«      }
t        ||f«      }t        ||f	«      }|
||fS )a  Return three linear operators related with a given matrix A.

    Parameters
    ----------
    A : sparse matrix (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)ÚNormalEquationrl   z%Method not allowed for sparse matrix.rm   zmOnly accepts 'NormalEquation' option when scikit-sparse is available. Using 'AugmentedSystem' option instead.r9   r:   ÚQRFactorization)rn   ÚSVDFactorizationz#Method not allowed for dense array.ro   )r   Úshaper   r   Ú
ValueErrorÚsksparse_availableÚwarningsr
   ÚImportWarningr7   rK   r_   rI   r   )r   Úmethodr*   r)   r6   r4   r5   r+   r0   r3   ÚZÚLSÚYs                r   r   r   #  ss  € ôT �8‰8�A‹;�D€A€qð 	ˆ�sˆa‚xÜ�q‹Mˆô �„{Øˆ>Ø&ˆFØÐ>Ñ>ÜÐDÓEÐEØÐ%Ò%Õ.@Ü�M‰Mð >ô (°Aõ7ð '‰Fàˆ>Ø&ˆFØÐ@Ñ@ÜÐBÓCÐCàÐ!Ò!ä)¨!¨Q°°8¸YÈÓLñ 	-ˆ
�M¡9à	Ð$Ò	$ä*¨1¨a°°H¸iÈÓMñ 	-ˆ
�M¡9à	Ð$Ò	$ä*¨1¨a°°H¸iÈÓMñ 	-ˆ
�M¡9à	Ð%Ò	%ä+¨A¨q°!°X¸yÈ#ÓNñ 	-ˆ
�M 9ô 	˜˜1�v˜zÓ*€AÜ	˜˜A˜ Ó	.€BÜ˜˜1�v˜yÓ)€Aàˆb�!ˆ8€Or   )Ngê-�™—q=r9   gVçž¯Ò<)Ú__doc__Úscipy.sparser   r   r   r   Úscipy.sparse.linalgr   Úscipy.linalgr   Úsksparse.cholmodr	   rr   ÚImportErrorrs   Únumpyr   r
   Ú__all__r   r7   rK   r_   rI   r   © r   r   ú<module>r‚      s|   ðÙ 7ç :Ó :Ý .Û Û ðÝ-ØÐó Ý ð Øð€ò òF 0òFP0òf;0ò|30ôltøðs ò ÛØÒðús   žA ÁAÁA