403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/lib/python3/dist-packages/scipy/optimize/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/scipy/optimize/__pycache__/_nonlin.cpython-311.pyc
�

d�c�����ddlZddlZddlmZmZmZmZmZm	Z	ddlm
Z
mZmZddl
ZddlZddlmZddlZddlmZddlmZmZgd�ZGd	�d
e��Zd�Zd�Zd
�Zd�Zed� ��d� �����Z!d�Z"				d>d�Z#e"e#��		d?d�Z$Gd�d��Z%Gd�d��Z&Gd�d ��Z'd!�Z(Gd"�d#e&��Z)Gd$�d%��Z*d&� ��e!d'<Gd(�d)e)��Z+Gd*�d+e+��Z,Gd,�d-e)��Z-Gd.�d/e)��Z.Gd0�d1e)��Z/Gd2�d3e)��Z0Gd4�d5e&��Z1d6�Z2e2d7e+��Z3e2d8e,��Z4e2d9e-��Z5e2d:e/��Z6e2d;e.��Z7e2d<e0��Z8e2d=e1��Z9dS)@�N)�norm�solve�inv�qr�svd�LinAlgError)�asarray�dot�vdot)�get_blas_funcs)�getfullargspec_no_self�)�scalar_search_wolfe1�scalar_search_armijo)
�broyden1�broyden2�anderson�linearmixing�diagbroyden�excitingmixing�
newton_krylov�BroydenFirst�KrylovJacobian�InverseJacobianc��eZdZdS)�
NoConvergenceN)�__name__�
__module__�__qualname__���8/usr/lib/python3/dist-packages/scipy/optimize/_nonlin.pyrrs�������Dr!rc�N�tj|�����S�N)�np�absolute�max��xs r"�maxnormr*s��
�;�q�>�>�����r!c��t|��}tj|jtj��st|tj���S|S)z:Return `x` as an array, of either floats or complex floats��dtype)r	r%�
issubdtyper-�inexact�float_r(s r"�_as_inexactr1"s?����
�
�A�
�=���"�*�-�-�+��q��	�*�*�*�*��Hr!c��tj|tj|����}t|d|j��}||��S)z;Return ndarray `x` as same array subclass and shape as `x0`�__array_wrap__)r%�reshape�shape�getattrr3)r)�x0�wraps   r"�_array_liker9*s=��
�
�1�b�h�r�l�l�#�#�A��2�'��)9�:�:�D��4��7�7�Nr!c��tj|�����stjtj��St|��Sr$)r%�isfinite�all�array�infr)�vs r"�
_safe_normr@1s;��
�;�q�>�>����� ��x��������7�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�@�|jr|jtz|_dSdSr$)�__doc__�
_doc_parts)�objs r"�_set_docrGos(��
�{�/��k�J�.�����/�/r!�krylovF�armijoTc
�����|
�tn|
}
t||||	||
���}t������fd�}����}t	j|tj��}||��}t|��}t|��}|�	|�
��||��|�|�|dz}n
d|jdzz}|durd}n|durd}|d	vrtd
���d}d}d
}d}t|��D�]}}|�|||��}|r�n�t|||z��}|�||���}t|��dkrtd���|rt#|||||��\}}}}n!d}||z}||��}t|��}|�|�
��|��|r|||��||dzz|dzz}||dzz|krt||��}n$t|t'|||dzz����}|}|rLt(j�d||
|��|fz��t(j�����|rt1t3|������d}|
r,|j|||dkddd�|d�}t3|���|fSt3|���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�iterrc�t��t�t|����������Sr$)r1r9�flatten)�z�Fr7s ��r"�<lambda>znonlin_solve.<locals>.<lambda>�s/���[���;�q�"�#5�#5�!6�!6�7�7�?�?�A�A�r!r�dTrIF)NrI�wolfezInvalid line searchg�������?g��H.��?g�������?g����MbP?)�tolrz[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.)rrY)�nit�fun�status�success�message)r*�TerminationConditionr1rQr%�	full_liker>r�
asjacobian�setup�copy�size�
ValueError�range�check�minr�_nonlin_line_search�updater'�sys�stdout�write�flushrr9�	iteration) rSr7�jacobianrO�verbose�maxiterrKrLrMrN�tol_norm�line_search�callback�full_output�raise_exception�	condition�funcr)�dx�Fx�Fx_norm�gamma�eta_max�eta_treshold�eta�nr\rW�s�Fx_norm_new�eta_A�infos ``                              r"�nonlin_solver�ts�����Z#�*�w�w��H�$�5��+0��*.�X�?�?�?�I�
�R���B�A�A�A�A�A�D�
�
�
���A�	��a���	 �	 �B�	
��a���B��2�h�h�G��(�#�#�H��N�N�1�6�6�8�8�R��&�&�&������Q�h�G�G��1�6�!�8�n�G��d������	��	�	����3�3�3��.�/�/�/�
�E��G��L�
�C�
�7�^�^�/�/������Q��+�+���	��E��#�s�7�{�#�#���n�n�R�S�n�)�)�
)����8�8�q�=�=��.�/�/�
/�
�	#�$7��a��R�8C�%E�%E�!�A�q�"�k�k��A��B��A���a���B��r�(�(�K���������"�%�%�%��	��H�Q��O�O�O���Q��&��!��3���3��6�>�L�(�(��g�u�%�%�C�C��g�s�5�%��Q��,�7�7�8�8�C����	��J���:��8�8�B�<�<��>$�$�
%�
%�
%��J��������	���A�r� 2� 2�3�3�3��F��
"� �*�� �!�Q�;� ,� 3���%�	&�		�	���1�b�!�!�4�'�'��1�b�!�!�!r!�:�0�yE>�{�G�z�?c��������
����dg�|g�t|��dzg�t���t���z�
d������fd�	����
fd�}|dkrt�|�dd|���\}}	}
n)|d	kr#t��d�d|�
��\}}	|�d}�|�zz�|�dkr	�d}n����}t|��}|�||fS)
NrrYTc���|�	dkr�dS�
|�zz}�|��}t|��dz}|r|�	d<|�d<|�d<|S)NrrY)r@)r��store�xtr?�przry�tmp_Fx�tmp_phi�tmp_sr)s     ������r"�phiz _nonlin_line_search.<locals>.phisl�����a��=�=��1�:��
��2��X���D��H�H���q�M�M�1����	��E�!�H��G�A�J��F�1�I��r!c�r��t|���zdz�z}�||zd����|��z
|zS)NrF)r�)�abs)r��dsr��rdiff�s_norms  ���r"�derphiz#_nonlin_line_search.<locals>.derphisG����!�f�f�v�o��!�U�
*����A�b�D��&�&�&���Q���/�2�5�5r!rVr�)�xtol�aminrI)r�rX)T)rrr)ryr)r{rz�search_typer��sminr�r��phi1�phi0r|r�r�r�r�r�s`` ` `      @@@@@r"riri	se�����������
�C�E��T�F��B�x�x��{�m�G�
�!�W�W�t�B�x�x�
�F�
�
�
�
�
�
�
�
�
�
�
�6�6�6�6�6�6�6��g���,�S�&�'�!�*�26�T�C�C�C�
��4���	��	 �	 �&�s�G�A�J�����,0�2�2�2���4�	�y�
��	�A�b�D��A��E�!�H�}�}�
�A�Y���
�T�!�W�W���2�h�h�G��a��W��r!c�,�eZdZdZdddddefd�Zd�ZdS)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��|�&tjtj��jdz}|�tj}|�tj}|�tj}||_||_||_||_||_	||_
d|_d|_dS)NgUUUUUU�?r)
r%�finfor0�epsr>rMrNrKrLrrO�f0_normro)�selfrKrLrMrNrOrs       r"�__init__zTerminationCondition.__init__Cs����=��H�R�Y�'�'�+��5�E��>��V�F��=��F�E��>��V�F���
������
������	���	��������r!c��|xjdz
c_|�|��}|�|��}|�|��}|j�||_|dkrdS|j�d|j|jkzSt	||jko+||jz|jko||jko
||jz|k��S)NrrrY)	rorr�rO�intrKrLrMrN)r��fr)rz�f_norm�x_norm�dx_norms       r"rgzTerminationCondition.check[s������!�������1�������1�����)�)�B�-�-���<��!�D�L��Q�;�;��1��9� ������2�3�3��F�d�j�(�;��t�{�*�d�l�:�;��4�:�-�:�#�D�K�/�6�9�<�<�	<r!)rrrrDr*r�rgr r!r"r_r_6sQ��������"�$�d�4�������0<�<�<�<�<r!r_c�2�eZdZdZd�Zd�Zd	d�Zd�Zd�ZdS)
�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����gd�}|���D]4\}}||vrtd|z���|�t�|||���5t�d��r�fd��_dSdS)N)	rrj�matvec�rmatvec�rsolve�matmat�todenser5r-zUnknown keyword argument %sr�c�,������Sr$)r��r�s�r"rTz#Jacobian.__init__.<locals>.<lambda>�s���T�\�\�^�^�r!)�itemsre�setattr�hasattr�	__array__)r��kw�names�name�values`    r"r�zJacobian.__init__�s����8�8�8���8�8�:�:�	.�	.�K�D�%��5� � � �!>��!E�F�F�F�� ���d�B�t�H�-�-�-���4��#�#�	4�3�3�3�3�D�N�N�N�	4�	4r!c� �t|��Sr$)rr�s r"�aspreconditionerzJacobian.aspreconditioner�s���t�$�$�$r!rc��t�r$��NotImplementedError�r�r?rWs   r"rzJacobian.solve����!�!r!c��dSr$r �r�r)rSs   r"rjzJacobian.update�����r!c��||_|j|jf|_|j|_|jjtjur|�||��dSdSr$)ryrdr5r-�	__class__rbr�rj�r�r)rSrys    r"rbzJacobian.setup�sV����	��f�a�f�%��
��W��
��>��8�>�1�1��K�K��1������2�1r!N�r)	rrrrDr�r�rrjrbr r!r"r�r�vso������#�#�J
4�
4�
4�%�%�%�"�"�"�"�
�
�
�����r!r�c�@�eZdZd�Zed���Zed���ZdS)rc��||_|j|_|j|_t	|d��r|j|_t	|d��r|j|_dSdS)Nrbr�)rprr�rjr�rbr�r�)r�rps  r"r�zInverseJacobian.__init__�s_�� ��
��n����o����8�W�%�%�	(�!��D�J��8�X�&�&�	+�#�?�D�L�L�L�	+�	+r!c��|jjSr$)rpr5r�s r"r5zInverseJacobian.shape��
���}�"�"r!c��|jjSr$)rpr-r�s r"r-zInverseJacobian.dtype�r�r!N)rrrr��propertyr5r-r r!r"rr�sY������+�+�+��#�#��X�#��#�#��X�#�#�#r!rc����tjjj�t	�t
��r�St
j���rt�t
��r
���St	�tj
��r��jdkrtd���tj
tj�������jd�jdkrtd���t�fd��fd��fd��fd	��j�j�
��Stj����rX�jd�jdkrtd���t�fd��fd
���fd���fd��j�j�
��St%�d��r�t%�d��r|t%�d��rltt'�d��t'�d���jt'�d��t'�d��t'�d���j�j���St+���r G��fd�dt
��}|��St	�t,��rGt/t0t2t4t6t8t:t<������St?d���)zE
    Convert given object to one suitable for use as a Jacobian.
    rYzarray must have rank <= 2rrzarray must be squarec�$��t�|��Sr$)r
�r?�Js �r"rTzasjacobian.<locals>.<lambda>�s����Q����r!c�R��t����j|��Sr$)r
�conj�Tr�s �r"rTzasjacobian.<locals>.<lambda>�s���#�a�f�f�h�h�j�!�*<�*<�r!c�$��t�|��Sr$)rr�s �r"rTzasjacobian.<locals>.<lambda>�s����a����r!c�R��t����j|��Sr$)rr�r�r�s �r"rTzasjacobian.<locals>.<lambda>�s����q�v�v�x�x�z�1�)=�)=�r!)r�r�rr�r-r5zmatrix must be squarec����|zSr$r r�s �r"rTzasjacobian.<locals>.<lambda>�s����1��r!c�<������j|zSr$�r�r�r�s �r"rTzasjacobian.<locals>.<lambda>�s���!�&�&�(�(�*�q�.�r!c�����|��Sr$r �r?r��spsolves ��r"rTzasjacobian.<locals>.<lambda>�s������1�
�
�r!c�J�������j|��Sr$r�r�s ��r"rTzasjacobian.<locals>.<lambda>�s�����������Q�)?�)?�r!r5r-rr�r�r�rjrb)r�r�rr�rjrbr-r5c�F��eZdZd�Zd��fd�	Z�fd�Zd��fd�	Z�fd�ZdS)	�asjacobian.<locals>.Jacc��||_dSr$r(r�s   r"rjzasjacobian.<locals>.Jac.update�s
������r!rc�����|j��}t|tj��rt	||��St
j�|��r�||��Std����NzUnknown matrix type)	r)�
isinstancer%�ndarrayr�scipy�sparse�
isspmatrixre�r�r?rW�mr�r�s    ��r"rzasjacobian.<locals>.Jac.solve�sk����A�d�f�I�I���a���,�,�<� ��A�;�;�&��\�,�,�Q�/�/�<�"�7�1�a�=�=�(�$�%:�;�;�;r!c�����|j��}t|tj��rt	||��St
j�|��r||zStd���r�)	r)r�r%r�r
r�r�r�re�r�r?r�r�s   �r"r�zasjacobian.<locals>.Jac.matvecsd����A�d�f�I�I���a���,�,�<��q�!�9�9�$��\�,�,�Q�/�/�<��Q�3�J�$�%:�;�;�;r!c�H���|j��}t|tj��r't	|���j|��Stj�	|��r#�|���j|��Std���r�)r)r�r%r�rr�r�r�r�r�rer�s    ��r"r�zasjacobian.<locals>.Jac.rsolves�����A�d�f�I�I���a���,�,�<� �������Q�/�/�/��\�,�,�Q�/�/�<�"�7�1�6�6�8�8�:�q�1�1�1�$�%:�;�;�;r!c�:���|j��}t|tj��r't	|���j|��Stj�	|��r|���j|zStd���r�)r)r�r%r�r
r�r�r�r�r�rer�s   �r"r�zasjacobian.<locals>.Jac.rmatvecs{����A�d�f�I�I���a���,�,�<��q�v�v�x�x�z�1�-�-�-��\�,�,�Q�/�/�<��6�6�8�8�:��>�)�$�%:�;�;�;r!Nr�)rrrrjrr�r�r�)r�r�s��r"�Jacr��s��������
�
�
�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<r!r�)rrrrrrrHz#Cannot convert object to a Jacobian) r�r��linalgr�r�r��inspect�isclass�
issubclassr%r��ndimre�
atleast_2dr	r5r-r�r�r6r�callable�str�dictr�
BroydenSecond�Anderson�DiagBroyden�LinearMixing�ExcitingMixingr�	TypeError)r�r�r�s` @r"rara�s�����l�!�)�G��!�X���T?���	���	�	�R?�
�1�h� 7� 7�R?��q�s�s�
�	�A�r�z�	"�	"�P?��6�A�:�:��8�9�9�9��M�"�*�Q�-�-�(�(���7�1�:�����#�#��3�4�4�4��2�2�2�2� <� <� <� <�3�3�3�3�=�=�=�=��g�Q�W�	6�6�6�	6�

��	 �	 ��	#�	#�D?��7�1�:�����#�#��4�5�5�5��}�}�}�}� 8� 8� 8� 8�5�5�5�5�5�?�?�?�?�?��g�Q�W�	6�6�6�	6�

��G�	�	�<?���G�!4�!4�<?���G�9L�9L�<?��w�q�(�3�3� '��9� 5� 5��g�&�q�(�3�3�&�q�(�3�3�%�a��1�1��g��g�'�'�'�	'�
�!���3?�&	<�&	<�&	<�&	<�&	<�&	<�&	<�&	<�(�&	<�&	<�&	<�N�s�u�u��	�A�s�	�	�	?�.�t�\�*�%� +�!-�#1�)�
+�+�+�,-�
.�0�0�	0��=�>�>�>r!c� �eZdZd�Zd�Zd�ZdS)�GenericBroydenc��t�||||��||_||_t	|d��rK|j�Ft
|��}|r*dtt
|��d��z|z|_dSd|_dSdSdS)N�alpha��?rrX)r�rb�last_f�last_xr�rrr')r�r7�f0ry�normf0s     r"rbzGenericBroyden.setup.s������t�R��T�*�*�*��������4��!�!�	!�d�j�&8��"�X�X�F��
!� ��T�"�X�X�q�!1�!1�1�F�:��
�
�
� ��
�
�
�	!�	!�&8�&8r!c��t�r$r��r�r)r�rz�dfr��df_norms       r"�_updatezGenericBroyden._update<r�r!c
��||jz
}||jz
}|�||||t|��t|����||_||_dSr$)rrrr)r�r)r�rrzs     r"rjzGenericBroyden.update?sR��
���_��
���_�����Q��2�r�4��8�8�T�"�X�X�6�6�6��������r!N)rrrrbrrjr r!r"rr-sA������!�!�!�"�"�"�����r!rc��eZdZdZd�Zed���Zed���Zd�Zd�Z	dd�Z
dd	�Zd
�Zd�Z
d�Zd
�Zd�Zdd�ZdS)�
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�Z�||_g|_g|_||_||_d|_dSr$)r�csr�r�r-�	collapsed)r�rr�r-s    r"r�zLowRankMatrix.__init__Rs0����
������������
�����r!c��tgd�|dd�|gz��\}}}||z}t||��D]$\}}	||	|��}
||||j|
��}�%|S)N)�axpy�scal�dotcr)r�ziprd)r?rrr�rrr�w�c�d�as           r"�_matveczLowRankMatrix._matvecZs���)�*B�*B�*B�*,�R�a�R�&�A�3�,�8�8���d�D��A�I����B�K�K�	&�	&�D�A�q���Q��
�
�A���Q��1�6�1�%�%�A�A��r!c	��t|��dkr||zStddg|dd�|gz��\}}|d}|tjt|��|j���z}t|��D]6\}}	t|��D]!\}
}|||
fxx||	|��z
cc<�"�7tjt|��|j���}t|��D]\}
}	||	|��||
<�||z}t||��}||z}
t||��D]\}}|||
|
j	|��}
�|
S)�Evaluate w = M^-1 vrrrNrr,)
�lenrr%�identityr-�	enumerate�zerosrrrd)r?rrr�rr�c0�A�ir�jr�qr�qcs               r"�_solvezLowRankMatrix._solvedsq���r�7�7�a�<�<��U�7�N�$�V�V�$4�b��!��f��s�l�C�C�
��d�
��U���B�K��B���r�x�8�8�8�8���b�M�M�	%�	%�D�A�q�!�"�
�
�
%�
%���1��!�A�#����$�$�q�!�*�*�$�����
%�
�H�S��W�W�B�H�-�-�-���b�M�M�	�	�D�A�q��4��1�:�:�A�a�D�D�	�U�
���!�Q�K�K��
�e�G����Q�Z�Z�	(�	(�E�A�r���Q��1�6�B�3�'�'�A�A��r!c��|j�tj|j|��St�||j|j|j��S)zEvaluate w = M v)rr%r
rrrrr��r�r?s  r"r�zLowRankMatrix.matvec�s>���>�%��6�$�.�!�,�,�,��$�$�Q��
�D�G�T�W�E�E�Er!c���|j�1tj|jj���|��St
�|tj|j��|j|j	��S)zEvaluate w = M^H v)
rr%r
r�r�rrrr�rr-s  r"r�zLowRankMatrix.rmatvec�sW���>�%��6�$�.�*�/�/�1�1�1�5�5�5��$�$�Q����
�(;�(;�T�W�d�g�N�N�Nr!rc��|j�t|j|��St�||j|j|j��S)r )rrrr+rrr�r�s   r"rzLowRankMatrix.solve�s<���>�%�����+�+�+��#�#�A�t�z�4�7�D�G�D�D�Dr!c���|j�,t|jj���|��St�|t
j|j��|j|j	��S)zEvaluate w = M^-H v)
rrr�r�rr+r%rr�rr�s   r"r�zLowRankMatrix.rsolve�sU���>�%����)�.�.�0�0�!�4�4�4��#�#�A�r�w�t�z�':�':�D�G�T�W�M�M�Mr!c�X�|j�;|xj|dd�df|ddd�f���zz
c_dS|j�|��|j�|��t|j��|jkr|���dSdSr$)rr�r�appendr�r!rd�collapse)r�rrs   r"r2zLowRankMatrix.append�s����>�%��N�N�a����$��i�!�D����F�)�.�.�*:�*:�:�:�N�N��F�����q��������q�����t�w�<�<�!�&� � ��M�M�O�O�O�O�O�!� r!c��|j�|jS|jtj|j|j���z}t
|j|j��D]3\}}||dd�df|ddd�f�	��zz
}�4|S)Nr,)
rrr%r"r�r-rrr�r�)r��Gmrrs    r"r�zLowRankMatrix.__array__�s����>�%��>�!�
�Z���D�F�$�*�=�=�=�
=�������)�)�	-�	-�D�A�q��!�A�A�A�d�F�)�A�d�1�1�1�f�I�N�N�,�,�,�,�B�B��	r!c�b�tj|��|_d|_d|_d|_dS)z0Collapse the low-rank matrix to a full-rank one.N)r%r=rrr�rr�s r"r3zLowRankMatrix.collapse�s*����$�������������
�
�
r!c��|j�dS|dksJ�t|j��|kr|jdd�=|jdd�=dSdS)zH
        Reduce the rank of the matrix by dropping all vectors.
        Nr�rr!rr��r��ranks  r"�restart_reducezLowRankMatrix.restart_reduce�sW���>�%��F��a�x�x�x�x��t�w�<�<�$��������
������
�
�
��r!c��|j�dS|dksJ�t|j��|kr*|jd=|jd=t|j��|k�(dSdS)zK
        Reduce the rank of the matrix by dropping oldest vectors.
        Nrr8r9s  r"�
simple_reducezLowRankMatrix.simple_reduce�sd���>�%��F��a�x�x�x�x��$�'�l�l�T�!�!����
����
��$�'�l�l�T�!�!�!�!�!�!r!Nc��|j�dS|}|�|}n|dz
}|jr(t|t|jd����}t	dt||dz
����}t|j��}||krdStj|j��j}tj|j��j}t|d���\}}t||j�����}t|d���\}	}
}t|t|����}t||j�����}t|��D]N}|dd�|f���|j|<|dd�|f���|j|<�O|j|d�=|j|d�=dS)	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

        NrYrr�economic)�modeF)�
full_matrices)rrrhr!r'r%r=r�r�rr
r�rrrfrc)
r��max_rank�	to_retainr�r)r��C�D�R�U�S�WH�ks
             r"�
svd_reducezLowRankMatrix.svd_reduce�s���:�>�%��F���� ��A�A��A��A��7�	(��A�s�4�7�1�:���'�'�A���3�q�!�A�#�;�;�������L�L���q�5�5��F��H�T�W������H�T�W������!�*�%�%�%���1���1�3�8�8�:�:�����q��.�.�.���1�b���3�r�7�7�O�O����2�4�9�9�;�;�����q���	'�	'�A��1�1�1�Q�3������D�G�A�J��1�1�1�Q�3������D�G�A�J�J��G�A�B�B�K��G�A�B�B�K�K�Kr!r�r$)rrrrDr��staticmethodrr+r�r�rr�r2r�r3r;r=rKr r!r"rrGs���������������\������\��6F�F�F�O�O�O�E�E�E�E�N�N�N�N�	�	�	�������	�	�	�	�	�	�?�?�?�?�?�?r!ra�
    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�H�eZdZdZd
d�Zd�Zd�Zdd�Zd	�Zdd
�Z	d�Z
d�ZdS)ra�
    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://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.broyden1(fun, [0, 0])
    >>> sol
    array([0.84116396, 0.15883641])

    N�restartc�|���t����|�_d�_|�tj}|�_t|t��rd�n|dd��|d}|dz
f�z�|dkr
��fd��_	dS|dkr
��fd��_	dS|dkr
��fd	��_	dStd
|z���)Nr rrrc�"���jj��Sr$)r5rK��
reduce_paramsr�s��r"rTz'BroydenFirst.__init__.<locals>.<lambda>js���#5�4�7�#5�}�#E�r!�simplec�"���jj��Sr$)r5r=rRs��r"rTz'BroydenFirst.__init__.<locals>.<lambda>ls���#8�4�7�#8�-�#H�r!rOc�"���jj��Sr$)r5r;rRs��r"rTz'BroydenFirst.__init__.<locals>.<lambda>ns���#9�4�7�#9�=�#I�r!z"Unknown rank reduction method '%s')rr�rr5r%r>rBr�r��_reducere)r�r�reduction_methodrBrSs`   @r"r�zBroydenFirst.__init__Ys��������%�%�%���
�������v�H� ��
��&��,�,�	3��M�M�,�Q�R�R�0�M�/��2��!�A���-�7�
��u�$�$�E�E�E�E�E�D�L�L�L�
��
)�
)�H�H�H�H�H�D�L�L�L�
��
*�
*�I�I�I�I�I�D�L�L�L��A�-�.�/�/�
/r!c��t�||||��t|j|jd|j��|_dS)Nr)rrbrrr5r-r5r�s    r"rbzBroydenFirst.setupss?�����T�1�a��.�.�.�����T�Z��]�D�J�G�G����r!c�*�t|j��Sr$)rr5r�s r"r�zBroydenFirst.todensews���4�7�|�|�r!rc��|j�|��}tj|�����s@|�|j|j|j��|j�|��S|Sr$)	r5r�r%r;r<rbrrry)r�r�rW�rs    r"rzBroydenFirst.solvezsf���G�N�N�1�����{�1�~�~�!�!�#�#�	%��J�J�t�{�D�K���;�;�;��7�>�>�!�$�$�$��r!c�6�|j�|��Sr$)r5r�r�r�s  r"r�zBroydenFirst.matvec�s���w�}�}�Q���r!c�6�|j�|��Sr$)r5r��r�r�rWs   r"r�zBroydenFirst.rsolve�s���w���q�!�!�!r!c�6�|j�|��Sr$)r5r�r^s  r"r�zBroydenFirst.rmatvec�s���w�~�~�a� � � r!c��|���|j�|��}||j�|��z
}|t	||��z}	|j�||	��dSr$)rWr5r�r�rr2�
r�r)r�rzrr�r
r?rrs
          r"rzBroydenFirst._update�sg���������G�O�O�B����������#�#�#��
��R����O������q�!�����r!)NrONr�)rrrrDr�rbr�rr�r�r�rr r!r"rr#s�������3�3�j/�/�/�/�4H�H�H�������� � � �"�"�"�"�!�!�!�����r!rc��eZdZdZd�ZdS)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�|��z
}||dzz}	|j�||	��dS�NrY)rWr5r�r2rcs
          r"rzBroydenSecond._update�sU����������������#�#�#��
���
�N������q�!�����r!N)rrrrDrr r!r"r�r��s.������0�0�d����r!r�c�.�eZdZdZd
d�Zdd�Zd�Zd	�ZdS)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])

    Nr��c��t�|��||_||_g|_g|_d|_||_dSr$)rr�r�Mrzrr}�w0)r�rrkrjs    r"r�zAnderson.__init__sD������%�%�%���
������������
�����r!rc���|j|z}t|j��}|dkr|Stj||j���}t
|��D] }t|j||��||<�!	t|j
|��}n&#t$r|jdd�=|jdd�=|cYSwxYwt
|��D]1}||||j||j|j|zzzz
}�2|S�Nrr,)rr!rzr%�emptyr-rfrrrrr)	r�r�rWrzr��df_frJr}r�s	         r"rzAnderson.solve%s���j�[��]�����L�L����6�6��I��x����)�)�)���q���	*�	*�A��4�7�1�:�q�)�)�D��G�G�	��$�&�$�'�'�E�E���	�	�	������
������
��I�I�I�		�����q���	@�	@�A��%��(�D�G�A�J���D�G�A�J�)>�>�?�?�B�B��	s�4B
�
 B-�,B-c
��||jz}t|j��}|dkr|Stj||j���}t
|��D] }t|j||��||<�!tj||f|j���}t
|��D]�}t
|��D]�}t|j||j|��|||f<||krT|j	dkrI|||fxxt|j||j|��|j	dzz|jzzcc<����t||��}	t
|��D]1}
||	|
|j|
|j|
|jzzzz
}�2|S)Nrr,rY)rr!rzr%rnr-rfrrrkr)r�r�rzr�rorJ�br'r(r}r�s           r"r�zAnderson.matvec<s����R��
�]�����L�L����6�6��I��x����)�)�)���q���	*�	*�A��4�7�1�:�q�)�)�D��G�G��H�a��V�1�7�+�+�+���q���	Q�	Q�A��1�X�X�
Q�
Q���d�g�a�j�$�'�!�*�5�5��!�A�#����6�6�d�g��l�l��a��c�F�F�F�d�4�7�1�:�t�w�q�z�:�:�4�7�A�:�E�d�j�P�P�F�F�F��
Q��a������q���	@�	@�A��%��(�D�G�A�J�����D�J�)>�>�?�?�B�B��	r!c��|jdkrdS|j�|��|j�|��t	|j��|jkrQ|j�d��|j�d��t	|j��|jk�Qt	|j��}t
j||f|j���}t|��D]Y}	t|	|��D]F}
|	|
kr|j
dz}nd}d|zt|j|	|j|
��z||	|
f<�G�Z|t
j|d��j
���z
}||_dS)Nrr,rYr)rjrzr2rr!�popr%r$r-rfrkr�triur�r�r)r�r)r�rzrr�r
r�rr'r(�wds            r"rzAnderson._updateSsZ���6�Q�;�;��F�����r��������r�����$�'�l�l�T�V�#�#��G�K�K��N�N�N��G�K�K��N�N�N��$�'�l�l�T�V�#�#�
���L�L���H�a��V�1�7�+�+�+���q���	=�	=�A��1�a�[�[�
=�
=����6�6���!��B�B��B��B�$��T�W�Q�Z����� <� <�<��!�A�#���
=�	
�R�W�Q��]�]�_�
!�
!�
#�
#�#������r!)Nr�rhr�)rrrrDr�rr�rr r!r"r�r��se������+�+�L��������.���.����r!r�c�H�eZdZdZdd�Zd�Zd
d�Zd�Zd
d�Zd	�Z	d
�Z
d�ZdS)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�H�t�|��||_dSr$�rr�r�r�rs  r"r�zDiagBroyden.__init__��!������%�%�%���
�
�
r!c��t�||||��tj|jdfd|jz|j���|_dS)Nrrr,)rrbr%�fullr5rr-rr�s    r"rbzDiagBroyden.setup�sI�����T�1�a��.�.�.���$�*�Q�-�)�1�t�z�>���L�L�L����r!rc��||jzSr$�rr`s   r"rzDiagBroyden.solve�����r�D�F�{�r!c��||jzSr$r~r^s  r"r�zDiagBroyden.matvec�rr!c�<�||j���zSr$�rr�r`s   r"r�zDiagBroyden.rsolve�����r�D�F�K�K�M�M�!�!r!c�<�||j���zSr$r�r^s  r"r�zDiagBroyden.rmatvec�r�r!c�6�tj|j��Sr$)r%�diagrr�s r"r�zDiagBroyden.todense�s���w���w���r!c�N�|xj||j|zz|z|dzzzc_dSrfr~rs       r"rzDiagBroyden._update�s.�����2���r�	�>�2�%�g�q�j�0�0����r!r$r��rrrrDr�rbrr�r�r�r�rr r!r"r�r�qs�������&�&�P����M�M�M��������"�"�"�"�"�"�"� � � �1�1�1�1�1r!r�c�B�eZdZdZdd�Zdd�Zd�Zdd�Zd�Zd	�Z	d
�Z
dS)
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�H�t�|��||_dSr$rxrys  r"r�zLinearMixing.__init__�rzr!rc��||jzSr$�rr`s   r"rzLinearMixing.solve�����r�$�*�}�r!c��||jzSr$r�r^s  r"r�zLinearMixing.matvec�r�r!c�<�|tj|j��zSr$�r%r�rr`s   r"r�zLinearMixing.rsolve�����r�"�'�$�*�%�%�%�%r!c�<�|tj|j��zSr$r�r^s  r"r�zLinearMixing.rmatvec�r�r!c�v�tjtj|jdd|jz����S)Nr���)r%r�r|r5rr�s r"r�zLinearMixing.todense�s*���w�r�w�t�z�!�}�b���m�<�<�=�=�=r!c��dSr$r rs       r"rzLinearMixing._update�r�r!r$r�)rrrrDr�rr�r�r�r�rr r!r"r�r��s���������,�����������&�&�&�&�&�&�&�>�>�>�
�
�
�
�
r!r�c�H�eZdZdZd
d�Zd�Zdd�Zd�Zdd	�Zd
�Z	d�Z
d�ZdS)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
    NrXc�d�t�|��||_||_d|_dSr$)rr�r�alphamax�beta)r�rr�s   r"r�zExcitingMixing.__init__�s/������%�%�%���
� ��
���	�	�	r!c��t�||||��tj|jdf|j|j���|_dSrm)rrbr%r|r5rr-r�r�s    r"rbzExcitingMixing.setupsE�����T�1�a��.�.�.��G�T�Z��]�,�d�j��
�K�K�K��	�	�	r!rc��||jzSr$�r�r`s   r"rzExcitingMixing.solve����r�$�)�|�r!c��||jzSr$r�r^s  r"r�zExcitingMixing.matvecr�r!c�<�||j���zSr$�r�r�r`s   r"r�zExcitingMixing.rsolve����r�$�)�.�.�"�"�"�"r!c�<�||j���zSr$r�r^s  r"r�zExcitingMixing.rmatvecr�r!c�:�tjd|jz��S)Nr�)r%r�r�r�s r"r�zExcitingMixing.todenses���w�r�$�)�|�$�$�$r!c���||jzdk}|j|xx|jz
cc<|j|j|<tj|jd|j|j���dS)Nr)�out)rr�rr%�clipr�)r�r)r�rzrr�r
�incrs        r"rzExcitingMixing._updatesa�����}�q� ���	�$����4�:�%�����:��	�4�%��
���	�1�d�m���;�;�;�;�;�;r!)NrXr�r�r r!r"r�r��s���������4����L�L�L��������#�#�#�#�#�#�#�%�%�%�<�<�<�<�<r!r�c�>�eZdZdZ		d
d�Zd�Zd�Zdd
�Zd�Zd�Z	dS)ra�
    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])

    N�lgmres��
c���||_||_ttjjjtjjjtjjjtjjj	tjjj
tjjj����||��|_
t||j���|_|j
tjjjur1||jd<d|jd<|j�dd���n|j
tjjjtjjjtjjj	fvr|j�dd��n�|j
tjjjur�||jd<d|jd<|j�d	g��|j�d
d��|j�dd
��|j�dd��|���D]>\}}|�d��st'd|z���||j|dd�<�?dS)N)�bicgstab�gmresr��cgs�minres�tfqmr)rrrjrOrrr�atolr�outer_k�outer_v�prepend_outer_vT�store_outer_AvF�inner_zUnknown parameter %s�)�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�zKrylovJacobian.__init__�s&��%�����
���\�(�1��,�%�+��<�&�-���#�'��<�&�-��,�%�+�
����c�&�&�!�!�	
���m�t�7J�K�K�K����;�%�,�-�3�3�3�(5�D�N�9�%�()�D�N�9�%��N�%�%�f�a�0�0�0�0�
�[�U�\�0�8�"�\�0�9�"�\�0�4�6�6�6�
�N�%�%�f�a�0�0�0�0�
�[�E�L�/�6�
6�
6�(/�D�N�9�%�()�D�N�9�%��N�%�%�i��4�4�4��N�%�%�&7��>�>�>�
�N�%�%�&6��>�>�>��N�%�%�f�a�0�0�0��(�(�*�*�	,�	,�J�C���>�>�(�+�+�
?� �!7�#�!=�>�>�>�&+�D�N�3�q�r�r�7�#�#�	,�	,r!c��t|j�����}t|j�����}|jtd|��ztd|��z|_dS)Nr)r�r7r'rr��omega)r��mx�mfs   r"�_update_diff_stepz KrylovJacobian._update_diff_step�s[��
���\�\�
�
�
�
��
���\�\�
�
�
�
���Z�#�a��*�*�,�s�1�b�z�z�9��
�
�
r!c�Z�t|��}|dkrd|zS|j|z}|�|j||zz��|jz
|z}tjtj|����s5tjtj|����rtd���|S)Nrz$Function returned non-finite results)	rr�ryr7rr%r<r;re)r�r?�nv�scr\s     r"r�zKrylovJacobian.matvec�s���
�!�W�W��
��7�7��Q�3�J�
�Z�"�_��
�Y�Y�t�w��A��~�
&�
&���
0�B�6���v�b�k�!�n�n�%�%�	E�"�&���Q���*@�*@�	E��C�D�D�D��r!rc��d|jvr|j|j|fi|j��\}}n|j|j|fd|i|j��\}}|S)NrW)r�r��op)r��rhsrW�solr�s     r"rzKrylovJacobian.solve�sa���D�N�"�"�#���D�G�S�C�C�D�N�C�C�I�C���#���D�G�S�L�L�c�L�T�^�L�L�I�C���
r!c��||_||_|���|j�2t	|jd��r|j�||��dSdSdS)Nrj)r7rr�r�r�rj)r�r)r�s   r"rjzKrylovJacobian.update�ss����������� � � ���*��t�*�H�5�5�
1��#�*�*�1�a�0�0�0�0�0�+�*�
1�
1r!c��t�||||��||_||_tjj�|��|_|j	�&tj|j��j
dz|_	|���|j�3t!|jd��r |j�|||��dSdSdS)Nrrb)r�rbr7rr�r�r��aslinearoperatorr�r�r%r�r-r�r�r�r�)r�r)r�rys    r"rbzKrylovJacobian.setup�s������t�Q��4�(�(�(��������,�%�6�6�t�<�<����:����!�'�*�*�.�4�8�D�J���� � � ���*��t�*�G�4�4�
6��#�)�)�!�Q��5�5�5�5�5�+�*�
6�
6r!)Nr�r�Nr�r�)
rrrrDr�r�r�rrjrbr r!r"rr"s�������c�c�JCE�')�-,�-,�-,�-,�^:�:�:�
�������1�1�1�6�6�6�6�6r!rc�N�t|j��}|\}}}}}}}	tt|t	|��d�|����}
d�d�|
D����}|rd|z}d�d�|
D����}|r|dz}|rt
d|z���d}
|
t|||j|���z}
i}|�	t����t|
|��||}|j|_t|��|S)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, c�"�g|]\}}|�d|����
S��=r ��.0rJr?s   r"�
<listcomp>z#_nonlin_wrapper.<locals>.<listcomp>�s'��<�<�<�T�Q��1�1�1�a�a�(�<�<�<r!c�"�g|]\}}|�d|����
Sr�r r�s   r"r�z#_nonlin_wrapper.<locals>.<listcomp>�s'��>�>�>�t�q�!�Q�Q�Q���*�>�>�>r!zUnexpected signature %sa�
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��listrr!�joinrer�rrj�globals�execrDrG)r�r��	signature�args�varargs�varkw�defaults�
kwonlyargs�
kwdefaults�_�kwargs�kw_str�kwkw_str�wrapper�nsrys                r"�_nonlin_wrapperr��sJ�� ���-�-�I�@I�=�D�'�5�(�J�
�A�
�#�d�C��M�M�>�?�?�+�X�6�6�
7�
7�F�
�Y�Y�<�<�V�<�<�<�
=�
=�F�
�������y�y�>�>�v�>�>�>�?�?�H��#��d�?���@��2�Y�>�?�?�?��G���$�6�s�|�"*�,�,�,�,�G�	�B��I�I�g�i�i������"����
�d�8�D��;�D�L��T�N�N�N��Kr!rrrrrrr)
rHNFNNNNNNrINFT)rIr�r�):rk�numpyr%�scipy.linalgrrrrrrr	r
r�scipy.sparse.linalgr��scipy.sparserr��scipy._lib._utilr
r��_linesearchrr�__all__�	Exceptionrr*r1r9r@r��striprErGr�rir_r�rrarrrr�r�r�r�r�rr�rrrrrrrr r!r"�<module>r�s����
�
�
�����?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�$�$�$�$�$�$�$�$�$�$���������'�'�'�'�'�'�����F�F�F�F�F�F�C�C�C�C�C�C�C�C�9�9�9��	�	�	�	�	�I�	�	�	� � � �
�
�
��������T��	����(�P	����a1�1�1�
�h/�/�/�
?D�KO�?C�48�O"�O"�O"�O"�d	������FJ�!�*�*�*�*�Z9<�9<�9<�9<�9<�9<�9<�9<�@A�A�A�A�A�A�A�A�H#�#�#�#�#�#�#�#�&Y?�Y?�Y?�@�����X����4A�A�A�A�A�A�A�A�H �*	����+���0o�o�o�o�o�>�o�o�o�d9�9�9�9�9�L�9�9�9�@U�U�U�U�U�~�U�U�U�xA1�A1�A1�A1�A1�.�A1�A1�A1�H+
�+
�+
�+
�+
�>�+
�+
�+
�\8<�8<�8<�8<�8<�^�8<�8<�8<�~C6�C6�C6�C6�C6�X�C6�C6�C6�T)�)�)�X�?�:�|�4�4���?�:�}�5�5���?�:�x�0�0����~�|�<�<���o�m�[�9�9�� ��!1�>�B�B������@�@�
�
�
r!

Youez - 2016 - github.com/yon3zu
LinuXploit