ó
î&]\c        	   @` sœ  d  d l  m Z m Z m Z d  d l m Z m Z m Z m Z m	 Z	 d  d l
 m Z d d l m Z d g Z e d d e e e e e d	 „ Z e d
 k r˜d  d l m Z m Z d  d l m Z d  d l m Z d Z g  Z d „  Z e e d e d d e ƒg d  g e e d d ƒZ e d e d e d d e ƒg d  g e e d d ƒZ e j e _  d  e e j! d  ƒ Z" e e e" d d d e d e ƒZ# n  d S(   i    (   t   divisiont   print_functiont   absolute_import(   t   sqrtt   innert   zerost   inft   finfo(   t   normi   (   t   make_systemt   minresg        gñhãˆµøä>c
   H      C` sî  t  |  | | | ƒ \ }  } }
 } } |  j } | j } d } d } |  j d } | d+ k rh d | } n  d d d d d	 d
 d d d d d g } | rÝ t | d ƒ t | d | | f ƒ t | d | | f ƒ t ƒ  n  d } d } d } d } d } d } |
 j } t | ƒ j } t | d | ƒ}
 | } | } | | ƒ } t	 | | ƒ } | d k  rmt
 d ƒ ‚ n | d k r‰| |
 ƒ d f St | ƒ } |	 rx| | ƒ } | | ƒ } t	 | | ƒ } t	 | | ƒ }  t | |  ƒ }! | | | d, }" |! |" k rt
 d ƒ ‚ n  | | ƒ } t	 | | ƒ } t	 | | ƒ }  t | |  ƒ }! | | | d- }" |! |" k rxt
 d ƒ ‚ qxn  d }# | }$ d }% d }& | }' | }( | }) d }* d }+ d }, t | ƒ j }- d }. d }/ t | d | ƒ} t | d | ƒ}0 | } | rt ƒ  t ƒ  t d ƒ n  x#| | k  r?| d 7} d |$ } | | }1 | |1 ƒ } | | |1 } | d k r‚| |$ |# | } n  t	 |1 | ƒ }2 | |2 |$ | } | } | } | | ƒ } |$ }# t	 | | ƒ }$ |$ d k  rët
 d ƒ ‚ n  t |$ ƒ }$ |+ |2 d |# d |$ d 7}+ | d k rA|$ | d | k rAd } qAn  |& }3 |. |% |/ |2 }4 |/ |% |. |2 }5 |/ |$ }& |. |$ }% t |5 |% g ƒ }6 |( |6 }7 t |5 |$ g ƒ }8 t |8 | ƒ }8 |5 |8 }. |$ |8 }/ |. |( }9 |/ |( }( d |8 }: |0 }; | }0 |1 |3 |; |4 |0 |: } |
 |9 | }
 t |, |8 ƒ }, t |- |8 ƒ }- |) |8 }! |* |4 |! }) |& |! }* t |+ ƒ } t |
 ƒ } | | }" | | | }< | | | }= |5 }> |> d k r½|" }> n  |( }' |' } | d k sá| d k rêt }? n | | | }? | d k rt }@ n
 |6 | }@ |, |- } | d k rÛd |? }A d |@ }B |B d k rVd } n  |A d k rkd } n  | | k r€d } n  | d | k r™d  } n  |< | k r®d! } n  |@ | k rÃd } n  |? | k rÛd } qÛn  t }C | d" k röt }C n  | d k rt }C n  | | d k r$t }C n  | d d k r=t }C n  |' d |< k rVt }C n  |' d |= k rot }C n  | d# | k rˆt }C n  | d k rt }C n  | r|C rd$ | |
 d |? f }D d% |@ f }E d& | | |5 | f }F t |D |E |F ƒ | d d k rt ƒ  qn  | d+ k	 r,| |
 ƒ n  | d k rPqqW| rÃt ƒ  t | d' | | f ƒ t | d( | | f ƒ t | d) | | f ƒ t | d* |7 f ƒ t | | | d ƒ n  | d k rØ| }G n d }G | |
 ƒ |G f S(.   s  
    Use MINimum RESidual iteration to solve Ax=b

    MINRES minimizes norm(A*x - 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, dense matrix, LinearOperator}
        The real symmetric N-by-N matrix of the linear system
    b : {array, matrix}
        Right hand side of the linear system. Has shape (N,) or (N,1).

    Returns
    -------
    x : {array, matrix}
        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  : {array, matrix}
        Starting guess for the solution.
    tol : float
        Tolerance to achieve. The algorithm terminates when the relative
        residual is below `tol`.
    maxiter : integer
        Maximum number of iterations.  Iteration will stop after maxiter
        steps even if the specified tolerance has not been achieved.
    M : {sparse matrix, dense matrix, 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.

    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

    s   Enter minres.   s   Exit  minres.   i    i   s3    beta2 = 0.  If M = I, b and x are eigenvectors    s3    beta1 = 0.  The exact solution is  x = 0          s3    A solution to Ax = b was found, given rtol        s3    A least-squares solution was found, given rtol    s3    Reasonable accuracy achieved, given eps           s3    x has converged to an eigenvector                 s3    acond has exceeded 0.1/eps                        s3    The iteration limit was reached                   s3    A  does not define a symmetric matrix             s3    M  does not define a symmetric matrix             s3    M  does not define a pos-def preconditioner       s   Solution of symmetric Ax = bs#   n      =  %3g     shift  =  %23.14es"   itnlim =  %3g     rtol   =  %11.2et   dtypes   indefinite preconditionerg      ð?g      @s   non-symmetric matrixs   non-symmetric preconditioneriÿÿÿÿsD      Itn     x(1)     Compatible    LS       norm(A)  cond(A) gbar/|A|i   i   i
   i   gš™™™™™¹?i   i   i(   g{®Gáz„?s   %6g %12.5e %10.3es    %10.3es    %8.1e %8.1e %8.1es(    istop   =  %3g               itn   =%5gs'    Anorm   =  %12.4e      Acond =  %12.4es'    rnorm   =  %12.4e      ynorm =  %12.4es    Arnorm  =  %12.4eNgUUUUUUÕ?gUUUUUUÕ?(   R	   t   matvect   shapet   Nonet   printR   R   t   epsR   R   t
   ValueErrorR   t   abst   maxR   t   minR   t   Falset   True(H   t   At   bt   x0t   shiftt   tolt   maxitert   Mt   callbackt   showt   checkt   xt   postprocessR   t   psolvet   firstt   lastt   nt   msgt   istopt   itnt   Anormt   Acondt   rnormt   ynormt   xtypeR   t   yt   r1t   beta1t   wt   r2t   st   tt   zt   epsat   oldbt   betat   dbart   epslnt   qrnormt   phibart   rhs1t   rhs2t   tnorm2t   gmaxt   gmint   cst   snt   w2t   vt   alfat   oldepst   deltat   gbart   roott   Arnormt   gammat   phit   denomt   w1t   epsxt   epsrt   diagt   test1t   test2t   t1t   t2t   prntt   str1t   str2t   str3t   info(    (    s@   lib/python2.7/site-packages/scipy/sparse/linalg/isolve/minres.pyR
      sˆ   9$			
	











			



															t   __main__(   t   onest   arange(   t   spdiagsi
   c         C` s   t  j t t t |  ƒ ƒ d  S(   N(   t	   residualst   appendR   R   R   (   R!   (    (    s@   lib/python2.7/site-packages/scipy/sparse/linalg/isolve/minres.pyt   cbd  s    R   t   formatt   csrg      ð?R   gê-™—q=R   R   N($   t
   __future__R    R   R   t   numpyR   R   R   R   R   t   numpy.linalgR   t   utilsR	   t   __all__R   R   R
   t   __name__t   scipyR^   R_   t   scipy.linalgt   scipy.sparseR`   R&   Ra   Rc   t   floatR   R   R   R#   R   R   R!   (    (    (    s@   lib/python2.7/site-packages/scipy/sparse/linalg/isolve/minres.pyt   <module>   s&   (	ÿ P	48