Ë
    ÏÍ:jÈÌ  ã                   óz  — d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZ d dl	m
Z
mZmZmZmZmZ d dlZd dlZd dl	mZ d dlmZmZ d dlmZ ddlmZmZ d d	l mZ d d
lmZ d dlm Z  g d¢Z! G d„ de"«      Z#d„ Z$d„ Z%d„ Z&d„ Z' e( ed«      jS                  «        ed«      jS                  «       ¬«      Z*d„ Z+d„ Z,	 	 	 	 d=d„Z- e+e-«       	 	 d>d„Z. G d„ d«      Z/ G d„ d«      Z0 G d„ d«      Z1d „ Z2 G d!„ d"e0«      Z3 G d#„ d$«      Z4 ed%«      jS                  «       e*d&<    G d'„ d(e3«      Z5 G d)„ d*e5«      Z6 G d+„ d,e3«      Z7 G d-„ d.e3«      Z8 G d/„ d0e3«      Z9 G d1„ d2e3«      Z: G d3„ d4e0«      Z;d5„ Z< e<d6e5«      Z= e<d7e6«      Z> e<d8e7«      Z? e<d9e9«      Z@ e<d:e8«      ZA e<d;e:«      ZB e<d<e;«      ZC e,e5«        e,e;«       y)?é    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                   ó   — e Zd ZdZy)r    z\Exception raised when nonlinear solver fails to converge within the specified
    `maxiter`.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úk/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/scipy/optimize/_nonlin.pyr    r    "   s
   „ ñàr'   r    c                 óH   — t        j                  | «      j                  «       S ©N)ÚnpÚabsoluteÚmax©Úxs    r(   Úmaxnormr0   (   s   € Ü�;‰;�q‹>×ÑÓÐr'   c                 ó®   — t        | «      } t        j                  | j                  t        j                  «      st        | t        j
                  ¬«      S | S )z:Return `x` as an array, of either floats or complex floats©Údtype)r   r+   Ú
issubdtyper3   ÚinexactÚfloat64r.   s    r(   Ú_as_inexactr7   ,   s7   € ä�‹
€AÜ�=‰=˜Ÿ™¤"§*¡*Ô-Ü�q¤§
¡
Ô+Ð+Ø€Hr'   c                 ó’   — t        j                  | t        j                  |«      «      } t        |d| j                  «      } || «      S )z;Return ndarray `x` as same array subclass and shape as `x0`Ú__array_wrap__)r+   ÚreshapeÚshapeÚgetattrr9   )r/   Úx0Úwraps      r(   Ú_array_liker?   4   s8   € ä
�
‰
�1”b—h‘h˜r“lÓ#€AÜ�2Ð'¨×)9Ñ)9Ó:€DÙ�‹7€Nr'   c                 ó¤   — t        j                  | «      j                  «       s#t        j                  t         j                  «      S t        | «      S r*   )r+   ÚisfiniteÚallÚarrayÚinfr   )Úvs    r(   Ú
_safe_normrF   ;   s2   € Ü�;‰;�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                 óN   — | j                   r| j                   t        z  | _         y y r*   )r%   Ú
_doc_parts)Úobjs    r(   Ú_set_docrL   y   s   € Ø
‡{‚{Ø—k‘k¤JÑ.ˆ�ð r'   c                 ó‚   — | j                   r3t        j                  «       }d|d<   d|d<   | j                   |z  | _         y y )NÚ rG   rH   )r%   rJ   Úcopy)rK   Ú	doc_partss     r(   Ú_set_doc_classrQ   ~   s>   € Ø
‡{‚{Ü—O‘OÓ%ˆ	Ø$&ˆ	�.Ñ!Ø$&ˆ	�.Ñ!Ø—k‘k IÑ-ˆ�ð	 r'   c           
      ó  ‡ ‡— |
€t         n|
}
t        ||||	||
¬«      }t        ‰«      Šˆ ˆfd„}‰j                  «       }t	        j
                  |t        j                  «      } ||«      }t        |«      }t        |«      }|j                  |j                  «       ||«       |€|�|dz   }nd|j                  dz   z  }|du rd}n|du rd}|d	vrt        d
«      ‚d}d}d}d}t        |«      D �]H  }|j                  |||«      }|r �nIt        |||z  «      }|j!                  ||¬«       }t        |«      dk(  rt        d«      ‚|rt#        |||||«      \  }}}}nd}||z   } ||«      }t        |«      }|j%                  |j                  «       |«       |r	 |||«       ||dz  z  |dz  z  }||dz  z  |k  rt        ||«      }nt        |t'        |||dz  z  «      «      }|}|sŒût(        j*                  j-                  |› d |
|«      d›d|d›d�«       t(        j*                  j/                  «        �ŒK |rt1        t3        |‰«      «      ‚d}|r)|j4                  |||dk(  dddœ|   dœ}t3        |‰«      |fS t3        |‰«      S )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         ‰t        | ‰«      «      «      j                  «       S r*   )r7   r?   Úflatten)ÚzÚFr=   s    €€r(   Úfuncz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   rb   )ÚnitÚfunÚstatusÚsuccessÚmessage)r0   ÚTerminationConditionr7   rY   r+   Ú	full_likerD   r   Ú
asjacobianÚsetuprO   ÚsizeÚ
ValueErrorÚrangeÚcheckÚminr   Ú_nonlin_line_searchÚupdater-   ÚsysÚstdoutÚwriteÚflushr    r?   Ú	iteration) r[   r=   ÚjacobianrW   ÚverboseÚmaxiterrS   rT   rU   rV   Útol_normÚline_searchÚcallbackÚfull_outputÚraise_exceptionÚ	conditionr\   r/   ÚdxÚFxÚFx_normÚgammaÚeta_maxÚeta_tresholdÚetaÚnrg   r`   ÚsÚFx_norm_newÚeta_AÚinfos    ``                              r(   Únonlin_solver�   †   sÚ  ù€ ðZ #Ð*�w°€HÜ$¨5¸Ø+0¸Ø*.°Xô?€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àˆò Ü�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                 ól  ‡ ‡‡‡‡‡‡‡‡— dgŠ|gŠt        |«      dz  gŠt        ‰«      t        ‰«      z  Šdˆˆ ˆˆˆˆfd„	Šˆˆˆfd„}|dk(  rt        ‰|‰d   d|¬«      \  }}	}
n|dk(  rt        ‰‰d   ‰d    |¬	«      \  }}	€d
}‰|‰z  z   Š|‰d   k(  r‰d   }n ‰ ‰«      }t        |«      }|‰||fS )Nr   rb   c                 ó€   •— | ‰	d   k(  r‰d   S ‰
| ‰z  z   } ‰|«      }t        |«      dz  }|r| ‰	d<   |‰d<   |‰d<   |S )Nr   rb   )rF   )r‹   ÚstoreÚxtrE   Úprƒ   r\   Útmp_FxÚtmp_phiÚtmp_sr/   s        €€€€€€r(   Úphiz _nonlin_line_search.<locals>.phi"  s_   ø€ Ø��a‘Š=Ø˜1‘:ÐØ��2‘‰XˆÙ�‹HˆÜ�q‹M˜1ÑˆÙØˆE�!‰HØˆG�A‰JØˆF�1‰IØˆr'   c                 ó^   •— t        | «      ‰z   dz   ‰z  } ‰| |z   d¬«       ‰| «      z
  |z  S )Nr   F)r’   )Úabs)r‹   Údsr˜   ÚrdiffÚs_norms     €€€r(   Úderphiz#_nonlin_line_search.<locals>.derphi.  s9   ø€ Ü�!‹f�v‰o Ñ! UÑ*ˆÙ�A�b‘D Ô&©¨Q«Ñ/°2Ñ5Ð5r'   r_   ç{®Gáz„?)ÚxtolÚaminr^   )r¡   ra   )T)r   r   r   )r\   r/   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‰ˆˆ4‘à	˜Ò	 Ü& s¨G°A©J¸À¹¸Ø,0ô2‰ˆˆ4ð 	€yð ˆà	ˆAˆb‰D‰€AØˆE�!‰H‚}Ø�A‰Y‰á�!‹WˆÜ�2‹h€Gàˆa��WÐÐr'   c                   ó*   — e Zd ZdZdddddefd„Zd„ Zy)rj   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                 óD  — |€0t        j                  t         j                  «      j                  dz  }|€t         j                  }|€t         j                  }|€t         j                  }|| _        || _        || _        || _        || _	        || _
        d | _        d| _        y )NgUUUUUUÕ?r   )r+   Úfinfor6   ÚepsrD   rU   rV   rS   rT   r   rW   Úf0_normry   )ÚselfrS   rT   rU   rV   rW   r   s          r(   Ú__init__zTerminationCondition.__init__U  sˆ   € ð ˆ=Ü—H‘HœRŸZ™ZÓ(×,Ñ,°Ñ6ˆEØˆ>Ü—V‘VˆFØˆ=Ü—F‘FˆEØˆ>Ü—V‘VˆFàˆŒ
ØˆŒØˆŒ
ØˆŒàˆŒ	àˆŒ	àˆŒØˆ�r'   c                 óÊ  — | xj                   dz  c_         | j                  |«      }| j                  |«      }| j                  |«      }| j                  €|| _        |dk(  ry| j                  �d| j                   | j                  kD  z  S t	        || j
                  k  xr || j                  z  | j                  k  xr# || j                  k  xr || j                  z  |k  «      S )Nr   r   rb   )	ry   r   rª   rW   ÚintrS   rT   rU   rV   )r«   Úfr/   rƒ   Úf_normÚx_normÚdx_norms          r(   rq   zTerminationCondition.checkm  sÏ   € Ø�Š˜!Ñ�Ø—‘˜1“ˆØ—‘˜1“ˆØ—)‘)˜B“-ˆà�<‰<ÐØ!ˆDŒLà�QŠ;Øà�9‰9Ð à˜Ÿ™¨¯©Ñ2Ñ3Ð3ô �F˜dŸj™jÑ(ò ;Ø˜tŸ{™{Ñ*¨d¯l©lÑ:ò;à 4§:¡:Ñ-ò :Ø# D§K¡KÑ/°6Ñ9ó<ð 	<r'   )r"   r#   r$   r%   r0   r¬   rq   r&   r'   r(   rj   rj   H  s!   „ ñð "¨$°dÀ4Ø óó0<r'   rj   c                   óL   — e Zd ZU dZ ee«      Zeed<   d„ Zd„ Z	d	d„Z
d„ Zd„ Zy)
ÚJacobiana¦  
    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

    Ú__class_getitem__c                 ó¨   — g d¢}|j                  «       D ]*  \  }}||vrt        d|› �«      ‚|€Œt        | |||   «       Œ, t        | d«      rdd„}y y )N)	r   rt   ÚmatvecÚrmatvecÚrsolveÚmatmatÚtodenser;   r3   zUnknown keyword argument r»   c                 óB   — |�t        d|› �«      ‚| j                  «       S )Nz`dtype` must be None, was )ro   r»   )r«   r3   rO   s      r(   Ú	__array__z$Jacobian.__init__.<locals>.__array__¼  s'   € ØÐ$Ü$Ð'AÀ%ÀÐ%IÓJÐJØ—|‘|“~Ð%r'   ©NN)Úitemsro   ÚsetattrÚhasattr)r«   ÚkwÚnamesÚnameÚvaluer½   s         r(   r¬   zJacobian.__init__±  si   € ò8ˆàŸ8™8›:ò 	.‰KˆD�%Ø˜5Ñ Ü Ð#<¸T¸FÐ!CÓDÐDØÑ Ü˜˜d B t¡HÕ-ð		.ô �4˜Ô#ô&ð $r'   c                 ó   — t        | «      S r*   )r   ©r«   s    r(   ÚaspreconditionerzJacobian.aspreconditionerÁ  s   € Ü˜tÓ$Ð$r'   c                ó   — t         ‚r*   ©ÚNotImplementedError©r«   rE   r`   s      r(   r   zJacobian.solveÄ  ó   € Ü!Ð!r'   c                 ó   — y r*   r&   ©r«   r/   r[   s      r(   rt   zJacobian.updateÇ  ó   € Ør'   c                óà   — || _         |j                  |j                  f| _        |j                  | _        | j                  j
                  t        j
                  u r| j                  ||«       y y r*   )r\   rn   r;   r3   Ú	__class__rm   r´   rt   ©r«   r/   r[   r\   s       r(   rm   zJacobian.setupÊ  sQ   € ØˆŒ	Ø—f‘f˜aŸf™fÐ%ˆŒ
Ø—W‘WˆŒ
Ø�>‰>×Ñ¤8§>¡>Ñ1à�K‰K˜˜1Õð 2r'   N©r   )r"   r#   r$   r%   Úclassmethodr   rµ   Ú__annotations__r¬   rÈ   r   rt   rm   r&   r'   r(   r´   r´   ˆ  s3   … ñ#ñL &1°Ó%>Ð�{Ó>ò&ò %ó"òór'   r´   c                   óR   — e Zd ZU dZ ee«      Zeed<   d„ Ze	d„ «       Z
e	d„ «       Zy)r   a  
    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.

    rµ   c                 óÌ   — || _         |j                  | _        |j                  | _        t	        |d«      r|j
                  | _        t	        |d«      r|j                  | _        y y )Nrm   r¹   )rz   r   r·   rt   rÁ   rm   r¹   r¸   )r«   rz   s     r(   r¬   zInverseJacobian.__init__ì  sN   € Ø ˆŒØ—n‘nˆŒØ—o‘oˆŒÜ�8˜WÔ%Ø!Ÿ™ˆDŒJÜ�8˜XÔ&Ø#Ÿ?™?ˆD�Lð 'r'   c                 ó.   — | j                   j                  S r*   )rz   r;   rÇ   s    r(   r;   zInverseJacobian.shapeõ  ó   € à�}‰}×"Ñ"Ð"r'   c                 ó.   — | j                   j                  S r*   )rz   r3   rÇ   s    r(   r3   zInverseJacobian.dtypeù  rÚ   r'   N)r"   r#   r$   r%   rÕ   r   rµ   rÖ   r¬   Úpropertyr;   r3   r&   r'   r(   r   r   Ó  sF   … ññ, &1°Ó%>Ð�{Ó>ò+ð ñ#ó ð#ð ñ#ó ñ#r'   r   c                 ó0  ‡ ‡— t         j                  j                  j                  Št	        ‰ t
        «      r‰ S t        j                  ‰ «      rt        ‰ t
        «      r ‰ «       S t	        ‰ t        j                  «      rŸ‰ j                  dkD  rt        d«      ‚t        j                  t        j                  ‰ «      «      Š ‰ j                  d   ‰ j                  d   k7  rt        d«      ‚t        ˆ fd„ˆ fd„dˆ fd„	dˆ fd	„	‰ j                   ‰ j                  ¬
«      S t         j                  j#                  ‰ «      r_‰ j                  d   ‰ j                  d   k7  rt        d«      ‚t        ˆ fd„ˆ fd„dˆ ˆfd„	dˆ ˆfd„	‰ j                   ‰ j                  ¬
«      S t%        ‰ d«      r{t%        ‰ d«      rot%        ‰ d«      rct        t'        ‰ d«      t'        ‰ d«      ‰ j(                  t'        ‰ d«      t'        ‰ d«      t'        ‰ d«      ‰ j                   ‰ j                  ¬«      S t+        ‰ «      r G ˆ ˆfd„dt
        «      } |«       S t	        ‰ t,        «      r6 t/        t0        t2        t4        t6        t8        t:        t<        ¬«      ‰    «       S t?        d«      ‚)zE
    Convert given object to one suitable for use as a Jacobian.
    rb   zarray must have rank <= 2r   r   zarray must be squarec                 ó   •— t        ‰| «      S r*   )r   ©rE   ÚJs    €r(   ú<lambda>zasjacobian.<locals>.<lambda>  s   ø€ ¬¨Q°«€ r'   c                 óL   •— t        ‰j                  «       j                  | «      S r*   )r   ÚconjÚTrß   s    €r(   rá   zasjacobian.<locals>.<lambda>  s   ø€ ¬#¨a¯f©f«h¯j©j¸!Ó*<€ r'   c                 ó   •— t        ‰| «      S r*   )r   ©rE   r`   rà   s     €r(   rá   zasjacobian.<locals>.<lambda>  s   ø€ ¬u°Q¸«{€ r'   c                 óL   •— t        ‰j                  «       j                  | «      S r*   )r   rã   rä   ræ   s     €r(   rá   zasjacobian.<locals>.<lambda>  s   ø€ ´°a·f±f³h·j±jÀ!Ó0D€ r'   )r·   r¸   r   r¹   r3   r;   zmatrix must be squarec                 ó   •— ‰| z  S r*   r&   rß   s    €r(   rá   zasjacobian.<locals>.<lambda>  s   ø€ ¨¨Q©€ r'   c                 ó>   •— ‰j                  «       j                  | z  S r*   ©rã   rä   rß   s    €r(   rá   zasjacobian.<locals>.<lambda>  s   ø€ ¨!¯&©&«(¯*©*°q©.€ r'   c                 ó   •—  ‰‰| «      S r*   r&   ©rE   r`   rà   Úspsolves     €€r(   rá   zasjacobian.<locals>.<lambda>  s   ø€ ©w°q¸!«}€ r'   c                 óF   •—  ‰‰j                  «       j                  | «      S r*   rê   rì   s     €€r(   rá   zasjacobian.<locals>.<lambda>  s   ø€ ±¸¿¹»¿
¹
ÀAÓ0F€ r'   r;   r3   r   r·   r¸   r¹   rt   rm   )r·   r¸   r   r¹   rt   rm   r3   r;   c                   óD   •— e Zd Zd„ Zdˆ ˆfd„	Zˆ fd„Zdˆ ˆfd„	Zˆ fd„Zy)úasjacobian.<locals>.Jacc                 ó   — || _         y r*   r.   rÏ   s      r(   rt   zasjacobian.<locals>.Jac.update'  s	   € Ø�•r'   c                 óÚ   •—  ‰| j                   «      }t        |t        j                  «      rt	        ||«      S t
        j                  j                  |«      r	 ‰||«      S t        d«      ‚©NzUnknown matrix type)	r/   Ú
isinstancer+   Úndarrayr   ÚscipyÚsparseÚissparsero   ©r«   rE   r`   Úmrà   rí   s       €€r(   r   zasjacobian.<locals>.Jac.solve*  sT   ø€ Ù�d—f‘f“I�Ü˜a¤§¡Ô,Ü   A›;Ð&Ü—\‘\×*Ñ*¨1Ô-Ù" 1 a›=Ð(ä$Ð%:Ó;Ð;r'   c                 óÒ   •—  ‰| j                   «      }t        |t        j                  «      rt	        ||«      S t
        j                  j                  |«      r||z  S t        d«      ‚ró   )	r/   rô   r+   rõ   r   rö   r÷   rø   ro   ©r«   rE   rú   rà   s      €r(   r·   zasjacobian.<locals>.Jac.matvec3  sQ   ø€ Ù�d—f‘f“I�Ü˜a¤§¡Ô,Ü˜q !›9Ð$Ü—\‘\×*Ñ*¨1Ô-Ø˜q™5�Lä$Ð%:Ó;Ð;r'   c                 ó:  •—  ‰| j                   «      }t        |t        j                  «      r$t	        |j                  «       j                  |«      S t        j                  j                  |«      r! ‰|j                  «       j                  |«      S t        d«      ‚ró   )r/   rô   r+   rõ   r   rã   rä   rö   r÷   rø   ro   rù   s       €€r(   r¹   zasjacobian.<locals>.Jac.rsolve<  sj   ø€ Ù�d—f‘f“I�Ü˜a¤§¡Ô,Ü  §¡£§¡¨QÓ/Ð/Ü—\‘\×*Ñ*¨1Ô-Ù" 1§6¡6£8§:¡:¨qÓ1Ð1ä$Ð%:Ó;Ð;r'   c                 ó2  •—  ‰| j                   «      }t        |t        j                  «      r$t	        |j                  «       j                  |«      S t        j                  j                  |«      r|j                  «       j                  |z  S t        d«      ‚ró   )r/   rô   r+   rõ   r   rã   rä   rö   r÷   rø   ro   rü   s      €r(   r¸   zasjacobian.<locals>.Jac.rmatvecE  sg   ø€ Ù�d—f‘f“I�Ü˜a¤§¡Ô,Ü˜qŸv™v›xŸz™z¨1Ó-Ð-Ü—\‘\×*Ñ*¨1Ô-ØŸ6™6›8Ÿ:™:¨™>Ð)ä$Ð%:Ó;Ð;r'   NrÔ   )r"   r#   r$   rt   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;   r3   rø   rÁ   r<   r   ÚcallableÚstrÚdictr   ÚBroydenSecondÚAndersonÚDiagBroydenÚLinearMixingÚExcitingMixingr   Ú	TypeError)rà   rÿ   rí   s   ` @r(   rl   rl   þ  s  ù€ ô �l‰l×!Ñ!×)Ñ)€GÜ�!”XÔØˆÜ	�‰˜Ô	¤
¨1¬hÔ 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¼ÀÀGÔ9LÜœw q¨(Ó3Ü '¨¨9Ó 5ØŸg™gÜ& q¨(Ó3Ü& q¨(Ó3Ü% a¨Ó1ØŸg™gØŸg™gô'ð 	'ô 
�!Œ÷&	<”(ô &	<ñN ‹uˆÜ	�A”sÔ	ð.Œtœ\Ü*Ü%Ü +Ü!-Ü#1Ü)ô+ð ,-ñ.ó 0ð 	0ô Ð=Ó>Ð>r'   c                   ó:   — e Zd ZU  ee«      Zeed<   d„ Zd„ Zd„ Z	y)ÚGenericBroydenrµ   c                óî   — t         j                  | |||«       || _        || _        t	        | d«      rC| j
                  €6t        |«      }|r!dt        t        |«      d«      z  |z  | _        y d| _        y y y )NÚalphaç      à?r   ra   )r´   rm   Úlast_fÚlast_xrÁ   r  r   r-   )r«   r=   Úf0r\   Únormf0s        r(   rm   zGenericBroyden.setupb  sn   € Ü�‰�t˜R  TÔ*ØˆŒØˆŒä�4˜Ô! d§j¡jÐ&8ô ˜"“XˆFÙØ ¤¤T¨"£X¨qÓ!1Ñ1°FÑ:�•
à �•
ð '9Ð!r'   c                 ó   — t         ‚r*   rÊ   ©r«   r/   r¯   rƒ   Údfr²   Údf_norms          r(   Ú_updatezGenericBroyden._updatep  rÍ   r'   c           
      ó¬   — || j                   z
  }|| j                  z
  }| j                  ||||t        |«      t        |«      «       || _         || _        y r*   )r  r  r  r   )r«   r/   r¯   r  rƒ   s        r(   rt   zGenericBroyden.updates  sH   € Ø�—‘‰_ˆØ�—‘‰_ˆØ�‰�Q˜˜2˜r¤4¨£8¬T°"«XÔ6ØˆŒØˆ�r'   N)
r"   r#   r$   rÕ   r   rµ   rÖ   rm   r  rt   r&   r'   r(   r  r  ^  s!   … á%0°Ó%>Ð�{Ó>ò!ò"ór'   r  c                   ó–   — e Zd ZU dZ ee«      Zeed<   d„ Ze	d„ «       Z
e	d„ «       Zd„ Zd„ Zdd„Zdd	„Zd
„ Zdd„Zd„ Zd„ Zd„ Zdd„Zy)ÚLowRankMatrixzà
    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.

    rµ   c                 óX   — || _         g | _        g | _        || _        || _        d | _        y r*   )r  Úcsr›   rŠ   r3   Ú	collapsed)r«   r  rŠ   r3   s       r(   r¬   zLowRankMatrix.__init__‰  s,   € ØˆŒ
ØˆŒØˆŒØˆŒØˆŒ
Øˆ�r'   c                 ó¦   — t        g d¢|d d | gz   «      \  }}}|| z  }t        ||«      D ]#  \  }}	 ||	| «      }
 ||||j                  |
«      }Œ% |S )N)ÚaxpyÚscalÚdotcr   )r   Úziprn   )rE   r  r"  r›   r%  r&  r'  ÚwÚcÚdÚas              r(   Ú_matveczLowRankMatrix._matvec‘  sm   € ä)Ò*BØ*,¨R¨a¨&°A°3©,ó8Ñˆˆd�Dà�A‰IˆÜ˜˜B“Kò 	&‰DˆAˆqÙ�Q˜“
ˆAÙ�Q˜˜1Ÿ6™6 1Ó%‰Að	&ð ˆr'   c           	      óJ  — t        |«      dk(  r| |z  S t        ddg|dd | gz   «      \  }}|d   }|t        j                  t        |«      |j                  ¬«      z  }t        |«      D ].  \  }}	t        |«      D ]  \  }
}|||
fxx    ||	|«      z  cc<   Œ Œ0 t        j                  t        |«      |j                  ¬«      }t        |«      D ]  \  }
}	 ||	| «      ||
<   Œ ||z  }t        ||«      }| |z  }t        ||«      D ]  \  }} ||||j                  | «      }Œ |S )úEvaluate w = M^-1 vr   r%  r'  Nr   r2   )
Úlenr   r+   Úidentityr3   Ú	enumerateÚzerosr   r(  rn   )rE   r  r"  r›   r%  r'  Úc0ÚAÚir+  Újr*  Úqr)  Úqcs                  r(   Ú_solvezLowRankMatrix._solve›  s:  € ô ˆr‹7�aŠ<Ø�U‘7ˆNô $ V¨VÐ$4°b¸¸!°fÀ¸s±lÓC‰
ˆˆdà�‰UˆØ”B—K‘K¤ B£¨r¯x©xÔ8Ñ8ˆÜ˜b“Mò 	%‰DˆAˆqÜ! "›ò %‘��1Ø�!�A�#“™$˜q !›*Ñ$”ñ%ð	%ô �H‰H”S˜“W B§H¡HÔ-ˆÜ˜b“Mò 	‰DˆAˆqÙ˜˜1“:ˆAˆaŠDð	à	ˆU‰
ˆÜ�!�Q‹Kˆàˆe‰GˆÜ˜˜Q“Zò 	(‰EˆAˆrÙ�Q˜˜1Ÿ6™6 B 3Ó'‰Að	(ð ˆr'   c                 óÆ   — | j                   � t        j                  | j                   |«      S t        j	                  || j
                  | j                  | j                  «      S )zEvaluate w = M v)r#  r+   r   r   r-  r  r"  r›   ©r«   rE   s     r(   r·   zLowRankMatrix.matvec·  sD   € à�>‰>Ð%Ü—6‘6˜$Ÿ.™.¨!Ó,Ð,Ü×$Ñ$ Q¨¯
©
°D·G±G¸T¿W¹WÓEÐEr'   c                 ó  — | j                   �8t        j                  | j                   j                  j	                  «       |«      S t
        j                  |t        j                  | j                  «      | j                  | j                  «      S )zEvaluate w = M^H v)
r#  r+   r   rä   rã   r   r-  r  r›   r"  r<  s     r(   r¸   zLowRankMatrix.rmatvec½  s\   € à�>‰>Ð%Ü—6‘6˜$Ÿ.™.×*Ñ*×/Ñ/Ó1°1Ó5Ð5Ü×$Ñ$ Q¬¯©°·
±
Ó(;¸T¿W¹WÀdÇgÁgÓNÐNr'   c                 ó²   — | j                   �t        | j                   |«      S t        j                  || j                  | j
                  | j                  «      S )r/  )r#  r   r   r:  r  r"  r›   rÌ   s      r(   r   zLowRankMatrix.solveÃ  s@   € à�>‰>Ð%Ü˜Ÿ™¨Ó+Ð+Ü×#Ñ# A t§z¡z°4·7±7¸D¿G¹GÓDÐDr'   c                 ó  — | j                   �.t        | j                   j                  j                  «       |«      S t        j                  |t        j                  | j                  «      | j                  | j                  «      S )zEvaluate w = M^-H v)
r#  r   rä   rã   r   r:  r+   r  r›   r"  rÌ   s      r(   r¹   zLowRankMatrix.rsolveÉ  sX   € à�>‰>Ð%Ü˜Ÿ™×)Ñ)×.Ñ.Ó0°!Ó4Ð4Ü×#Ñ# A¤r§w¡w¨t¯z©zÓ':¸D¿G¹GÀTÇWÁWÓMÐMr'   c                 óX  — | j                   �5| xj                   |d d …d f   |d d d …f   j                  «       z  z  c_         y | j                  j                  |«       | j                  j                  |«       t        | j                  «      |j                  kD  r| j                  «        y y r*   )r#  rã   r"  Úappendr›   r0  rn   Úcollapse)r«   r*  r+  s      r(   rA  zLowRankMatrix.appendÏ  s{   € Ø�>‰>Ð%Ø�NŠN˜a¢ $ ™i¨!¨D²¨F©)¯.©.Ó*:Ñ:Ñ:�NØà�‰�‰�qÔØ�‰�‰�qÔäˆt�w‰w‹<˜!Ÿ&™&Ò Ø�M‰M�Oð !r'   Nc                 ó²  — |�t        j                  d|› d�d¬«       |�t        j                  d|› d�d¬«       | j                  �| j                  S | j                  t	        j
                  | j                  | j                  ¬«      z  }t        | j                  | j                  «      D ])  \  }}||d d …d f   |d d d …f   j                  «       z  z  }Œ+ |S )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 r2   )ÚwarningsÚwarnr#  r  r+   r1  rŠ   r3   r(  r"  r›   rã   )r«   r3   rO   ÚGmr*  r+  s         r(   r½   zLowRankMatrix.__array__Ú  sÖ   € ØÐÜ�M‰Mð 9Ø9>¸¸~ðOà%&õ(ð ÐÜ�M‰Mð 9Ø9=¸¸nðNà%&õ(ð �>‰>Ð%Ø—>‘>Ð!à�Z‰ZœŸ™ D§F¡F°$·*±*Ô=Ñ=ˆÜ˜Ÿ™ §¡Ó)ò 	-‰DˆAˆqØ�!’A�d�F‘)˜A˜d¢1˜f™IŸN™NÓ,Ñ,Ñ,‰Bð	-àˆ	r'   c                 ón   — t        j                  | t        ¬«      | _        d| _        d| _        d| _        y)z0Collapse the low-rank matrix to a full-rank one.)rO   N)r+   rC   r   r#  r"  r›   r  rÇ   s    r(   rB  zLowRankMatrix.collapseë  s)   € äŸ™ $¬^Ô<ˆŒØˆŒØˆŒØˆ�
r'   c                 óš   — | j                   �y|dkD  sJ ‚t        | j                  «      |kD  r| j                  dd…= | j                  dd…= yy)zH
        Reduce the rank of the matrix by dropping all vectors.
        Nr   ©r#  r0  r"  r›   ©r«   Úranks     r(   Úrestart_reducezLowRankMatrix.restart_reduceò  sG   € ð �>‰>Ð%ØØ�aŠxˆˆxÜˆt�w‰w‹<˜$ÒØ—‘š�
Ø—‘š‘
ð r'   c                 óÄ   — | j                   �y|dkD  sJ ‚t        | j                  «      |kD  r4| j                  d= | j                  d= t        | j                  «      |kD  rŒ3yy)zK
        Reduce the rank of the matrix by dropping oldest vectors.
        Nr   rK  rL  s     r(   Úsimple_reducezLowRankMatrix.simple_reduceý  sT   € ð �>‰>Ð%ØØ�aŠxˆˆxÜ�$—'‘'‹l˜TÒ!Ø—‘˜�
Ø—‘˜�
ô �$—'‘'‹l˜TÕ!r'   c                 ó†  — | j                   �y|}|�|}n|dz
  }| j                  r"t        |t        | j                  d   «      «      }t	        dt        ||dz
  «      «      }t        | j                  «      }||k  ryt        j                  | j                  «      j                  }t        j                  | j                  «      j                  }t        |d¬«      \  }}t        ||j                  j                  «       «      }t        |d¬«      \  }	}
}t        |t        |«      «      }t        ||j                  j                  «       «      }t        |«      D ]J  }|dd…|f   j                  «       | j                  |<   |dd…|f   j                  «       | j                  |<   ŒL | j                  |d…= | j                  |d…= y)	a  
        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

        Nrb   r   r   Úeconomic)ÚmodeF)Úfull_matrices)r#  r"  rr   r0  r-   r+   rC   rä   r›   r	   r   rã   r
   r   rp   rO   )r«   Úmax_rankÚ	to_retainr”   r8  rú   ÚCÚDÚRÚUÚSÚWHÚks                r(   Ú
svd_reducezLowRankMatrix.svd_reduce  sh  € ð: �>‰>Ð%ØàˆØÐ Ø‰Aà�A‘ˆAà�7Š7Ü�A”s˜4Ÿ7™7 1™:“Ó'ˆAÜ�”3�q˜!˜A™#“;Óˆä�—‘‹LˆØˆqŠ5àä�H‰H�T—W‘WÓ×ÑˆÜ�H‰H�T—W‘WÓ×Ñˆä�!˜*Ô%‰ˆˆ1Ü��1—3‘3—8‘8“:Óˆä�q¨Ô.‰ˆˆ1ˆbä�”3�r“7‹OˆÜ��2—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Ô   r¾   r*   )r"   r#   r$   r%   rÕ   r   rµ   rÖ   r¬   Ústaticmethodr-  r:  r·   r¸   r   r¹   rA  r½   rB  rN  rP  r^  r&   r'   r(   r   r   {  s|   … ññ &1°Ó%>Ð�{Ó>òð ñó ðð ñó ðò6FòOóEóNò	óò"ò	ò	ô?r'   r   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                   óF   — e Zd ZdZdd„Zd„ Zd„ Zdd„Zd„ Zdd„Z	d	„ Z
d
„ Zy)r   al  
    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                 óN  ‡ ‡— t         j                  ‰ «       |‰ _        d ‰ _        |€t        j
                  }|‰ _        t        |t        «      rdŠn
|dd  Š|d   }|dz
  f‰z   Š|dk(  rˆˆ fd„‰ _	        y |dk(  rˆˆ fd„‰ _	        y |dk(  rˆˆ fd	„‰ _	        y t        d
|› d�«      ‚)Nr&   r   r   r
   c                  ó6   •—  ‰j                   j                  ‰ Ž S r*   )rH  r^  ©Úreduce_paramsr«   s   €€r(   rá   z'BroydenFirst.__init__.<locals>.<lambda>¨  s   ø€ Ð#5 4§7¡7×#5Ñ#5°}Ð#E€ r'   Úsimplec                  ó6   •—  ‰j                   j                  ‰ Ž S r*   )rH  rP  rd  s   €€r(   rá   z'BroydenFirst.__init__.<locals>.<lambda>ª  s   ø€ Ð#8 4§7¡7×#8Ñ#8¸-Ð#H€ r'   Úrestartc                  ó6   •—  ‰j                   j                  ‰ Ž S r*   )rH  rN  rd  s   €€r(   rá   z'BroydenFirst.__init__.<locals>.<lambda>¬  s   ø€ Ð#9 4§7¡7×#9Ñ#9¸=Ð#I€ r'   zUnknown rank reduction method 'ú')r  r¬   r  rH  r+   rD   rU  rô   r  Ú_reducero   )r«   r  Úreduction_methodrU  re  s   `   @r(   r¬   z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                 óœ   — t         j                  | |||«       t        | j                   | j                  d   | j
                  «      | _        y )Nr   )r  rm   r   r  r;   r3   rH  rÓ   s       r(   rm   zBroydenFirst.setup°  s8   € Ü×Ñ˜T 1 a¨Ô.Ü §¡ ¨T¯Z©Z¸©]¸D¿J¹JÓGˆ�r'   c                 ó,   — t        | j                  «      S r*   )r   rH  rÇ   s    r(   r»   zBroydenFirst.todense´  s   € Ü�4—7‘7‹|Ðr'   c                 ó  — | j                   j                  |«      }t        j                  |«      j	                  «       sL| j                  | j                  | j                  | j                  «       | j                   j                  |«      S |S r*   )	rH  r·   r+   rA   rB   rm   r  r  r\   )r«   r¯   r`   Úrs       r(   r   zBroydenFirst.solve·  s\   € Ø�G‰G�N‰N˜1ÓˆÜ�{‰{˜1‹~×!Ñ!Ô#à�J‰J�t—{‘{ D§K¡K°·±Ô;Ø—7‘7—>‘> !Ó$Ð$Øˆr'   c                 ó8   — | j                   j                  |«      S r*   )rH  r   ©r«   r¯   s     r(   r·   zBroydenFirst.matvec¿  s   € Ø�w‰w�}‰}˜QÓÐr'   c                 ó8   — | j                   j                  |«      S r*   )rH  r¸   ©r«   r¯   r`   s      r(   r¹   zBroydenFirst.rsolveÂ  s   € Ø�w‰w�‰˜qÓ!Ð!r'   c                 ó8   — | j                   j                  |«      S r*   )rH  r¹   rr  s     r(   r¸   zBroydenFirst.rmatvecÅ  s   € Ø�w‰w�~‰~˜aÓ Ð r'   c                 óì   — | j                  «        | j                  j                  |«      }|| j                  j                  |«      z
  }|t	        ||«      z  }	| j                  j                  ||	«       y r*   )rk  rH  r¸   r·   r   rA  ©
r«   r/   r¯   rƒ   r  r²   r  rE   r*  r+  s
             r(   r  zBroydenFirst._updateÈ  sU   € Ø�‰Œà�G‰G�O‰O˜BÓˆØ�—‘—‘ Ó#Ñ#ˆØ”�R˜“‰Oˆà�‰�‰�q˜!Õr'   )Nrh  NrÔ   )r"   r#   r$   r%   r¬   rm   r»   r   r·   r¹   r¸   r  r&   r'   r(   r   r   b  s2   „ ñ2óhTò2Hòóò ó"ò!ór'   r   c                   ó   — e Zd ZdZd„ Zy)r
  aK  
    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                 ó¬   — | j                  «        |}|| j                  j                  |«      z
  }||dz  z  }	| j                  j                  ||	«       y ©Nrb   )rk  rH  r·   rA  rw  s
             r(   r  zBroydenSecond._update  sF   € Ø�‰ŒàˆØ�—‘—‘ Ó#Ñ#ˆØ�˜‘
‰NˆØ�‰�‰�q˜!Õr'   N)r"   r#   r$   r%   r  r&   r'   r(   r
  r
  Ò  s   „ ñ0ódr'   r
  c                   ó,   — e Zd ZdZdd„Zdd„Zd„ Zd„ Zy)	r  a  
    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                 ó‚   — t         j                  | «       || _        || _        g | _        g | _        d | _        || _        y r*   )r  r¬   r  ÚMrƒ   r  r†   Úw0)r«   r  r~  r}  s       r(   r¬   zAnderson.__init__Y  s:   € Ü×Ñ Ô%ØˆŒ
ØˆŒØˆŒØˆŒØˆŒ
Øˆ�r'   c                 ó  — | j                    |z  }t        | j                  «      }|dk(  r|S t        j                  ||j
                  ¬«      }t        |«      D ]  }t        | j                  |   |«      ||<   Œ  	 t        | j                  |«      }t        |«      D ]7  }|||   | j                  |   | j                   | j                  |   z  z   z  z  }Œ9 |S # t        $ r# | j                  d d …= | j                  d d …= |cY S w xY w©Nr   r2   )r  r0  rƒ   r+   Úemptyr3   rp   r   r  r   r,  r   )	r«   r¯   r`   rƒ   rŠ   Údf_fr]  r†   rú   s	            r(   r   zAnderson.solveb  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           
      óB  — | | j                   z  }t        | j                  «      }|dk(  r|S t        j                  ||j
                  ¬«      }t        |«      D ]  }t        | j                  |   |«      ||<   Œ  t        j                  ||f|j
                  ¬«      }t        |«      D ]£  }t        |«      D ]“  }t        | j                  |   | j                  |   «      |||f<   ||k(  sŒ4| j                  dk7  sŒD|||fxx   t        | j                  |   | j                  |   «      | j                  dz  z  | j                   z  z  cc<   Œ• Œ¥ t        ||«      }	t        |«      D ]7  }
||	|
   | j                  |
   | j                  |
   | j                   z  z   z  z  }Œ9 |S )Nr   r2   rb   )r  r0  rƒ   r+   r�  r3   rp   r   r  r~  r   )r«   r¯   rƒ   rŠ   r‚  r]  Úbr6  r7  r†   rú   s              r(   r·   zAnderson.matvecy  sy  € ØˆR�—
‘
‰]ˆä�—‘‹LˆØ�Š6ØˆIä�x‰x˜ §¡Ô)ˆÜ�q“ò 	*ˆAÜ˜4Ÿ7™7 1™: qÓ)ˆD�ŠGð	*ô �H‰H�a˜�V 1§7¡7Ô+ˆÜ�q“ò 	QˆAÜ˜1“Xò Q�Ü˜dŸg™g a™j¨$¯'©'°!©*Ó5��!�A�#‘Ø˜“6˜dŸg™g¨›lØ�a˜�c“Fœd 4§7¡7¨1¡:¨t¯w©w°q©zÓ:¸4¿7¹7ÀA¹:ÑEÀdÇjÁjÑPÑP”FñQð	Qô
 �a˜“ˆä�q“ò 	@ˆAØ�%˜‘(˜DŸG™G A™J¨¯©°©°D·J±JÑ)>Ñ>Ñ?Ñ?‰Bð	@àˆ	r'   c                 ó8  — | j                   dk(  ry | j                  j                  |«       | j                  j                  |«       t	        | j                  «      | j                   kD  rY| j                  j                  d«       | j                  j                  d«       t	        | j                  «      | j                   kD  rŒYt	        | j                  «      }t        j                  ||f|j                  ¬«      }t        |«      D ][  }	t        |	|«      D ]J  }
|	|
k(  r| j                  dz  }nd}d|z   t        | j                  |	   | j                  |
   «      z  ||	|
f<   ŒL Œ] |t        j                  |d«      j                  j                  «       z  }|| _        y )Nr   r2   rb   r   )r}  rƒ   rA  r  r0  Úpopr+   r3  r3   rp   r~  r   Útriurä   rã   r,  )r«   r/   r¯   rƒ   r  r²   r  rŠ   r,  r6  r7  Úwds               r(   r  zAnderson._update�  s7  € Ø�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˜a“[ò =�Ø˜’6ØŸ™ !™‘Bà�BØ˜B™$¤ T§W¡W¨Q¡Z°·±¸±Ó <Ñ<��!�A�#’ñ=ð	=ð 	
ŒR�W‰W�Q˜‹]�_‰_×!Ñ!Ó#Ñ#ˆØˆ�r'   )NrŸ   é   rÔ   )r"   r#   r$   r%   r¬   r   r·   r  r&   r'   r(   r  r    s   „ ñ+óLóò.ó.r'   r  c                   óF   — e Zd ZdZdd„Zd„ Zdd„Zd„ Zdd„Zd„ Z	d	„ Z
d
„ Zy)r  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                 ó<   — t         j                  | «       || _        y r*   ©r  r¬   r  ©r«   r  s     r(   r¬   zDiagBroyden.__init__×  ó   € Ü×Ñ Ô%Øˆ�
r'   c                 ó¸   — t         j                  | |||«       t        j                  | j                  d   fd| j
                  z  | j                  ¬«      | _        y )Nr   r   r2   )r  rm   r+   Úfullr;   r  r3   r+  rÓ   s       r(   rm   zDiagBroyden.setupÛ  sA   € Ü×Ñ˜T 1 a¨Ô.Ü—‘˜$Ÿ*™* Q™-Ð)¨1¨t¯z©z©>ÀÇÁÔLˆ�r'   c                 ó"   — | | j                   z  S r*   ©r+  rt  s      r(   r   zDiagBroyden.solveß  ó   € Øˆr�D—F‘F‰{Ðr'   c                 ó"   — | | j                   z  S r*   r’  rr  s     r(   r·   zDiagBroyden.matvecâ  r“  r'   c                 ó>   — | | j                   j                  «       z  S r*   ©r+  rã   rt  s      r(   r¹   zDiagBroyden.rsolveå  ó   € Øˆr�D—F‘F—K‘K“MÑ!Ð!r'   c                 ó>   — | | j                   j                  «       z  S r*   r–  rr  s     r(   r¸   zDiagBroyden.rmatvecè  r—  r'   c                 óB   — t        j                  | j                   «      S r*   )r+   Údiagr+  rÇ   s    r(   r»   zDiagBroyden.todenseë  s   € Ü�w‰w˜Ÿ™�wÓÐr'   c                 ó`   — | xj                   || j                   |z  z   |z  |dz  z  z  c_         y rz  r’  r  s          r(   r  zDiagBroyden._updateî  s*   € Ø�Š�2˜Ÿ™˜r™	‘> 2Ñ% g¨q¡jÑ0Ñ0Žr'   r*   rÔ   ©r"   r#   r$   r%   r¬   rm   r   r·   r¹   r¸   r»   r  r&   r'   r(   r  r  ®  s1   „ ñ&óPòMóòó"ò"ò ó1r'   r  c                   ó@   — e Zd ZdZd
d„Zdd„Zd„ Zdd„Zd„ Zd„ Z	d	„ Z
y)r  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                 ó<   — t         j                  | «       || _        y r*   rŒ  r�  s     r(   r¬   zLinearMixing.__init__	  rŽ  r'   c                 ó"   — | | j                   z  S r*   ©r  rt  s      r(   r   zLinearMixing.solve  ó   € Øˆr�$—*‘*‰}Ðr'   c                 ó"   — | | j                   z  S r*   r   rr  s     r(   r·   zLinearMixing.matvec  r¡  r'   c                 óH   — | t        j                  | j                  «      z  S r*   ©r+   rã   r  rt  s      r(   r¹   zLinearMixing.rsolve  ó   € Øˆr”"—'‘'˜$Ÿ*™*Ó%Ñ%Ð%r'   c                 óH   — | t        j                  | j                  «      z  S r*   r¤  rr  s     r(   r¸   zLinearMixing.rmatvec  r¥  r'   c                 óˆ   — t        j                  t        j                  | j                  d   d| j                  z  «      «      S )Nr   éÿÿÿÿ)r+   rš  r�  r;   r  rÇ   s    r(   r»   zLinearMixing.todense  s,   € Ü�w‰w”r—w‘w˜tŸz™z¨!™}¨b°·±©mÓ<Ó=Ð=r'   c                  ó   — y r*   r&   r  s          r(   r  zLinearMixing._update  rÐ   r'   r*   rÔ   )r"   r#   r$   r%   r¬   r   r·   r¹   r¸   r»   r  r&   r'   r(   r  r  ò  s*   „ ñó,óòó&ò&ò>ór'   r  c                   óF   — e Zd ZdZdd„Zd„ Zdd„Zd„ Zdd„Zd„ Z	d	„ Z
d
„ Zy)r  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.

    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

    See Also
    --------
    root : Interface to root finding algorithms for multivariate
           functions. See ``method='excitingmixing'`` in particular.
    Nc                 óX   — t         j                  | «       || _        || _        d | _        y r*   )r  r¬   r  ÚalphamaxÚbeta)r«   r  r¬  s      r(   r¬   zExcitingMixing.__init__;  s%   € Ü×Ñ Ô%ØˆŒ
Ø ˆŒØˆ�	r'   c                 ó²   — t         j                  | |||«       t        j                  | j                  d   f| j
                  | j                  ¬«      | _        y r€  )r  rm   r+   r�  r;   r  r3   r­  rÓ   s       r(   rm   zExcitingMixing.setupA  s=   € Ü×Ñ˜T 1 a¨Ô.Ü—G‘G˜TŸZ™Z¨™]Ð,¨d¯j©jÀÇ
Á
ÔKˆ�	r'   c                 ó"   — | | j                   z  S r*   ©r­  rt  s      r(   r   zExcitingMixing.solveE  ó   € Øˆr�$—)‘)‰|Ðr'   c                 ó"   — | | j                   z  S r*   r°  rr  s     r(   r·   zExcitingMixing.matvecH  r±  r'   c                 ó>   — | | j                   j                  «       z  S r*   ©r­  rã   rt  s      r(   r¹   zExcitingMixing.rsolveK  ó   € Øˆr�$—)‘)—.‘.Ó"Ñ"Ð"r'   c                 ó>   — | | j                   j                  «       z  S r*   r´  rr  s     r(   r¸   zExcitingMixing.rmatvecN  rµ  r'   c                 óF   — t        j                  d| j                  z  «      S )Nr¨  )r+   rš  r­  rÇ   s    r(   r»   zExcitingMixing.todenseQ  s   € Ü�w‰w�r˜$Ÿ)™)‘|Ó$Ð$r'   c                 ó  — || j                   z  dkD  }| j                  |xx   | j                  z  cc<   | j                  | j                  | <   t        j                  | j                  d| j
                  | j                  ¬«       y )Nr   )Úout)r  r­  r  r+   Úclipr¬  )r«   r/   r¯   rƒ   r  r²   r  Úincrs           r(   r  zExcitingMixing._updateT  s\   € Ø�—‘‰}˜qÑ ˆØ�	‰	�$‹˜4Ÿ:™:Ñ%‹ØŸ:™:ˆ�	‰	�4�%ÑÜ
�‰�—	‘	˜1˜dŸm™m°·±Ö;r'   )Nra   rÔ   rœ  r&   r'   r(   r  r     s0   „ ñó4òLóòó#ò#ò%ó<r'   r  c                   ó<   — e Zd ZdZ	 	 d	d„Zd„ Zd„ Zd
d„Zd„ Zd„ Z	y)r   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.
    kw : 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                 ó’  — || _         || _        t        t        j                  j
                  j                  t        j                  j
                  j                  t        j                  j
                  j                  t        j                  j
                  j                  t        j                  j
                  j                  t        j                  j
                  j                  ¬«      j                  ||«      | _        t        || j                   ¬«      | _        | j                  t        j                  j
                  j                  u r<|| j                  d<   d| j                  d<   | j                  j                  dd«       �nR| j                  t        j                  j
                  j                   t        j                  j
                  j                  t        j                  j
                  j                  fv r| j                  j                  dd«       n¾| j                  t        j                  j
                  j                  u rŽ|| j                  d<   d| j                  d<   | j                  j                  d	g «       | j                  j                  d
d«       | j                  j                  dd«       | j                  j                  dd«       t#        | j                  «      j$                  D �cg c]  }|dvr|‘Œ
 }}|j'                  «       D ]¥  \  }	}
|	j)                  d«      st+        d|	› �«      ‚|	dd  |vrht-        |	dd  |d¬«      }|r
d|d   › d�}nd}t/        j0                  d|	› d|› d�|z   t2        t4        j6                  j9                  t:        «      f¬«       Œ”|
| j                  |	dd  <   Œ§ y c c}w )N)ÚbicgstabÚgmresÚlgmresÚcgsÚminresÚtfqmr)r|   r}  rh  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'?rN   zOption 'z#' is invalid for the inner method: zO. It will be ignored.Please check inner method documentation for valid options.)ÚcategoryÚskip_file_prefixes)Úpreconditionerrœ   r	  rö   r÷   r  r¾  r¿  rÀ  rÁ  rÂ  rÃ  ÚgetÚmethodÚ	method_kwÚ
setdefaultÚgcrotmkr   Ú
parametersr¿   Ú
startswithro   r   rF  rG  ÚUserWarningÚosÚpathÚdirnameÚ__file__)r«   rœ   rÑ  Úinner_maxiterÚinner_MrÅ  rÂ   r]  Úvalid_inner_paramsÚkeyrÅ   Úinner_param_suggestionsÚsuggestion_msgs                r(   r¬   zKrylovJacobian.__init__Å  s  € à%ˆÔØˆŒ
ô Ü—\‘\×(Ñ(×1Ñ1Ü—,‘,×%Ñ%×+Ñ+Ü—<‘<×&Ñ&×-Ñ-Ü—‘×#Ñ#×'Ñ'Ü—<‘<×&Ñ&×-Ñ-Ü—,‘,×%Ñ%×+Ñ+ô÷ ‰c�&˜&Ó!ð 	Œô  m°t×7JÑ7JÔKˆŒà�;‰;œ%Ÿ,™,×-Ñ-×3Ñ3Ñ3à(5ˆD�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Ø(/ˆD�N‰N˜9Ñ%à()ˆD�N‰N˜9Ñ%à�N‰N×%Ñ% i°Ô4Ø�N‰N×%Ñ%Ð&7¸Ô>ð �N‰N×%Ñ%Ð&6¸Ô>Ø�N‰N×%Ñ% f¨aÔ0ô ! §¡Ó-×8Ñ8ö
ØØÐ2Ñ2ò ð
Ðð 
ð
 Ÿ(™(›*ò 	,‰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ð %ñ%ô )Ü(*¯©¯©¼Ó(AÐ'Cõð Ø&+ˆD�N‰N˜3˜q˜r˜7Ò#ñ3	,ùò
s   Ë<Oc                 óæ   — t        | j                  «      j                  «       }t        | j                  «      j                  «       }| j                  t        d|«      z  t        d|«      z  | _        y )Nr   )rš   r=   r-   r  rœ   Úomega)r«   ÚmxÚmfs      r(   Ú_update_diff_stepz KrylovJacobian._update_diff_step  sO   € Ü�—‘‹\×ÑÓˆÜ�—‘‹\×ÑÓˆØ—Z‘Z¤# a¨£*Ñ,¬s°1°b«zÑ9ˆ�
r'   c                 óf  — t        |«      }|dk(  rd|z  S | j                  |z  }| j                  | j                  ||z  z   «      | j                  z
  |z  }t        j                  t        j                  |«      «      s3t        j                  t        j                  |«      «      rt        d«      ‚|S )Nr   z$Function returned non-finite results)	r   rã  r\   r=   r  r+   rB   rA   ro   )r«   rE   ÚnvÚscrp  s        r(   r·   zKrylovJacobian.matvec  sˆ   € Ü�!‹WˆØ�Š7Ø�Q‘3ˆJØ�Z‰Z˜"‰_ˆØ�Y‰Y�t—w‘w  A¡‘~Ó&¨¯©Ñ0°BÑ6ˆÜ�v‰v”b—k‘k !“nÔ%¬"¯&©&´·±¸Q³Ô*@ÜÐCÓDÐDØˆr'   c                 óÖ   — d| j                   v r- | j                  | j                  |fi | j                   ¤Ž\  }}|S  | j                  | j                  |fd|i| j                   ¤Ž\  }}|S )NÚrtol)rÒ  rÑ  Úop)r«   Úrhsr`   ÚsolrŽ   s        r(   r   zKrylovJacobian.solve  sg   € Ø�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                 óÀ   — || _         || _        | j                  «        | j                  �4t	        | j                  d«      r| j                  j                  ||«       y y y )Nrt   )r=   r  ræ  rÏ  rÁ   rt   )r«   r/   r¯   s      r(   rt   zKrylovJacobian.update&  sZ   € ØˆŒØˆŒØ×ÑÔ ð ×ÑÐ*Ü�t×*Ñ*¨HÔ5Ø×#Ñ#×*Ñ*¨1¨aÕ0ð 6ð +r'   c                 óÈ  — t         j                  | |||«       || _        || _        t        j
                  j                  j                  | «      | _        | j                  €1t        j                  |j                  «      j                  dz  | _	        | j                  «        | j                  �5t!        | j                  d«      r| j                  j                  |||«       y y y )Nr  rm   )r´   rm   r=   r  rö   r÷   r  Úaslinearoperatorrì  rœ   r+   r¨   r3   r©   ræ  rÏ  rÁ   )r«   r/   r¯   r\   s       r(   rm   zKrylovJacobian.setup0  s³   € Ü�‰�t˜Q  4Ô(ØˆŒØˆŒÜ—,‘,×%Ñ%×6Ñ6°tÓ<ˆŒà�:‰:ÐÜŸ™ !§'¡'Ó*×.Ñ.°4Ñ8ˆDŒJà×ÑÔ ð ×ÑÐ*Ü�t×*Ñ*¨GÔ4Ø×#Ñ#×)Ñ)¨!¨Q°Õ5ð 5ð +r'   )NrÀ  é   Né
   rÔ   )
r"   r#   r$   r%   r¬   ræ  r·   r   rt   rm   r&   r'   r(   r   r   _  s3   „ ñcðJ CEØ')óI,òV:ò
óò1ó6r'   r   c           	      óL  — t        |j                  «      }|\  }}}}}}}	t        t        |t	        |«       d |«      «      }
dj                  |
D ��cg c]  \  }}|› d|›�‘Œ c}}«      }|rd|z   }dj                  |
D ��cg c]  \  }}|› d|› �‘Œ c}}«      }|r|dz   }|rt        d|› �«      ‚d}|t        | ||j                  |¬«      z  }i }|j                  t        «       «       t        ||«       ||    }|j                  |_        t        |«       |S c c}}w c c}}w )a  
    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(  r0  Újoinro   r	  r"   rt   ÚglobalsÚexecr%   rL   )rÄ   rö  r   rÉ  ÚvarargsÚvarkwÚdefaultsÚ
kwonlyargsÚ
kwdefaultsÚ_rÊ  r]  rE   Úkw_strÚkwkw_strÚwrapperÚnsr\   s                     r(   Ú_nonlin_wrapperr  E  s.  € ô   §¡Ó-€IØ@IÑ=€Dˆ'�5˜( J°
¸AÜ”#�dœC ›M˜>˜?Ð+¨XÓ6Ó7€FØ�Y‰Y°×8©¨¨A˜1˜#˜Q˜q˜ešÓ8Ó9€FÙØ˜‘ˆØ�y‰y°×8©¨¨A˜Q˜C˜q  š*Ó8Ó9€HÙØ˜d‘?ˆÙÜÐ0°°Ð<Ó=Ð=ð€Gð œ $¨6°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Ÿ   )Dr  rØ  ru   rF  Únumpyr+   r   r   r   Úscipy.linalgr   r   r   r	   r
   r   Úscipy.sparse.linalgrö   Úscipy.sparser   Úscipy._lib._utilr   r   r   rø  Ú_linesearchr   r   r   Údifflibr   Útypesr   Ú__all__Ú	Exceptionr    r0   r7   r?   rF   r	  ÚstriprJ   rL   rQ   r�   rs   rj   r´   r   rl   r  r   r   r
  r  r  r  r  r   r  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<ô~_6�Xô _6òL)ñX ˜: |Ó4€Ù˜: }Ó5€Ù˜: xÓ0€Ù˜~¨|Ó<€Ù˜m¨[Ó9€Ù Ð!1°>ÓB€Ù °Ó@€Ù ˆ|Ô Ù ˆ~Õ r'   