+
    /i P                     R   R t ^ RIHt ^ RIt^ RIHt ^ RIHtH	t	H
t
 ^ RIHtHt ^ RIHt ]P                   ! ]4      P$                  tR tR!R ltR	 tR
 tR"R ltR#R ltR$R ltR tR tR%R ltR%R ltR tR t R t!R t"R t#R t$R t%R$R lt&R t'R t(R t)R&R lt*R&R lt+R t,R  t-R# )'z+Functions used by least-squares algorithms.)copysignN)norm)
cho_factor	cho_solveLinAlgError)LinearOperatoraslinearoperator)issparsec                   \         P                  ! W4      pV^ 8X  d   \        R4      h\         P                  ! W4      p\         P                  ! W 4      V^,          ,
          pV^ 8  d   \        R4      h\         P                  ! WD,          W5,          ,
          4      pV\	        Wd4      ,           ) pWs,          pWW,          p	W8  d   W3# W3# )aE  Find the intersection of a line with the boundary of a trust region.

This function solves the quadratic equation with respect to t
||(x + s*t)||**2 = Delta**2.

Returns
-------
t_neg, t_pos : tuple of float
    Negative and positive roots.

Raises
------
ValueError
    If `s` is zero or `x` is not within the trust region.
z`s` is zero.z#`x` is not within the trust region.)npdot
ValueErrorsqrtr   )
xsDeltaabcdqt1t2s
   &&&       X/var/www/html/photoedit/myenv/lib/python3.14/site-packages/scipy/optimize/_lsq/common.pyintersect_trust_regionr      s      	qAAv((
qA
quaxA1u>??
ac	A hqn
A	
B	
B	wvv    c	                   R p	W2,          p
W8  d)   \         V,          V^ ,          ,          pVR,          V8  pMRpV'       d.   VP                  W#,          4      ) p\        V4      V8:  d   VR^ 3# \        V
4      V,          pV'       d   V	! RWV4      w  ppV) V,          pMRpVe   V'       g*   V^ 8X  d#   \        RV,          VV,          R,          4      pMTp\	        V4       F  pVV8  g   VV8  d"   \        RV,          VV,          R,          4      pV	! VWV4      w  ppV^ 8  d   TpVV,          p\        VVV,
          4      pVW,           V,          V,          ,          p\
        P                  ! V4      Wu,          8  g   K   M	  VP                  W^,          V,           ,          4      ) pW\        V4      ,          ,          pVVX^,           3# )a  Solve a trust-region problem arising in least-squares minimization.

This function implements a method described by J. J. More [1]_ and used
in MINPACK, but it relies on a single SVD of Jacobian instead of series
of Cholesky decompositions. Before running this function, compute:
``U, s, VT = svd(J, full_matrices=False)``.

Parameters
----------
n : int
    Number of variables.
m : int
    Number of residuals.
uf : ndarray
    Computed as U.T.dot(f).
s : ndarray
    Singular values of J.
V : ndarray
    Transpose of VT.
Delta : float
    Radius of a trust region.
initial_alpha : float, optional
    Initial guess for alpha, which might be available from a previous
    iteration. If None, determined automatically.
rtol : float, optional
    Stopping tolerance for the root-finding procedure. Namely, the
    solution ``p`` will satisfy ``abs(norm(p) - Delta) < rtol * Delta``.
max_iter : int, optional
    Maximum allowed number of iterations for the root-finding procedure.

Returns
-------
p : ndarray, shape (n,)
    Found solution of a trust-region problem.
alpha : float
    Positive value such that (J.T*J + alpha*I)*p = -J.T*f.
    Sometimes called Levenberg-Marquardt parameter.
n_iter : int
    Number of iterations made by root-finding procedure. Zero means
    that Gauss-Newton step was selected as the solution.

References
----------
.. [1] More, J. J., "The Levenberg-Marquardt Algorithm: Implementation
       and Theory," Numerical Analysis, ed. G. A. Watson, Lecture Notes
       in Mathematics 630, Springer Verlag, pp. 105-116, 1977.
c                    V^,          V ,           p\        W,          4      pWS,
          p\        P                  ! V^,          V^,          ,          4      ) V,          pWg3# )zFunction of which to find zero.

It is defined as "norm of regularized (by alpha) least-squares
solution minus `Delta`". Refer to [1]_.
)r   r   sum)alphasufr   r   denomp_normphi	phi_primes   &&&&    r   phi_and_derivative2solve_lsq_trust_region.<locals>.phi_and_derivativej   sO     1uck"nVVC1Huax/0069	~r   Fg        gMbP?      ?)EPSr   r   maxranger   abs)nmufr   Vr   initial_alphartolmax_iterr%   r    	threshold	full_rankpalpha_upperr#   r$   alpha_lowerr   itratios   &&&&&&&&&            r   solve_lsq_trust_regionr;   9   s   b
 &C 	v!GadN	bEI%		UU26]N7ec19s)e#K+C?YdY&I-12DEK'+*Cc)IJHo;%+"5+kK.G#-MNE+E35AY7Ki+uu}5#+&..66#;%   
sdUl#	$$A
 aAeR!Vr   c                `    \        V 4      w  r4\        W43V4      ) p\        P                  ! WU4      V^,          8:  d   VR3#  V R,          V^,          ,          pV R,          V^,          ,          pV R,          V^,          ,          pV^ ,          V,          p	V^,          V,          p
\        P
                  ! V) V	,           ^Wh,
          V
,           ,          ^V,          ^V) V,           V
,           ,          V) V	,
          .4      p\        P                  ! V4      p\        P                  ! V\        P                  ! V4      ,          4      pV\        P                  ! ^V,          ^V^,          ,           ,          ^V^,          ,
          ^V^,          ,           ,          34      ,          pR\        P                  ! WPP                  V4      ,          ^ R7      ,          \        P                  ! W4      ,           p\        P                  ! V4      pVRV3,          pVR3#   \         d     ELi ; i)	a2  Solve a general trust-region problem in 2 dimensions.

The problem is reformulated as a 4th order algebraic equation,
the solution of which is found by numpy.roots.

Parameters
----------
B : ndarray, shape (2, 2)
    Symmetric matrix, defines a quadratic term of the function.
g : ndarray, shape (2,)
    Defines a linear term of the function.
Delta : float
    Radius of a trust region.

Returns
-------
p : ndarray, shape (2,)
    Found solution.
newton_step : bool
    Whether the returned solution is the Newton step which lies within
    the trust region.
Tr'   axisNNNF)    r@   )r@      )rA   rA   )r   r   r   r   r   arrayrootsrealisrealvstackr   argmin)Bgr   Rlowerr6   r   r   r   r   fcoeffstvalueis   &&&            r   solve_trust_region_2drQ      s   .a=z1%%66!<5!8#d7N $
 	
$%(A	$%(A	$%(A	!uA	!uAXX
aaeai!a%qb1fqj)9A26BDF
A
"))A, A		1q5A1H-AqDQAX/FGHHA"&&UU1XA..=E
		%A	!Q$Ae8O)  s   A H H-,H-c                    V^ 8  d
   W,          pMY!u;8X  d   ^ 8X  d   M M^pM^ pVR8  d   RV,          p W3# VR8  d   V'       d
   V R,          p W3# )zUpdate the radius of a trust region based on the cost reduction.

Returns
-------
Delta : float
    New radius.
ratio : float
    Ratio between actual and predicted reductions.
      ?g      ?g       @ )r   actual_reductionpredicted_reduction	step_norm	bound_hitr:   s   &&&&& r   update_tr_radiusrY      s`     Q 6		5A	5t|y  < 
)<r   c                f   V P                  V4      p\        P                   ! WU4      pVe%   V\        P                   ! W#,          V4      ,          pVR,          p\        P                   ! W4      pVe   V P                  V4      pV\        P                   ! W4      ,          pR\        P                   ! W4      ,          \        P                   ! W4      ,           p	VeP   V\        P                   ! WC,          V4      ,          pV	R\        P                   ! WC,          V4      ,          ,          p	WgV	3# Wg3# )aH  Parameterize a multivariate quadratic function along a line.

The resulting univariate quadratic function is given as follows::

    f(t) = 0.5 * (s0 + s*t).T * (J.T*J + diag) * (s0 + s*t) +
           g.T * (s0 + s*t)

Parameters
----------
J : ndarray, sparse array or LinearOperator shape (m, n)
    Jacobian matrix, affects the quadratic term.
g : ndarray, shape (n,)
    Gradient, defines the linear term.
s : ndarray, shape (n,)
    Direction vector of a line.
diag : None or ndarray with shape (n,), optional
    Addition diagonal part, affects the quadratic term.
    If None, assumed to be 0.
s0 : None or ndarray with shape (n,), optional
    Initial point. If None, assumed to be 0.

Returns
-------
a : float
    Coefficient for t**2.
b : float
    Coefficient for t.
c : float
    Free term. Returned only if `s0` is provided.
r'   )r   r   )
JrI   r   diags0vr   r   ur   s
   &&&&&     r   build_quadratic_1dr`      s    > 	
aA
qA	RVVAHa  HA
qA	~EE"I	RVVA\"&&,.	1%%Arvvbi,,,AQwtr   c                ,   W#.pV ^ 8w  d3   RV,          V ,          pY&u;8  d   V8  d   M MVP                  V4       \        P                  ! V4      pWPV,          V,           ,          V,           p\        P                  ! V4      pWX,          Wx,          3# )zMinimize a 1-D quadratic function subject to bounds.

The free term `c` is 0 by default. Bounds must be finite.

Returns
-------
t : float
    Minimum point.
y : float
    Minimum value.
g      )appendr   asarrayrG   )	r   r   lbubr   rN   extremumy	min_indexs	   &&&&&    r   minimize_quadratic_1dri   .  ss     
AAv!8a<2HHX


1A	UQY!A		!I<%%r   c                   VP                   ^8X  dQ   V P                  V4      p\        P                  ! WD4      pVe%   V\        P                  ! W#,          V4      ,          pMjV P                  VP                  4      p\        P                  ! V^,          ^ R7      pVe-   V\        P                  ! W2^,          ,          ^R7      ,          p\        P                  ! W!4      pRV,          V,           # )a  Compute values of a quadratic function arising in least squares.

The function is 0.5 * s.T * (J.T * J + diag) * s + g.T * s.

Parameters
----------
J : ndarray, sparse array or LinearOperator, shape (m, n)
    Jacobian matrix, affects the quadratic term.
g : ndarray, shape (n,)
    Gradient, defines the linear term.
s : ndarray, shape (k, n) or (n,)
    Array containing steps as rows.
diag : ndarray, shape (n,), optional
    Addition diagonal part, affects the quadratic term.
    If None, assumed to be 0.

Returns
-------
values : ndarray with shape (k,) or float
    Values of the function. If `s` was 2-D, then ndarray is
    returned, otherwise, float is returned.
r=   r'   )ndimr   r   Tr   )r[   rI   r   r\   Jsr   ls   &&&&   r   evaluate_quadraticro   E  s    . 	vv{UU1XFF2N!$$AUU133ZFF2q5q!!t!,,A
qA7Q;r   c                D    \         P                  ! W8  W8*  ,          4      # )z$Check if a point lies within bounds.)r   all)r   rd   re   s   &&&r   	in_boundsrr   o  s    6617qw'((r   c                X   \         P                  ! V4      pW,          p\         P                  ! V 4      pVP                  \         P                  4       \         P
                  ! RR7      ;_uu_ 4        \         P                  ! W ,
          V,          V,          W0,
          V,          V,          4      Wd&   RRR4       \         P                  ! V4      pV\         P                  ! Wg4      \         P                  ! V4      P                  \        4      ,          3#   + '       g   i     Ll; i)a  Compute a min_step size required to reach a bound.

The function computes a positive scalar t, such that x + s * t is on
the bound.

Returns
-------
step : float
    Computed step. Non-negative value.
hits : ndarray of int with shape of x
    Each element indicates whether a corresponding variable reaches the
    bound:

         *  0 - the bound was not hit.
         * -1 - the lower bound was hit.
         *  1 - the upper bound was hit.
ignore)overN)r   nonzero
empty_likefillinferrstatemaximumminequalsignastypeint)r   r   rd   re   non_zero
s_non_zerostepsmin_steps   &&&&    r   step_size_to_boundr   t  s    $ zz!}HJMM!E	JJrvv	(	#	#**bfh%7*%D&(fh%7*%DF 
$ vve}HRXXe.1B1B31GGGG	 
$	#s   3ADD)	c                4   \         P                  ! V \        R7      pV^ 8X  d   RW@V8*  &   ^W@V8  &   V# W,
          pW ,
          pV\         P                  ! ^\         P                  ! V4      4      ,          pV\         P                  ! ^\         P                  ! V4      4      ,          p\         P
                  ! V4      V\         P                  ! Wg4      8*  ,          p	RWI&   \         P
                  ! V4      V\         P                  ! WX4      8*  ,          p
^WJ&   V# )a  Determine which constraints are active in a given point.

The threshold is computed using `rtol` and the absolute value of the
closest bound.

Returns
-------
active : ndarray of int with shape of x
    Each component shows whether the corresponding constraint is active:

         *  0 - a constraint is not active.
         * -1 - a lower bound is active.
         *  1 - a upper bound is active.
dtyper(   )r   
zeros_liker   r{   r,   isfiniteminimum)r   rd   re   r2   active
lower_dist
upper_distlower_thresholdupper_thresholdlower_activeupper_actives   &&&&       r   find_active_constraintsr     s     ]]1C(FqyBwBwJJRZZ266":66ORZZ266":66OKKO2::j#JJLLFKKO2::j#JJLLFMr   c           	        V P                  4       p\        WW#4      p\        P                  ! VR4      p\        P                  ! V^4      pV^ 8X  dL   \        P                  ! W,          W&,          4      WF&   \        P                  ! W',          W,          4      WG&   MW,          V\        P
                  ! ^\        P                  ! W,          4      4      ,          ,           WF&   W',          V\        P
                  ! ^\        P                  ! W',          4      4      ,          ,
          WG&   WA8  WB8  ,          pRW,          W(,          ,           ,          WH&   V# )zShift a point to the interior of a feasible region.

Each element of the returned vector is at least at a relative distance
`rstep` from the closest bound. If ``rstep=0`` then `np.nextafter` is used.
r'   r(   )copyr   r   r}   	nextafterr{   r,   )	r   rd   re   rstepx_newr   
lower_mask
upper_masktight_boundss	   &&&&     r   make_strictly_feasibler     s     FFHE$QB6F&"%J&!$JzLLHLLH^"RZZ266".3I%JJK^"RZZ266".3I%JJK J5:.L!1B4D!DEELr   c                L   \         P                  ! V 4      p\         P                  ! V 4      pV^ 8  \         P                  ! V4      ,          pW6,          W,          ,
          WF&   RWV&   V^ 8  \         P                  ! V4      ,          pW,          W&,          ,
          WF&   ^WV&   WE3# )a  Compute Coleman-Li scaling vector and its derivatives.

Components of a vector v are defined as follows::

           | ub[i] - x[i], if g[i] < 0 and ub[i] < np.inf
    v[i] = | x[i] - lb[i], if g[i] > 0 and lb[i] > -np.inf
           | 1,           otherwise

According to this definition v[i] >= 0 for all i. It differs from the
definition in paper [1]_ (eq. (2.2)), where the absolute value of v is
used. Both definitions are equivalent down the line.
Derivatives of v with respect to x take value 1, -1 or 0 depending on a
case.

Returns
-------
v : ndarray with shape of x
    Scaling vector.
dv : ndarray with shape of x
    Derivatives of v[i] with respect to x[i], diagonal elements of v's
    Jacobian.

References
----------
.. [1] M.A. Branch, T.F. Coleman, and Y. Li, "A Subspace, Interior,
       and Conjugate Gradient Method for Large-Scale Bound-Constrained
       Minimization Problems," SIAM Journal on Scientific Computing,
       Vol. 21, Number 1, pp 1-23, 1999.
r(   )r   	ones_liker   r   )r   rI   rd   re   r^   dvmasks   &&&&   r   CL_scaling_vectorr     s    < 	QA	q	BER[[_$Dh AGBHER[[_$Dg AGBH5Lr   c                   \        WV4      '       d   V \        P                  ! V 4      3# \        P                  ! V4      p\        P                  ! V4      pV P	                  4       p\        P
                  ! V \        R7      pW4( ,          p\        P                  ! W,          ^W,          ,          W,          ,
          4      WW&   W,          W,          8  Wg&   V( V,          p\        P                  ! W,          ^W',          ,          W,          ,
          4      WW&   W,          W',          8  Wg&   W4,          pW!,
          p\        P                  ! W,          W,          ,
          ^W,          ,          4      p	W,          \        P                  ! V	^W,          ,          V	,
          4      ,           WW&   WV,          8  Wg&   \        P                  ! V 4      p
RW&   WZ3# )z3Compute reflective transformation and its gradient.r   r(   )
rr   r   r   r   r   r   boolr{   r   	remainder)rg   rd   re   	lb_finite	ub_finiter   
g_negativer   r   rN   rI   s   &&&        r   reflective_transformationr     sK   ",,q/!!BIBI	Aq-Jz!Djj!bh,"89AGw)J:	!Djj!bh,"89AGw)J D
A
QWrx'QW5AhAq17{Q77AGT7{J
QAAM4Kr   c            
      D    \        R P                  RRRRRR4      4       R# )z${:^15}{:^15}{:^15}{:^15}{:^15}{:^15}	Iterationz
Total nfevCostCost reduction	Step norm
OptimalityNprintformatrT   r   r   print_header_nonlinearr   !  s%    	
06+|V5E|-.r   c           	      h    Vf   RpMVR pVf   RpMVR p\        V R VR VR V V VR 24       R # Nz^15.2ez^15z^15.4ez               r   )	iterationnfevcostcost_reductionrW   
optimalitys   &&&&&&r   print_iteration_nonlinearr   '  sX    !*62	 (		YsOD:d6]>2B9+jY_M`
abr   c            	      B    \        R P                  RRRRR4      4       R# )z{:^15}{:^15}{:^15}{:^15}{:^15}r   r   r   r   r   Nr   rT   r   r   print_header_linearr   6  s#    	
*6+v'7 !r   c                 b    Vf   RpMVR pVf   RpMVR p\        V R VR V V VR 24       R # r   r   )r   r   r   rW   r   s   &&&&&r   print_iteration_linearr   <  sQ    !*62	 (		YsOD=(8JvCV
WXr   c                    \        V \        4      '       d   V P                  V4      # V P                  P	                  V4      # )z4Compute gradient of the least-squares cost function.)
isinstancer   rmatvecrl   r   )r[   rL   s   &&r   compute_gradr   N  s/    !^$$yy|sswwqzr   c                `   \        V 4      '       dL   \        P                  ! V P                  ^4      P	                  ^ R7      4      P                  4       R,          pM&\        P                  ! V ^,          ^ R7      R,          pVf	   ^W"^ 8H  &   M\        P                  ! W!4      p^V,          V3# )z5Compute variables scale based on the Jacobian matrix.r=   r'   )r	   r   rc   powerr   ravelr{   )r[   scale_inv_old	scale_invs   && r   compute_jac_scaler   V  s    {{JJqwwqz~~1~56<<>C	FF1a4a(#-	$%	q.!JJy8	y=)##r   c                v   a a \        S 4      o V V3R lpV V3R lpV V3R lp\        S P                  W#VR7      # )z#Return diag(d) J as LinearOperator.c                 4   < SSP                  V 4      ,          # N)matvecr   r[   r   s   &r   r   (left_multiplied_operator.<locals>.matveci  s    188A;r   c                 b   < SR \         P                  3,          SP                  V 4      ,          # r?   )r   newaxismatmatXr[   r   s   &r   r   (left_multiplied_operator.<locals>.matmatl  s#    BJJ!((1+--r   c                 P   < SP                  V P                  4       S,          4      # r   )r   r   r   s   &r   r   )left_multiplied_operator.<locals>.rmatveco  s    yyQ''r   r   r   r   r   r   shaper[   r   r   r   r   s   ff   r   left_multiplied_operatorr   e  s6    A.( !''&")+ +r   c                v   a a \        S 4      o V V3R lpV V3R lpV V3R lp\        S P                  W#VR7      # )z#Return J diag(d) as LinearOperator.c                 \   < SP                  \        P                  ! V 4      S,          4      # r   )r   r   r   r   s   &r   r   )right_multiplied_operator.<locals>.matvecz  s    xxa((r   c                 b   < SP                  V SR \        P                  3,          ,          4      # r   )r   r   r   r   s   &r   r   )right_multiplied_operator.<locals>.matmat}  s$    xxAam,,--r   c                 4   < SSP                  V 4      ,          # r   r   r   s   &r   r   *right_multiplied_operator.<locals>.rmatvec  s    199Q<r   r   r   r   s   ff   r   right_multiplied_operatorr   v  s6    A).  !''&")+ +r   c                   a aa \        S 4      o S P                  w  opV V3R lpV VV3R lp\        SV,           V3W4R7      # )zReturn a matrix arising in regularized least squares as LinearOperator.

The matrix is
    [ J ]
    [ D ]
where D is diagonal matrix with elements from `diag`.
c                 `   < \         P                  ! SP                  V 4      SV ,          34      # r   )r   hstackr   )r   r[   r\   s   &r   r   (regularized_lsq_operator.<locals>.matvec  s#    yy!((1+tax011r   c                 V   < V R S pV SR  pSP                  V4      SV,          ,           # r   r   )r   x1x2r[   r\   r.   s   &  r   r   )regularized_lsq_operator.<locals>.rmatvec  s0    rUqrUyy}tby((r   )r   r   )r   r   r   )r[   r\   r-   r   r   r.   s   ff   @r   regularized_lsq_operatorr     s=     	A77DAq2)
 1q5!*VEEr   c                F   V'       d'   \        V \        4      '       g   V P                  4       p \        V 4      '       d7   V ;P                  VP                  V P                  RR7      ,          un        V # \        V \        4      '       d   \        W4      p V # W,          p V # )z`Compute J diag(d).

If `copy` is False, `J` is modified in place (unless being LinearOperator).
clip)mode)r   r   r   r	   datatakeindicesr   r[   r   r   s   &&&r   right_multiplyr     s{    
 Jq.11FFH{{	!&&&00 H 
A~	&	&%a+ H 	
Hr   c                   V'       d'   \        V \        4      '       g   V P                  4       p \        V 4      '       dO   V ;P                  \
        P                  ! V\
        P                  ! V P                  4      4      ,          un        V # \        V \        4      '       d   \        W4      p V # WR\
        P                  3,          ,          p V # )z`Compute diag(d) J.

If `copy` is False, `J` is modified in place (unless being LinearOperator).
r?   )r   r   r   r	   r   r   repeatdiffindptrr   r   r   s   &&&r   left_multiplyr     s    
 Jq.11FFH{{	"))Arwwqxx011 H 
A~	&	&$Q* H 	
q"**}Hr   c                    WV,          8  ;'       d    VR8  pW&Wc,           ,          8  pV'       d   V'       d   ^# V'       d   ^# V'       d   ^# R# )z8Check termination condition for nonlinear least squares.rS   NrT   )	dFFdx_normx_normr:   ftolxtolftol_satisfiedxtol_satisfieds	   &&&&&&&  r   check_terminationr    s?    (]33ut|Nt}55N.		r   c                    V^,          ^V^,          ,          V^,          ,          ,           p\         W3\         8  &   VR,          pW^,          V,          ,          p\        WRR7      V3# )zXScale Jacobian and residuals for a robust loss function.

Arrays are modified in place.
r'   F)r   )r)   r   )r[   rL   rhoJ_scales   &&& r   scale_for_robust_loss_functionr
    s[    
 !fq3q6zAqD((G GcMOGQ'	A%0!33r   )Ng{Gz?
   )NN)r@   r   )g|=)T).__doc__mathr   numpyr   numpy.linalgr   scipy.linalgr   r   r   scipy.sparse.linalgr   r   scipy._lib._sparser	   finfofloatepsr)   r   r;   rQ   rY   r`   ri   ro   rr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  rT   r   r   <module>r     s    1    ; ; @ ' 	hhuo$Nod0f:0f&.$T)
H:$N6)XD.c!Y$$+"+"F,$$4r   