a
    h[-                     @   s   d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	 ddl
mZ d dlmZmZ dgZed	d
ddedddddddddZdS )    N)innerzerosinffinfo)norm)sqrt   )make_system)_NoValue_deprecate_positional_argsminresz1.14.0)versiong        Fgh㈵>)shifttolmaxiterMcallbackshowcheckrtolc          J      C   s.  t | |||\} }}}}|turHd}tj|tdd |durDt|n|
}
| j}|j}d}d}| jd }|du rvd| }g d	}|rt|d
  t|d|dd|d  t|d|dd|
d  t  d}d}d}d}d}d}|j	}t
|j}|du r| }n|| |  }||}t||}|dk r:tdn|dkrP||dfS t|}|dkrr|}||dfS t|}|	r||}||} t||}!t|| }"t|!|" }#|!| |d  }$|#|$krtd||} t||}!t|| }"t|!|" }#|!| |d  }$|#|$krtdd}%|}&d}'d}(|})|}*|}+d},d}-d}.t
|j}/d}0d}1t||d}t||d}2|} |rt  t  td ||k r|d7 }d|& }!|!| }3||3}|||3  }|dkr||&|% |  }t|3|}4||4|& |   }| }|} || }|&}%t| |}&|&dk r&tdt|&}&|-|4d |%d  |&d  7 }-|dkrj|&| d| krjd}|(}5|0|' |1|4  }6|1|' |0|4  }7|1|& }(|0 |& }'t|7|'g}8|*|8 }9t|7|&g}:t|:|}:|7|: }0|&|: }1|0|* };|1|* }*d|: }<|2}=|}2|3|5|=  |6|2  |< }||;|  }t|.|:}.t|/|:}/|+|: }#|,|6|#  }+|( |# },t|-}t|}|| }$|| | }>|| |
 }?|7}@|@dkr|$}@|*})|)}|dks|dkrt}An|||  }A|dkrt}Bn|8| }B|.|/ }|dkr`d|A }Cd|B }D|Ddkrd}|Cdkrd}||kr$d}|d| kr6d}|>|krDd}|B|
krRd}|A|
kr`d}d }E|d!krrd"}E|dkrd"}E||d krd"}E|d dkrd"}E|)d|> krd"}E|)d|? krd"}E|d#| krd"}E|dkrd"}E|rb|Erb|d$d%|d d&d%|Ad'}Fd%|Bd'}Gd%|d(d%|d(d%|7| d(}Ht|F|G |H  |d dkrbt  |durt|| |dkrqq|rt  t|d)|dd*|d+  t|d,|d-d.|d-  t|d/|d-d0|d-  t|d1|9d-  t|||d    |dkr|}Ind}I|||IfS )2a  
    Use MINimum RESidual iteration to solve Ax=b

    MINRES minimizes norm(Ax - b) for a real symmetric matrix A.  Unlike
    the Conjugate Gradient method, A can be indefinite or singular.

    If shift != 0 then the method solves (A - shift*I)x = b

    Parameters
    ----------
    A : {sparse matrix, ndarray, LinearOperator}
        The real symmetric N-by-N matrix of the linear system
        Alternatively, ``A`` can be a linear operator which can
        produce ``Ax`` using, e.g.,
        ``scipy.sparse.linalg.LinearOperator``.
    b : ndarray
        Right hand side of the linear system. Has shape (N,) or (N,1).

    Returns
    -------
    x : ndarray
        The converged solution.
    info : integer
        Provides convergence information:
            0  : successful exit
            >0 : convergence to tolerance not achieved, number of iterations
            <0 : illegal input or breakdown

    Other Parameters
    ----------------
    x0 : ndarray
        Starting guess for the solution.
    shift : float
        Value to apply to the system ``(A - shift * I)x = b``. Default is 0.
    rtol : float
        Tolerance to achieve. The algorithm terminates when the relative
        residual is below ``rtol``.
    maxiter : integer
        Maximum number of iterations.  Iteration will stop after maxiter
        steps even if the specified tolerance has not been achieved.
    M : {sparse matrix, ndarray, LinearOperator}
        Preconditioner for A.  The preconditioner should approximate the
        inverse of A.  Effective preconditioning dramatically improves the
        rate of convergence, which implies that fewer iterations are needed
        to reach a given error tolerance.
    callback : function
        User-supplied function to call after each iteration.  It is called
        as callback(xk), where xk is the current solution vector.
    show : bool
        If ``True``, print out a summary and metrics related to the solution
        during iterations. Default is ``False``.
    check : bool
        If ``True``, run additional input validation to check that `A` and
        `M` (if specified) are symmetric. Default is ``False``.
    tol : float, optional, deprecated

        .. deprecated:: 1.12.0
           `minres` keyword argument ``tol`` is deprecated in favor of ``rtol``
           and will be removed in SciPy 1.14.0.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy.sparse import csc_matrix
    >>> from scipy.sparse.linalg import minres
    >>> A = csc_matrix([[3, 2, 0], [1, -1, 0], [0, 5, 1]], dtype=float)
    >>> A = A + A.T
    >>> b = np.array([2, 4, -1], dtype=float)
    >>> x, exitCode = minres(A, b)
    >>> print(exitCode)            # 0 indicates successful convergence
    0
    >>> np.allclose(A.dot(x), b)
    True

    References
    ----------
    Solution of sparse indefinite systems of linear equations,
        C. C. Paige and M. A. Saunders (1975),
        SIAM J. Numer. Anal. 12(4), pp. 617-629.
        https://web.stanford.edu/group/SOL/software/minres/

    This file is a translation of the following MATLAB implementation:
        https://web.stanford.edu/group/SOL/software/minres/minres-matlab.zip

    z'scipy.sparse.linalg.minres' keyword argument `tol` is deprecated in favor of `rtol` and will be removed in SciPy v1.14. Until then, if set, it will override `rtol`.   )category
stacklevelNzEnter minres.   zExit  minres.   r      )z3 beta2 = 0.  If M = I, b and x are eigenvectors    z/ beta1 = 0.  The exact solution is x0          z3 A solution to Ax = b was found, given rtol        z3 A least-squares solution was found, given rtol    z3 Reasonable accuracy achieved, given eps           z3 x has converged to an eigenvector                 z3 acond has exceeded 0.1/eps                        z3 The iteration limit was reached                   z3 A  does not define a symmetric matrix             z3 M  does not define a symmetric matrix             z3 M  does not define a pos-def preconditioner       zSolution of symmetric Ax = bz
n      =  Z3gz     shift  =  z23.14ez
itnlim =  z     rtol   =  z11.2ezindefinite preconditionergUUUUUU?znon-symmetric matrixznon-symmetric preconditioner)dtypezD   Itn     x(1)     Compatible    LS       norm(A)  cond(A) gbar/|A|r   g      ?   
      g?   F(   Tg{Gz?Z6g z12.5ez10.3ez8.1ez istop   =  z               itn   =Z5gz Anorm   =  z12.4ez      Acond =  z rnorm   =  z      ynorm =  z Arnorm  =  )r	   r
   warningswarnDeprecationWarningfloatmatvecshapeprintr   r   epscopyr   
ValueErrorr   r   absmaxr   minr   )JAbZx0r   r   r   r   r   r   r   r   xpostprocessmsgr&   ZpsolvefirstlastnistopitnZAnormZAcondZrnormZynormZxtyper)   r1yZbeta1Zbnormwr2stzZepsaZoldbbetaZdbarZepslnZqrnormZphibarZrhs1Zrhs2Ztnorm2ZgmaxZgmincsZsnZw2vZalfaZoldepsdeltaZgbarrootZArnormgammaphidenomZw1ZepsxZepsrZdiagZtest1Ztest2t1t2ZprntZstr1Zstr2Zstr3info rK   ^/var/www/html/assistant/venv/lib/python3.9/site-packages/scipy/sparse/linalg/_isolve/minres.pyr      s   X






































 


)N)r"   numpyr   r   r   r   Znumpy.linalgr   mathr   utilsr	   Zscipy._lib.deprecationr
   r   __all__r   rK   rK   rK   rL   <module>   s   
