ó
    pñ:iòÉ  ã                   ó  • S SK r S SKrS SKrS SKrS SKJrJrJr  S SKJ	r	J
r
JrJrJrJr  S SKrS SKrS SKJr  S SKJr  S SKJr  SSKJrJr  S S	K Jr  S S
KJr  / SQr " S S\5      rS r S r!S r"S r#\$" SRK                  5       SRK                  5       S9r&S r'    S;S jr(\'" \(5          S<S jr) " S S5      r* " S S5      r+ " S S5      r,S r- " S S \+5      r. " S! S"5      r/S#RK                  5       \&S$'    " S% S&\.5      r0 " S' S(\05      r1 " S) S*\.5      r2 " S+ S,\.5      r3 " S- S.\.5      r4 " S/ S0\.5      r5 " S1 S2\+5      r6S3 r7\7" S4\05      r8\7" S5\15      r9\7" S6\25      r:\7" S7\45      r;\7" S8\35      r<\7" S9\55      r=\7" S:\65      r>g)=é    N)ÚasarrayÚdotÚvdot)ÚnormÚsolveÚinvÚqrÚsvdÚLinAlgError)Úget_blas_funcs)Úcopy_if_needed)Úgetfullargspec_no_selfé   )Úscalar_search_wolfe1Úscalar_search_armijo)Ú	signature)Úget_close_matches)Úbroyden1Úbroyden2ÚandersonÚlinearmixingÚdiagbroydenÚexcitingmixingÚnewton_krylovÚBroydenFirstÚKrylovJacobianÚInverseJacobianÚNoConvergencec                   ó   • \ rS rSrSrSrg)r   é    zXException raised when nonlinear solver fails to converge within the specified
`maxiter`.© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__static_attributes__r!   ó    ÚY/srv/projetos/modelo_ml_acdoc/venv/lib/python3.13/site-packages/scipy/optimize/_nonlin.pyr   r       s
   † ñâr(   r   c                 óJ   • [         R                  " U 5      R                  5       $ ©N)ÚnpÚabsoluteÚmax©Úxs    r)   Úmaxnormr1   &   s   € Ü�;Š;�q‹>×ÑÓÐr(   c                 ó´   • [        U 5      n [        R                  " U R                  [        R                  5      (       d  [        U [        R
                  S9$ U $ )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                 ó–   • [         R                  " U [         R                  " U5      5      n [        USU R                  5      nU" U 5      $ )z;Return ndarray `x` as same array subclass and shape as `x0`Ú__array_wrap__)r,   ÚreshapeÚshapeÚgetattrr:   )r0   Úx0Úwraps      r)   Ú_array_liker@   2   s8   € ä
�
Š
�1”b—h’h˜r“lÓ#€AÜ�2Ð'¨×)9Ñ)9Ó:€DÙ�‹7€Nr(   c                 ó²   • [         R                  " U 5      R                  5       (       d$  [         R                  " [         R                  5      $ [        U 5      $ r+   )r,   ÚisfiniteÚallÚarrayÚinfr   )Úvs    r)   Ú
_safe_normrG   9   s5   € Ü�;Š;�q‹>×Ñ×ÑÜ�xŠxœŸ™ÓÐÜ�‹7€Nr(   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                 óX   • U R                   (       a  U R                   [        -  U l         g g r+   )r&   Ú
_doc_parts)Úobjs    r)   Ú_set_docrM   w   s   € Ø
‡{‡{Ø—k‘k¤JÑ.ˆ�ð r(   c           
      óZ  ^ ^• U
c  [         OU
n
[        XgX‰X:S9n[        T5      mU U4S jnTR                  5       n[        R
                  " U[        R                  5      nU" U5      n[        U5      n[        U5      nUR                  UR                  5       UU5        Uc  Ub  US-   nOSUR                  S-   -  nUSL a  SnOUSL a  SnUS	;  a  [        S
5      eSnSnSnSn[        U5       GH^  nUR                  UUU5      nU(       a    GO`[        UUU-  5      nUR!                  UUS9* n[        U5      S:X  a  [        S5      eU(       a  [#        UUUUU5      u  nnnnOSnUU-   nU" U5      n[        U5      nUR%                  UR                  5       U5        U(       a	  U" UU5        UUS-  -  US-  -  nUUS-  -  U:  a  [        UU5      nO[        U['        UUUS-  -  5      5      nUnU(       d  GM  [(        R*                  R-                  U SU
" U5      S SUS S35        [(        R*                  R/                  5         GMa     U(       a  [1        [3        UT5      5      eSnU(       a)  UR4                  UUUS:H  SSS.U   S.n[3        UT5      U4$ [3        UT5      $ )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   >• [        T" [        U T5      5      5      R                  5       $ r+   )r8   r@   Úflatten)ÚzÚFr>   s    €€r)   ÚfuncÚnonlin_solve.<locals>.func¯   s#   ø€ Ü™1œ[¨¨BÓ/Ó0Ó1×9Ñ9Ó;Ð;r(   r   éd   TÚarmijoF)Nr[   ÚwolfezInvalid line searchgÍÌÌÌÌÌì?g§èH.ÿï?gš™™™™™¹?gü©ñÒMbP?)Útolr   z[Jacobian inversion yielded zero vector. This indicates a bug in the Jacobian approximation.ç      ð?é   z:  |F(x)| = Úgz; step Ú
z0A solution was found at the specified tolerance.z:The maximum number of iterations allowed has been reached.)r   r_   )ÚnitÚfunÚstatusÚsuccessÚmessage)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Únrd   r]   ÚsÚFx_norm_newÚeta_AÚinfos    ``                              r)   Únonlin_solver�   |   sÑ  ù€ ðZ #Ñ*�w°€HÜ$¨5Ø+0Ø*.ñ?€Iô 
�R‹€Bö<à
�
‰
‹€Aä	�Š�aœŸ™Ó	 €BÙ	ˆa‹€BÜ�2‹h€Gä˜(Ó#€HØ‡N�N�1—6‘6“8˜R Ô&à�ØÑØ˜Q‘h‰Gà˜1Ÿ6™6 !™8‘nˆGà�dÒØ‰Ø	˜Ò	ØˆàÐ3Ó3ÜÐ.Ó/Ð/ð €EØ€GØ€LØ
€Cä�7�^ˆØ—‘  Q¨Ó+ˆÞÚô �#�s˜7‘{Ó#ˆØ�n‰n˜R SˆnÐ)Ð)ˆä�‹8�q‹=Üð .ó /ð /ö
 Ü$7¸¸aÀÀRØ8Có%EÑ!ˆAˆq�"‘kð ˆAØ�B‘ˆAÙ�a“ˆBÜ˜r›(ˆKà�‰˜Ÿ™› "Ô%æÙ�Q˜ŒOð ˜ Q™Ñ&¨°!©Ñ3ˆØ�3˜‘6‰>˜LÓ(Ü�g˜uÓ%‰Cä�gœs 5¨%°°Q±©,Ó7Ó8ˆCàˆ÷ ‰7Ü�J‰J×Ñ ˜s ,©x¸«|¸AÐ.>¸gÀaÈÀUÈ"ÐMÔNÜ�J‰J×Ñ×ñS öV Ü¤¨A¨rÓ 2Ó3Ð3àˆFæØ ×*Ñ*ØØ Ø! Q™;ð ,ð 3ñð %ñ	&ñ		ˆô ˜1˜bÓ! 4Ð'Ð'ä˜1˜bÓ!Ð!r(   c                 óh  ^ ^^^^^^^^• S/mU/m[        U5      S-  /m[        T5      [        T5      -  mSUU UUUU4S jjmUUU4S jnUS:X  a  [        TUTS   SUS9u  p‰n
OUS:X  a  [        TTS   TS   * US	9u  p‰Wc  S
nTUT-  -   mUTS   :X  a  TS   nOT " T5      n[        U5      nUTX+4$ )Nr   r_   c                 óŒ   >• U T	S   :X  a  TS   $ T
U T-  -   nT" U5      n[        U5      S-  nU(       a  U T	S'   UTS'   UTS'   U$ )Nr   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ˆÜ�q‹M˜1ÑˆÞØˆE�!‰HØˆG�A‰JØˆF�1‰IØˆr(   c                 óV   >• [        U 5      T-   S-   T-  nT" X-   SS9T" U 5      -
  U-  $ )Nr   F)r�   )Úabs)r‰   Údsr–   ÚrdiffÚs_norms     €€€r)   ÚderphiÚ#_nonlin_line_search.<locals>.derphi$  s7   ø€ Ü�!‹f�v‰o Ñ! UÑ*ˆÙ�A‘D Ñ&©¨Q«Ñ/°2Ñ5Ð5r(   r\   ç{®Gáz„?)ÚxtolÚaminr[   )r¡   r^   )T)r   r   r   )rX   r0   r‚   r�   Úsearch_typer›   Úsminr�   r‰   Úphi1Úphi0rƒ   r–   rœ   r“   r”   r•   s   `` ` `      @@@@@r)   rq   rq     sß   ÿø€ àˆC€EØˆT€FÜ�B‹x˜‰{ˆm€GÜ�!‹W”t˜B“xÑ€F÷
ô 
÷6ð �gÓÜ,¨S°&¸'À!¹*Ø26¸TñC‰ˆ‘à	˜Ó	 Ü& s¨G°A©J¸À¹¸Ø,0ñ2‰ˆð 	�yð ˆà	ˆAˆb‰D‰€AØˆE�!‰Hƒ}Ø�A‰Y‰á�!‹WˆÜ�2‹h€Gàˆa�ÐÐr(   c                   ó4   • \ rS rSrSrSSSSS\4S jrS rSrg)rg   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                 óB  • Uc1  [         R                  " [         R                  5      R                  S-  nUc  [         R                  nUc  [         R                  nUc  [         R                  nX0l        X@l        Xl        X l        X`l	        XPl
        S U l        SU l        g )NgUUUUUUÕ?r   )r,   Úfinfor7   ÚepsrE   rQ   rR   rO   rP   r   rS   Úf0_normrw   )ÚselfrO   rP   rQ   rR   rS   r   s          r)   Ú__init__ÚTerminationCondition.__init__K  s|   € ð ‰=Ü—H’HœRŸZ™ZÓ(×,Ñ,°Ñ6ˆEØ‰>Ü—V‘VˆFØ‰=Ü—F‘FˆEØ‰>Ü—V‘VˆFàŒ
ØŒØŒ
ØŒàŒ	àŒ	àˆŒØˆ�r(   c                 óä  • U =R                   S-  sl         U R                  U5      nU R                  U5      nU R                  U5      nU R                  c  X@l        US:X  a  gU R                  b  SU R                   U R                  :„  -  $ [	        X@R
                  :*  =(       a    X@R                  -  U R                  :*  =(       a&    X`R                  :*  =(       a    X`R                  -  U:*  5      $ )Nr   r   r_   )	rw   r   rª   rS   ÚintrO   rP   rQ   rR   )r«   Úfr0   r�   Úf_normÚx_normÚdx_norms          r)   ro   ÚTerminationCondition.checkc  sÅ   € Ø�Š˜!Ñ�Ø—‘˜1“ˆØ—‘˜1“ˆØ—)‘)˜B“-ˆà�<‰<ÑØ!ŒLà�Q‹;Øà�9‰9Ñ à˜Ÿ™¨¯©Ñ2Ñ3Ð3ô �FŸj™jÑ(÷ ;ØŸ{™{Ñ*¨d¯l©lÑ:÷;à§:¡:Ñ-÷ :Ø#§K¡KÑ/°6Ñ9ó<ð 	<r(   )rª   rP   rO   rS   rw   r   rR   rQ   )	r"   r#   r$   r%   r&   r1   r¬   ro   r'   r!   r(   r)   rg   rg   >  s!   † ñð "¨$°dÀ4Ø ôõ0<r(   rg   c                   ó:   • \ rS rSrSrS rS rS
S jrS rS r	Sr
g	)Ú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                 ó¸   • / SQnUR                  5        H+  u  p4X2;  a  [        SU 35      eUc  M  [        XX   5        M-     [        U S5      (       a  SS jng g )N)	r   rr   ÚmatvecÚrmatvecÚrsolveÚmatmatÚtodenser<   r4   zUnknown keyword argument r¼   c                 óD   • Ub  [        SU 35      eU R                  5       $ )Nz`dtype` must be None, was )rm   r¼   )r«   r4   rk   s      r)   Ú	__array__Ú$Jacobian.__init__.<locals>.__array__¯  s'   € ØÑ$Ü$Ð'AÀ%ÀÐ%IÓJÐJØ—|‘|“~Ð%r(   ©NN)Úitemsrm   ÚsetattrÚhasattr)r«   ÚkwÚnamesÚnameÚvaluer¾   s         r)   r¬   ÚJacobian.__init__¤  s_   € ò8ˆàŸ8™8ž:‰KˆDØÓ Ü Ð#<¸T¸FÐ!CÓDÐDØÓ Ü˜ B¡HÖ-ñ	 &ô �4˜×#Ñ#õ&ð $r(   c                 ó   • [        U 5      $ r+   )r   ©r«   s    r)   ÚaspreconditionerÚJacobian.aspreconditioner´  s   € Ü˜tÓ$Ð$r(   c                 ó   • [         er+   ©ÚNotImplementedError©r«   rF   r]   s      r)   r   ÚJacobian.solve·  ó   € Ü!Ð!r(   c                 ó   • g r+   r!   ©r«   r0   rW   s      r)   rr   ÚJacobian.updateº  ó   € Ør(   c                 óÞ   • X0l         UR                  UR                  4U l        UR                  U l        U R                  R
                  [        R
                  L a  U R                  X5        g g r+   )rX   rl   r<   r4   Ú	__class__rj   r¶   rr   ©r«   r0   rW   rX   s       r)   rj   ÚJacobian.setup½  sM   € ØŒ	Ø—f‘f˜aŸf™fÐ%ˆŒ
Ø—W‘WˆŒ
Ø�>‰>×Ñ¤8§>¡>Ò1à�K‰K˜Õð 2r(   )r4   rX   r<   N©r   )r"   r#   r$   r%   r&   r¬   rË   r   rr   rj   r'   r!   r(   r)   r¶   r¶   ~  s!   † ñ#òJ&ò %ô"òõr(   r¶   c                   ó>   • \ rS rSrSrS r\S 5       r\S 5       rSr	g)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                 óÞ   • Xl         UR                  U l        UR                  U l        [	        US5      (       a  UR
                  U l        [	        US5      (       a  UR                  U l        g g )Nrj   rº   )rx   r   r¸   rr   rÃ   rj   rº   r¹   )r«   rx   s     r)   r¬   ÚInverseJacobian.__init__Û  sR   € Ø ŒØ—n‘nˆŒØ—o‘oˆŒÜ�8˜W×%Ñ%Ø!Ÿ™ˆDŒJÜ�8˜X×&Ñ&Ø#Ÿ?™?ˆD�Lð 'r(   c                 ó.   • U R                   R                  $ r+   )rx   r<   rÊ   s    r)   r<   ÚInverseJacobian.shapeä  ó   € à�}‰}×"Ñ"Ð"r(   c                 ó.   • U R                   R                  $ r+   )rx   r4   rÊ   s    r)   r4   ÚInverseJacobian.dtypeè  rá   r(   )rx   r¸   r¹   rj   rr   N)
r"   r#   r$   r%   r&   r¬   Úpropertyr<   r4   r'   r!   r(   r)   r   r   Æ  s4   † ñò(+ð ñ#ó ð#ð ñ#ó ó#r(   r   c                 ó¢  ^ ^• [         R                  R                  R                  m[	        T [
        5      (       a  T $ [        R                  " T 5      (       a  [        T [
        5      (       a  T " 5       $ [	        T [        R                  5      (       a¦  T R                  S:”  a  [        S5      e[        R                  " [        R                  " T 5      5      m T R                  S   T R                  S   :w  a  [        S5      e[        U 4S jU 4S jSU 4S jjSU 4S	 jjT R                   T R                  S
9$ [         R                  R#                  T 5      (       ac  T R                  S   T R                  S   :w  a  [        S5      e[        U 4S jU 4S jSU U4S jjSU U4S jjT R                   T R                  S
9$ [%        T S5      (       a‚  [%        T S5      (       aq  [%        T S5      (       a`  [        ['        T S5      ['        T S5      T R(                  ['        T S5      ['        T S5      ['        T S5      T R                   T R                  S9$ [+        T 5      (       a   " U U4S jS[
        5      nU" 5       $ [	        T [,        5      (       a3  [/        [0        [2        [4        [6        [8        [:        [<        S9T    " 5       $ [?        S5      e)z=
Convert given object to one suitable for use as a Jacobian.
r_   zarray must have rank <= 2r   r   zarray must be squarec                 ó   >• [        TU 5      $ r+   )r   ©rF   ÚJs    €r)   Ú<lambda>Úasjacobian.<locals>.<lambda>ý  s   ø€ ¬¨Q°¬r(   c                 óL   >• [        TR                  5       R                  U 5      $ r+   )r   ÚconjÚTrç   s    €r)   ré   rê   þ  s   ø€ ¬#¨a¯f©f«h¯j©j¸!Ô*<r(   c                 ó   >• [        TU 5      $ r+   )r   ©rF   r]   rè   s     €r)   ré   rê   ÿ  s   ø€ ¬u°Q¸¬{r(   c                 óL   >• [        TR                  5       R                  U 5      $ r+   )r   rì   rí   rï   s     €r)   ré   rê      s   ø€ ´°a·f±f³h·j±jÀ!Ô0Dr(   )r¸   r¹   r   rº   r4   r<   zmatrix must be squarec                 ó   >• TU -  $ r+   r!   rç   s    €r)   ré   rê     s	   ø€ ¨¨Qªr(   c                 ó>   >• TR                  5       R                  U -  $ r+   ©rì   rí   rç   s    €r)   ré   rê     s   ø€ ¨!¯&©&«(¯*©*°qª.r(   c                 ó   >• T" TU 5      $ r+   r!   ©rF   r]   rè   Úspsolves     €€r)   ré   rê     s   ø€ ©w°q¸!¬}r(   c                 óF   >• T" TR                  5       R                  U 5      $ r+   ró   rõ   s     €€r)   ré   rê     s   ø€ ±¸¿¹»¿
¹
ÀAÔ0Fr(   r<   r4   r   r¸   r¹   rº   rr   rj   )r¸   r¹   r   rº   rr   rj   r4   r<   c                   óX   >• \ rS rSrS rS	U U4S jjrU 4S jrS	U U4S jjrU 4S jrSr	g)
Úasjacobian.<locals>.Jaci  c                 ó   • Xl         g r+   r/   rÔ   s      r)   rr   Úasjacobian.<locals>.Jac.update  s   € Ø•r(   c                 óê   >• T" U R                   5      n[        U[        R                  5      (       a  [	        X15      $ [
        R                  R                  U5      (       a  T" X15      $ [        S5      e©NzUnknown matrix type)	r0   Ú
isinstancer,   Úndarrayr   ÚscipyÚsparseÚissparserm   ©r«   rF   r]   Úmrè   rö   s       €€r)   r   Úasjacobian.<locals>.Jac.solve  sV   ø€ Ù�d—f‘f“I�Ü˜a¤§¡×,Ñ,Ü  ›;Ð&Ü—\‘\×*Ñ*¨1×-Ñ-Ù" 1›=Ð(ä$Ð%:Ó;Ð;r(   c                 óâ   >• T" U R                   5      n[        U[        R                  5      (       a  [	        X!5      $ [
        R                  R                  U5      (       a  X!-  $ [        S5      erý   )	r0   rþ   r,   rÿ   r   r   r  r  rm   ©r«   rF   r  rè   s      €r)   r¸   Úasjacobian.<locals>.Jac.matvec"  sS   ø€ Ù�d—f‘f“I�Ü˜a¤§¡×,Ñ,Ü˜q›9Ð$Ü—\‘\×*Ñ*¨1×-Ñ-Ø™5�Lä$Ð%:Ó;Ð;r(   c                 óN  >• T" U R                   5      n[        U[        R                  5      (       a$  [	        UR                  5       R                  U5      $ [        R                  R                  U5      (       a!  T" UR                  5       R                  U5      $ [        S5      erý   )r0   rþ   r,   rÿ   r   rì   rí   r   r  r  rm   r  s       €€r)   rº   Úasjacobian.<locals>.Jac.rsolve+  sp   ø€ Ù�d—f‘f“I�Ü˜a¤§¡×,Ñ,Ü  §¡£§¡¨QÓ/Ð/Ü—\‘\×*Ñ*¨1×-Ñ-Ù" 1§6¡6£8§:¡:¨qÓ1Ð1ä$Ð%:Ó;Ð;r(   c                 óF  >• T" U R                   5      n[        U[        R                  5      (       a$  [	        UR                  5       R                  U5      $ [        R                  R                  U5      (       a  UR                  5       R                  U-  $ [        S5      erý   )r0   rþ   r,   rÿ   r   rì   rí   r   r  r  rm   r  s      €r)   r¹   Úasjacobian.<locals>.Jac.rmatvec4  sm   ø€ Ù�d—f‘f“I�Ü˜a¤§¡×,Ñ,Ü˜qŸv™v›xŸz™z¨1Ó-Ð-Ü—\‘\×*Ñ*¨1×-Ñ-ØŸ6™6›8Ÿ:™:¨™>Ð)ä$Ð%:Ó;Ð;r(   r/   NrÛ   )
r"   r#   r$   r%   rr   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ÿ   Úndimrm   Ú
atleast_2dr   r<   r4   r  rÃ   r=   r   ÚcallableÚstrÚdictr   ÚBroydenSecondÚAndersonÚDiagBroydenÚLinearMixingÚExcitingMixingr   Ú	TypeError)rè   r  rö   s   ` @r)   ri   ri   í  s!  ù€ ô �l‰l×!Ñ!×)Ñ)€GÜ�!”X×ÑØˆÜ	�Š˜×	Ñ	¤
¨1¬h× 7Ñ 7Ù‹sˆ
Ü	�A”r—z‘z×	"Ñ	"Ø�6‰6�A‹:ÜÐ8Ó9Ð9Ü�MŠMœ"Ÿ*š* Q›-Ó(ˆØ�7‰7�1‰:˜Ÿ™ ™Ó#ÜÐ3Ó4Ð4äÔ2Ü <Þ:ÞDØŸg™g¨Q¯W©Wñ	6ð 	6ô
 
�‰×	Ñ	˜q×	!Ñ	!Ø�7‰7�1‰:˜Ÿ™ ™Ó#ÜÐ4Ó5Ð5ÜœÜ 8ß<ßFØŸg™g¨Q¯W©Wñ	6ð 	6ô
 
��G×	Ñ	¤¨¨G×!4Ñ!4¼ÀÀG×9LÑ9LÜœw q¨(Ó3Ü '¨¨9Ó 5ØŸg™gÜ& q¨(Ó3Ü& q¨(Ó3Ü% a¨Ó1ØŸg™gØŸg™gñ'ð 	'ô 
�!�‰÷&	<ð &	<”(ô &	<ñN ‹uˆÜ	�A”s×	Ñ	Üœ\Ü*Ü%Ü +Ü!-Ü#1Ü)ñ+ð ,-ò.ó 0ð 	0ô Ð=Ó>Ð>r(   c                   ó&   • \ rS rSrS rS rS rSrg)ÚGenericBroydeniM  c                 óü   • [         R                  XX#5        X l        Xl        [	        U S5      (       aI  U R
                  c;  [        U5      nU(       a!  S[        [        U5      S5      -  U-  U l        g SU l        g g g )NÚalphaç      à?r   r^   )r¶   rj   Úlast_fÚlast_xrÃ   r!  r   r.   )r«   r>   Úf0rX   Únormf0s        r)   rj   ÚGenericBroyden.setupN  si   € Ü�‰�t Ô*ØŒØŒä�4˜×!Ñ! d§j¡jÑ&8ô ˜"“XˆFÞØ ¤¤T¨"£X¨qÓ!1Ñ1°FÑ:�•
à �•
ð '9Ð!r(   c                 ó   • [         er+   rÎ   ©r«   r0   r°   r�   Údfr³   Údf_norms          r)   Ú_updateÚGenericBroyden._update\  rÒ   r(   c           
      ó    • X R                   -
  nXR                  -
  nU R                  XXC[        U5      [        U5      5        X l         Xl        g r+   )r#  r$  r,  r   )r«   r0   r°   r*  r�   s        r)   rr   ÚGenericBroyden.update_  s<   € Ø—‘‰_ˆØ—‘‰_ˆØ�‰�Q˜2¤4¨£8¬T°"«XÔ6ØŒØ�r(   )r!  r#  r$  N)r"   r#   r$   r%   rj   r,  rr   r'   r!   r(   r)   r  r  M  s   † ò!ò"õr(   r  c                   óŠ   • \ rS rSrSrS r\S 5       r\S 5       rS r	S r
SS jrSS	 jrS
 rSS jrS rS rS rSS jrSrg)ÚLowRankMatrixig  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                 óR   • Xl         / U l        / U l        X l        X0l        S U l        g r+   )r!  Úcsrš   rˆ   r4   Ú	collapsed)r«   r!  rˆ   r4   s       r)   r¬   ÚLowRankMatrix.__init__r  s&   € ØŒ
ØˆŒØˆŒØŒØŒ
Øˆ�r(   c                 óž   • [        / SQUS S U /-   5      u  pEnX-  n[        X#5       H!  u  p‰U" X�5      n
U" X‡UR                  U
5      nM#     U$ )N)ÚaxpyÚscalÚdotcr   )r   Úziprl   )rF   r!  r3  rš   r7  r8  r9  ÚwÚcÚdÚas              r)   Ú_matvecÚLowRankMatrix._matvecz  s\   € ä)Ò*BØ*,¨R¨a¨&°A°3©,ó8Ñˆ�Dà‰IˆÜ˜–K‰DˆAÙ�Q“
ˆAÙ�Q˜1Ÿ6™6 1Ó%ŠAñ  ð ˆr(   c           	      ó6  • [        U5      S:X  a  X-  $ [        SS/USS U /-   5      u  pEUS   nU[        R                  " [        U5      UR                  S9-  n[        U5       H-  u  p‰[        U5       H  u  p«XxU
4==   U" X›5      -  ss'   M     M/     [        R                  " [        U5      UR                  S9n[        U5       H  u  p©U" X�5      XÊ'   M     XÁ-  n[        X|5      nX-  n[        X,5       H  u  p¾U" X½UR                  U* 5      nM     U$ )úEvaluate w = M^-1 vr   r7  r9  Nr   r3   )
Úlenr   r,   Úidentityr4   Ú	enumerateÚzerosr   r:  rl   )rF   r!  r3  rš   r7  r9  Úc0ÚAÚir=  Újr<  Úqr;  Úqcs                  r)   Ú_solveÚLowRankMatrix._solve„  s  € ô ˆr‹7�a‹<Ø‘7ˆNô $ V¨VÐ$4°b¸¸!°fÀ¸s±lÓC‰
ˆà�‰UˆØ”B—K’K¤ B£¨r¯x©xÑ8Ñ8ˆÜ˜b–M‰DˆAÜ! "ž‘�Ø�A�#“™$˜q›*Ñ$•ó &ñ "ô �HŠH”S˜“W B§H¡HÑ-ˆÜ˜b–M‰DˆAÙ˜“:ˆA‹Dñ "à	‰
ˆÜ�!‹Kˆà‰GˆÜ˜–Z‰EˆAÙ�Q˜1Ÿ6™6 B 3Ó'ŠAñ  ð ˆr(   c                 óÈ   • U R                   b!  [        R                  " U R                   U5      $ [        R	                  XR
                  U R                  U R                  5      $ )zEvaluate w = M v)r4  r,   r   r1  r?  r!  r3  rš   ©r«   rF   s     r)   r¸   ÚLowRankMatrix.matvec   sB   € à�>‰>Ñ%Ü—6’6˜$Ÿ.™.¨!Ó,Ð,Ü×$Ñ$ Q¯
©
°D·G±G¸T¿W¹WÓEÐEr(   c                 ó"  • U R                   b9  [        R                  " U R                   R                  R	                  5       U5      $ [
        R                  U[        R                  " U R                  5      U R                  U R                  5      $ )zEvaluate w = M^H v)
r4  r,   r   rí   rì   r1  r?  r!  rš   r3  rP  s     r)   r¹   ÚLowRankMatrix.rmatvec¦  s\   € à�>‰>Ñ%Ü—6’6˜$Ÿ.™.×*Ñ*×/Ñ/Ó1°1Ó5Ð5Ü×$Ñ$ Q¬¯ª°·
±
Ó(;¸T¿W¹WÀdÇgÁgÓNÐNr(   c                 ó²   • U R                   b  [        U R                   U5      $ [        R                  XR                  U R
                  U R                  5      $ )rB  )r4  r   r1  rM  r!  r3  rš   rÐ   s      r)   r   ÚLowRankMatrix.solve¬  s>   € à�>‰>Ñ%Ü˜Ÿ™¨Ó+Ð+Ü×#Ñ# A§z¡z°4·7±7¸D¿G¹GÓDÐDr(   c                 ó  • U R                   b.  [        U R                   R                  R                  5       U5      $ [        R                  U[        R                  " U R                  5      U R                  U R                  5      $ )zEvaluate w = M^-H v)
r4  r   rí   rì   r1  rM  r,   r!  rš   r3  rÐ   s      r)   rº   ÚLowRankMatrix.rsolve²  sX   € à�>‰>Ñ%Ü˜Ÿ™×)Ñ)×.Ñ.Ó0°!Ó4Ð4Ü×#Ñ# A¤r§w¢w¨t¯z©zÓ':¸D¿G¹GÀTÇWÁWÓMÐMr(   c                 ó\  • U R                   b5  U =R                   US S 2S 4   US S S 24   R                  5       -  -  sl         g U R                  R                  U5        U R                  R                  U5        [        U R                  5      UR                  :”  a  U R                  5         g g r+   )r4  rì   r3  Úappendrš   rC  rl   Úcollapse)r«   r<  r=  s      r)   rY  ÚLowRankMatrix.append¸  s{   € Ø�>‰>Ñ%Ø�NŠN˜a¢ $ ™i¨!¨D²¨F©)¯.©.Ó*:Ñ:Ñ:�NØà�‰�‰�qÔØ�‰�‰�qÔäˆt�w‰w‹<˜!Ÿ&™&Ó Ø�M‰M�Oð !r(   Nc                 ó¬  • Ub  [         R                  " SU S3SS9  Ub  [         R                  " SU S3SS9  U R                  b  U R                  $ U R                  [        R
                  " U R                  U R                  S9-  n[        U R                  U R                  5       H(  u  pEX4S S 2S 4   US S S 24   R                  5       -  -  nM*     U$ )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   )ÚwarningsÚwarnr4  r!  r,   rD  rˆ   r4   r:  r3  rš   rì   )r«   r4   rk   ÚGmr<  r=  s         r)   r¾   ÚLowRankMatrix.__array__Ã  sÍ   € ØÑÜ�MŠMð 9Ø9>¸¸~ðOà%&ò(ð ÑÜ�MŠMð 9Ø9=¸¸nðNà%&ò(ð �>‰>Ñ%Ø—>‘>Ð!à�Z‰ZœŸš D§F¡F°$·*±*Ñ=Ñ=ˆÜ˜Ÿ™ §¡Ö)‰DˆAØ’A�d�F‘)˜A˜d¢1˜f™IŸN™NÓ,Ñ,Ñ,ŠBñ *àˆ	r(   c                 ój   • [         R                  " U [        S9U l        SU l        SU l        SU l        g)z0Collapse the low-rank matrix to a full-rank one.)rk   N)r,   rD   r   r4  r3  rš   r!  rÊ   s    r)   rZ  ÚLowRankMatrix.collapseÔ  s)   € äŸš $¬^Ñ<ˆŒØˆŒØˆŒØˆ�
r(   c                 ó    • U R                   b  gUS:”  d   e[        U R                  5      U:”  a  U R                  SS2	 U R                  SS2	 gg)z8
Reduce the rank of the matrix by dropping all vectors.
Nr   ©r4  rC  r3  rš   ©r«   Úranks     r)   Úrestart_reduceÚLowRankMatrix.restart_reduceÛ  sG   € ð �>‰>Ñ%ØØ�a‹xˆˆxÜˆt�w‰w‹<˜$ÓØ—‘š�
Ø—‘š‘
ð r(   c                 óÎ   • U R                   b  gUS:”  d   e[        U R                  5      U:”  a6  U R                  S	 U R                  S	 [        U R                  5      U:”  a  M5  gg)z;
Reduce the rank of the matrix by dropping oldest vectors.
Nr   rf  rg  s     r)   Úsimple_reduceÚLowRankMatrix.simple_reduceæ  sT   € ð �>‰>Ñ%ØØ�a‹xˆˆxÜ�$—'‘'‹l˜TÓ!Ø—‘˜�
Ø—‘˜�
ô �$—'‘'‹l˜T×!r(   c                 ó†  • U R                   b  gUnUb  UnOUS-
  nU R                  (       a"  [        U[        U R                  S   5      5      n[	        S[        XCS-
  5      5      n[        U R                  5      nXS:  a  g[
        R                  " U R                  5      R                  n[
        R                  " U R                  5      R                  n[        USS9u  px[        XhR                  R                  5       5      n[        USS9u  pšn[        U[        U5      5      n[        X{R                  R                  5       5      n[        U5       HK  nUSS2U4   R                  5       U R                  U'   USS2U4   R                  5       U R                  U'   MM     U R                  US2	 U R                  US2	 g)	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

Nr_   r   r   Úeconomic)ÚmodeF)Úfull_matrices)r4  r3  rp   rC  r.   r,   rD   rí   rš   r	   r   rì   r
   r   rn   rk   )r«   Úmax_rankÚ	to_retainr’   rK  r  ÚCÚDÚRÚUÚSÚWHÚks                r)   Ú
svd_reduceÚLowRankMatrix.svd_reduceñ  sW  € ð: �>‰>Ñ%ØàˆØÑ Ø‰Aà�A‘ˆAà�7�7Ü�A”s˜4Ÿ7™7 1™:“Ó'ˆAÜ�”3�q˜A™#“;Óˆä�—‘‹LˆØ‹5àä�HŠH�T—W‘WÓ×ÑˆÜ�HŠH�T—W‘WÓ×Ñˆä�!˜*Ñ%‰ˆÜ�—3‘3—8‘8“:Óˆä�q¨Ñ.‰ˆˆbä�”3�r“7‹OˆÜ�—4‘4—9‘9“;Óˆä�q–ˆAØš1˜Q˜3™Ÿ™›ˆD�G‰G�A‰JØš1˜Q˜3™Ÿ™›ˆD�G‰G�A‹Jñ ð �G‰G�A‘BˆKØ�G‰G�A‘B‰Kr(   )r!  r4  r3  rš   r4   rˆ   rÛ   rÀ   r+   )r"   r#   r$   r%   r&   r¬   Ústaticmethodr?  rM  r¸   r¹   r   rº   rY  r¾   rZ  ri  rl  r{  r'   r!   r(   r)   r1  r1  g  sj   † ñòð ñó ðð ñó ðò6FòOôEôNò	ôò"ò	ò	÷?r(   r1  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                   óT   • \ rS rSrSrSS jrS rS rSS jrS r	SS	 jr
S
 rS rSrg)r   iK  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                 óf  ^ ^• [         R                  T 5        UT l        S T l        Uc  [        R
                  nUT l        [        U[        5      (       a  SmO
USS  mUS   nUS-
  4T-   mUS:X  a  UU 4S jT l	        g US:X  a  UU 4S jT l	        g US:X  a  UU 4S	 jT l	        g [        S
U S35      e)Nr!   r   r   r
   c                  ó6   >• TR                   R                  " T 6 $ r+   )ra  r{  ©Úreduce_paramsr«   s   €€r)   ré   Ú'BroydenFirst.__init__.<locals>.<lambda>‘  s   ø€  4§7¡7×#5Ò#5°}Ñ#Er(   Úsimplec                  ó6   >• TR                   R                  " T 6 $ r+   )ra  rl  r‚  s   €€r)   ré   r„  “  s   ø€  4§7¡7×#8Ò#8¸-Ñ#Hr(   Úrestartc                  ó6   >• TR                   R                  " T 6 $ r+   )ra  ri  r‚  s   €€r)   ré   r„  •  s   ø€  4§7¡7×#9Ò#9¸=Ñ#Ir(   zUnknown rank reduction method 'Ú')r  r¬   r!  ra  r,   rE   rr  rþ   r  Ú_reducerm   )r«   r!  Úreduction_methodrr  rƒ  s   `   @r)   r¬   ÚBroydenFirst.__init__€  s´   ù€ Ü×Ñ Ô%ØˆŒ
ØˆŒàÑÜ—v‘vˆHØ ˆŒäÐ&¬×,Ñ,Ø‰Mà,¨Q¨RÐ0ˆMØ/°Ñ2ÐØ! A™˜¨-Ñ7ˆà˜uÓ$ÝEˆD�LØ Ó)ÝHˆD�LØ Ó*ÝIˆD�LäÐ>Ð?OÐ>PÐPQÐRÓSÐSr(   c                 ó˜   • [         R                  XX#5        [        U R                  * U R                  S   U R
                  5      U l        g )Nr   )r  rj   r1  r!  r<   r4   ra  rÙ   s       r)   rj   ÚBroydenFirst.setup™  s4   € Ü×Ñ˜T aÔ.Ü §¡ ¨T¯Z©Z¸©]¸D¿J¹JÓGˆ�r(   c                 ó,   • [        U R                  5      $ r+   )r   ra  rÊ   s    r)   r¼   ÚBroydenFirst.todense�  s   € Ü�4—7‘7‹|Ðr(   c                 ó&  • U R                   R                  U5      n[        R                  " U5      R	                  5       (       dL  U R                  U R                  U R                  U R                  5        U R                   R                  U5      $ U$ r+   )	ra  r¸   r,   rB   rC   rj   r$  r#  rX   )r«   r°   r]   Úrs       r)   r   ÚBroydenFirst.solve   s_   € Ø�G‰G�N‰N˜1ÓˆÜ�{Š{˜1‹~×!Ñ!×#Ñ#à�J‰J�t—{‘{ D§K¡K°·±Ô;Ø—7‘7—>‘> !Ó$Ð$Øˆr(   c                 ó8   • U R                   R                  U5      $ r+   )ra  r   ©r«   r°   s     r)   r¸   ÚBroydenFirst.matvec¨  s   € Ø�w‰w�}‰}˜QÓÐr(   c                 ó8   • U R                   R                  U5      $ r+   )ra  r¹   ©r«   r°   r]   s      r)   rº   ÚBroydenFirst.rsolve«  s   € Ø�w‰w�‰˜qÓ!Ð!r(   c                 ó8   • U R                   R                  U5      $ r+   )ra  rº   r•  s     r)   r¹   ÚBroydenFirst.rmatvec®  s   € Ø�w‰w�~‰~˜aÓ Ð r(   c                 óæ   • U R                  5         U R                  R                  U5      nX0R                  R                  U5      -
  nU[	        XG5      -  n	U R                  R                  X‰5        g r+   )rŠ  ra  r¹   r¸   r   rY  ©
r«   r0   r°   r�   r*  r³   r+  rF   r<  r=  s
             r)   r,  ÚBroydenFirst._update±  sO   € Ø�‰Œà�G‰G�O‰O˜BÓˆØ—‘—‘ Ó#Ñ#ˆØ”�R“‰Oˆà�‰�‰�qÕr(   )ra  rŠ  r!  rr  )Nr‡  NrÛ   )r"   r#   r$   r%   r&   r¬   rj   r¼   r   r¸   rº   r¹   r,  r'   r!   r(   r)   r   r   K  s2   † ñ2ôhTò2Hòôò ô"ò!õr(   r   c                   ó   • \ rS rSrSrS rSrg)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                 ó¦   • U R                  5         UnX0R                  R                  U5      -
  nXvS-  -  n	U R                  R                  X‰5        g ©Nr_   )rŠ  ra  r¸   rY  r�  s
             r)   r,  ÚBroydenSecond._updateî  s@   € Ø�‰ŒàˆØ—‘—‘ Ó#Ñ#ˆØ˜‘
‰NˆØ�‰�‰�qÕr(   r!   N)r"   r#   r$   r%   r&   r,  r'   r!   r(   r)   r  r  »  s   † ñ0õdr(   r  c                   ó8   • \ rS rSrSrS	S jrS
S jrS rS rSr	g)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                 ó|   • [         R                  U 5        Xl        X0l        / U l        / U l        S U l        X l        g r+   )r  r¬   r!  ÚMr�   r*  r„   Úw0)r«   r!  r¦  r¥  s       r)   r¬   ÚAnderson.__init__B  s4   € Ü×Ñ Ô%ØŒ
ØŒØˆŒØˆŒØˆŒ
Ø�r(   c                 ó  • U R                   * U-  n[        U R                  5      nUS:X  a  U$ [        R                  " XAR
                  S9n[        U5       H  n[        U R                  U   U5      XV'   M       [        U R                  U5      n[        U5       H7  nX7U   U R                  U   U R                   U R                  U   -  -   -  -  nM9     U$ ! [         a#    U R                  S S 2	 U R                  S S 2	 Us $ f = f©Nr   r3   )r!  rC  r�   r,   Úemptyr4   rn   r   r*  r   r>  r   )	r«   r°   r]   r�   rˆ   Údf_frz  r„   r  s	            r)   r   ÚAnderson.solveK  så   € Ø�j‰jˆ[˜‰]ˆä�—‘‹LˆØ�‹6ØˆIä�xŠx˜§¡Ñ)ˆÜ�q–ˆAÜ˜4Ÿ7™7 1™: qÓ)ˆD‹Gñ ð	Ü˜$Ÿ&™& $Ó'ˆEô �q–ˆAØ˜‘(˜DŸG™G A™J¨¯©°D·G±G¸A±JÑ)>Ñ>Ñ?Ñ?ŠBñ àˆ	øô ó 	à—‘š�
Ø—‘š�
ØŠIð		ús   Á:C Ã*DÄDc           
      óD  • U* U R                   -  n[        U R                  5      nUS:X  a  U$ [        R                  " X1R
                  S9n[        U5       H  n[        U R                  U   U5      XE'   M      [        R                  " X34UR
                  S9n[        U5       H§  n[        U5       H•  n[        U R                  U   U R                  U   5      XgU4'   Xx:X  d  M4  U R                  S:w  d  MF  XgU4==   [        U R                  U   U R                  U   5      U R                  S-  -  U R                   -  -  ss'   M—     M©     [        Xd5      n	[        U5       H7  n
X)U
   U R                  U
   U R                  U
   U R                   -  -   -  -  nM9     U$ )Nr   r3   r_   )r!  rC  r�   r,   rª  r4   rn   r   r*  r¦  r   )r«   r°   r�   rˆ   r«  rz  ÚbrI  rJ  r„   r  s              r)   r¸   ÚAnderson.matvecb  sO  € ØˆR�—
‘
‰]ˆä�—‘‹LˆØ�‹6ØˆIä�xŠx˜§¡Ñ)ˆÜ�q–ˆAÜ˜4Ÿ7™7 1™: qÓ)ˆD‹Gñ ô �HŠH�a�V 1§7¡7Ñ+ˆÜ�q–ˆAÜ˜1–X�Ü˜dŸg™g a™j¨$¯'©'°!©*Ó5��A�#‘Ø•6˜dŸg™g¨�lØ˜�c“Fœd 4§7¡7¨1¡:¨t¯w©w°q©zÓ:¸4¿7¹7ÀA¹:ÑEÀdÇjÁjÑPÑP•Fó ñ ô
 �a“ˆä�q–ˆAØ˜‘(˜DŸG™G A™J¨¯©°©°D·J±JÑ)>Ñ>Ñ?Ñ?ŠBñ àˆ	r(   c                 ó>  • U R                   S:X  a  g U R                  R                  U5        U R                  R                  U5        [	        U R                  5      U R                   :”  a[  U R                  R                  S5        U R                  R                  S5        [	        U R                  5      U R                   :”  a  M[  [	        U R                  5      n[        R                  " Xw4UR                  S9n[        U5       H\  n	[        X—5       HJ  n
Xš:X  a  U R                  S-  nOSnSU-   [        U R                  U	   U R                  U
   5      -  X‰U
4'   ML     M^     U[        R                  " US5      R                  R                  5       -  nX€l        g )Nr   r3   r_   r   )r¥  r�   rY  r*  rC  Úpopr,   rF  r4   rn   r¦  r   Útriurí   rì   r>  )r«   r0   r°   r�   r*  r³   r+  rˆ   r>  rI  rJ  Úwds               r)   r,  ÚAnderson._updatey  s#  € Ø�6‰6�Q‹;Øà�‰�‰�rÔØ�‰�‰�rÔä�$—'‘'‹l˜TŸV™VÓ#Ø�G‰G�K‰K˜ŒNØ�G‰G�K‰K˜ŒNô �$—'‘'‹l˜TŸV™VÕ#ô �—‘‹LˆÜ�HŠH�a�V 1§7¡7Ñ+ˆä�q–ˆAÜ˜1–[�Ø“6ØŸ™ !™‘Bà�BØ˜B™$¤ T§W¡W¨Q¡Z°·±¸±Ó <Ñ<��A�#“ó !ñ ð 	
ŒR�WŠW�Q˜‹]�_‰_×!Ñ!Ó#Ñ#ˆØ�r(   )r¥  r>  r!  r*  r�   r„   r¦  )NrŸ   é   rÛ   )
r"   r#   r$   r%   r&   r¬   r   r¸   r,  r'   r!   r(   r)   r  r  û  s   † ñ+ôLôò.õ.r(   r  c                   óT   • \ rS rSrSrSS jrS rSS jrS rSS jr	S	 r
S
 rS rSrg)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                 ó:   • [         R                  U 5        Xl        g r+   ©r  r¬   r!  ©r«   r!  s     r)   r¬   ÚDiagBroyden.__init__À  ó   € Ü×Ñ Ô%Ø�
r(   c                 ó°   • [         R                  XX#5        [        R                  " U R                  S   4SU R
                  -  U R                  S9U l        g )Nr   r   r3   )r  rj   r,   Úfullr<   r!  r4   r=  rÙ   s       r)   rj   ÚDiagBroyden.setupÄ  s=   € Ü×Ñ˜T aÔ.Ü—’˜$Ÿ*™* Q™-Ð)¨1¨t¯z©z©>ÀÇÁÑLˆ�r(   c                 ó"   • U* U R                   -  $ r+   ©r=  r˜  s      r)   r   ÚDiagBroyden.solveÈ  ó   € Øˆr�D—F‘F‰{Ðr(   c                 ó"   • U* U R                   -  $ r+   rÀ  r•  s     r)   r¸   ÚDiagBroyden.matvecË  rÂ  r(   c                 ó>   • U* U R                   R                  5       -  $ r+   ©r=  rì   r˜  s      r)   rº   ÚDiagBroyden.rsolveÎ  ó   € Øˆr�D—F‘F—K‘K“MÑ!Ð!r(   c                 ó>   • U* U R                   R                  5       -  $ r+   rÆ  r•  s     r)   r¹   ÚDiagBroyden.rmatvecÑ  rÈ  r(   c                 óD   • [         R                  " U R                  * 5      $ r+   )r,   Údiagr=  rÊ   s    r)   r¼   ÚDiagBroyden.todenseÔ  s   € Ü�wŠw˜Ÿ™�wÓÐr(   c                 ó^   • U =R                   X@R                   U-  -   U-  US-  -  -  sl         g r¡  rÀ  r)  s          r)   r,  ÚDiagBroyden._update×  s(   € Ø�Š�2Ÿ™˜r™	‘> 2Ñ% g¨q¡jÑ0Ñ0Žr(   )r!  r=  r+   rÛ   ©r"   r#   r$   r%   r&   r¬   rj   r   r¸   rº   r¹   r¼   r,  r'   r!   r(   r)   r  r  —  s1   † ñ&ôPòMôòô"ò"ò õ1r(   r  c                   óN   • \ rS rSrSrSS jrSS jrS rSS jrS r	S	 r
S
 rSrg)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                 ó:   • [         R                  U 5        Xl        g r+   r¸  r¹  s     r)   r¬   ÚLinearMixing.__init__ò  r»  r(   c                 ó"   • U* U R                   -  $ r+   ©r!  r˜  s      r)   r   ÚLinearMixing.solveö  ó   € Øˆr�$—*‘*‰}Ðr(   c                 ó"   • U* U R                   -  $ r+   rÕ  r•  s     r)   r¸   ÚLinearMixing.matvecù  r×  r(   c                 óJ   • U* [         R                  " U R                  5      -  $ r+   ©r,   rì   r!  r˜  s      r)   rº   ÚLinearMixing.rsolveü  ó   € Øˆr”"—'’'˜$Ÿ*™*Ó%Ñ%Ð%r(   c                 óJ   • U* [         R                  " U R                  5      -  $ r+   rÛ  r•  s     r)   r¹   ÚLinearMixing.rmatvecÿ  rÝ  r(   c                 óŒ   • [         R                  " [         R                  " U R                  S   SU R                  -  5      5      $ )Nr   éÿÿÿÿ)r,   rÌ  r½  r<   r!  rÊ   s    r)   r¼   ÚLinearMixing.todense  s,   € Ü�wŠw”r—w’w˜tŸz™z¨!™}¨b°·±©mÓ<Ó=Ð=r(   c                 ó   • g r+   r!   r)  s          r)   r,  ÚLinearMixing._update  rÖ   r(   rÕ  r+   rÛ   )r"   r#   r$   r%   r&   r¬   r   r¸   rº   r¹   r¼   r,  r'   r!   r(   r)   r  r  Û  s*   † ñô,ôòô&ò&ò>õr(   r  c                   óT   • \ rS rSrSrSS jrS rSS jrS rSS jr	S	 r
S
 rS rSrg)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                 óT   • [         R                  U 5        Xl        X l        S U l        g r+   )r  r¬   r!  ÚalphamaxÚbeta)r«   r!  rç  s      r)   r¬   ÚExcitingMixing.__init__$  s!   € Ü×Ñ Ô%ØŒ
Ø ŒØˆ�	r(   c                 óª   • [         R                  XX#5        [        R                  " U R                  S   4U R
                  U R                  S9U l        g r©  )r  rj   r,   r½  r<   r!  r4   rè  rÙ   s       r)   rj   ÚExcitingMixing.setup*  s9   € Ü×Ñ˜T aÔ.Ü—G’G˜TŸZ™Z¨™]Ð,¨d¯j©jÀÇ
Á
ÑKˆ�	r(   c                 ó"   • U* U R                   -  $ r+   ©rè  r˜  s      r)   r   ÚExcitingMixing.solve.  ó   € Øˆr�$—)‘)‰|Ðr(   c                 ó"   • U* U R                   -  $ r+   rí  r•  s     r)   r¸   ÚExcitingMixing.matvec1  rï  r(   c                 ó>   • U* U R                   R                  5       -  $ r+   ©rè  rì   r˜  s      r)   rº   ÚExcitingMixing.rsolve4  ó   € Øˆr�$—)‘)—.‘.Ó"Ñ"Ð"r(   c                 ó>   • U* U R                   R                  5       -  $ r+   ró  r•  s     r)   r¹   ÚExcitingMixing.rmatvec7  rõ  r(   c                 óH   • [         R                  " SU R                  -  5      $ )Nrá  )r,   rÌ  rè  rÊ   s    r)   r¼   ÚExcitingMixing.todense:  s   € Ü�wŠw�r˜$Ÿ)™)‘|Ó$Ð$r(   c                 ó  • X R                   -  S:„  nU R                  U==   U R                  -  ss'   U R                  U R                  U) '   [        R                  " U R                  SU R
                  U R                  S9  g )Nr   )Úout)r#  rè  r!  r,   Úcliprç  )r«   r0   r°   r�   r*  r³   r+  Úincrs           r)   r,  ÚExcitingMixing._update=  sZ   € Ø—‘‰}˜qÑ ˆØ�	‰	�$‹˜4Ÿ:™:Ñ%‹ØŸ:™:ˆ�	‰	�4�%ÑÜ
�Š�—	‘	˜1˜dŸm™m°·±Ó;r(   )r!  rç  rè  )Nr^   rÛ   rÐ  r!   r(   r)   r  r  	  s0   † ñô4òLôòô#ò#ò%õ<r(   r  c                   óH   • \ rS rSrSr  SS jrS rS rSS jrS r	S	 r
S
rg)r   iH  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           	      ó\  • X@l         Xl        [        [        R                  R
                  R                  [        R                  R
                  R                  [        R                  R
                  R                  [        R                  R
                  R                  [        R                  R
                  R                  [        R                  R
                  R                  S9R                  X"5      U l        [        X0R                   S9U l        U R                  [        R                  R
                  R                  L a;  X0R                  S'   SU R                  S'   U R                  R                  SS5        GOTU R                  [        R                  R
                  R                   [        R                  R
                  R                  [        R                  R
                  R                  4;   a  U R                  R                  SS5        O¾U R                  [        R                  R
                  R                  L a�  XPR                  S'   SU R                  S'   U R                  R                  S	/ 5        U R                  R                  S
S5        U R                  R                  SS5        U R                  R                  SS5        [#        U R                  5      R$                   Vs/ s H  nUS;  d  M  UPM     nnUR'                  5        HŠ  u  pšU	R)                  S5      (       d  [+        SU	 35      eU	SS  U;  aG  [-        U	SS  USS9nU(       a
  SUS    S3nOSn[.        R0                  " SU	 SU S3U-   S[2        S9  My  X R                  U	SS  '   MŒ     g s  snf )N)ÚbicgstabÚgmresÚlgmresÚcgsÚminresÚtfqmr)rz   r¥  r‡  r   rz   Úatolr   Úouter_kÚouter_vÚprepend_outer_vTÚstore_outer_AvF)r«   ÚargsÚkwargsÚinner_zUnknown parameter é   )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.r]  )r^  Úcategory)Úpreconditionerr›   r  r   r  r  r  r  r  r  r  r  ÚgetÚmethodÚ	method_kwÚ
setdefaultÚgcrotmkr   Ú
parametersrÁ   Ú
startswithrm   r   r_  r`  ÚUserWarning)r«   r›   r  Úinner_maxiterÚinner_Mr  rÄ   rz  Úvalid_inner_paramsÚkeyrÇ   Úinner_param_suggestionsÚsuggestion_msgs                r)   r¬   ÚKrylovJacobian.__init__®  s÷  € à%ÔØŒ
ô Ü—\‘\×(Ñ(×1Ñ1Ü—,‘,×%Ñ%×+Ñ+Ü—<‘<×&Ñ&×-Ñ-Ü—‘×#Ñ#×'Ñ'Ü—<‘<×&Ñ&×-Ñ-Ü—,‘,×%Ñ%×+Ñ+ñ÷ ‰c�&Ó!ð 	Œô  m×7JÑ7JÑKˆŒà�;‰;œ%Ÿ,™,×-Ñ-×3Ñ3Ò3à(5�N‰N˜9Ñ%Ø()ˆD�N‰N˜9Ñ%Ø�N‰N×%Ñ% f¨aÖ0Ø�[‰[œUŸ\™\×0Ñ0×8Ñ8Ü"Ÿ\™\×0Ñ0×9Ñ9Ü"Ÿ\™\×0Ñ0×4Ñ4ð6ó 6ð �N‰N×%Ñ% f¨aÕ0Ø�[‰[œEŸL™L×/Ñ/×6Ñ6Ò6Ø(/�N‰N˜9Ñ%à()ˆD�N‰N˜9Ñ%à�N‰N×%Ñ% i°Ô4Ø�N‰N×%Ñ%Ð&7¸Ô>ð �N‰N×%Ñ%Ð&6¸Ô>Ø�N‰N×%Ñ% f¨aÔ0ô ! §¡Ó-×8Ò8ó
Ú8�!ØÐ2Ñ2÷ Ñ8ð 	ð 
ð
 Ÿ(™(ž*‰JˆCØ—>‘> (×+Ñ+Ü Ð#5°c°UÐ!;Ó<Ð<Ø�1�2ˆwÐ0Ó0ä*;¸CÀÀ¸GØ<NØ>?ñ+AÐ'ö +Ø(7Ø)@ÀÑ)CÐ(DÀBð'H‘Nð &(�Nô —’Ø˜s˜eÐ#FÀvÀhð OQð Qð %ñ%ð  !Ü(ò	ñ Ø&+�N‰N˜3˜q˜r˜7Ó#ò7 %ùò
s   Ë4
N)ÌN)c                 óæ   • [        U R                  5      R                  5       n[        U R                  5      R                  5       nU R                  [        SU5      -  [        SU5      -  U l        g )Nr   )r™   r>   r.   r%  r›   Úomega)r«   ÚmxÚmfs      r)   Ú_update_diff_stepÚ KrylovJacobian._update_diff_stepû  sO   € Ü�—‘‹\×ÑÓˆÜ�—‘‹\×ÑÓˆØ—Z‘Z¤# a¨£*Ñ,¬s°1°b«zÑ9ˆ�
r(   c                 ó‚  • [        U5      nUS:X  a  SU-  $ U R                  U-  nU R                  U R                  X1-  -   5      U R                  -
  U-  n[
        R                  " [
        R                  " U5      5      (       d:  [
        R                  " [
        R                  " U5      5      (       a  [        S5      eU$ )Nr   z$Function returned non-finite results)	r   r#  rX   r>   r%  r,   rC   rB   rm   )r«   rF   ÚnvÚscr’  s        r)   r¸   ÚKrylovJacobian.matvec   sŒ   € Ü�!‹WˆØ�‹7Ø�Q‘3ˆJØ�Z‰Z˜"‰_ˆØ�Y‰Y�t—w‘w ¡‘~Ó&¨¯©Ñ0°BÑ6ˆÜ�vŠv”b—k’k !“n×%Ñ%¬"¯&ª&´·²¸Q³×*@Ñ*@ÜÐCÓDÐDØˆr(   c                 óÖ   • SU R                   ;   a,  U R                  " U R                  U40 U R                   D6u  p4U$ U R                  " U R                  U4SU0U R                   D6u  p4U$ )NÚrtol)r  r  Úop)r«   Úrhsr]   ÚsolrŒ   s        r)   r   ÚKrylovJacobian.solve
  s_   € Ø�T—^‘^Ó#ØŸš D§G¡G¨SÑC°D·N±NÑC‰IˆCð ˆ
ð Ÿš D§G¡G¨SÑM°sÐM¸d¿n¹nÑM‰IˆCØˆ
r(   c                 óÆ   • Xl         X l        U R                  5         U R                  b8  [	        U R                  S5      (       a  U R                  R                  X5        g g g )Nrr   )r>   r%  r&  r  rÃ   rr   )r«   r0   r°   s      r)   rr   ÚKrylovJacobian.update  sW   € ØŒØŒØ×ÑÔ ð ×ÑÑ*Ü�t×*Ñ*¨H×5Ñ5Ø×#Ñ#×*Ñ*¨1Õ0ð 6ð +r(   c                 óÎ  • [         R                  XX#5        Xl        X l        [        R
                  R                  R                  U 5      U l        U R                  c2  [        R                  " UR                  5      R                  S-  U l	        U R                  5         U R                  b9  [!        U R                  S5      (       a  U R                  R                  XU5        g g g )Nr"  rj   )r¶   rj   r>   r%  r   r  r  Úaslinearoperatorr.  r›   r,   r¨   r4   r©   r&  r  rÃ   )r«   r0   r°   rX   s       r)   rj   ÚKrylovJacobian.setup  s¬   € Ü�‰�t Ô(ØŒØŒÜ—,‘,×%Ñ%×6Ñ6°tÓ<ˆŒà�:‰:ÑÜŸš !§'¡'Ó*×.Ñ.°4Ñ8ˆDŒJà×ÑÔ ð ×ÑÑ*Ü�t×*Ñ*¨G×4Ñ4Ø×#Ñ#×)Ñ)¨!°Õ5ð 5ð +r(   )r%  r  r  r#  r.  r  r›   r>   )Nr  é   Né
   rÛ   )r"   r#   r$   r%   r&   r¬   r&  r¸   r   rr   rj   r'   r!   r(   r)   r   r   H  s3   † ñcðJ CEØ')ôK,òZ:ò
ôò1õ6r(   r   c           	      óf  • [        UR                  5      nUu  p4pVpxn	[        [        U[	        U5      * S U5      5      n
SR                  U
 VVs/ s H  u  p¼U SU< 3PM     snn5      nU(       a  SU-   nSR                  U
 VVs/ s H  u  p¼U SU 3PM     snn5      nU(       a  US-   nU(       a  [        SU 35      eSnU[        XUR                  US9-  n0 nUR                  [        5       5        [        UU5        UU    nUR                  Ul        [        U5        U$ s  snnf s  snnf )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:  rC  Újoinrm   r  r"   rr   ÚglobalsÚexecr&   rM   )rÆ   r;  r   r  ÚvarargsÚvarkwÚdefaultsÚ
kwonlyargsÚ
kwdefaultsÚ_r  rz  rF   Úkw_strÚkwkw_strÚwrapperÚnsrX   s                     r)   Ú_nonlin_wrapperrL  0  s*  € ô   §¡Ó-€IØ@IÑ=€D�5 J¸AÜ”#�dœC ›M˜>˜?Ð+¨XÓ6Ó7€FØ�Y‰Y±Ô8²©¨˜1˜#˜Q˜q™e›±Ò8Ó9€FÞØ˜‘ˆØ�y‰y±Ô8²©¨˜Q˜C˜q  ›*±Ò8Ó9€HÞØ˜d‘?ˆÞÜÐ0°°Ð<Ó=Ð=ð€Gð œ $°s·|±|Ø"*ñ,ñ ,€Gà	€BØ‡I�IŒg‹iÔÜˆ�"ÔØˆd‰8€DØ—;‘;€D„LÜˆT„NØ€Kùó; 9ùó 9s   ÁD'
ÂD-
r   r   r   r   r   r   r   )r  NFNNNNNNr[   NFT)r[   g:Œ0âŽyE>rŸ   )?r  rs   r_  Únumpyr,   r   r   r   Úscipy.linalgr   r   r   r	   r
   r   Úscipy.sparse.linalgr   Úscipy.sparser   Úscipy._lib._utilr   r   r=  Ú_linesearchr   r   r   Údifflibr   Ú__all__Ú	Exceptionr   r1   r8   r@   rG   r  ÚstriprK   rM   r�   rq   rg   r¶   r   ri   r  r1  r   r  r  r  r  r  r   rL  r   r   r   r   r   r   r   r!   r(   r)   Ú<module>rW     sÛ  ðó Û 
Û ã ß $Ñ $ç ?× ?Û Û Ý 'Ý +Ý Fß CÝ Ý %òJ€ô	�Iô 	ò òòòñ ð÷ 	‰‹ð(÷P 	‰‹ña1€
òh/ð
 ?DØKOØ?CØ48ôO"ñd 	ˆÔ ð FJØ!ô*÷Z9<ñ 9<÷@Eñ E÷P$#ñ $#òNY?ô@�Xô ÷4Iñ IðX ÷* 	‰‹ð+ ÐÑ ô0m�>ô mô`9�Lô 9ô@Uˆ~ô UôxA1�.ô A1ôH+�>ô +ô\8<�^ô 8<ô~a6�Xô a6òP)ñX ˜: |Ó4€Ù˜: }Ó5€Ù˜: xÓ0€Ù˜~¨|Ó<€Ù˜m¨[Ó9€Ù Ð!1°>ÓB€Ù °Ó@�r(   