+
    /i                     F   ^ RI t ^ RIt^ RIt^ RIt^ RIHtHtHt ^ RIH	t	H
t
HtHtHtHt ^ RIt^ RIt^ RIHt ^ RIHtHt ^ RIHt ^RIHtHt ^ RI Ht ^ R	IHt ^ R
IHt . R:Ot  ! R R]!4      t"R t#R t$R t%R t&]'! ]! R4      PQ                  4       ]! R4      PQ                  4       R7      t)R t*R;R lt+]*! ]+4       R<R  lt, ! R! R"4      t- ! R# R$4      t. ! R% R4      t/R& t0 ! R' R(].4      t1 ! R) R*4      t2]! R+4      PQ                  4       ])R,&    ! R- R]14      t3 ! R. R/]34      t4 ! R0 R1]14      t5 ! R2 R3]14      t6 ! R4 R5]14      t7 ! R6 R7]14      t8 ! R8 R].4      t9R9 t:]:! R]34      t;]:! R]44      t<]:! R]54      t=]:! R]74      t>]:! R]64      t?]:! R]84      t@]:! R]94      tAR# )=    N)asarraydotvdot)normsolveinvqrsvdLinAlgError)get_blas_funcs)copy_if_needed_dedent_for_py313)getfullargspec_no_self)scalar_search_wolfe1scalar_search_armijo)	signature)get_close_matches)GenericAliasbroyden1broyden2andersonlinearmixingdiagbroydenexcitingmixingnewton_krylovBroydenFirstKrylovJacobianInverseJacobianNoConvergencec                       ] tR t^!tRtRtR# )r   zXException raised when nonlinear solver fails to converge within the specified
`maxiter`. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r!       T/var/www/html/photoedit/myenv/lib/python3.14/site-packages/scipy/optimize/_nonlin.pyr   r   !   s
    r(   c                 J    \         P                  ! V 4      P                  4       # N)npabsolutemaxxs   &r)   maxnormr1   '   s    ;;q>r(   c                    \        V 4      p \        P                  ! V P                  \        P                  4      '       g   \        V \        P
                  R7      # V # )z:Return `x` as an array, of either floats or complex floatsdtype)r   r,   
issubdtyper4   inexactfloat64r/   s   &r)   _as_inexactr8   +   s:    
A=="**--q

++Hr(   c                    \         P                  ! V \         P                  ! V4      4      p \        VRV P                  4      pV! V 4      # )z;Return ndarray `x` as same array subclass and shape as `x0`__array_wrap__)r,   reshapeshapegetattrr:   )r0   x0wraps   && r)   _array_liker@   3   s8    


1bhhrl#A2')9)9:D7Nr(   c                     \         P                  ! V 4      P                  4       '       g%   \         P                  ! \         P                  4      # \        V 4      # r+   )r,   isfiniteallarrayinfr   )vs   &r)   
_safe_normrG   :   s5    ;;q>xx7Nr(   z
    F : function(x) -> f
        Function whose root to find; should take and return an array-like
        object.
    xin : array_like
        Initial guess for the solution
    a  
    iter : int, optional
        Number of iterations to make. If omitted (default), make as many
        as required to meet tolerances.
    verbose : bool, optional
        Print status to stdout on every iteration.
    maxiter : int, optional
        Maximum number of iterations to make. If more are needed to
        meet convergence, `NoConvergence` is raised.
    f_tol : float, optional
        Absolute tolerance (in max-norm) for the residual.
        If omitted, default is 6e-6.
    f_rtol : float, optional
        Relative tolerance for the residual. If omitted, not used.
    x_tol : float, optional
        Absolute minimum step size, as determined from the Jacobian
        approximation. If the step size is smaller than this, optimization
        is terminated as successful. If omitted, not used.
    x_rtol : float, optional
        Relative minimum step size. If omitted, not used.
    tol_norm : function(vector) -> scalar, optional
        Norm to use in convergence check. Default is the maximum norm.
    line_search : {None, 'armijo' (default), 'wolfe'}, optional
        Which type of a line search to use to determine the step size in the
        direction given by the Jacobian approximation. Defaults to 'armijo'.
    callback : function, optional
        Optional callback function. It is called on every iteration as
        ``callback(x, f)`` where `x` is the current solution and `f`
        the corresponding residual.

    Returns
    -------
    sol : ndarray
        An array (of similar array type as `x0`) containing the final solution.

    Raises
    ------
    NoConvergence
        When a solution was not found.

    )params_basicparams_extrac                 f    V P                   '       d   V P                   \        ,          V n         R # R # r+   )r&   
_doc_parts)objs   &r)   _set_docrM   x   s     
{{{kkJ. r(   c                  a a V
f   \         MT
p
\        WgWW:R7      p\        S4      oV V3R lpSP                  4       p\        P
                  ! V\        P                  4      pV! V4      p\        V4      p\        V4      pVP                  VP                  4       VV4       Vf)   Ve   V^,           pM^dVP                  ^,           ,          pVRJ d   RpMVRJ d   RpVR9  d   \        R4      hRpR	pR
pRp\        V4       EF  pVP                  VVV4      pV'       d    EM\        VVV,          4      pVP!                  VVR7      ) p\        V4      ^ 8X  d   \        R4      hV'       d   \#        VVVVV4      w  ppppMRpVV,           pV! V4      p\        V4      pVP%                  VP                  4       V4       V'       d
   V! VV4       VV^,          ,          V^,          ,          pVV^,          ,          V8  d   \        VV4      pM$\        V\'        VVV^,          ,          4      4      pTpV'       g   EKA  \(        P*                  P-                  V RV
! V4      R RVR R24       \(        P*                  P/                  4        EK  	  V'       d   \1        \3        VS4      4      h^pV'       d3   RVP4                  RVRVRV^8H  R^R^R/V,          /p\3        VS4      V3# \3        VS4      # )a>  
Find a root of a function, in a way suitable for large-scale problems.

Parameters
----------
%(params_basic)s
jacobian : Jacobian
    A Jacobian approximation: `Jacobian` object or something that
    `asjacobian` can transform to one. Alternatively, a string specifying
    which of the builtin Jacobian approximations to use:

        krylov, broyden1, broyden2, anderson
        diagbroyden, linearmixing, excitingmixing

%(params_extra)s
full_output : bool
    If true, returns a dictionary `info` containing convergence
    information.
raise_exception : bool
    If True, a `NoConvergence` exception is raise if no solution is found.

See Also
--------
asjacobian, Jacobian

Notes
-----
This algorithm implements the inexact Newton method, with
backtracking or full line searches. Several Jacobian
approximations are available, including Krylov and Quasi-Newton
methods.

References
----------
.. [KIM] C. T. Kelley, "Iterative Methods for Linear and Nonlinear
   Equations". Society for Industrial and Applied Mathematics. (1995)
   https://archive.siam.org/books/kelley/fr16/

N)f_tolf_rtolx_tolx_rtoliterr   c                 V   < \        S! \        V S4      4      4      P                  4       # r+   )r8   r@   flatten)zFr>   s   &r)   funcnonlin_solve.<locals>.func   s#    1[B/0199;;r(   TarmijoFzInvalid line searchg?gH.?g?gMbP?)tolz[Jacobian inversion yielded zero vector. This indicates a bug in the Jacobian approximation.      ?z:  |F(x)| = gz; step 
nitfunstatussuccessmessagez0A solution was found at the specified tolerance.z:The maximum number of iterations allowed has been reached.)NrZ   wolfe)r1   TerminationConditionr8   rU   r,   	full_likerE   r   
asjacobiansetupcopysize
ValueErrorrangecheckminr   _nonlin_line_searchupdater.   sysstdoutwriteflushr   r@   	iteration) rW   r>   jacobianrS   verbosemaxiterrO   rP   rQ   rR   tol_normline_searchcallbackfull_outputraise_exception	conditionrX   r0   dxFxFx_normgammaeta_maxeta_tresholdetanra   r[   sFx_norm_neweta_Ainfos    ff&&&&&&&&&&&&&                 r)   nonlin_solver   }   s   Z #*wH$5+0*.?I 
RB<


A	a	 B	aB2hG(#HNN1668R&QhG166!8nGd		33.// EGL
C7^Q+ #s7{#nnRSn))8q= . / /
 $7aR8C%E!Aq"k ABAaBr(K"%QO Q&!336>L(gu%Cgs5%Q,78C 7JJs,x|A.>gaU"MNJJS V Ar 233Fy**r&6Q;A  ,  3 %	&		 1b!4''1b!!r(   c                   a aaaaaaaa ^ .oV.o\        V4      ^,          .o\        S4      \        S4      ,          oR	VV VVVV3R lloVVV3R lpVR8X  d   \        SVS^ ,          RVR7      w  rp
M'VR8X  d!   \        SS^ ,          S^ ,          ) VR7      w  rXf   RpSVS,          ,           oVS^ ,          8X  d   S^ ,          pMS ! S4      p\        V4      pVSW+3# )
r   c                    < V S	^ ,          8X  d
   S^ ,          # S
V S,          ,           pS! V4      p\        V4      ^,          pV'       d   V S	^ &   VS^ &   VS^ &   V# r   )rG   )r   storextrF   pr   rX   tmp_Fxtmp_phitmp_sr0   s   &&   r)   phi _nonlin_line_search.<locals>.phi  s_    a=1:2XHqM1E!HGAJF1Ir(   c                    < \        V 4      S,           ^,           S,          pS! W,           RR7      S! V 4      ,
          V,          # )   F)r   )abs)r   dsr   rdiffs_norms   & r)   derphi#_nonlin_line_search.<locals>.derphi%  s7    !fvo!U*AD&Q/255r(   rd   {Gz?)xtolaminrZ   )r   r\   )T)r   r   r   )rX   r0   r   r   search_typer   sminr   r   phi1phi0r   r   r   r   r   r   s   ff&f&f&     @@@@@r)   ro   ro     s    CETFBx{mG!WtBxF
 
6 g,S&'!*26TC		 &sGAJ,02 	y 	AbDAE!H}AY!W2hGar(   c                   @   a  ] tR tRt o RtRRRRR]3R ltR tRtV t	R# )re   i?  z
Termination condition for an iteration. It is terminated if

- |F| < f_rtol*|F_0|, AND
- |F| < f_tol

AND

- |dx| < x_rtol*|x|, AND
- |dx| < x_tol

Nc                T   Vf6   \         P                  ! \         P                  4      P                  R,          pVf   \         P                  pVf   \         P                  pVf   \         P                  pW0n        W@n        Wn        W n        W`n	        WPn
        R V n        ^ V n        R # )NgUUUUUU?)r,   finfor7   epsrE   rQ   rR   rO   rP   r   rS   f0_normru   )selfrO   rP   rQ   rR   rS   r   s   &&&&&&&r)   __init__TerminationCondition.__init__L  s|     =HHRZZ(,,6E>VVF=FFE>VVF

		r(   c                   V ;P                   ^,          un         V P                  V4      pV P                  V4      pV P                  V4      pV P                  f   W@n        V^ 8X  d   ^# V P                  e!   ^V P                   V P                  8  ,          # \	        W@P
                  8*  ;'       dS    W@P                  ,          V P                  8*  ;'       d,    W`P                  8*  ;'       d    W`P                  ,          V8*  4      # )r   )	ru   r   r   rS   intrO   rP   rQ   rR   )r   fr0   r   f_normx_normdx_norms   &&&&   r)   rm   TerminationCondition.checkd  s    !11))B-<<!LQ;99 233 Fjj( ; ;{{*dll:; ;::- : :#KK/69< 	<r(   )r   rP   rO   rS   ru   r   rR   rQ   )
r"   r#   r$   r%   r&   r1   r   rm   r'   __classdictcell____classdict__s   @r)   re   re   ?  s)      "$d40< <r(   re   c                   V   a  ] tR tRt o Rt]! ]4      tR tR t	R
R lt
R tR tRtV tR	# )Jacobiani  a.  
Common interface for Jacobians or Jacobian approximations.

The optional methods come useful when implementing trust region
etc., algorithms that often require evaluating transposes of the
Jacobian.

Methods
-------
solve
    Returns J^-1 * v
update
    Updates Jacobian to point `x` (where the function has residual `Fx`)

matvec : optional
    Returns J * v
rmatvec : optional
    Returns A^H * v
rsolve : optional
    Returns A^-H * v
matmat : optional
    Returns A * V, where V is a dense matrix with dimensions (N,K).
todense : optional
    Form the dense Jacobian matrix. Necessary for dense trust region
    algorithms, and useful for testing.

Attributes
----------
shape
    Matrix dimensions (M, N)
dtype
    Data type of the matrix.
func : callable, optional
    Function the Jacobian corresponds to

c                    . ROpVP                  4        F1  w  r4W29  d   \        RV 24      hVf   K  \        WW,          4       K3  	  \        V R4      '       d   RR lpR# R# )r   todensezUnknown keyword argument Nc                 F    Ve   \        RV 24      hV P                  4       # )Nz`dtype` must be None, was )rk   r   )r   r4   ri   s   &&&r)   	__array__$Jacobian.__init__.<locals>.__array__  s'    $$'A%%IJJ||~%r(   )	r   rp   matvecrmatvecrsolvematmatr   r<   r4   NN)itemsrk   setattrhasattr)r   kwnamesnamevaluer   s   &,    r)   r   Jacobian.__init__  s_    888:KD  #<TF!CDD BH-	 & 4##& $r(   c                    \        V 4      # r+   )r   r   s   &r)   aspreconditionerJacobian.aspreconditioner  s    t$$r(   c                    \         hr+   NotImplementedErrorr   rF   r[   s   &&&r)   r   Jacobian.solve      !!r(   c                    R # r+   r!   r   r0   rW   s   &&&r)   rp   Jacobian.update      r(   c                    W0n         VP                  VP                  3V n        VP                  V n        V P                  P
                  \        P
                  J d   V P                  W4       R # R # r+   )rX   rj   r<   r4   	__class__rh   r   rp   r   r0   rW   rX   s   &&&&r)   rh   Jacobian.setup  sM    	ffaff%
WW
>>8>>1KK 2r(   )r4   rX   r<   Nr   )r"   r#   r$   r%   r&   classmethodr   __class_getitem__r   r   r   rp   rh   r'   r   r   s   @r)   r   r     s6     #L $L1& %" r(   r   c                   Z   a  ] tR tRt o Rt]! ]4      tR t]	R 4       t
]	R 4       tRtV tR# )r   i  aG  
A simple wrapper that inverts the Jacobian using the `solve` method.

.. legacy:: class

    See the newer, more consistent interfaces in :mod:`scipy.optimize`.

Parameters
----------
jacobian : Jacobian
    The Jacobian to invert.

Attributes
----------
shape
    Matrix dimensions (M, N)
dtype
    Data type of the matrix.

c                    Wn         VP                  V n        VP                  V n        \	        VR 4      '       d   VP
                  V n        \	        VR4      '       d   VP                  V n        R# R# )rh   r   N)rv   r   r   rp   r   rh   r   r   )r   rv   s   &&r)   r   InverseJacobian.__init__  sR     nnoo8W%%!DJ8X&&#??DL 'r(   c                .    V P                   P                  # r+   )rv   r<   r   s   &r)   r<   InverseJacobian.shape      }}"""r(   c                .    V P                   P                  # r+   )rv   r4   r   s   &r)   r4   InverseJacobian.dtype  r   r(   )rv   r   r   rh   rp   N)r"   r#   r$   r%   r&   r   r   r   r   propertyr<   r4   r'   r   r   s   @r)   r   r     sD     , $L1+ # # # #r(   c                  a a \         P                  P                  P                  o\	        S \
        4      '       d   S # \        P                  ! S 4      '       d   \        S \
        4      '       d   S ! 4       # \	        S \        P                  4      '       d   S P                  ^8  d   \        R4      h\        P                  ! \        P                  ! S 4      4      o S P                  ^ ,          S P                  ^,          8w  d   \        R4      h\        V 3R lV 3R lRV 3R llRV 3R llS P                   S P                  R7      # \         P                  P#                  S 4      '       dp   S P                  ^ ,          S P                  ^,          8w  d   \        R4      h\        V 3R	 lV 3R
 lRV V3R llRV V3R llS P                   S P                  R7      # \%        S R4      '       d   \%        S R4      '       dv   \%        S R4      '       dd   \        \'        S R4      \'        S R4      S P(                  \'        S R4      \'        S R4      \'        S R4      S P                   S P                  R7      # \+        S 4      '       d    ! V V3R lR\
        4      pV! 4       # \	        S \,        4      '       d;   \/        \0        \2        \4        \6        \8        \:        \<        R7      S ,          ! 4       # \?        R4      h)z=
Convert given object to one suitable for use as a Jacobian.
zarray must have rank <= 2zarray must be squarec                    < \        SV 4      # r+   )r   rF   Js   &r)   <lambda>asjacobian.<locals>.<lambda>  s    Qr(   c                 L   < \        SP                  4       P                  V 4      # r+   )r   conjTr   s   &r)   r   r     s    #affhjj!*<r(   c                    < \        SV 4      # r+   )r   rF   r[   r   s   &&r)   r   r     s    uQ{r(   c                 L   < \        SP                  4       P                  V 4      # r+   )r   r   r   r   s   &&r)   r   r     s    affhjj!0Dr(   )r   r   r   r   r4   r<   zmatrix must be squarec                    < SV ,          # r+   r!   r   s   &r)   r   r     s	    Qr(   c                 F   < SP                  4       P                  V ,          # r+   r   r   r   s   &r)   r   r     s    !&&(**q.r(   c                    < S! SV 4      # r+   r!   rF   r[   r   spsolves   &&r)   r   r     s    wq!}r(   c                 F   < S! SP                  4       P                  V 4      # r+   r   r   s   &&r)   r   r     s    

A0Fr(   r<   r4   r   r   r   r   rp   rh   )r   r   r   r   rp   rh   r4   r<   c                   d   <a  ] tR tRt o R tR	VV3R lltV3R ltR	VV3R lltV3R ltRt	V t
R# )
asjacobian.<locals>.Jaci  c                    Wn         R # r+   r/   r   s   &&&r)   rp   asjacobian.<locals>.Jac.update  s    r(   c                   < S! V P                   4      p\        V\        P                  4      '       d   \	        W14      # \
        P                  P                  V4      '       d	   S! W14      # \        R 4      hzUnknown matrix type)	r0   
isinstancer,   ndarrayr   scipysparseissparserk   r   rF   r[   mr   r   s   &&& r)   r   asjacobian.<locals>.Jac.solve!  sV    dffIa,, ;&\\**1--"1=($%:;;r(   c                   < S! V P                   4      p\        V\        P                  4      '       d   \	        W!4      # \
        P                  P                  V4      '       d	   W!,          # \        R 4      hr  )	r0   r  r,   r  r   r  r  r  rk   r   rF   r  r   s   && r)   r   asjacobian.<locals>.Jac.matvec*  sS    dffIa,,q9$\\**1--5L$%:;;r(   c                R  < S! V P                   4      p\        V\        P                  4      '       d%   \	        VP                  4       P                  V4      # \        P                  P                  V4      '       d"   S! VP                  4       P                  V4      # \        R 4      hr  )r0   r  r,   r  r   r   r   r  r  r  rk   r  s   &&& r)   r   asjacobian.<locals>.Jac.rsolve3  sp    dffIa,, Q//\\**1--"1668::q11$%:;;r(   c                R  < S! V P                   4      p\        V\        P                  4      '       d%   \	        VP                  4       P                  V4      # \        P                  P                  V4      '       d"   VP                  4       P                  V,          # \        R 4      hr  )r0   r  r,   r  r   r   r   r  r  r  rk   r  s   && r)   r   asjacobian.<locals>.Jac.rmatvec<  sm    dffIa,,qvvxzz1--\\**1--668::>)$%:;;r(   r/   Nr   )r"   r#   r$   r%   rp   r   r   r   r   r'   r   )r   r   r   s   @r)   Jacr     s-     < <<< << <r(   r  )r   r   r   r   r   r   krylovz#Cannot convert object to a Jacobianr   ) r  r  linalgr   r  r   inspectisclass
issubclassr,   r  ndimrk   
atleast_2dr   r<   r4   r  r   r=   r   callablestrdictr   BroydenSecondAndersonDiagBroydenLinearMixingExcitingMixingr   	TypeError)r   r  r   s   f @r)   rg   rg     s!    ll!!))G!X			
1h 7 7s
	Arzz	"	"66A:899MM"**Q-(771:#3442 <:DggQWW	6 	6
 
		q	!	!771:#455 8<FggQWW	6 	6
 
G		G!4!4G9L9Lwq(3 '9 5gg&q(3&q(3%a1gggg' 	' 
!&	< &	<( &	<N u	As		\*% +!-#1)+ ,-. 0 	0 =>>r(   c                   B   a  ] tR tRt o ]! ]4      tR tR tR t	Rt
V tR# )GenericBroydeniU  c                   \         P                  WW#4       W n        Wn        \	        V R 4      '       dW   V P
                  fG   \        V4      pV'       d+   R\        \        V4      ^4      ,          V,          V n        R# RV n        R# R# R# )alphaN      ?r\   )r   rh   last_flast_xr   r%  r   r.   )r   r>   f0rX   normf0s   &&&& r)   rh   GenericBroyden.setupY  si    t*4!!djj&8 "XF T"Xq!11F:
 
 '9!r(   c                    \         hr+   r   r   r0   r   r   dfr   df_norms   &&&&&&&r)   _updateGenericBroyden._updateg  r   r(   c           
         W P                   ,
          pWP                  ,
          pV P                  WWC\        V4      \        V4      4       W n         Wn        R # r+   )r'  r(  r0  r   )r   r0   r   r.  r   s   &&&  r)   rp   GenericBroyden.updatej  s<    __Q248T"X6r(   )r%  r'  r(  N)r"   r#   r$   r%   r   r   r   rh   r0  rp   r'   r   r   s   @r)   r#  r#  U  s$     #L1!" r(   r#  c                      a  ] tR tRt o Rt]! ]4      tR t]	R 4       t
]	R 4       tR tR tRR ltRR	 ltR
 tRR ltR tR tR tRR ltRtV tR# )LowRankMatrixir  z
A matrix represented as

.. math:: \alpha I + \sum_{n=0}^{n=M} c_n d_n^\dagger

However, if the rank of the matrix reaches the dimension of the vectors,
full matrix representation will be used thereon.

c                T    Wn         . V n        . V n        W n        W0n        R V n        R # r+   )r%  csr   r   r4   	collapsed)r   r%  r   r4   s   &&&&r)   r   LowRankMatrix.__init__  s&    

r(   c                    \        . ROVR,          V .,           4      w  rEpW,          p\        W#4       F!  w  rV! W4      p
V! WVP                  V
4      pK#  	  V# )axpyNr   N)r;  scaldotc)r   ziprj   )rF   r%  r7  r   r;  r=  r>  wcdas   &&&&       r)   _matvecLowRankMatrix._matvec  sZ    )*B*,R&A3,8DIKDAQ
AQ1661%A   r(   c           	        \        V4      ^ 8X  d	   W,          # \        RR.VR,          V .,           4      w  rEV^ ,          pV\        P                  ! \        V4      VP                  R7      ,          p\        V4       F5  w  r\        V4       F!  w  rWxV
3;;,          V! W4      ,          uu&   K#  	  K7  	  \        P                  ! \        V4      VP                  R7      p\        V4       F  w  rV! W4      W&   K  	  W,          p\        W|4      pW,          p\        W,4       F  w  rV! WVP                  V) 4      pK  	  V# )Evaluate w = M^-1 vr;  r>  r<  r3   )
lenr   r,   identityr4   	enumeratezerosr   r?  rj   )rF   r%  r7  r   r;  r>  c0AirB  jrA  qr@  qcs   &&&&           r)   _solveLowRankMatrix._solve  s    r7a<7N $VV$4bfslC
UBKKBrxx88bMDA!"A#$q*$ & " HHSWBHH-bMDA:AD "	
!KGZEAQ166B3'A   r(   c                    V P                   e"   \        P                  ! V P                   V4      # \        P	                  WP
                  V P                  V P                  4      # )zEvaluate w = M v)r8  r,   r   r5  rD  r%  r7  r   r   rF   s   &&r)   r   LowRankMatrix.matvec  sB    >>%66$..!,,$$Q

DGGTWWEEr(   c                $   V P                   e:   \        P                  ! V P                   P                  P	                  4       V4      # \
        P                  V\        P                  ! V P                  4      V P                  V P                  4      # )zEvaluate w = M^H v)
r8  r,   r   r   r   r5  rD  r%  r   r7  rU  s   &&r)   r   LowRankMatrix.rmatvec  s\    >>%66$..**//1155$$Q

(;TWWdggNNr(   c                    V P                   e   \        V P                   V4      # \        P                  WP                  V P
                  V P                  4      # )rG  )r8  r   r5  rR  r%  r7  r   r   s   &&&r)   r   LowRankMatrix.solve  s>    >>%++##Azz477DGGDDr(   c                   V P                   e/   \        V P                   P                  P                  4       V4      # \        P                  V\        P                  ! V P                  4      V P                  V P                  4      # )zEvaluate w = M^-H v)
r8  r   r   r   r5  rR  r,   r%  r   r7  r   s   &&&r)   r   LowRankMatrix.rsolve  sX    >>%))..0!44##Arwwtzz':DGGTWWMMr(   c                v   V P                   e?   V ;P                   VR,          VR,          P                  4       ,          ,          un         R # V P                  P                  V4       V P                  P                  V4       \        V P                  4      VP                  8  d   V P                  4        R # R # )NNNNNNr_  )r8  r   r7  appendr   rH  rj   collapse)r   rA  rB  s   &&&r)   ra  LowRankMatrix.append  ss    >>%NNai!F)..*:::Nqqtww<!&& MMO !r(   Nc                   Ve   \         P                  ! RV R2^R7       Ve   \         P                  ! RV R2^R7       V P                  e   V P                  # V P                  \        P
                  ! V P                  V P                  R7      ,          p\        V P                  V P                  4       F0  w  rEW4R,          VR,          P                  4       ,          ,          pK2  	  V# )NzJLowRankMatrix is scipy-internal code, `dtype` should only be None but was z (not handled))
stacklevelzILowRankMatrix is scipy-internal code, `copy` should only be None but was r3   r^  r`  )warningswarnr8  r%  r,   rI  r   r4   r?  r7  r   r   )r   r4   ri   GmrA  rB  s   &&&   r)   r   LowRankMatrix.__array__  s    MM 99>~O%&( MM 99=nN%&( >>%>>!ZZDFF$**==)DAF)AfINN,,,B *	r(   c                r    \         P                  ! V \        R7      V n        RV n        RV n        RV n        R# )z0Collapse the low-rank matrix to a full-rank one.)ri   N)r,   rD   r   r8  r7  r   r%  r   s   &r)   rb  LowRankMatrix.collapse  s)    $^<
r(   c                    V P                   e   R# V^ 8  g   Q h\        V P                  4      V8  d   V P                  R V P                  R R# R# )z8
Reduce the rank of the matrix by dropping all vectors.
Nr_  r8  rH  r7  r   r   ranks   &&r)   restart_reduceLowRankMatrix.restart_reduce  sG     >>%axxtww<$

 r(   c                    V P                   e   R# V^ 8  g   Q h\        V P                  4      V8  d   V P                  ^  V P                  ^  K6  R# )z;
Reduce the rank of the matrix by dropping oldest vectors.
Nrm  rn  s   &&r)   simple_reduceLowRankMatrix.simple_reduce  sG     >>%axx$''lT!

 "r(   c                   V P                   e   R# TpVe   TpM	V^,
          pV P                  '       d'   \        V\        V P                  ^ ,          4      4      p\	        ^ \        WC^,
          4      4      p\        V P                  4      pWS8  d   R# \
        P                  ! V P                  4      P                  p\
        P                  ! V P                  4      P                  p\        VRR7      w  rx\        WhP                  P                  4       4      p\        VRR7      w  rp\        V\        V4      4      p\        W{P                  P                  4       4      p\        V4       FO  pVRV3,          P                  4       V P                  V&   VRV3,          P                  4       V P                  V&   KQ  	  V P                  VR1 V P                  VR1 R# )al  
Reduce the rank of the matrix by retaining some SVD components.

This corresponds to the "Broyden Rank Reduction Inverse"
algorithm described in [1]_.

Note that the SVD decomposition can be done by solving only a
problem whose size is the effective rank of this matrix, which
is viable even for large problems.

Parameters
----------
max_rank : int
    Maximum rank of this matrix after reduction.
to_retain : int, optional
    Number of SVD components to retain when reduction is done
    (ie. rank > max_rank). Default is ``max_rank - 2``.

References
----------
.. [1] B.A. van der Rotten, PhD thesis,
   "A limited memory Broyden method to solve high-dimensional
   systems of nonlinear equations". Mathematisch Instituut,
   Universiteit Leiden, The Netherlands (2003).

   https://web.archive.org/web/20161022015821/http://www.math.leidenuniv.nl/scripties/Rotten.pdf

Neconomic)modeF)full_matricesr_  )r8  r7  rn   rH  r.   r,   rD   r   r   r	   r   r   r
   r   rl   ri   )r   max_rank	to_retainr   rP  r  CDRUSWHks   &&&          r)   
svd_reduceLowRankMatrix.svd_reduce  sY   : >>% AAA777As4771:'A3qA#;L5HHTWWHHTWW!*%3388:q.b3r7O4499;qA1Q3DGGAJ1Q3DGGAJ  GGABKGGABKr(   )r%  r8  r7  r   r4   r   r   r   r+   )r"   r#   r$   r%   r&   r   r   r   r   staticmethodrD  rR  r   r   r   r   ra  r   rb  rp  rs  r  r'   r   r   s   @r)   r5  r5  r  s      $L1    6FOEN	"		? ?r(   r5  a  
    alpha : float, optional
        Initial guess for the Jacobian is ``(-1/alpha)``.
    reduction_method : str or tuple, optional
        Method used in ensuring that the rank of the Broyden matrix
        stays low. Can either be a string giving the name of the method,
        or a tuple of the form ``(method, param1, param2, ...)``
        that gives the name of the method and values for additional parameters.

        Methods available:

        - ``restart``: drop all matrix columns. Has no extra parameters.
        - ``simple``: drop oldest matrix column. Has no extra parameters.
        - ``svd``: keep only the most significant SVD components.
          Takes an extra parameter, ``to_retain``, which determines the
          number of SVD components to retain when rank reduction is done.
          Default is ``max_rank - 2``.

    max_rank : int, optional
        Maximum rank for the Broyden matrix.
        Default is infinity (i.e., no rank reduction).
    broyden_paramsc                   `   a  ] tR tRt o RtRR ltR tR tRR ltR t	RR	 lt
R
 tR tRtV tR# )r   iY  a  
Find a root of a function, using Broyden's first Jacobian approximation.

This method is also known as "Broyden's good method".

Parameters
----------
%(params_basic)s
%(broyden_params)s
%(params_extra)s

See Also
--------
root : Interface to root finding algorithms for multivariate
       functions. See ``method='broyden1'`` in particular.

Notes
-----
This algorithm implements the inverse Jacobian Quasi-Newton update

.. math:: H_+ = H + (dx - H df) dx^\dagger H / ( dx^\dagger H df)

which corresponds to Broyden's first Jacobian update

.. math:: J_+ = J + (df - J dx) dx^\dagger / dx^\dagger dx


References
----------
.. [1] B.A. van der Rotten, PhD thesis,
   "A limited memory Broyden method to solve high-dimensional
   systems of nonlinear equations". Mathematisch Instituut,
   Universiteit Leiden, The Netherlands (2003).
   https://math.leidenuniv.nl/scripties/Rotten.pdf

Examples
--------
The following functions define a system of nonlinear equations

>>> def fun(x):
...     return [x[0]  + 0.5 * (x[0] - x[1])**3 - 1.0,
...             0.5 * (x[1] - x[0])**3 + x[1]]

A solution can be obtained as follows.

>>> from scipy import optimize
>>> sol = optimize.broyden1(fun, [0, 0])
>>> sol
array([0.84116396, 0.15883641])

Nc                  a a \         P                  S 4       VS n        R S n        Vf   \        P
                  pVS n        \        V\        4      '       d   R
oMVR,          oV^ ,          pV^,
          3S,           oVR8X  d   VV 3R lS n	        R # VR8X  d   VV 3R lS n	        R # VR8X  d   VV 3R lS n	        R # \        RV R	24      h)N:r   NNr
   c                  8   < SP                   P                  ! S !  # r+   )rh  r  reduce_paramsr   s   r)   r   'BroydenFirst.__init__.<locals>.<lambda>  s    477#5#5}#Er(   simplec                  8   < SP                   P                  ! S !  # r+   )rh  rs  r  s   r)   r   r    s    477#8#8-#Hr(   restartc                  8   < SP                   P                  ! S !  # r+   )rh  rp  r  s   r)   r   r    s    477#9#9=#Ir(   zUnknown rank reduction method ''r!   )r#  r   r%  rh  r,   rE   ry  r  r  _reducerk   )r   r%  reduction_methodry  r  s   f&&&@r)   r   BroydenFirst.__init__  s    %
vvH &,,M,R0M/2!A-7u$EDL)HDL*IDL>?O>PPQRSSr(   c                    \         P                  WW#4       \        V P                  ) V P                  ^ ,          V P
                  4      V n        R# )r   N)r#  rh   r5  r%  r<   r4   rh  r   s   &&&&r)   rh   BroydenFirst.setup  s4    Ta.TZZ]DJJGr(   c                ,    \        V P                  4      # r+   )r   rh  r   s   &r)   r   BroydenFirst.todense  s    477|r(   c                (   V P                   P                  V4      p\        P                  ! V4      P	                  4       '       gM   V P                  V P                  V P                  V P                  4       V P                   P                  V4      # V# r+   )	rh  r   r,   rB   rC   rh   r(  r'  rX   )r   r   r[   rs   &&& r)   r   BroydenFirst.solve  s_    GGNN1{{1~!!##JJt{{DKK;77>>!$$r(   c                8    V P                   P                  V4      # r+   )rh  r   r   r   s   &&r)   r   BroydenFirst.matvec  s    ww}}Qr(   c                8    V P                   P                  V4      # r+   )rh  r   r   r   r[   s   &&&r)   r   BroydenFirst.rsolve  s    wwq!!r(   c                8    V P                   P                  V4      # r+   )rh  r   r  s   &&r)   r   BroydenFirst.rmatvec  s    ww~~a  r(   c                    V P                  4        V P                  P                  V4      pW0P                  P                  V4      ,
          pV\	        WG4      ,          p	V P                  P                  W4       R # r+   )r  rh  r   r   r   ra  
r   r0   r   r   r.  r   r/  rF   rA  rB  s
   &&&&&&&   r)   r0  BroydenFirst._update  sO    GGOOB##ROqr(   )rh  r  r%  ry  )Nr  Nr   )r"   r#   r$   r%   r&   r   rh   r   r   r   r   r   r0  r'   r   r   s   @r)   r   r   Y  s:     2hT2H "! r(   c                   *   a  ] tR tRt o RtR tRtV tR# )r  i  a  
Find a root of a function, using Broyden's second Jacobian approximation.

This method is also known as "Broyden's bad method".

Parameters
----------
%(params_basic)s
%(broyden_params)s
%(params_extra)s

See Also
--------
root : Interface to root finding algorithms for multivariate
       functions. See ``method='broyden2'`` in particular.

Notes
-----
This algorithm implements the inverse Jacobian Quasi-Newton update

.. math:: H_+ = H + (dx - H df) df^\dagger / ( df^\dagger df)

corresponding to Broyden's second method.

References
----------
.. [1] B.A. van der Rotten, PhD thesis,
   "A limited memory Broyden method to solve high-dimensional
   systems of nonlinear equations". Mathematisch Instituut,
   Universiteit Leiden, The Netherlands (2003).

   https://web.archive.org/web/20161022015821/http://www.math.leidenuniv.nl/scripties/Rotten.pdf

Examples
--------
The following functions define a system of nonlinear equations

>>> def fun(x):
...     return [x[0]  + 0.5 * (x[0] - x[1])**3 - 1.0,
...             0.5 * (x[1] - x[0])**3 + x[1]]

A solution can be obtained as follows.

>>> from scipy import optimize
>>> sol = optimize.broyden2(fun, [0, 0])
>>> sol
array([0.84116365, 0.15883529])

c                    V P                  4        TpW0P                  P                  V4      ,
          pWv^,          ,          p	V P                  P                  W4       R#    N)r  rh  r   ra  r  s
   &&&&&&&   r)   r0  BroydenSecond._update  s@    ##
Nqr(   r!   N)r"   r#   r$   r%   r&   r0  r'   r   r   s   @r)   r  r    s     0d r(   r  c                   D   a  ] tR tRt o RtR	R ltR
R ltR tR tRt	V t
R# )r  i	  az  
Find a root of a function, using (extended) Anderson mixing.

The Jacobian is formed by for a 'best' solution in the space
spanned by last `M` vectors. As a result, only a MxM matrix
inversions and MxN multiplications are required. [Ey]_

Parameters
----------
%(params_basic)s
alpha : float, optional
    Initial guess for the Jacobian is (-1/alpha).
M : float, optional
    Number of previous vectors to retain. Defaults to 5.
w0 : float, optional
    Regularization parameter for numerical stability.
    Compared to unity, good values of the order of 0.01.
%(params_extra)s

See Also
--------
root : Interface to root finding algorithms for multivariate
       functions. See ``method='anderson'`` in particular.

References
----------
.. [Ey] V. Eyert, J. Comp. Phys., 124, 271 (1996).

Examples
--------
The following functions define a system of nonlinear equations

>>> def fun(x):
...     return [x[0]  + 0.5 * (x[0] - x[1])**3 - 1.0,
...             0.5 * (x[1] - x[0])**3 + x[1]]

A solution can be obtained as follows.

>>> from scipy import optimize
>>> sol = optimize.anderson(fun, [0, 0])
>>> sol
array([0.84116588, 0.15883789])

Nc                ~    \         P                  V 4       Wn        W0n        . V n        . V n        R V n        W n        R # r+   )r#  r   r%  Mr   r.  r   w0)r   r%  r  r  s   &&&&r)   r   Anderson.__init__P  s4    %

r(   c                Z   V P                   ) V,          p\        V P                  4      pV^ 8X  d   V# \        P                  ! WAP
                  R7      p\        V4       F"  p\        V P                  V,          V4      WV&   K$  	   \        V P                  V4      p\        T4       FS  pY7T,          T P                  T,          T P                   T P                  T,          ,          ,           ,          ,          pKU  	  T#   \         d     T P                  R T P                  R Tu # i ; i)r   r3   r_  )r%  rH  r   r,   emptyr4   rl   r   r.  r   rC  r   )	r   r   r[   r   r   df_fr  r   r  s	   &&&      r)   r   Anderson.solveY  s    jj[]L6Ixx)qA4771:q)DG 	$&&$'E qA(DGGAJDGGAJ)>>??B 	  	

I		s   D   'D*)D*c           
        V) V P                   ,          p\        V P                  4      pV^ 8X  d   V# \        P                  ! W1P
                  R7      p\        V4       F"  p\        V P                  V,          V4      WE&   K$  	  \        P                  ! W33VP
                  R7      p\        V4       F  p\        V4       F  p\        V P                  V,          V P                  V,          4      WgV3&   Wx8X  g   K=  V P                  ^ 8w  g   KP  WgV3;;,          \        V P                  V,          V P                  V,          4      V P                  ^,          ,          V P                   ,          ,          uu&   K  	  K  	  \        Wd4      p	\        V4       FS  p
W)V
,          V P                  V
,          V P                  V
,          V P                   ,          ,           ,          ,          pKU  	  V# )r   r3   )r%  rH  r   r,   r  r4   rl   r   r.  r  r   )r   r   r   r   r  r  brN  rO  r   r  s   &&         r)   r   Anderson.matvecp  sO   R

]L6Ixx)qA4771:q)DG  HHaV177+qA1Xdggaj$''!*5A#6dgglcFd4771:twwqz:477A:EdjjPPF  
 aqA(DGGAJDJJ)>>??B 	r(   c                8   V P                   ^ 8X  d   R# V P                  P                  V4       V P                  P                  V4       \	        V P                  4      V P                   8  d9   V P                  P                  ^ 4       V P                  P                  ^ 4       K\  \	        V P                  4      p\        P                  ! Ww3VP                  R7      p\        V4       Fq  p	\        W4       F_  p
W8X  d   V P                  ^,          pM^ p^V,           \        V P                  V	,          V P                  V
,          4      ,          WV
3&   Ka  	  Ks  	  V\        P                  ! V^4      P                  P                  4       ,          pWn        R# )r   Nr3   )r  r   ra  r.  rH  popr,   rK  r4   rl   r  r   triur   r   rC  )r   r0   r   r   r.  r   r/  r   rC  rN  rO  wds   &&&&&&&     r)   r0  Anderson._update  s   66Q;rr$''lTVV#GGKKNGGKKNLHHaV177+qA1[6!BBB$TWWQZ <<A# !  	
RWWQ]__!!##r(   )r  rC  r%  r.  r   r   r  )Nr      r   )r"   r#   r$   r%   r&   r   r   r   r0  r'   r   r   s   @r)   r  r  	  s$     +L.. r(   r  c                   `   a  ] tR tRt o RtRR ltR tRR ltR tRR lt	R	 t
R
 tR tRtV tR# )r  i  a  
Find a root of a function, using diagonal Broyden Jacobian approximation.

The Jacobian approximation is derived from previous iterations, by
retaining only the diagonal of Broyden matrices.

.. warning::

   This algorithm may be useful for specific problems, but whether
   it will work may depend strongly on the problem.

Parameters
----------
%(params_basic)s
alpha : float, optional
    Initial guess for the Jacobian is (-1/alpha).
%(params_extra)s

See Also
--------
root : Interface to root finding algorithms for multivariate
       functions. See ``method='diagbroyden'`` in particular.

Examples
--------
The following functions define a system of nonlinear equations

>>> def fun(x):
...     return [x[0]  + 0.5 * (x[0] - x[1])**3 - 1.0,
...             0.5 * (x[1] - x[0])**3 + x[1]]

A solution can be obtained as follows.

>>> from scipy import optimize
>>> sol = optimize.diagbroyden(fun, [0, 0])
>>> sol
array([0.84116403, 0.15883384])

Nc                <    \         P                  V 4       Wn        R # r+   r#  r   r%  r   r%  s   &&r)   r   DiagBroyden.__init__      %
r(   c                    \         P                  WW#4       \        P                  ! V P                  ^ ,          3^V P
                  ,          V P                  R7      V n        R# r   r3   N)r#  rh   r,   fullr<   r%  r4   rB  r   s   &&&&r)   rh   DiagBroyden.setup  s=    Ta.$**Q-)1tzz>Lr(   c                *    V) V P                   ,          # r+   rB  r  s   &&&r)   r   DiagBroyden.solve      rDFF{r(   c                *    V) V P                   ,          # r+   r  r  s   &&r)   r   DiagBroyden.matvec  r  r(   c                F    V) V P                   P                  4       ,          # r+   rB  r   r  s   &&&r)   r   DiagBroyden.rsolve      rDFFKKM!!r(   c                F    V) V P                   P                  4       ,          # r+   r  r  s   &&r)   r   DiagBroyden.rmatvec  r  r(   c                D    \         P                  ! V P                  ) 4      # r+   )r,   diagrB  r   s   &r)   r   DiagBroyden.todense  s    wwwr(   c                    V ;P                   W@P                   V,          ,           V,          V^,          ,          ,          un         R# r  r  r-  s   &&&&&&&r)   r0  DiagBroyden._update  s(    2r	>2%gqj00r(   )r%  rB  r+   r   r"   r#   r$   r%   r&   r   rh   r   r   r   r   r   r0  r'   r   r   s   @r)   r  r    s9     &PM"" 1 1r(   r  c                   Z   a  ] tR tRt o RtRR ltRR ltR tRR ltR t	R	 t
R
 tRtV tR# )r  i  a  
Find a root of a function, using a scalar Jacobian approximation.

.. warning::

   This algorithm may be useful for specific problems, but whether
   it will work may depend strongly on the problem.

Parameters
----------
%(params_basic)s
alpha : float, optional
    The Jacobian approximation is (-1/alpha).
%(params_extra)s

See Also
--------
root : Interface to root finding algorithms for multivariate
       functions. See ``method='linearmixing'`` in particular.

Nc                <    \         P                  V 4       Wn        R # r+   r  r  s   &&r)   r   LinearMixing.__init__   r  r(   c                *    V) V P                   ,          # r+   r%  r  s   &&&r)   r   LinearMixing.solve      r$**}r(   c                *    V) V P                   ,          # r+   r  r  s   &&r)   r   LinearMixing.matvec  r  r(   c                R    V) \         P                  ! V P                  4      ,          # r+   r,   r   r%  r  s   &&&r)   r   LinearMixing.rsolve
      r"''$**%%%r(   c                R    V) \         P                  ! V P                  4      ,          # r+   r  r  s   &&r)   r   LinearMixing.rmatvec  r  r(   c                    \         P                  ! \         P                  ! V P                  ^ ,          RV P                  ,          4      4      # )r   )r,   r  r  r<   r%  r   s   &r)   r   LinearMixing.todense  s,    wwrwwtzz!}bm<==r(   c                    R # r+   r!   r-  s   &&&&&&&r)   r0  LinearMixing._update  r   r(   r  r+   r   )r"   r#   r$   r%   r&   r   r   r   r   r   r   r0  r'   r   r   s   @r)   r  r    s2     ,&&> r(   r  c                   `   a  ] tR tRt o RtRR ltR tRR ltR tRR lt	R	 t
R
 tR tRtV tR# )r   i  a  
Find a root of a function, using a tuned diagonal Jacobian approximation.

The Jacobian matrix is diagonal and is tuned on each iteration.

.. warning::

   This algorithm may be useful for specific problems, but whether
   it will work may depend strongly on the problem.

See Also
--------
root : Interface to root finding algorithms for multivariate
       functions. See ``method='excitingmixing'`` in particular.

Parameters
----------
%(params_basic)s
alpha : float, optional
    Initial Jacobian approximation is (-1/alpha).
alphamax : float, optional
    The entries of the diagonal Jacobian are kept in the range
    ``[alpha, alphamax]``.
%(params_extra)s
Nc                V    \         P                  V 4       Wn        W n        R V n        R # r+   )r#  r   r%  alphamaxbeta)r   r%  r  s   &&&r)   r   ExcitingMixing.__init__2  s!    %
 	r(   c                    \         P                  WW#4       \        P                  ! V P                  ^ ,          3V P
                  V P                  R7      V n        R# r  )r#  rh   r,   r  r<   r%  r4   r  r   s   &&&&r)   rh   ExcitingMixing.setup8  s9    Ta.GGTZZ],djj

K	r(   c                *    V) V P                   ,          # r+   r  r  s   &&&r)   r   ExcitingMixing.solve<      r$))|r(   c                *    V) V P                   ,          # r+   r  r  s   &&r)   r   ExcitingMixing.matvec?  r  r(   c                F    V) V P                   P                  4       ,          # r+   r  r   r  s   &&&r)   r   ExcitingMixing.rsolveB      r$)).."""r(   c                F    V) V P                   P                  4       ,          # r+   r  r  s   &&r)   r   ExcitingMixing.rmatvecE  r  r(   c                P    \         P                  ! RV P                  ,          4      # )r   r  )r,   r  r  r   s   &r)   r   ExcitingMixing.todenseH  s    wwr$))|$$r(   c                &   W P                   ,          ^ 8  pV P                  V;;,          V P                  ,          uu&   V P                  V P                  V( &   \        P                  ! V P                  ^ V P
                  V P                  R7       R# )r   )outN)r'  r  r%  r,   clipr  )r   r0   r   r   r.  r   r/  incrs   &&&&&&& r)   r0  ExcitingMixing._updateK  sZ    }q 		$4::%::		4%
		1dmm;r(   )r%  r  r  )Nr\   r   r  r   s   @r)   r   r     s8     4L##%< <r(   r   c                   P   a  ] tR tRt o RtRR ltR tR tRR ltR t	R	 t
R
tV tR# )r   iV  a\  
Find a root of a function, using Krylov approximation for inverse Jacobian.

This method is suitable for solving large-scale problems.

Parameters
----------
%(params_basic)s
rdiff : float, optional
    Relative step size to use in numerical differentiation.
method : str or callable, optional
    Krylov method to use to approximate the Jacobian.  Can be a string,
    or a function implementing the same interface as the iterative
    solvers in `scipy.sparse.linalg`. If a string, needs to be one of:
    ``'lgmres'``, ``'gmres'``, ``'bicgstab'``, ``'cgs'``, ``'minres'``,
    ``'tfqmr'``.

    The default is `scipy.sparse.linalg.lgmres`.
inner_maxiter : int, optional
    Parameter to pass to the "inner" Krylov solver: maximum number of
    iterations. Iteration will stop after maxiter steps even if the
    specified tolerance has not been achieved.
inner_M : LinearOperator or InverseJacobian
    Preconditioner for the inner Krylov iteration.
    Note that you can use also inverse Jacobians as (adaptive)
    preconditioners. For example,

    >>> from scipy.optimize import BroydenFirst, KrylovJacobian
    >>> from scipy.optimize import InverseJacobian
    >>> jac = BroydenFirst()
    >>> kjac = KrylovJacobian(inner_M=InverseJacobian(jac))

    If the preconditioner has a method named 'update', it will be called
    as ``update(x, f)`` after each nonlinear step, with ``x`` giving
    the current point, and ``f`` the current function value.
outer_k : int, optional
    Size of the subspace kept across LGMRES nonlinear iterations.
    See `scipy.sparse.linalg.lgmres` for details.
inner_kwargs : kwargs
    Keyword parameters for the "inner" Krylov solver
    (defined with `method`). Parameter names must start with
    the `inner_` prefix which will be stripped before passing on
    the inner method. See, e.g., `scipy.sparse.linalg.gmres` for details.
%(params_extra)s

See Also
--------
root : Interface to root finding algorithms for multivariate
       functions. See ``method='krylov'`` in particular.
scipy.sparse.linalg.gmres
scipy.sparse.linalg.lgmres

Notes
-----
This function implements a Newton-Krylov solver. The basic idea is
to compute the inverse of the Jacobian with an iterative Krylov
method. These methods require only evaluating the Jacobian-vector
products, which are conveniently approximated by a finite difference:

.. math:: J v \approx (f(x + \omega*v/|v|) - f(x)) / \omega

Due to the use of iterative matrix inverses, these methods can
deal with large nonlinear problems.

SciPy's `scipy.sparse.linalg` module offers a selection of Krylov
solvers to choose from. The default here is `lgmres`, which is a
variant of restarted GMRES iteration that reuses some of the
information obtained in the previous Newton steps to invert
Jacobians in subsequent steps.

For a review on Newton-Krylov methods, see for example [1]_,
and for the LGMRES sparse inverse method, see [2]_.

References
----------
.. [1] C. T. Kelley, Solving Nonlinear Equations with Newton's Method,
       SIAM, pp.57-83, 2003.
       :doi:`10.1137/1.9780898718898.ch3`
.. [2] D.A. Knoll and D.E. Keyes, J. Comp. Phys. 193, 357 (2004).
       :doi:`10.1016/j.jcp.2003.08.010`
.. [3] A.H. Baker and E.R. Jessup and T. Manteuffel,
       SIAM J. Matrix Anal. Appl. 26, 962 (2005).
       :doi:`10.1137/S0895479803422014`

Examples
--------
The following functions define a system of nonlinear equations

>>> def fun(x):
...     return [x[0] + 0.5 * x[1] - 1.0,
...             0.5 * (x[1] - x[0]) ** 2]

A solution can be obtained as follows.

>>> from scipy import optimize
>>> sol = optimize.newton_krylov(fun, [0, 0])
>>> sol
array([0.66731771, 0.66536458])

Nc           	        W@n         Wn        \        \        P                  P
                  P                  \        P                  P
                  P                  \        P                  P
                  P                  \        P                  P
                  P                  \        P                  P
                  P                  \        P                  P
                  P                  R 7      P                  W"4      V n        \        W0P                   R7      V n        V P                  \        P                  P
                  P                  J d<   W0P                  R&   ^V P                  R&   V P                  P                  R^ 4       EMVV P                  \        P                  P
                  P                   \        P                  P
                  P                  \        P                  P
                  P                  39   d   V P                  P                  R^ 4       MV P                  \        P                  P
                  P                  J d   WPP                  R&   ^V P                  R&   V P                  P                  R. 4       V P                  P                  RR4       V P                  P                  R	R
4       V P                  P                  R^ 4       \#        V P                  4      P$                   Uu. uF  pVR9  g   K  VNK  	  ppVP'                  4        F  w  rV	P)                  R4      '       g   \+        RV	 24      hV	R,          V9  d[   \-        V	R,          V^R7      pV'       d   RV^ ,           R2pMRp\.        P0                  ! RV	 RV R2V,           ^\2        R7       K  WP                  V	R,          &   K  	  R# u upi ))bicgstabgmreslgmrescgsminrestfqmr)rx   r  r  rx   atolouter_kouter_vprepend_outer_vTstore_outer_AvFinner_zUnknown parameter :   NN)r   z Did you mean 'z'? zOption 'z#' is invalid for the inner method: zO. It will be ignored.Please check inner method documentation for valid options.)re  categoryN)r   argskwargs)preconditionerr   r  r  r  r  r	  r
  r  r  r  r  getmethod	method_kw
setdefaultgcrotmkr   
parametersr   
startswithrk   r   rf  rg  UserWarning)r   r   r  inner_maxiterinner_Mr  r   r  valid_inner_paramskeyr   inner_param_suggestionssuggestion_msgs   &&&&&&,      r)   r   KrylovJacobian.__init__  s   %
 \\((11,,%%++<<&&--##''<<&&--,,%%++ c&! 	 m7J7JK;;%,,--333(5NN9%()DNN9%NN%%fa0[[U\\0088"\\0099"\\00446 6 NN%%fa0[[ELL//666(/NN9%()DNN9%NN%%i4NN%%&7> NN%%&6>NN%%fa0 !-88
8!22 A8 	 

 ((*JC>>(++ #5cU!;<<2w00*;CG<N>?+A' +(7)@)C(DB'HN &(N se#Fvh OQ Q %%  !(	 &+NN3r7#7 %
s   =	OOc                    \        V P                  4      P                  4       p\        V P                  4      P                  4       pV P                  \        ^V4      ,          \        ^V4      ,          V n        R# )r   N)r   r>   r.   r)  r   omega)r   mxmfs   &  r)   _update_diff_step KrylovJacobian._update_diff_step	  sO    \\ZZ#a*,s1bz9
r(   c                   \        V4      pV^ 8X  d
   ^ V,          # V P                  V,          pV P                  V P                  W1,          ,           4      V P                  ,
          V,          p\
        P                  ! \
        P                  ! V4      4      '       g<   \
        P                  ! \
        P                  ! V4      4      '       d   \        R4      hV# )r   z$Function returned non-finite results)	r   r+  rX   r>   r)  r,   rC   rB   rk   )r   rF   nvscr  s   &&   r)   r   KrylovJacobian.matvec  s    !W7Q3JZZ"_YYtww~&0B6vvbkk!n%%"&&Q*@*@CDDr(   c                    R V P                   9   d-   V P                  ! V P                  V3/ V P                   B w  r4V# V P                  ! V P                  V3R V/V P                   B w  r4V# )rtol)r  r  op)r   rhsr[   solr   s   &&&  r)   r   KrylovJacobian.solve  s_    T^^#DGGSCDNNCIC 
 DGGSMsMdnnMIC
r(   c                    Wn         W n        V P                  4        V P                  e<   \	        V P                  R4      '       d   V P                  P                  W4       R # R # R # )Nrp   )r>   r)  r.  r  r   rp   )r   r0   r   s   &&&r)   rp   KrylovJacobian.update  sW      *t**H55##**10 6 +r(   c                   \         P                  WW#4       Wn        W n        \        P
                  P                  P                  V 4      V n        V P                  f7   \        P                  ! VP                  4      P                  R,          V n	        V P                  4        V P                  e=   \!        V P                  R4      '       d   V P                  P                  WV4       R # R # R # )Nrh   r&  )r   rh   r>   r)  r  r  r  aslinearoperatorr6  r   r,   r   r4   r   r.  r  r   )r   r0   r   rX   s   &&&&r)   rh   KrylovJacobian.setup)  s    t(,,%%66t<::!''*..48DJ  *t**G44##))!5 5 +r(   )r)  r  r  r+  r6  r  r   r>   )Nr     N
   r   )r"   r#   r$   r%   r&   r   r.  r   r   rp   rh   r'   r   r   s   @r)   r   r   V  s1     cJK,Z:
16 6r(   c           	        \        VP                  4      pVw  r4rVrxp	\        \        V\	        V4      ) R V4      4      p
RP                  V
 UUu. uF  w  rV RV: 2NK  	  upp4      pV'       d
   RV,           pRP                  V
 UUu. uF  w  rV RV 2NK  	  upp4      pV'       d
   VR,           pV'       d   \        RV 24      hRpV\        WVP                  VR7      ,          p/ pVP                  \        4       4       \        VV4       VV ,          pVP                  Vn        \        V4       V# u uppi u uppi )z
Construct a solver wrapper with given name and Jacobian approx.

It inspects the keyword arguments of ``jac.__init__``, and allows to
use the same arguments in the wrapper function, in addition to the
keyword arguments of `nonlin_solve`

Nz, =zUnexpected signature a  
def %(name)s(F, xin, iter=None %(kw)s, verbose=False, maxiter=None,
             f_tol=None, f_rtol=None, x_tol=None, x_rtol=None,
             tol_norm=None, line_search='armijo', callback=None, **kw):
    jac = %(jac)s(%(kwkw)s **kw)
    return nonlin_solve(F, xin, jac, iter, verbose, maxiter,
                        f_tol, f_rtol, x_tol, x_rtol, tol_norm, line_search,
                        callback)
)r   r   jackwkw)_getfullargspecr   listr?  rH  joinrk   r  r"   rp   globalsexecr&   rM   )r   rC  r   r  varargsvarkwdefaults
kwonlyargs
kwdefaults_r  r  rF   kw_strkwkw_strwrappernsrX   s   &&                r)   _nonlin_wrapperrT  >  s*     -I@I=D5JA#dCM>?+X67FYY81#Qqe89Fyy8QCq*89Hd?0<==G $s||"*, ,G	BIIgi"d8D;;DLTNK; 9 9s   D;
E
)r   r   r   r   r   r   r   r   r   r   r   )r  NFNNNNNNrZ   NFT)rZ   g:0yE>r   )Br  rq   rf  numpyr,   r   r   r   scipy.linalgr   r   r   r	   r
   r   scipy.sparse.linalgr  scipy.sparser   scipy._lib._utilr   r   r   rE  _linesearchr   r   r   difflibr   typesr   __all__	Exceptionr   r1   r8   r@   rG   r  striprK   rM   r   ro   re   r   r   rg   r#  r5  r   r  r  r  r  r   r   rT  r   r   r   r   r   r   r   r!   r(   r)   <module>r`     s    
   $ $ ? ?   ' > F C  % J	I 	  " $ 	 
" ($ (	P 
a1
h/
O"d 	 *Z9< 9<@H HV(# (#VY?@X :L L^  1 2  	* 
+  0m> m`9L 9@U~ UxA1. A1H+> +\8<^ 8<~a6X a6P)X :|4:}5:x0~|<m[9 !1>B@r(   