ó
    EñiîË  ã                   óJ  • 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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 SKJr  / SQr  " S S\!5      r"S r#S r$S r%S r&\'" \" S5      RQ                  5       \" S5      RQ                  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 r0 " S  S!\.5      r1 " S" S#5      r2\" S$5      RQ                  5       \)S%'    " S& S'\15      r3 " S( S)\35      r4 " S* S+\15      r5 " S, S-\15      r6 " S. S/\15      r7 " S0 S1\15      r8 " S2 S3\.5      r9S4 r:\:" S5\35      r;\:" S6\45      r<\:" S7\55      r=\:" S8\75      r>\:" S9\65      r?\:" S:\85      r@\:" S;\95      rAg)>é    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                   ó   • \ 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#   ó    ÚS/home/mande/repo/quber/.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+   Úmaxnormr3   '   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.   Ú
issubdtyper6   ÚinexactÚfloat64r1   s    r+   Ú_as_inexactr:   +   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<   )r2   Úx0Úwraps      r+   Ú_array_likerB   3   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_normrI   :   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_docrO   x   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-   )r:   rB   Ú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   ra   )ÚnitÚfunÚstatusÚsuccessÚmessage)r3   ÚTerminationConditionr:   rW   r.   Ú	full_likerG   r   Ú
asjacobianÚsetupÚcopyÚsizeÚ
ValueErrorÚrangeÚcheckÚminr   Ú_nonlin_line_searchÚupdater0   ÚsysÚstdoutÚwriteÚflushr    rB   Ú	iteration) rY   r@   ÚjacobianrU   ÚverboseÚmaxiterrQ   rR   rS   rT   Útol_normÚline_searchÚcallbackÚfull_outputÚraise_exceptionÚ	conditionrZ   r2   ÚdxÚFxÚFx_normÚgammaÚeta_maxÚeta_tresholdÚetaÚnrf   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   ra   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   ra   )rI   )r‹   ÚstoreÚxtrH   Úprƒ   rZ   Útmp_FxÚtmp_phiÚtmp_sr2   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   )rZ   r2   r„   rƒ   Úsearch_typer�   ÚsminrŸ   r‹   Úphi1Úphi0r…   r˜   rž   r•   r–   r—   s   `` ` `      @@@@@r+   rs   rs     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)ri   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.   Úfinfor9   ÚepsrG   rS   rT   rQ   rR   r   rU   Úf0_normry   )ÚselfrQ   rR   rS   rT   rU   r   s          r+   Ú__init__ÚTerminationCondition.__init__L  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   ra   )	ry   r   r¬   rU   ÚintrQ   rR   rS   rT   )r­   Úfr2   rƒ   Úf_normÚx_normÚdx_norms          r+   rq   ÚTerminationCondition.checkd  sÅ   € Ø�Š˜!Ñ�Ø—‘˜1“ˆØ—‘˜1“ˆØ—)‘)˜B“-ˆà�<‰<ÑØ!ŒLà�Q‹;Øà�9‰9Ñ à˜Ÿ™¨¯©Ñ2Ñ3Ð3ô �FŸj™jÑ(÷ ;ØŸ{™{Ñ*¨d¯l©lÑ:÷;à§:¡:Ñ-÷ :Ø#§K¡KÑ/°6Ñ9ó<ð 	<r*   )r¬   rR   rQ   rU   ry   r   rT   rS   )	r$   r%   r&   r'   r(   r3   r®   rq   r)   r#   r*   r+   ri   ri   ?  s!   † ñð "¨$°dÀ4Ø ôõ0<r*   ri   c                   óJ   • \ rS rSrSr\" \5      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   rt   ÚmatvecÚrmatvecÚrsolveÚmatmatÚtodenser>   r6   zUnknown keyword argument r¾   c                 óD   • Ub  [        SU 35      eU R                  5       $ )Nz`dtype` must be None, was )ro   r¾   )r­   r6   rm   s      r+   Ú	__array__Ú$Jacobian.__init__.<locals>.__array__³  s'   € ØÑ$Ü$Ð'AÀ%ÀÐ%IÓJÐJØ—|‘|“~Ð%r*   ©NN)Úitemsro   Ú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­   rH   r_   s      r+   r   ÚJacobian.solve»  ó   € Ü!Ð!r*   c                 ó   • g r-   r#   ©r­   r2   rY   s      r+   rt   Ú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-   )rZ   rn   r>   r6   Ú	__class__rl   r¸   rt   ©r­   r2   rY   rZ   s       r+   rl   ÚJacobian.setupÁ  sM   € ØŒ	Ø—f‘f˜aŸf™fÐ%ˆŒ
Ø—W‘WˆŒ
Ø�>‰>×Ñ¤8§>¡>Ò1à�K‰K˜Õð 2r*   )r6   rZ   r>   N©r   )r$   r%   r&   r'   r(   Úclassmethodr   Ú__class_getitem__r®   rÍ   r   rt   rl   r)   r#   r*   r+   r¸   r¸     s.   † ñ#ñL $ LÓ1Ðò&ò %ô"òõr*   r¸   c                   óN   • \ rS rSrSr\" \5      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 )Nrl   r¼   )rz   r   rº   rt   rÅ   rl   r¼   r»   )r­   rz   s     r+   r®   ÚInverseJacobian.__init__ã  sR   € Ø ŒØ—n‘nˆŒØ—o‘oˆŒÜ�8˜W×%Ñ%Ø!Ÿ™ˆDŒJÜ�8˜X×&Ñ&Ø#Ÿ?™?ˆD�Lð 'r*   c                 ó.   • U R                   R                  $ r-   )rz   r>   rÌ   s    r+   r>   ÚInverseJacobian.shapeì  ó   € à�}‰}×"Ñ"Ð"r*   c                 ó.   • U R                   R                  $ r-   )rz   r6   rÌ   s    r+   r6   ÚInverseJacobian.dtypeð  rå   r*   )rz   rº   r»   rl   rt   N)r$   r%   r&   r'   r(   rÞ   r   rß   r®   Úpropertyr>   r6   r)   r#   r*   r+   r   r   Ê  sA   † ññ, $ LÓ1Ðò+ð ñ#ó ð#ð ñ#ó ó#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.
ra   zarray must have rank <= 2r   r   zarray must be squarec                 ó   >• [        TU 5      $ r-   )r   ©rH   Ú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   ©rH   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¼   r6   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#   ©rH   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>   r6   r   rº   r»   r¼   rt   rl   )rº   r»   r   r¼   rt   rl   r6   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-   r1   rÖ   s      r+   rt   Ú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)	r2   Ú
isinstancer.   Úndarrayr   ÚscipyÚsparseÚissparsero   ©r­   rH   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  )	r2   r  r.   r  r   r  r  r  ro   ©r­   rH   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  )r2   r  r.   r  r   rð   rñ   r  r  r  ro   r  s       €€r+   r¼   Úasjacobian.<locals>.Jac.rsolve3  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  )r2   r  r.   r  r   rð   rñ   r  r  r  ro   r  s      €r+   r»   Úasjacobian.<locals>.Jac.rmatvec<  sm   ø€ Ù�d—f‘f“I�Ü˜a¤§¡×,Ñ,Ü˜qŸv™v›xŸz™z¨1Ó-Ð-Ü—\‘\×*Ñ*¨1×-Ñ-ØŸ6™6›8Ÿ:™:¨™>Ð)ä$Ð%:Ó;Ð;r*   r1   NrÝ   )
r$   r%   r&   r'   rt   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  Úndimro   Ú
atleast_2dr   r>   r6   r  rÅ   r?   r   ÚcallableÚstrÚdictr   ÚBroydenSecondÚAndersonÚDiagBroydenÚLinearMixingÚExcitingMixingr   Ú	TypeError)rì   r  rú   s   ` @r+   rk   rk   õ  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                   ó6   • \ rS rSr\" \5      rS rS rS r	Sr
g)ÚGenericBroydeniU  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¸   rl   Úlast_fÚlast_xrÅ   r%  r   r0   )r­   r@   Úf0rZ   Únormf0s        r+   rl   ÚGenericBroyden.setupY  si   € Ü�‰�t Ô*ØŒØŒä�4˜×!Ñ! d§j¡jÑ&8ô ˜"“XˆFÞØ ¤¤T¨"£X¨qÓ!1Ñ1°FÑ:�•
à �•
ð '9Ð!r*   c                 ó   • [         er-   rÐ   ©r­   r2   r²   rƒ   Údfrµ   Údf_norms          r+   Ú_updateÚGenericBroyden._updateg  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(  r0  r   )r­   r2   r²   r.  rƒ   s        r+   rt   ÚGenericBroyden.updatej  s<   € Ø—‘‰_ˆØ—‘‰_ˆØ�‰�Q˜2¤4¨£8¬T°"«XÔ6ØŒØ�r*   )r%  r'  r(  N)r$   r%   r&   r'   rÞ   r   rß   rl   r0  rt   r)   r#   r*   r+   r#  r#  U  s   † á# LÓ1Ðò!ò"õr*   r#  c                   óš   • \ rS rSrSr\" \5      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)Ú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                 óR   • Xl         / U l        / U l        X l        X0l        S U l        g r-   )r%  Úcsrœ   rŠ   r6   Ú	collapsed)r­   r%  rŠ   r6   s       r+   r®   ÚLowRankMatrix.__init__€  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   Úziprn   )rH   r%  r7  rœ   r;  r<  r=  ÚwÚcÚdÚas              r+   Ú_matvecÚLowRankMatrix._matvecˆ  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   r;  r=  Nr   r5   )
Úlenr   r.   Úidentityr6   Ú	enumerateÚzerosr   r>  rn   )rH   r%  r7  rœ   r;  r=  Úc0ÚAÚirA  Ú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)r8  r.   r   r5  rC  r%  r7  rœ   ©r­   rH   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)
r8  r.   r   rñ   rð   r5  rC  r%  rœ   r7  rT  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      $ )rF  )r8  r   r5  rQ  r%  r7  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)
r8  r   rñ   rð   r5  rQ  r.   r%  rœ   r7  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-   )r8  rð   r7  Úappendrœ   rG  rn   Úcollapse)r­   r@  rA  s      r+   r]  Ú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 r5   )ÚwarningsÚwarnr8  r%  r.   rH  rŠ   r6   r>  r7  rœ   rð   )r­   r6   rm   ÚGmr@  rA  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.)rm   N)r.   rF   r   r8  r7  rœ   r%  rÌ   s    r+   r^  Ú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   ©r8  rG  r7  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   rj  rk  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

Nra   r   r   Úeconomic)ÚmodeF)Úfull_matrices)r8  r7  rr   rG  r0   r.   rF   rñ   rœ   r	   r   rð   r
   r   rp   rm   )r­   Úmax_rankÚ	to_retainr”   rO  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%  r8  r7  rœ   r6   rŠ   rÝ   rÂ   r-   )r$   r%   r&   r'   r(   rÞ   r   rß   r®   ÚstaticmethodrC  rQ  rº   r»   r   r¼   r]  rÀ   r^  rm  rp  r  r)   r#   r*   r+   r5  r5  r  sw   † ññ $ 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                   ó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   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                 ó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-   )re  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-   )re  rp  r†  s   €€r+   rí   rˆ  ¡  s   ø€  4§7¡7×#8Ò#8¸-Ñ#Hr*   Úrestartc                  ó6   >• TR                   R                  " T 6 $ r-   )re  rm  r†  s   €€r+   rí   rˆ  £  s   ø€  4§7¡7×#9Ò#9¸=Ñ#Ir*   zUnknown rank reduction method 'Ú')r#  r®   r%  re  r.   rG   rv  r  r  Ú_reducero   )r­   r%  Úreduction_methodrv  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#  rl   r5  r%  r>   r6   re  rÛ   s       r+   rl   ÚBroydenFirst.setup§  s4   € Ü×Ñ˜T aÔ.Ü §¡ ¨T¯Z©Z¸©]¸D¿J¹JÓGˆ�r*   c                 ó,   • [        U R                  5      $ r-   )r   re  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-   )	re  rº   r.   rD   rE   rl   r(  r'  rZ   )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-   )re  r   ©r­   r²   s     r+   rº   ÚBroydenFirst.matvec¶  s   € Ø�w‰w�}‰}˜QÓÐr*   c                 ó8   • U R                   R                  U5      $ r-   )re  r»   ©r­   r²   r_   s      r+   r¼   ÚBroydenFirst.rsolve¹  s   € Ø�w‰w�‰˜qÓ!Ð!r*   c                 ó8   • U R                   R                  U5      $ r-   )re  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Ž  re  r»   rº   r   r]  ©
r­   r2   r²   rƒ   r.  rµ   r/  rH   r@  rA  s
             r+   r0  ÚBroydenFirst._update¿  sO   € Ø�‰Œà�G‰G�O‰O˜BÓˆØ—‘—‘ Ó#Ñ#ˆØ”�R“‰Oˆà�‰�‰�qÕr*   )re  rŽ  r%  rv  )Nr‹  NrÝ   )r$   r%   r&   r'   r(   r®   rl   r¾   r   rº   r¼   r»   r0  r)   r#   r*   r+   r   r   Y  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 ©Nra   )rŽ  re  rº   r]  r¡  s
             r+   r0  ÚBroydenSecond._updateü  s@   € Ø�‰ŒàˆØ—‘—‘ Ó#Ñ#ˆØ˜‘
‰NˆØ�‰�‰�qÕr*   r#   N)r$   r%   r&   r'   r(   r0  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__P  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   r5   )r%  rG  rƒ   r.   Úemptyr6   rp   r   r.  r   rB  r   )	r­   r²   r_   rƒ   rŠ   Údf_fr~  r†   r  s	            r+   r   ÚAnderson.solveY  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   r5   ra   )r%  rG  rƒ   r.   r®  r6   rp   r   r.  rª  r   )r­   r²   rƒ   rŠ   r¯  r~  ÚbrM  rN  r†   r  s              r+   rº   ÚAnderson.matvecp  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   r5   ra   r   )r©  rƒ   r]  r.  rG  Úpopr.   rJ  r6   rp   rª  r   Útriurñ   rð   rB  )r­   r2   r²   rƒ   r.  rµ   r/  rŠ   rB  rM  rN  Úwds               r+   r0  ÚAnderson._update‡  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©  rB  r%  r.  rƒ   r†   rª  )Nr¡   é   rÝ   )
r$   r%   r&   r'   r(   r®   r   rº   r0  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   r5   )r#  rl   r.   Úfullr>   r%  r6   rA  rÛ   s       r+   rl   ÚDiagBroyden.setupÒ  s=   € Ü×Ñ˜T aÔ.Ü—’˜$Ÿ*™* Q™-Ð)¨1¨t¯z©z©>ÀÇÁÑLˆ�r*   c                 ó"   • U* U R                   -  $ r-   ©rA  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-   ©rA  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.   ÚdiagrA  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+   r0  ÚDiagBroyden._updateå  s(   € Ø�Š�2Ÿ™˜r™	‘> 2Ñ% g¨q¡jÑ0Ñ0Žr*   )r%  rA  r-   rÝ   ©r$   r%   r&   r'   r(   r®   rl   r   rº   r¼   r»   r¾   r0  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+   r0  ÚLinearMixing._update  rØ   r*   rÙ  r-   rÝ   )r$   r%   r&   r'   r(   r®   r   rº   r¼   r»   r¾   r0  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__2  s!   € Ü×Ñ Ô%ØŒ
Ø ŒØˆ�	r*   c                 óª   • [         R                  XX#5        [        R                  " U R                  S   4U R
                  U R                  S9U l        g r­  )r#  rl   r.   rÁ  r>   r%  r6   rì  rÛ   s       r+   rl   ÚExcitingMixing.setup8  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.matvec?  ró  r*   c                 ó>   • U* U R                   R                  5       -  $ r-   ©rì  rð   rœ  s      r+   r¼   ÚExcitingMixing.rsolveB  ó   € Øˆr�$—)‘)—.‘.Ó"Ñ"Ð"r*   c                 ó>   • U* U R                   R                  5       -  $ r-   r÷  r™  s     r+   r»   ÚExcitingMixing.rmatvecE  rù  r*   c                 óH   • [         R                  " SU R                  -  5      $ )Nrå  )r.   rÐ  rì  rÌ   s    r+   r¾   ÚExcitingMixing.todenseH  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­   r2   r²   rƒ   r.  rµ   r/  Úincrs           r+   r0  ÚExcitingMixing._updateK  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   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           	      ó\  • 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)r|   r©  r‹  r   r|   Ú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.ra  )rb  Úcategory)Úpreconditionerr�   r  r  r  r  r  r  r  r  r	  r
  ÚgetÚmethodÚ	method_kwÚ
setdefaultÚgcrotmkr   Ú
parametersrÃ   Ú
startswithro   r   rc  rd  Ú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�&Ó!ð 	Œô  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@   r0   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'  rZ   r@   r)  r.   rE   rD   ro   )r­   rH   Ú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 )Nrt   )r@   r)  r*  r  rÅ   rt   )r­   r2   r²   s      r+   rt   Ú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&  rl   )r¸   rl   r@   r)  r  r  r  Úaslinearoperatorr2  r�   r.   rª   r6   r«   r*  r  rÅ   )r­   r2   r²   rZ   s       r+   rl   ÚKrylovJacobian.setup)  s¬   € Ü�‰�t Ô(ØŒØŒÜ—,‘,×%Ñ%×6Ñ6°tÓ<ˆŒà�:‰:ÑÜŸš !§'¡'Ó*×.Ñ.°4Ñ8ˆDŒJà×ÑÔ ð ×ÑÑ*Ü�t×*Ñ*¨G×4Ñ4Ø×#Ñ#×)Ñ)¨!°Õ5ð 5ð +r*   )r)  r  r  r'  r2  r  r�   r@   )Nr  é   Né
   rÝ   )r$   r%   r&   r'   r(   r®   r*  rº   r   rt   rl   r)   r#   r*   r+   r   r   V  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>  rG  Újoinro   r  r$   rt   ÚglobalsÚexecr(   rO   )rÈ   r?  r   r  ÚvarargsÚvarkwÚdefaultsÚ
kwonlyargsÚ
kwdefaultsÚ_r  r~  rH   Úkw_strÚkwkw_strÚwrapperÚnsrZ   s                     r+   Ú_nonlin_wrapperrP  >  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¡   )Br  ru   rc  Únumpyr.   r   r   r   Úscipy.linalgr   r   r   r	   r
   r   Úscipy.sparse.linalgr  Úscipy.sparser   Úscipy._lib._utilr   r   r   rA  Ú_linesearchr   r   r   Údifflibr   Útypesr   Ú__all__Ú	Exceptionr    r3   r:   rB   rI   r  ÚstriprM   rO   r�   rs   ri   r¸   r   rk   r#  r5  r   r  r  r  r  r   r   rP  r   r   r   r   r   r   r   r#   r*   r+   Ú<module>r\     sø  ðó Û 
Û ã ß $Ñ $ç ?× ?Û Û Ý 'ß >Ý Fß CÝ Ý %Ý òJ€ô	�Iô 	ò òòòñ Ù"ð $ó 	÷ 
‰‹Ù"ð ($ó (	÷P 
‰‹ña1€
òh/ð
 ?DØKOØ?CØ48ôO"ñd 	ˆÔ ð FJØ!ô*÷Z9<ñ 9<÷@Hñ H÷V(#ñ (#òVY?ô@�Xô ÷:Lñ Lñ^  1ð 2ó  	÷* 
‰‹ð+ ÐÑ ô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*   