Ë
    âQ(hÄ  ã                   ó   — 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 d dlmZ ddlmZmZ g d	¢Z G d
„ de«      Zd„ Zd„ Zd„ Zd„ Z  e!djE                  «       djE                  «       ¬«      Z#d„ Z$	 	 	 	 d9d„Z% e$e%«       	 	 d:d„Z& G d„ d«      Z' G d„ d«      Z( G d„ d«      Z)d„ Z* G d„ de(«      Z+ G d„ d «      Z,d!jE                  «       e#d"<    G d#„ d$e+«      Z- G d%„ d&e-«      Z. G d'„ d(e+«      Z/ G d)„ d*e+«      Z0 G d+„ d,e+«      Z1 G d-„ d.e+«      Z2 G d/„ d0e(«      Z3d1„ Z4 e4d2e-«      Z5 e4d3e.«      Z6 e4d4e/«      Z7 e4d5e1«      Z8 e4d6e0«      Z9 e4d7e2«      Z: e4d8e3«      Z;y);é    N)ÚasarrayÚdotÚvdot)ÚnormÚsolveÚinvÚqrÚsvdÚLinAlgError)Úget_blas_funcs)Úcopy_if_needed)Úgetfullargspec_no_selfé   )Úscalar_search_wolfe1Úscalar_search_armijo)Ú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__© ó    úT/var/www/skyplay_api_hub/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$   Úmaxnormr,   $   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'   Ú
issubdtyper/   ÚinexactÚfloat64r*   s    r$   Ú_as_inexactr3   (   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Úgetattrr5   )r+   Úx0Úwraps      r$   Ú_array_liker;   0   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_normrB   7   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_docrH   u   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 �]C  }|j                  |||«      }|r �nDt        |||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| |
|«      |fz  «       t(        j*                  j/                  «        �ŒF |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&   )r3   r;   Úflatten)ÚzÚFr9   s    €€r$   Úfuncznonlin_solve.<locals>.func­   s#   ø€ Ü™1œ[¨¨BÓ/Ó0Ó1×9Ñ9Ó;Ð;r#   r   éd   TÚarmijoF)NrU   Ú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%d:  |F(x)| = %g; step %g
z0A solution was found at the specified tolerance.z:The maximum number of iterations allowed has been reached.)r   rY   )ÚnitÚfunÚstatusÚsuccessÚmessage)r,   ÚTerminationConditionr3   rP   r'   Ú	full_liker@   r   Ú
asjacobianÚsetupÚcopyÚsizeÚ
ValueErrorÚrangeÚcheckÚminr   Ú_nonlin_line_searchÚupdater)   ÚsysÚstdoutÚwriteÚflushr   r;   Ú	iteration) rR   r9   ÚjacobianrN   ÚverboseÚmaxiterrJ   rK   rL   rM   Útol_normÚline_searchÚcallbackÚfull_outputÚraise_exceptionÚ	conditionrS   r+   ÚdxÚFxÚFx_normÚgammaÚeta_maxÚeta_tresholdÚetaÚnr\   rW   ÚsÚFx_norm_newÚeta_AÚinfos    ``                              r$   Únonlin_solver…   z   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×ÑÐ:Ø‘8˜B“< ð>$ñ $ô %ä�J‰J×ÑÖðU/ñX Ü¤¨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   rY   c                 ó€   •— | ‰	d   k(  r‰d   S ‰
| ‰z  z   } ‰|«      }t        |«      dz  }|r| ‰	d<   |‰d<   |‰d<   |S )Nr   rY   )rB   )r�   ÚstoreÚxtrA   Úpry   rS   Ú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#   rV   ç{®Gáz„?)ÚxtolÚaminrU   )r—   rX   )T)r   r   r   )rS   r+   rz   ry   Úsearch_typer’   Úsminr”   r�   Úphi1Úphi0r{   rŽ   r“   r‹   rŒ   r�   s   `` ` `      @@@@@r$   ri   ri     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)r_   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'   Úfinfor2   Úepsr@   rL   rM   rJ   rK   r   rN   Úf0_normro   )ÚselfrJ   rK   rL   rM   rN   r   s          r$   Ú__init__zTerminationCondition.__init__J  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   rY   )	ro   r   r    rN   ÚintrJ   rK   rL   rM   )r¡   Úfr+   ry   Úf_normÚx_normÚdx_norms          r$   rg   zTerminationCondition.checkb  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!   r,   r¢   rg   r"   r#   r$   r_   r_   =  s!   „ ñð "¨$°dÀ4Ø óó0<r#   r_   c                   ó0   — e Zd Zd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   rj   ÚmatvecÚrmatvecÚrsolveÚmatmatÚtodenser7   r/   zUnknown keyword argument r°   c                 óB   — |�t        d|› �«      ‚| j                  «       S )Nz`dtype` must be None, was )re   r°   )r¡   r/   rc   s      r$   Ú	__array__z$Jacobian.__init__.<locals>.__array__®  s'   € ØÐ$Ü$Ð'AÀ%ÀÐ%IÓJÐJØ—|‘|“~Ð%r#   ©NN)Úitemsre   Ú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¡   rA   rW   s      r$   r   zJacobian.solve¶  ó   € Ü!Ð!r#   c                  ó   — y r&   r"   ©r¡   r+   rR   s      r$   rj   zJacobian.update¹  ó   € Ør#   c                 óà   — || _         |j                  |j                  f| _        |j                  | _        | j                  j
                  t        j
                  u r| j                  ||«       y y r&   )rS   rd   r7   r/   Ú	__class__rb   rª   rj   ©r¡   r+   rR   rS   s       r$   rb   zJacobian.setup¼  sQ   € ØˆŒ	Ø—f‘f˜aŸf™fÐ%ˆŒ
Ø—W‘WˆŒ
Ø�>‰>×Ñ¤8§>¡>Ñ1à�K‰K˜˜1Õð 2r#   N©r   )	r   r   r    r!   r¢   r½   r   rj   rb   r"   r#   r$   rª   rª   }  s!   „ ñ#òJ&ò %ó"òór#   rª   c                   ó6   — e Zd Zd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 )Nrb   r®   )rp   r   r¬   rj   r¶   rb   r®   r­   )r¡   rp   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&   )rp   r7   r¼   s    r$   r7   zInverseJacobian.shapeã  ó   € à�}‰}×"Ñ"Ð"r#   c                 ó.   — | j                   j                  S r&   )rp   r/   r¼   s    r$   r/   zInverseJacobian.dtypeç  rÍ   r#   N)r   r   r    r!   r¢   Úpropertyr7   r/   r"   r#   r$   r   r   Å  s4   „ ñò(+ð ñ#ó ð#ð ñ#ó ñ#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.
    rY   zarray must have rank <= 2r   r   zarray must be squarec                 ó   •— t        ‰| «      S r&   )r   ©rA   Ú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   ©rA   rW   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®   r/   r7   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"   ©rA   rW   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#   r7   r/   r   r¬   r­   r®   rj   rb   )r¬   r­   r   r®   rj   rb   r/   r7   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$   rj   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Úissparsere   ©r¡   rA   rW   Ú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ë   re   ©r¡   rA   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ë   re   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ë   re   rï   s      €r$   r­   zasjacobian.<locals>.Jac.rmatvec3  sg   ø€ Ù�d—f‘f“I�Ü˜a¤§¡Ô,Ü˜qŸv™v›xŸz™z¨1Ó-Ð-Ü—\‘\×*Ñ*¨1Ô-ØŸ6™6›8Ÿ:™:¨™>Ð)ä$Ð%:Ó;Ð;r#   NrÉ   )r   r   r    rj   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è   Úndimre   Ú
atleast_2dr   r7   r/   rë   r¶   r8   r   ÚcallableÚstrÚdictr   ÚBroydenSecondÚAndersonÚDiagBroydenÚLinearMixingÚExcitingMixingr   Ú	TypeError)rÓ   rò   rà   s   ` @r$   ra   ra   ì  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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   rX   )rª   rb   Úlast_fÚlast_xr¶   r  r   r)   )r¡   r9   Úf0rS   Únormf0s        r$   rb   zGenericBroyden.setupM  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¥   ry   Údfr¨   Údf_norms          r$   Ú_updatezGenericBroyden._update[  rÂ   r#   c           
      ó¬   — || j                   z
  }|| j                  z
  }| j                  ||||t        |«      t        |«      «       || _         || _        y r&   )r  r	  r  r   )r¡   r+   r¥   r  ry   s        r$   rj   zGenericBroyden.update^  sH   € Ø�—‘‰_ˆØ�—‘‰_ˆØ�‰�Q˜˜2˜r¤4¨£8¬T°"«XÔ6ØˆŒØˆ�r#   N)r   r   r    rb   r  rj   r"   r#   r$   r  r  L  s   „ ò!ò"ór#   r  c                   óz   — e Zd Zd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€   r/   Ú	collapsed)r¡   r  r€   r/   s       r$   r¢   zLowRankMatrix.__init__q  s,   € ØˆŒ
ØˆŒØˆŒØˆŒØˆŒ
Øˆ�r#   c                 ó¦   — t        g d¢|d d | gz   «      \  }}}|| z  }t        ||«      D ]#  \  }}	 ||	| «      }
 ||||j                  |
«      }Œ% |S )N)ÚaxpyÚscalÚdotcr   )r   Úziprd   )rA   r  r  r‘   r  r  r  ÚwÚcÚdÚas              r$   Ú_matveczLowRankMatrix._matvecy  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   r.   )
Úlenr   r'   Úidentityr/   Ú	enumerateÚzerosr   r  rd   )rA   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¡   rA   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‘   r#  rd   Úcollapse)r¡   r  r  s      r$   r4  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 r.   )ÚwarningsÚwarnr  r  r'   r$  r€   r/   r  r  r‘   rÖ   )r¡   r/   rc   Ú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.)rc   N)r'   r?   r   r  r  r‘   r  r¼   s    r$   r5  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   r>  r?  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

        NrY   r   r   Úeconomic)ÚmodeF)Úfull_matrices)r  r  rh   r#  r)   r'   r?   r×   r‘   r	   r   rÖ   r
   r   rf   rc   )r¡   Úmax_rankÚ	to_retainrŠ   r+  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¢   Ústaticmethodr   r-  r¬   r­   r   r®   r4  r²   r5  rA  rC  rQ  r"   r#   r$   r  r  f  sj   „ ñòð ñó ðð ñó ðò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&   )r;  rQ  ©Ú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&   )r;  rC  rW  s   €€r$   rÔ   z'BroydenFirst.__init__.<locals>.<lambda>’  s   ø€ Ð#8 4§7¡7×#8Ñ#8¸-Ð#H€ r#   Úrestartc                  ó6   •—  ‰j                   j                  ‰ Ž S r&   )r;  rA  rW  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  r;  r'   r@   rH  rç   rû   Ú_reducere   )r¡   r  Úreduction_methodrH  rX  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  rb   r  r  r7   r/   r;  rÈ   s       r$   rb   zBroydenFirst.setup˜  s8   € Ü×Ñ˜T 1 a¨Ô.Ü §¡ ¨T¯Z©Z¸©]¸D¿J¹JÓGˆ�r#   c                 ó,   — t        | j                  «      S r&   )r   r;  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&   )	r;  r¬   r'   r=   r>   rb   r	  r  rS   )r¡   r¥   rW   Ú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&   )r;  r   ©r¡   r¥   s     r$   r¬   zBroydenFirst.matvec§  s   € Ø�w‰w�}‰}˜QÓÐr#   c                 ó8   — | j                   j                  |«      S r&   )r;  r­   ©r¡   r¥   rW   s      r$   r®   zBroydenFirst.rsolveª  s   € Ø�w‰w�‰˜qÓ!Ð!r#   c                 ó8   — | j                   j                  |«      S r&   )r;  r®   re  s     r$   r­   zBroydenFirst.rmatvec­  s   € Ø�w‰w�~‰~˜aÓ Ð r#   c                 óì   — | j                  «        | j                  j                  |«      }|| j                  j                  |«      z
  }|t	        ||«      z  }	| j                  j                  ||	«       y r&   )r^  r;  r­   r¬   r   r4  ©
r¡   r+   r¥   ry   r  r¨   r  rA   r  r  s
             r$   r  zBroydenFirst._update°  sU   € Ø�‰Œà�G‰G�O‰O˜BÓˆØ�—‘—‘ Ó#Ñ#ˆØ”�R˜“‰Oˆà�‰�‰�q˜!Õr#   )Nr[  NrÉ   )r   r   r    r!   r¢   rb   r°   r   r¬   r®   r­   r  r"   r#   r$   r   r   J  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 ©NrY   )r^  r;  r¬   r4  rj  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  ÚMry   r  r|   Úw0)r¡   r  rq  rp  s       r$   r¢   zAnderson.__init__A  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   r.   )r  r#  ry   r'   Úemptyr/   rf   r   r  r   r  r   )	r¡   r¥   rW   ry   r€   Údf_frP  r|   rí   s	            r$   r   zAnderson.solveJ  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   r.   rY   )r  r#  ry   r'   rt  r/   rf   r   r  rq  r   )r¡   r¥   ry   r€   ru  rP  Úbr)  r*  r|   rí   s              r$   r¬   zAnderson.matveca  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   r.   rY   r   )rp  ry   r4  r  r#  Úpopr'   r&  r/   rf   rq  r   Útriur×   rÖ   r  )r¡   r+   r¥   ry   r  r¨   r  r€   r  r)  r*  Úwds               r$   r  zAnderson._updatex  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   r.   )r  rb   r'   Úfullr7   r  r/   r  rÈ   s       r$   rb   zDiagBroyden.setupÃ  sA   € Ü×Ñ˜T 1 a¨Ô.Ü—‘˜$Ÿ*™* Q™-Ð)¨1¨t¯z©z©>ÀÇÁÔLˆ�r#   c                 ó"   — | | j                   z  S r&   ©r  rg  s      r$   r   zDiagBroyden.solveÇ  ó   € Øˆr�D—F‘F‰{Ðr#   c                 ó"   — | | j                   z  S r&   r…  re  s     r$   r¬   zDiagBroyden.matvecÊ  r†  r#   c                 ó>   — | | j                   j                  «       z  S r&   ©r  rÖ   rg  s      r$   r®   zDiagBroyden.rsolveÍ  ó   € Øˆr�D—F‘F—K‘K“MÑ!Ð!r#   c                 ó>   — | | j                   j                  «       z  S r&   r‰  re  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 rm  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¢   rb   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  rg  s      r$   r   zLinearMixing.solveõ  ó   € Øˆr�$—*‘*‰}Ðr#   c                 ó"   — | | j                   z  S r&   r“  re  s     r$   r¬   zLinearMixing.matvecø  r”  r#   c                 óH   — | t        j                  | j                  «      z  S r&   ©r'   rÖ   r  rg  s      r$   r®   zLinearMixing.rsolveû  ó   € Øˆr”"—'‘'˜$Ÿ*™*Ó%Ñ%Ð%r#   c                 óH   — | t        j                  | j                  «      z  S r&   r—  re  s     r$   r­   zLinearMixing.rmatvecþ  r˜  r#   c                 óˆ   — t        j                  t        j                  | j                  d   d| j                  z  «      «      S )Nr   éÿÿÿÿ)r'   r�  rƒ  r7   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__#  s%   € Ü×Ñ Ô%ØˆŒ
Ø ˆŒØˆ�	r#   c                 ó²   — t         j                  | |||«       t        j                  | j                  d   f| j
                  | j                  ¬«      | _        y rs  )r  rb   r'   rƒ  r7   r  r/   r   rÈ   s       r$   rb   zExcitingMixing.setup)  s=   € Ü×Ñ˜T 1 a¨Ô.Ü—G‘G˜TŸZ™Z¨™]Ð,¨d¯j©jÀÇ
Á
ÔKˆ�	r#   c                 ó"   — | | j                   z  S r&   ©r   rg  s      r$   r   zExcitingMixing.solve-  ó   € Øˆr�$—)‘)‰|Ðr#   c                 ó"   — | | j                   z  S r&   r£  re  s     r$   r¬   zExcitingMixing.matvec0  r¤  r#   c                 ó>   — | | j                   j                  «       z  S r&   ©r   rÖ   rg  s      r$   r®   zExcitingMixing.rsolve3  ó   € Øˆr�$—)‘)—.‘.Ó"Ñ"Ð"r#   c                 ó>   — | | j                   j                  «       z  S r&   r§  re  s     r$   r­   zExcitingMixing.rmatvec6  r¨  r#   c                 óF   — t        j                  d| j                  z  «      S )Nr›  )r'   r�  r   r¼   s    r$   r°   zExcitingMixing.todense9  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¥   ry   r  r¨   r  Úincrs           r$   r  zExcitingMixing._update<  s\   € Ø�—‘‰}˜qÑ ˆØ�	‰	�$‹˜4Ÿ:™:Ñ%‹ØŸ:™:ˆ�	‰	�4�%ÑÜ
�‰�—	‘	˜1˜dŸm™m°·±Ö;r#   )NrX   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                 óJ  — || _         || _        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«       |j#                  «       D ]6  \  }}|j%                  d«      st'        d|› �«      ‚|| j                  |dd  <   Œ8 y )N)ÚbicgstabÚgmresÚlgmresÚcgsÚminresÚtfqmr)rr   rp  r[  r   rr   Úatolr   Úouter_kÚouter_vÚprepend_outer_vTÚstore_outer_AvFÚinner_zUnknown parameter é   )Úpreconditionerr’   rü   ré   rê   rô   r±  r²  r³  r´  rµ  r¶  ÚgetÚmethodÚ	method_kwÚ
setdefaultÚgcrotmkr´   Ú
startswithre   )	r¡   r’   rÀ  Úinner_maxiterÚinner_Mr¸  r·   Úkeyrº   s	            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àŸ(™(›*ò 	,‰JˆC�Ø—>‘> (Ô+Ü Ð#5°c°UÐ!;Ó<Ð<Ø&+ˆD�N‰N˜3˜q˜r˜7Ò#ñ	,r#   c                 óæ   — t        | j                  «      j                  «       }t        | j                  «      j                  «       }| j                  t        d|«      z  t        d|«      z  | _        y )Nr   )r�   r9   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É  rS   r9   r
  r'   r>   r=   re   )r¡   rA   ÚnvÚscrc  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¡   ÚrhsrW   Ú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 )Nrj   )r9   r
  rÌ  r¾  r¶   rj   )r¡   r+   r¥   s      r$   rj   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  rb   )rª   rb   r9   r
  ré   rê   rô   ÚaslinearoperatorrÒ  r’   r'   rž   r/   rŸ   rÌ  r¾  r¶   )r¡   r+   r¥   rS   s       r$   rb   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   rj   rb   r"   r#   r$   r   r   G  s2   „ ñcðJ CEØ')ó-,ò^:ò
óò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#  Újoinre   rü   r   rj   ÚglobalsÚexecr!   rH   )r¹   rÜ  Ú	signatureÚargsÚvarargsÚvarkwÚdefaultsÚ
kwonlyargsÚ
kwdefaultsÚ_ÚkwargsrP  rA   Úkw_strÚkwkw_strÚwrapperÚnsrS   s                     r$   Ú_nonlin_wrapperrð    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ó   NFNNNNNNrU   NFT)rU   g:Œ0âŽyE>r•   )<rõ   rk   r9  Únumpyr'   r   r   r   Úscipy.linalgr   r   r   r	   r
   r   Úscipy.sparse.linalgré   Úscipy.sparser   Úscipy._lib._utilr   r   rÞ  Ú_linesearchr   r   Ú__all__Ú	Exceptionr   r,   r3   r;   rB   rü   ÚstriprF   rH   r…   ri   r_   rª   r   ra   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óP"ñf 	ˆÔ ð FJØ!ó*÷Z9<ñ 9<÷@Eñ E÷P$#ñ $#òNY?ô@�Xô ÷4Iñ IðX ÷* 	‰‹ð+ ÐÑ ô0m�>ô mô`9�Lô 9ô@Uˆ~ô UôxA1�.ô A1ôH+�>ô +ô\8<�^ô 8<ô~C6�Xô C6òT)ñX ˜: |Ó4€Ù˜: }Ó5€Ù˜: xÓ0€Ù˜~¨|Ó<€Ù˜m¨[Ó9€Ù Ð!1°>ÓB€Ù °Ó@�r#   