+
    øª¨j¼Z  ã                   ó¤   € R t ^ RIHtHt ^ RIHt ^ RIt^ RIH	t	 . ROt
R tRR ltRR ltRR	 ltR
 tR tR t]P$                  RRRRRR3R ltR# )z3Equality-constrained quadratic programming solvers.)ÚlinalgÚblock_array)ÚcopysignN)Únormc                óB  € \         P                  ! V4      w  p\         P                  ! V4      w  p\        WP                  .VR..RR7      p\         P                  ! V) V) .4      p\
        P                  ! V4      pVP                  V4      p	V	RV p
W”WE,            ) pW«3# )a  Solve equality-constrained quadratic programming (EQP) problem.

Solve ``min 1/2 x.T H x + x.t c`` subject to ``A x + b = 0``
using direct factorization of the KKT system.

Parameters
----------
H : sparse array, shape (n, n)
    Hessian matrix of the EQP problem.
c : array_like, shape (n,)
    Gradient of the quadratic objective function.
A : sparse array
    Jacobian matrix of the EQP problem.
b : array_like, shape (m,)
    Right-hand side of the constraint equation.

Returns
-------
x : array_like, shape (n,)
    Solution of the KKT problem.
lagrange_multipliers : ndarray, shape (m,)
    Lagrange multipliers of the KKT problem.
NÚcsc)Úformat)ÚnpÚshaper   ÚTÚhstackr   ÚspluÚsolve)ÚHÚcÚAÚbÚnÚmÚ
kkt_matrixÚkkt_vecÚluÚkkt_solÚxÚlagrange_multiplierss   &&&&        ÚlC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\scipy\optimize\_trustregion_constr\qp_subproblem.pyÚeqp_kktfactr      s•   € ô0 
�Š�!‹�B€AÜ	�Š�!‹�B€Aô
 ˜q§#¡#˜h¨¨D¨	Ð2¸5ÔA€Jä�iŠi˜!˜˜a˜R˜Ó!€Gô
 
�Š�ZÓ	 €BØ�h‰h�wÓ€GØ��ˆ€AØ# a¥c˜N˜?ÐàÐ"Ð"ó    Fc                óô  € \        V4      ^ 8X  d   R# \        P                  ! V4      '       d5   V'       d#   \        P                  ) p\        P                  pM^ p^pRpWEV3# \        P                  ! W4      p^\        P                  ! W4      ,          p\        P                  ! W 4      V^,          ,
          p	Wˆ,          ^V,          V	,          ,
          p
V
^ 8  d   Rp^ ^ V3# \        P
                  ! V
4      pV\        W¸4      ,           pV) ^V,          ,          pRV	,          V,          p\        WE.4      w  rEV'       d   RpM/V^ 8  g   V^8”  d   Rp^ p^ pMRp\        ^ V4      p\        ^V4      pWEV3# )aá  Find the intersection between segment (or line) and spherical constraints.

Find the intersection between the segment (or line) defined by the
parametric  equation ``x(t) = z + t*d`` and the ball
``||x|| <= trust_radius``.

Parameters
----------
z : array_like, shape (n,)
    Initial point.
d : array_like, shape (n,)
    Direction.
trust_radius : float
    Ball radius.
entire_line : bool, optional
    When ``True``, the function returns the intersection between the line
    ``x(t) = z + t*d`` (``t`` can assume any value) and the ball
    ``||x|| <= trust_radius``. When ``False``, the function returns the intersection
    between the segment ``x(t) = z + t*d``, ``0 <= t <= 1``, and the ball.

Returns
-------
ta, tb : float
    The line/segment ``x(t) = z + t*d`` is inside the ball for
    for ``ta <= t <= tb``.
intersect : bool
    When ``True``, there is an intersection between the line/segment
    and the sphere. On the other hand, when ``False``, there is no
    intersection.
FT©é    r    Féþÿÿÿ)
r   r	   ÚisinfÚinfÚdotÚsqrtr   ÚsortedÚmaxÚmin)ÚzÚdÚtrust_radiusÚentire_lineÚtaÚtbÚ	intersectÚar   r   ÚdiscriminantÚsqrt_discriminantÚauxs   &&&&         r   Úsphere_intersectionsr4   A   sP  € ôB ˆAƒw�!„|ØÐä	‡x‚x�×ÒßÜ—&‘&�ˆBÜ—‘‰BàˆBØˆBØˆ	Ø�yÐ Ð ä
�Šˆq‹€AØ	ŒB�FŠF�1‹LÕ€AÜ
�Šˆq‹�| Q•Õ&€AØ•3˜˜1�˜Q�•;€LØ�aÔØˆ	Ø�!�YˆÐÜŸš Ó-Ðð ŒhÐ(Ó,Õ
,€CØ
ˆ��1•�€BØ	ˆA���€BÜ�R�HÓ�F€BçØ‰	ð �Œ6�R˜!”VØˆIØˆBØ‰BàˆIô �Q˜“ˆBÜ�Q˜“ˆBà�9ÐÐr   c                ó.  € \         P                  ! V 4      p \         P                  ! V4      p\         P                  ! V4      p\         P                  ! V4      p\        V4      ^ 8X  d   R# V^ 8H  pW,          W%,          8  P                  4       '       g&   W,          W5,          8„  P                  4       '       d   Rp^ ^ V3# \         P                  ! V4      pW,          p W,          pW',          pW7,          pW ,
          V,          pW0,
          V,          p	\        \         P                  ! W‰4      4      p
\        \         P                  ! W‰4      4      pW«8:  d   RpMRpV'       g.   V^ 8  g   V
^8”  d   Rp^ p
^ pM\        ^ V
4      p
\        ^V4      pW«V3# )a¾  Find the intersection between segment (or line) and box constraints.

Find the intersection between the segment (or line) defined by the
parametric  equation ``x(t) = z + t*d`` and the rectangular box
``lb <= x <= ub``.

Parameters
----------
z : array_like, shape (n,)
    Initial point.
d : array_like, shape (n,)
    Direction.
lb : array_like, shape (n,)
    Lower bounds to each one of the components of ``x``. Used
    to delimit the rectangular box.
ub : array_like, shape (n, )
    Upper bounds to each one of the components of ``x``. Used
    to delimit the rectangular box.
entire_line : bool, optional
    When ``True``, the function returns the intersection between the line
    ``x(t) = z + t*d`` (``t`` can assume any value) and the rectangular
    box. When ``False``, the function returns the intersection between the segment
    ``x(t) = z + t*d``, ``0 <= t <= 1``, and the rectangular box.

Returns
-------
ta, tb : float
    The line/segment ``x(t) = z + t*d`` is inside the box for
    for ``ta <= t <= tb``.
intersect : bool
    When ``True``, there is an intersection between the line (or segment)
    and the rectangular box. On the other hand, when ``False``, there is no
    intersection.
FTr   )	r	   Úasarrayr   ÚanyÚlogical_notr'   Úminimumr(   Úmaximum)r)   r*   ÚlbÚubr,   Úzero_dr/   Ú
not_zero_dÚt_lbÚt_ubr-   r.   s   &&&&&       r   Úbox_intersectionsrA   —   sR  € ôJ 	�
Š
�1‹€AÜ
�
Š
�1‹€AÜ	�Š�B‹€BÜ	�Š�B‹€BäˆAƒw�!„|ØÐð �1‰f€Fð 	
�	�B•JÑ×#Ñ#×%Ò%¨!­)°bµjÑ*@×)EÑ)E×)GÒ)GØˆ	Ø�!�YˆÐä—’ Ó'€JØ	�€AØ	�€AØ	�€BØ	�€Bð �D�A�:€DØ�D�A�:€Dä	ŒR�ZŠZ˜Ó#Ó	$€BÜ	ŒR�ZŠZ˜Ó#Ó	$€Bð 
„xØ‰	àˆ	çØ�Œ6�R˜!”VØˆIØˆBØ‰Bô �Q˜“ˆBÜ�Q˜“ˆBà�9ÐÐr   c                ó  € \        WW#V4      w  rxp	\        WVV4      w  r«p\        P                  ! Wz4      p\        P                  ! W‹4      pV	'       d   V'       d
   WÞ8:  d   RpMRpV'       d   RV
RVRV/pRVRVRV	/pWÞVVV3# WÞV3# )aV  Find the intersection between segment (or line) and box/sphere constraints.

Find the intersection between the segment (or line) defined by the
parametric  equation ``x(t) = z + t*d``, the rectangular box
``lb <= x <= ub`` and the ball ``||x|| <= trust_radius``.

Parameters
----------
z : array_like, shape (n,)
    Initial point.
d : array_like, shape (n,)
    Direction.
lb : array_like, shape (n,)
    Lower bounds to each one of the components of ``x``. Used
    to delimit the rectangular box.
ub : array_like, shape (n, )
    Upper bounds to each one of the components of ``x``. Used
    to delimit the rectangular box.
trust_radius : float
    Ball radius.
entire_line : bool, optional
    When ``True``, the function returns the intersection between the line
    ``x(t) = z + t*d`` (``t`` can assume any value) and the constraints.
    When ``False``, the function returns the intersection between the segment
    ``x(t) = z + t*d``, ``0 <= t <= 1`` and the constraints.
extra_info : bool, optional
    When ``True``, the function returns ``intersect_sphere`` and ``intersect_box``.

Returns
-------
ta, tb : float
    The line/segment ``x(t) = z + t*d`` is inside the rectangular box and
    inside the ball for ``ta <= t <= tb``.
intersect : bool
    When ``True``, there is an intersection between the line (or segment)
    and both constraints. On the other hand, when ``False``, there is no
    intersection.
sphere_info : dict, optional
    Dictionary ``{ta, tb, intersect}`` containing the interval ``[ta, tb]``
    for which the line intercepts the ball. And a boolean value indicating
    whether the sphere is intersected by the line.
box_info : dict, optional
    Dictionary ``{ta, tb, intersect}`` containing the interval ``[ta, tb]``
    for which the line intercepts the box. And a boolean value indicating
    whether the box is intersected by the line.
TFr-   r.   r/   )rA   r4   r	   r:   r9   )r)   r*   r;   r<   r+   r,   Ú
extra_infoÚta_bÚtb_bÚintersect_bÚta_sÚtb_sÚintersect_sr-   r.   r/   Úsphere_infoÚbox_infos   &&&&&&&           r   Úbox_sphere_intersectionsrL   ì   s¥   € ôb 0°°bØ0;ó=Ñ€D�ä2°1Ø3?Ø3>ó@Ñ€D�ô 
�Š�DÓ	€BÜ	�Š�DÓ	€Bß—{ r¤xØ‰	àˆ	çØ˜T 4¨¨{¸KÐHˆØ˜$  d¨K¸ÐEˆØ�y +¨xÐ7Ð7à�yÐ Ð r   c                óZ   € W8*  P                  4       ;'       d    W8*  P                  4       # )zCheck if lb <= x <= ub.)Úall©r   r;   r<   s   &&&r   Úinside_box_boundariesrP   1  s    € à‰G�=‰=‹?×.Ð. ¡Ÿ}™}›Ð.r   c                óX   € \         P                  ! \         P                  ! W4      V4      # )zReturn clipped value of x)r	   r9   r:   rO   s   &&&r   Úreinforce_box_boundariesrR   6  s   € ä�:Š:”b—j’j Ó'¨Ó,Ð,r   c                óê  € VP                  V4      ) p\        WdV4      '       d   \        V4      V8:  d   TpV# V P                  P                  V4      pV P                  V4      p	\        P                   ! Wˆ4      ) \        P                   ! W™4      ,          V,          p
\        P
                  ! V
4      pT
pWj,
          p\        WÍWEV4      w  rïpV'       d   WÏV,          ,           pM#TpT
p\        WÍWEV4      w  rïpWÏV,          ,           pTpTp\        WÍWEV4      w  rïpWÏV,          ,           p\        V P                  V4      V,           4      \        V P                  V4      V,           4      8  d   V# V# )aŸ  Approximately  minimize ``1/2*|| A x + b ||^2`` inside trust-region.

Approximately solve the problem of minimizing ``1/2*|| A x + b ||^2``
subject to ``||x|| < Delta`` and ``lb <= x <= ub`` using a modification
of the classical dogleg approach.

Parameters
----------
A : LinearOperator (or sparse array or ndarray), shape (m, n)
    Matrix ``A`` in the minimization problem. It should have
    dimension ``(m, n)`` such that ``m < n``.
Y : LinearOperator (or sparse array or ndarray), shape (n, m)
    LinearOperator that apply the projection matrix
    ``Q = A.T inv(A A.T)`` to the vector. The obtained vector
    ``y = Q x`` being the minimum norm solution of ``A y = x``.
b : array_like, shape (m,)
    Vector ``b``in the minimization problem.
trust_radius: float
    Trust radius to be considered. Delimits a sphere boundary
    to the problem.
lb : array_like, shape (n,)
    Lower bounds to each one of the components of ``x``.
    It is expected that ``lb <= 0``, otherwise the algorithm
    may fail. If ``lb[i] = -Inf``, the lower
    bound for the ith component is just ignored.
ub : array_like, shape (n, )
    Upper bounds to each one of the components of ``x``.
    It is expected that ``ub >= 0``, otherwise the algorithm
    may fail. If ``ub[i] = Inf``, the upper bound for the ith
    component is just ignored.

Returns
-------
x : array_like, shape (n,)
    Solution to the problem.

Notes
-----
Based on implementations described in pp. 885-886 from [1]_.

References
----------
.. [1] Byrd, Richard H., Mary E. Hribar, and Jorge Nocedal.
       "An interior point algorithm for large-scale nonlinear
       programming." SIAM Journal on Optimization 9.4 (1999): 877-900.
)r$   rP   r   r   r	   Ú
zeros_likerL   )r   ÚYr   r+   r;   r<   Únewton_pointr   ÚgÚA_gÚcauchy_pointÚorigin_pointr)   ÚpÚ_Úalphar/   Úx1Úx2s   &&&&&&             r   Úmodified_doglegr`   ;  sL  € ð` —E‘E˜!“H�9€Lä˜\¨r×2Ò2Ü�Ó Ô-ØˆØˆð 	
�‰�‰�‹
€Að �%‰%�‹(€CÜ—F’F˜1“L�=¤2§6¢6¨#Ó#3Õ3°aÕ7€Lä—=’= Ó.€Lð 	€AØÕ#€AÜ2°1¸Ø3?óAÑ€AˆiçØ�q•�[‰ð ˆØˆÜ.¨q°RØ/;ó=‰ˆ�!à�q•�[ˆð 	€AØ€AÜ*¨1°Ø+7ó9�K€Aˆaà	
�1�W�€Bô ˆA�E‰E�"‹I˜�MÓœT !§%¡%¨£)¨a¥-Ó0Ô0Øˆ	àˆ	r   c           
     óv  € Rp\         P                  ! V4      w  p\         P                  ! V4      w  pVP                  V) 4      pVP                  V P                  V4      V,           4      pVP                  V4      pV) pV'       d   V.pV P                  V4      p\        V4      ^,          pV\        V4      ,
          pV^ 8  d   \	        R4      hVV8  d+   R^ R^RR/pV'       d   XP                  V4       VVR&   VV3# Vf9   \        \        R\         P                  ! V4      ,          R	V,          4      V4      pVf'   \         P                  ! V\         P                  ) 4      pVf&   \         P                  ! V\         P                  4      pV	f	   WÞ,
          p	\        W�V,
          4      p	V
f	   WÞ,
          p
R
p^p^ p\         P                  ! V4      p^ p\        V	4       EF"  pVV8  d   ^p EMV^,          pVP                  V4      pV^ 8:  dg   \         P                  ! V4      '       d   \	        R4      h\        VVWgVRR7      w  pp p!V!'       d   VV V,          ,           p\        WöV4      p^pRp EM�VV,          p VV V,          ,           p"\         P                   P                  V"4      V8¼  dL   \        VV V,          WgV4      w  pp#p!V!'       d   VV#V ,          V,          ,           p\        WöV4      p^pRp EM\#        V"Wg4      '       d   ^ pM	V^,          pV^ 8”  dG   \        VV V,          WgV4      w  pp#p!V!'       d&   VV#V ,          V,          ,           p\        VWg4      p^ pVV
8”  d    M”V'       d   XP                  V"4       VV V,          ,           p$VP                  V$4      p%\        V%4      ^,          p&V&V,          p'V%) V'V,          ,           pT"pT%pT%p\        V4      ^,          pV P                  V4      pEK%  	  \#        WöV4      '       g   TpRpRVRVRV/pV'       d   XVR&   VV3# )a–  Solve EQP problem with projected CG method.

Solve equality-constrained quadratic programming problem
``min 1/2 x.T H x + x.t c``  subject to ``A x + b = 0`` and,
possibly, to trust region constraints ``||x|| < trust_radius``
and box constraints ``lb <= x <= ub``.

Parameters
----------
H : LinearOperator (or sparse array or ndarray), shape (n, n)
    Operator for computing ``H v``.
c : array_like, shape (n,)
    Gradient of the quadratic objective function.
Z : LinearOperator (or sparse array or ndarray), shape (n, n)
    Operator for projecting ``x`` into the null space of A.
Y : LinearOperator,  sparse array, ndarray, shape (n, m)
    Operator that, for a given a vector ``b``, compute smallest
    norm solution of ``A x + b = 0``.
b : array_like, shape (m,)
    Right-hand side of the constraint equation.
trust_radius : float, optional
    Trust radius to be considered. By default, uses ``trust_radius=inf``,
    which means no trust radius at all.
lb : array_like, shape (n,), optional
    Lower bounds to each one of the components of ``x``.
    If ``lb[i] = -Inf`` the lower bound for the i-th
    component is just ignored (default).
ub : array_like, shape (n, ), optional
    Upper bounds to each one of the components of ``x``.
    If ``ub[i] = Inf`` the upper bound for the i-th
    component is just ignored (default).
tol : float, optional
    Tolerance used to interrupt the algorithm.
max_iter : int, optional
    Maximum algorithm iterations. Where ``max_inter <= n-m``.
    By default, uses ``max_iter = n-m``.
max_infeasible_iter : int, optional
    Maximum infeasible (regarding box constraints) iterations the
    algorithm is allowed to take.
    By default, uses ``max_infeasible_iter = n-m``.
return_all : bool, optional
    When ``true``, return the list of all vectors through the iterations.

Returns
-------
x : array_like, shape (n,)
    Solution of the EQP problem.
info : dict
    Dictionary containing the following:

        - niter : Number of iterations.
        - stop_cond : Reason for algorithm termination:
            1. Iteration limit was reached;
            2. Reached the trust-region boundary;
            3. Negative curvature detected;
            4. Tolerance was satisfied.
        - allvecs : List containing all intermediary vectors (optional).
        - hits_boundary : True if the proposed step is on the boundary
          of the trust region.

Notes
-----
Implementation of Algorithm 6.2 on [1]_.

In the absence of spherical and box constraints, for sufficient
iterations, the method returns a truly optimal result.
In the presence of those constraints, the value returned is only
an inexpensive approximation of the optimal value.

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.
gÙ}ÚõÐò¾:z.Trust region problem does not have a solution.ÚniterÚ	stop_condÚhits_boundaryTÚallvecsg{®Gáz„?gš™™™™™¹?Fz9Negative curvature not allowed for unrestricted problems.)r,   )r	   r
   r$   r   Ú
ValueErrorÚappendr'   r(   r%   Úfullr#   rT   Úranger"   rL   rR   r   rP   )(r   r   ÚZrU   r   r+   r;   r<   ÚtolÚmax_iterÚmax_infeasible_iterÚ
return_allÚCLOSE_TO_ZEROr   r   r   ÚrrW   r[   re   ÚH_pÚrt_gÚtr_distanceÚinford   rc   ÚcounterÚlast_feasible_xÚkÚiÚpt_H_pr\   r]   r/   Úx_nextÚthetaÚr_nextÚg_nextÚ	rt_g_nextÚbetas(   &&&&&&&&&&&&                            r   Úprojected_cgr€   ›  sù  € ð` €Mä	�Š�!‹�B€AÜ	�Š�!‹�B€Að 	
�‰ˆqˆb‹	€AØ	�‰ˆa�e‰e�A‹h˜�lÓ€AØ	�‰ˆa‹€AØ	
ˆ€A÷ Ø�#ˆà
�%‰%�‹(€CÜ�‹7�A�:€Dð ¤ a£Õ(€KØ�Q„ÜÐIÓJÐJð 
�}Ô	$Ø˜˜K¨¨O¸TÐBˆßØ�N‰N˜1ÔØ%ˆD�‰OØ�$ˆwˆð ‚{Ü”#�dœRŸWšW T›]Õ*¨C°$­JÓ7¸ÓGˆà	‚zÜ�WŠW�QœŸ™˜Ó ˆØ	‚zÜ�WŠW�QœŸ™ÓˆàÒØ•3ˆÜ�8˜q�SÓ!€HàÒ"Ø�cÐà€MØ€IØ€GÜ—m’m AÓ&€OØ	€AÜ�8�_ˆà�#Œ:ØˆIÚØ	ˆQ�ˆà—‘˜“ˆà�QŒ;Ü�xŠx˜×%Ò%Ü ð ">ó ?ð ?ô '?Ø�q˜" ,¸Dô'BÑ#��5˜)÷ Ø˜E !�G��Aô -¨Q°BÓ7�à�	Ø $�Úð �v•ˆØ�U˜1•W•ˆô �9‰9�>‰>˜&Ó! \Ô1ä":¸1¸eÀA½gÀrØ;Gó#IÑˆAˆu�i÷ Ø˜˜e� A�Õ%�ô )¨°Ó3ˆAàˆIØ ˆMÚô ! ¨×0Ò0Ø‰Gà�q�LˆGà�QŒ;Ü":¸1¸eÀA½gÀrØ;Gó#IÑˆAˆu�içØ"# e¨E¥k°!¥mÕ"3�ô #;¸?Ø;=ó#C�à�àÐ(Ô(ÙçØ�N‰N˜6Ô"ð �U˜3•Y•ˆà—‘�v“ˆä˜“L !•Oˆ	Ø˜4ÕˆØˆH�t˜A•vÕˆàˆØˆØˆÜ�A‹w˜�zˆØ�e‰e�A‹h‹ñi ôl ! ¨×+Ò+ØˆØˆØ�Q˜ YØ˜]ð,€DçØ!ˆˆY‰Øˆdˆ7€Nr   )r   r4   rA   rL   rP   r`   r€   )F)FF)Ú__doc__Úscipy.sparser   r   Úmathr   Únumpyr	   Únumpy.linalgr   Ú__all__r   r4   rA   rL   rP   rR   r`   r#   r€   © r   r   Ú<module>rˆ      se   ðÙ 9ç ,Ý Û Ý ò€ò*#ôZSôlRôjB!òJ/ò
-ò
]ð@ .0¯V©VØ˜T tØ°DØ!öbr   