Ë
    çÿæiîË  ã                   óL  — 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«      jQ                  «        ed«      jQ                  «       ¬«      Z)d„ Z*	 	 	 	 d<d„Z+ e*e+«       	 	 d=d„Z, G d„ d«      Z- G d„ d«      Z. G d„ d«      Z/d„ Z0 G d „ d!e.«      Z1 G d"„ d#«      Z2 ed$«      jQ                  «       e)d%<    G d&„ d'e1«      Z3 G d(„ d)e3«      Z4 G d*„ d+e1«      Z5 G d,„ d-e1«      Z6 G d.„ d/e1«      Z7 G d0„ d1e1«      Z8 G d2„ d3e.«      Z9d4„ Z: e:d5e3«      Z; e:d6e4«      Z< e:d7e5«      Z= e:d8e7«      Z> e:d9e6«      Z? e:d:e8«      Z@ e:d;e9«      ZAy)>é    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/Volumes/fast/ai/experiments/voice-extract-mac/.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?   3   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   x   s   € Ø
‡{‚{Ø—k‘k¤JÑ.ˆ�ð 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)NrY   ÚwolfezInvalid line searchgÍÌÌÌÌÌì?g§èH.ÿï?gš™™™™™¹?gü©ñÒMbP?)Útolr   z[Jacobian inversion yielded zero vector. This indicates a bug in the Jacobian approximation.ç      ð?é   z:  |F(x)| = Úgz; step Ú
z0A solution was found at the specified tolerance.z:The maximum number of iterations allowed has been reached.)r   r]   )ÚnitÚfunÚstatusÚsuccessÚmessage)r0   ÚTerminationConditionr7   rT   r+   Ú	full_likerD   r   Ú
asjacobianÚsetupÚcopyÚsizeÚ
ValueErrorÚrangeÚcheckÚminr   Ú_nonlin_line_searchÚupdater-   ÚsysÚstdoutÚwriteÚflushr    r?   Ú	iteration) rV   r=   ÚjacobianrR   ÚverboseÚmaxiterrN   rO   rP   rQ   Útol_normÚline_searchÚcallbackÚfull_outputÚraise_exceptionÚ	conditionrW   r/   ÚdxÚFxÚFx_normÚgammaÚeta_maxÚeta_tresholdÚetaÚnrb   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   r]   c                 ó€   •— | ‰	d   k(  r‰d   S ‰
| ‰z  z   } ‰|«      }t        |«      dz  }|r| ‰	d<   |‰d<   |‰d<   |S )Nr   r]   )rF   )r‡   ÚstoreÚxtrE   Úpr   rW   Ú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'   rZ   ç{®Gáz„?)ÚxtolÚaminrY   )r�   r\   )T)r   r   r   )rW   r/   r€   r   Úsearch_typer˜   Úsminrš   r‡   Úphi1Úphi0r�   r”   r™   r‘   r’   r“   s   `` ` `      @@@@@r(   ro   ro     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)re   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   rP   rQ   rN   rO   r   rR   Úf0_normru   )ÚselfrN   rO   rP   rQ   rR   r   s          r(   Ú__init__zTerminationCondition.__init__L  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   r]   )	ru   r   r¦   rR   ÚintrN   rO   rP   rQ   )r§   Úfr/   r   Úf_normÚx_normÚdx_norms          r(   rm   zTerminationCondition.checkd  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¨   rm   r&   r'   r(   re   re   ?  s!   „ ñð "¨$°dÀ4Ø óó0<r'   re   c                   ó@   — e Zd ZdZ ee«      Z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

    c                 ó¨   — g d¢}|j                  «       D ]*  \  }}||vrt        d|› �«      ‚|€Œt        | |||   «       Œ, t        | d«      rdd„}y y )N)	r   rp   ÚmatvecÚrmatvecÚrsolveÚmatmatÚtodenser;   r3   zUnknown keyword argument r¶   c                 óB   — |�t        d|› �«      ‚| j                  «       S )Nz`dtype` must be None, was )rk   r¶   )r§   r3   ri   s      r(   Ú	__array__z$Jacobian.__init__.<locals>.__array__³  s'   € ØÐ$Ü$Ð'AÀ%ÀÐ%IÓJÐJØ—|‘|“~Ð%r'   ©NN)Úitemsrk   ÚsetattrÚhasattr)r§   ÚkwÚnamesÚnameÚvaluer¸   s         r(   r¨   zJacobian.__init__¨  sd   € ò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/   rV   s      r(   rp   zJacobian.update¾  ó   € Ør'   c                 óà   — || _         |j                  |j                  f| _        |j                  | _        | j                  j
                  t        j
                  u r| j                  ||«       y y r*   )rW   rj   r;   r3   Ú	__class__rh   r°   rp   ©r§   r/   rV   rW   s       r(   rh   zJacobian.setupÁ  sQ   € ØˆŒ	Ø—f‘f˜aŸf™fÐ%ˆŒ
Ø—W‘WˆŒ
Ø�>‰>×Ñ¤8§>¡>Ñ1à�K‰K˜˜1Õð 2r'   N©r   )r"   r#   r$   r%   Úclassmethodr   Ú__class_getitem__r¨   rÃ   r   rp   rh   r&   r'   r(   r°   r°     s.   „ ñ#ñL $ LÓ1Ðò&ò %ó"òór'   r°   c                   óF   — e Zd ZdZ ee«      Z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.

    c                 óÌ   — || _         |j                  | _        |j                  | _        t	        |d«      r|j
                  | _        t	        |d«      r|j                  | _        y y )Nrh   r´   )rv   r   r²   rp   r¼   rh   r´   r³   )r§   rv   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*   )rv   r;   rÂ   s    r(   r;   zInverseJacobian.shapeì  ó   € à�}‰}×"Ñ"Ð"r'   c                 ó.   — | j                   j                  S r*   )rv   r3   rÂ   s    r(   r3   zInverseJacobian.dtypeð  rÕ   r'   N)r"   r#   r$   r%   rÐ   r   rÑ   r¨   Úpropertyr;   r3   r&   r'   r(   r   r   Ê  sA   „ ññ, $ LÓ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.
    r]   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À!Ô0Dr'   )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Ô0Fr'   r;   r3   r   r²   r³   r´   rp   rh   )r²   r³   r   r´   rp   rh   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(   rp   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Úissparserk   ©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ó   rk   ©r§   rE   rõ   rÛ   s      €r(   r²   zasjacobian.<locals>.Jac.matvec*  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ó   rk   rô   s       €€r(   r´   zasjacobian.<locals>.Jac.rsolve3  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ó   rk   r÷   s      €r(   r³   zasjacobian.<locals>.Jac.rmatvec<  sg   ø€ Ù�d—f‘f“I�Ü˜a¤§¡Ô,Ü˜qŸv™v›xŸz™z¨1Ó-Ð-Ü—\‘\×*Ñ*¨1Ô-ØŸ6™6›8Ÿ:™:¨™>Ð)ä$Ð%:Ó;Ð;r'   NrÏ   )r"   r#   r$   rp   r   r²   r´   r³   )rÛ   rè   s   €€r(   ÚJacrë     s   ø„ òö<ô<ö<õ<r'   rú   )r   r   r   r   r   r   Úkrylovz#Cannot convert object to a JacobianrÏ   ) rñ   rò   Úlinalgrè   rï   r°   ÚinspectÚisclassÚ
issubclassr+   rð   Úndimrk   Ú
atleast_2dr   r;   r3   ró   r¼   r<   r   ÚcallableÚstrÚdictr   ÚBroydenSecondÚAndersonÚDiagBroydenÚLinearMixingÚExcitingMixingr   Ú	TypeError)rÛ   rú   rè   s   ` @r(   rg   rg   õ  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 ee«      Zd„ Zd„ Zd„ Zy)ÚGenericBroydenc                 óî   — t         j                  | |||«       || _        || _        t	        | d«      rC| j
                  €6t        |«      }|r!dt        t        |«      d«      z  |z  | _        y d| _        y y y )NÚalphaç      à?r   r\   )r°   rh   Úlast_fÚlast_xr¼   r  r   r-   )r§   r=   Úf0rW   Únormf0s        r(   rh   zGenericBroyden.setupY  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._updateg  rÈ   r'   c           
      ó¬   — || j                   z
  }|| j                  z
  }| j                  ||||t        |«      t        |«      «       || _         || _        y r*   )r  r  r  r   )r§   r/   r«   r  r   s        r(   rp   zGenericBroyden.updatej  sH   € Ø�—‘‰_ˆØ�—‘‰_ˆØ�‰�Q˜˜2˜r¤4¨£8¬T°"«XÔ6ØˆŒØˆ�r'   N)	r"   r#   r$   rÐ   r   rÑ   rh   r  rp   r&   r'   r(   r  r  U  s   „ á# LÓ1Ðò!ò"ór'   r  c                   óŠ   — e Zd ZdZ ee«      Z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.

    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   Úziprj   )rE   r  r  r—   r   r!  r"  ÚwÚcÚdÚas              r(   Ú_matveczLowRankMatrix._matvecˆ  sh   € ä)Ò*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#  rj   )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  r7  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  r5  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  r5  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—   r+  rj   Úcollapse)r§   r%  r&  s      r(   r<  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+   r,  r†   r3   r#  r  r—   rÞ   )r§   r3   ri   Ú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.)ri   N)r+   rC   r   r  r  r—   r  rÂ   s    r(   r=  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  r+  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   rF  rG  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

        Nr]   r   r   Úeconomic)ÚmodeF)Úfull_matrices)r  r  rn   r+  r-   r+   rC   rß   r—   r	   r   rÞ   r
   r   rl   ri   )r§   Úmax_rankÚ	to_retainr�   r3  rõ   ÚCÚDÚRÚUÚSÚWHÚks                r(   Ú
svd_reducezLowRankMatrix.svd_reduceÿ  sc  € ð: �>‰>Ð%ØàˆØÐ Ø‰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¨   Ústaticmethodr(  r5  r²   r³   r   r´   r<  r¸   r=  rI  rK  rY  r&   r'   r(   r  r  r  sw   „ ññ $ LÓ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*   )rC  rY  ©Úreduce_paramsr§   s   €€r(   rÜ   z'BroydenFirst.__init__.<locals>.<lambda>Ÿ  s   ø€ Ð#5 4§7¡7×#5Ñ#5°}Ñ#Er'   Úsimplec                  ó6   •—  ‰j                   j                  ‰ Ž S r*   )rC  rK  r_  s   €€r(   rÜ   z'BroydenFirst.__init__.<locals>.<lambda>¡  s   ø€ Ð#8 4§7¡7×#8Ñ#8¸-Ñ#Hr'   Úrestartc                  ó6   •—  ‰j                   j                  ‰ Ž S r*   )rC  rI  r_  s   €€r(   rÜ   z'BroydenFirst.__init__.<locals>.<lambda>£  s   ø€ Ð#9 4§7¡7×#9Ñ#9¸=Ñ#Ir'   zUnknown rank reduction method 'Ú')r  r¨   r  rC  r+   rD   rP  rï   r  Ú_reducerk   )r§   r  Úreduction_methodrP  r`  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  rh   r  r  r;   r3   rC  rÎ   s       r(   rh   zBroydenFirst.setup§  s8   € Ü×Ñ˜T 1 a¨Ô.Ü §¡ ¨T¯Z©Z¸©]¸D¿J¹JÓGˆ�r'   c                 ó,   — t        | j                  «      S r*   )r   rC  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*   )	rC  r²   r+   rA   rB   rh   r  r  rW   )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*   )rC  r   ©r§   r«   s     r(   r²   zBroydenFirst.matvec¶  s   € Ø�w‰w�}‰}˜QÓÐr'   c                 ó8   — | j                   j                  |«      S r*   )rC  r³   ©r§   r«   r[   s      r(   r´   zBroydenFirst.rsolve¹  s   € Ø�w‰w�‰˜qÓ!Ð!r'   c                 ó8   — | j                   j                  |«      S r*   )rC  r´   rm  s     r(   r³   zBroydenFirst.rmatvec¼  s   € Ø�w‰w�~‰~˜aÓ Ð r'   c                 óì   — | j                  «        | j                  j                  |«      }|| j                  j                  |«      z
  }|t	        ||«      z  }	| j                  j                  ||	«       y r*   )rf  rC  r³   r²   r   r<  ©
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'   )Nrc  NrÏ   )r"   r#   r$   r%   r¨   rh   r¶   r   r²   r´   r³   r  r&   r'   r(   r   r   Y  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 ©Nr]   )rf  rC  r²   r<  rr  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  ry  rx  s       r(   r¨   zAnderson.__init__P  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  r+  r   r+   Úemptyr3   rl   r   r  r   r'  r   )	r§   r«   r[   r   r†   Údf_frX  r‚   rõ   s	            r(   r   z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           
      ó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   r]   )r  r+  r   r+   r|  r3   rl   r   r  ry  r   )r§   r«   r   r†   r}  rX  Úbr1  r2  r‚   rõ   s              r(   r²   zAnderson.matvecp  s_  € Øˆ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Ø�a˜�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                 ó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   r]   r   )rx  r   r<  r  r+  Úpopr+   r.  r3   rl   ry  r   Útriurß   rÞ   r'  )r§   r/   r«   r   r  r®   r  r†   r'  r1  r2  Úwds               r(   r  z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˜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  rh   r+   Úfullr;   r  r3   r&  rÎ   s       r(   rh   zDiagBroyden.setupÒ  sA   € Ü×Ñ˜T 1 a¨Ô.Ü—‘˜$Ÿ*™* Q™-Ð)¨1¨t¯z©z©>ÀÇÁÔLˆ�r'   c                 ó"   — | | j                   z  S r*   ©r&  ro  s      r(   r   zDiagBroyden.solveÖ  ó   € Øˆr�D—F‘F‰{Ðr'   c                 ó"   — | | j                   z  S r*   r�  rm  s     r(   r²   zDiagBroyden.matvecÙ  rŽ  r'   c                 ó>   — | | j                   j                  «       z  S r*   ©r&  rÞ   ro  s      r(   r´   zDiagBroyden.rsolveÜ  ó   € Øˆr�D—F‘F—K‘K“MÑ!Ð!r'   c                 ó>   — | | j                   j                  «       z  S r*   r‘  rm  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 ru  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¨   rh   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  ro  s      r(   r   zLinearMixing.solve  ó   € Øˆr�$—*‘*‰}Ðr'   c                 ó"   — | | j                   z  S r*   r›  rm  s     r(   r²   zLinearMixing.matvec  rœ  r'   c                 óH   — | t        j                  | j                  «      z  S r*   ©r+   rÞ   r  ro  s      r(   r´   zLinearMixing.rsolve
  ó   € Øˆr”"—'‘'˜$Ÿ*™*Ó%Ñ%Ð%r'   c                 óH   — | t        j                  | j                  «      z  S r*   rŸ  rm  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.

    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                 óX   — t         j                  | «       || _        || _        d | _        y r*   )r  r¨   r  ÚalphamaxÚbeta)r§   r  r§  s      r(   r¨   zExcitingMixing.__init__2  s%   € Ü×Ñ Ô%ØˆŒ
Ø ˆŒØˆ�	r'   c                 ó²   — t         j                  | |||«       t        j                  | j                  d   f| j
                  | j                  ¬«      | _        y r{  )r  rh   r+   r‹  r;   r  r3   r¨  rÎ   s       r(   rh   zExcitingMixing.setup8  s=   € Ü×Ñ˜T 1 a¨Ô.Ü—G‘G˜TŸZ™Z¨™]Ð,¨d¯j©jÀÇ
Á
ÔKˆ�	r'   c                 ó"   — | | j                   z  S r*   ©r¨  ro  s      r(   r   zExcitingMixing.solve<  ó   € Øˆr�$—)‘)‰|Ðr'   c                 ó"   — | | j                   z  S r*   r«  rm  s     r(   r²   zExcitingMixing.matvec?  r¬  r'   c                 ó>   — | | j                   j                  «       z  S r*   ©r¨  rÞ   ro  s      r(   r´   zExcitingMixing.rsolveB  ó   € Øˆr�$—)‘)—.‘.Ó"Ñ"Ð"r'   c                 ó>   — | | j                   j                  «       z  S r*   r¯  rm  s     r(   r³   zExcitingMixing.rmatvecE  r°  r'   c                 óF   — t        j                  d| j                  z  «      S )Nr£  )r+   r•  r¨  rÂ   s    r(   r¶   zExcitingMixing.todenseH  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._updateK  s\   € Ø�—‘‰}˜qÑ ˆØ�	‰	�$‹˜4Ÿ:™:Ñ%‹ØŸ:™:ˆ�	‰	�4�%ÑÜ
�‰�—	‘	˜1˜dŸm™m°·±Ö;r'   )Nr\   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.
    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                 óN  — || _         || _        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rFt-        |	dd  |d¬«      }|r
d|d   › d�}nd}t/        j0                  d|	› d|› d�|z   dt2        ¬«       Œr|
| j                  |	dd  <   Œ… y c c}w )N)ÚbicgstabÚgmresÚlgmresÚcgsÚminresÚtfqmr)rx   rx  rc  r   rx   Úatolr   Úouter_kÚouter_vÚprepend_outer_vTÚstore_outer_AvF)r§   ÚargsÚkwargsÚinner_zUnknown parameter é   )r†   z Did you mean 'z'?Ú zOption 'z#' is invalid for the inner method: zO. It will be ignored.Please check inner method documentation for valid options.r?  )r@  Úcategory)Úpreconditionerr˜   r  rñ   rò   rü   r¹  rº  r»  r¼  r½  r¾  ÚgetÚmethodÚ	method_kwÚ
setdefaultÚgcrotmkr   Ú
parametersrº   Ú
startswithrk   r   rA  rB  ÚUserWarning)r§   r˜   rÌ  Úinner_maxiterÚinner_MrÀ  r½   rX  Ú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ó
Ù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ð %ñ%ð  !Ü(õ	ð Ø&+ˆD�N‰N˜3˜q˜r˜7Ò#ñ7 %ùò
s   Ë<N"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Ú  rW   r=   r  r+   rB   rA   rk   )r§   rE   ÚnvÚscrk  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 )Nrp   )r=   r  rÝ  rÊ  r¼   rp   )r§   r/   r«   s      r(   rp   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  rh   )r°   rh   r=   r  rñ   rò   rü   Úaslinearoperatorrã  r˜   r+   r¤   r3   r¥   rÝ  rÊ  r¼   )r§   r/   r«   rW   s       r(   rh   zKrylovJacobian.setup)  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   rp   rh   r&   r'   r(   r   r   V  s3   „ ñcðJ CEØ')óK,òZ:ò
óò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#  r+  Újoinrk   r  r"   rp   ÚglobalsÚexecr%   rL   )r¿   rí  r   rÄ  ÚvarargsÚvarkwÚdefaultsÚ
kwonlyargsÚ
kwdefaultsÚ_rÅ  rX  rE   Úkw_strÚkwkw_strÚwrapperÚnsrW   s                     r(   Ú_nonlin_wrapperrþ  >  s6  € ô   §¡Ó-€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û   NFNNNNNNrY   NFT)rY   g:Œ0âŽyE>r›   )Brý   rq   rA  Ú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   r‹   ro   re   r°   r   rg   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<ô~a6�Xô a6òP)ñX ˜: |Ó4€Ù˜: }Ó5€Ù˜: xÓ0€Ù˜~¨|Ó<€Ù˜m¨[Ó9€Ù Ð!1°>ÓB€Ù °Ó@�r'   