ó
î&]\c           @` s€  d  Z  d d l m Z m Z m Z d Z d d d d d g Z d	 d
 l m Z d d l	 Z
 d d l Z d d l m Z m Z d d l m Z m Z m Z m Z d d l m Z m Z m Z m Z d d l m Z d d l m Z m Z d d l m Z d d l  m! Z! i d d 6d d 6d d 6d d 6Z" i d d 6d d 6d d 6d d 6Z# i d d 6d d	 6d d 6d  d! 6d" d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6d. d/ 6d0 d1 6d2 d3 6d4 d5 6d6 d7 6d8 d9 6d: d; 6d< d= 6Z$ e$ Z% e$ j& ƒ  Z' d> e' d5 <e' Z( i d d 6d? d	 6d d 6d  d! 6d" d# 6d$ d% 6d@ d' 6d( d) 6dA d+ 6d, d- 6d. d/ 6dB d1 6d2 d3 6dC d5 6d6 d7 6d8 d9 6dD d; 6d< d= 6Z) e) Z* i d d 6dE d	 6d" d# 6d$ d% 6d& d' 6dF d+ 6d, d- 6dG d/ 6dH d1 6dI d3 6d4 d5 6d6 d7 6dJ d9 6dK d; 6dL dM 6dN dO 6Z+ e+ j& ƒ  Z, dP e, d	 <dQ e, dM <dR e, dO <i d d 6dS d	 6d" d# 6d$ d% 6dT d' 6dF d+ 6d, d- 6dG d/ 6dU d1 6dV d3 6dW d5 6d6 d7 6dJ d9 6dK d; 6dX dM 6dY dO 6Z- e- j& ƒ  Z. dZ e. dM <d[ e. dO <i d d 6d" d# 6d$ d% 6d@ d' 6dA d+ 6d, d- 6dG d/ 6d\ d1 6d2 d3 6dC d5 6d6 d7 6d: d9 6d] dM 6d^ dO 6dJ d_ 6d` da 6Z/ e/ j& ƒ  Z0 db e0 dM <dc e0 da <i e) d 6e* d 6Z1 i e$ d 6e% d 6e' d 6e( d 6Z2 i e/ d 6e0 d 6Z3 i e+ d 6e, d 6e- d 6e. d 6Z4 dd de df dg dh g Z5 dd de di dj dk dl g Z6 d e7 f dm „  ƒ  YZ8 d e8 f dn „  ƒ  YZ9 do „  Z: dp e; f dq „  ƒ  YZ< dr e< f ds „  ƒ  YZ= dt e< f du „  ƒ  YZ> dv „  Z? dw e f dx „  ƒ  YZ@ dy e f dz „  ƒ  YZA d{ „  ZB d| e f d} „  ƒ  YZC d~ e f d „  ƒ  YZD eE d d€ „ ZF eE d d „ ZG e! d‚ ƒ ZH dƒ eI eI dd eI eI eI d eJ eI eI eI d„ „ ZK dƒ eI eI dd eI eI eI d eJ eI eI d… d† „ ZL d‡ „  ZM dˆ „  ZN d‰ „  ZO dƒ eI d dd eI eI eJ dŠ „ ZP d S(‹   sp   
Find a few eigenvectors and eigenvalues of a matrix.


Uses ARPACK: http://www.caam.rice.edu/software/ARPACK/

i    (   t   divisiont   print_functiont   absolute_imports   restructuredtext ent   eigst   eigsht   svdst   ArpackErrort   ArpackNoConvergencei   (   t   _arpackN(   t   aslinearoperatort   LinearOperator(   t   eyet   issparset
   isspmatrixt   isspmatrix_csr(   t   eigt   eight	   lu_factort   lu_solve(   t   isdense(   t   gmrest   splu(   t   _aligned_zeros(   t   ReentrancyLockt   st   ft   dt   ct   Ft   zt   Di   i   s   Normal exit.s   Maximum number of iterations taken. All possible eigenvalues of OP has been found. IPARAM(5) returns the number of wanted converged Ritz values.sO   No longer an informational error. Deprecated starting with release 2 of ARPACK.i   s™   No shifts could be applied during a cycle of the Implicitly restarted Arnoldi iteration. One possibility is to increase the size of NCV relative to NEV. i   s   N must be positive.iÿÿÿÿs   NEV must be positive.iþÿÿÿs)   NCV-NEV >= 2 and less than or equal to N.iýÿÿÿsR   The maximum number of Arnoldi update iterations allowed must be greater than zero.iüÿÿÿs8    WHICH must be one of 'LM', 'SM', 'LR', 'SR', 'LI', 'SI'iûÿÿÿs   BMAT must be one of 'I' or 'G'.iúÿÿÿs5   Length of private work array WORKL is not sufficient.iùÿÿÿs0   Error return from LAPACK eigenvalue calculation;iøÿÿÿs   Starting vector is zero.i÷ÿÿÿs   IPARAM(7) must be 1,2,3,4.iöÿÿÿs.   IPARAM(7) = 1 and BMAT = 'G' are incompatible.iõÿÿÿs"   IPARAM(1) must be equal to 0 or 1.iôÿÿÿs&   NEV and WHICH = 'BE' are incompatible.ióÿÿÿsÃ   Could not build an Arnoldi factorization. IPARAM(5) returns the size of the current Arnoldi factorization. The user is advised to check that enough workspace and array storage has been allocated.iñØÿÿs   IPARAM(7) must be 1,2,3.sR   Maximum number of iterations taken. All possible eigenvalues of OP has been found.s9   NCV must be greater than NEV and less than or equal to N.s4   WHICH must be one of 'LM', 'SM', 'LA', 'SA' or 'BE'.s`   Error return from trid. eigenvalue calculation; Informational error from LAPACK routine dsteqr .s   IPARAM(7) must be 1,2,3,4,5.s'   NEV and WHICH = 'BE' are incompatible. ss  The Schur form computed by LAPACK routine dlahqr could not be reordered by LAPACK routine dtrsen. Re-enter subroutine dneupd  with IPARAM(5)NCV and increase the size of the arrays DR and DI to have dimension at least dimension NCV and allocate at least NCV columns for Z. NOTE: Not necessary if Z and V share the same space. Please notify the authors if this erroroccurs.s7   WHICH must be one of 'LM', 'SM', 'LR', 'SR', 'LI', 'SI's5   Length of private work WORKL array is not sufficient.sd   Error return from calculation of a real Schur form. Informational error from LAPACK routine dlahqr .s^   Error return from calculation of eigenvectors. Informational error from LAPACK routine dtrevc.s    HOWMNY = 'S' not yet implementeds1   HOWMNY must be one of 'A' or 'P' if RVEC = .true.s<   DNAUPD  did not find any eigenvalues to sufficient accuracy.iòÿÿÿsß   DNEUPD got a different count of the number of converged Ritz values than DNAUPD got.  This indicates the user probably made an error in passing data from DNAUPD to DNEUPD or that the data was modified before entering DNEUPDiñÿÿÿsv  The Schur form computed by LAPACK routine slahqr could not be reordered by LAPACK routine strsen . Re-enter subroutine dneupd  with IPARAM(5)=NCV and increase the size of the arrays DR and DI to have dimension at least dimension NCV and allocate at least NCV columns for Z. NOTE: Not necessary if Z and V share the same space. Please notify the authors if this error occurs.s;   SNAUPD did not find any eigenvalues to sufficient accuracy.sß   SNEUPD got a different count of the number of converged Ritz values than SNAUPD got.  This indicates the user probably made an error in passing data from SNAUPD to SNEUPD or that the data was modified before entering SNEUPDsk  The Schur form computed by LAPACK routine csheqr could not be reordered by LAPACK routine ztrsen. Re-enter subroutine zneupd with IPARAM(5)=NCV and increase the size of the array D to have dimension at least dimension NCV and allocate at least NCV columns for Z. NOTE: Not necessary if Z and V share the same space. Please notify the authors if this error occurs.s)   NCV-NEV >= 1 and less than or equal to N.sL   Error return from LAPACK eigenvalue calculation. This should never happened.s^   Error return from calculation of eigenvectors. Informational error from LAPACK routine ztrevc.s   IPARAM(7) must be 1,2,3s;   ZNAUPD did not find any eigenvalues to sufficient accuracy.sß   ZNEUPD got a different count of the number of converged Ritz values than ZNAUPD got.  This indicates the user probably made an error in passing data from ZNAUPD to ZNEUPD or that the data was modified before entering ZNEUPDs;   CNAUPD did not find any eigenvalues to sufficient accuracy.sß   CNEUPD got a different count of the number of converged Ritz values than CNAUPD got.  This indicates the user probably made an error in passing data from CNAUPD to CNEUPD or that the data was modified before entering CNEUPDs]   Error return from trid. eigenvalue calculation; Information error from LAPACK routine dsteqr.s<   DSAUPD  did not find any eigenvalues to sufficient accuracy.s1   HOWMNY must be one of 'A' or 'S' if RVEC = .true.iðÿÿÿså   DSEUPD  got a different count of the number of converged Ritz values than DSAUPD  got.  This indicates the user probably made an error in passing data from DSAUPD  to DSEUPD  or that the data was modified before entering  DSEUPD.iïÿÿÿs<   SSAUPD  did not find any eigenvalues to sufficient accuracy.så   SSEUPD  got a different count of the number of converged Ritz values than SSAUPD  got.  This indicates the user probably made an error in passing data from SSAUPD  to SSEUPD  or that the data was modified before entering  SSEUPD.t   LMt   SMt   LAt   SAt   BEt   LRt   SRt   LIt   SIc           B` s   e  Z d  Z e d „ Z RS(   s   
    ARPACK error
    c         C` s0   | j  | d ƒ } t j |  d | | f ƒ d  S(   Ns   Unknown errors   ARPACK error %d: %s(   t   gett   RuntimeErrort   __init__(   t   selft   infot   infodictt   msg(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR*     s    (   t   __name__t
   __module__t   __doc__t   _NAUPD_ERRORSR*   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR     s   c           B` s   e  Z d  Z d „  Z RS(   sß   
    ARPACK iteration did not converge

    Attributes
    ----------
    eigenvalues : ndarray
        Partial result. Converged eigenvalues.
    eigenvectors : ndarray
        Partial result. Converged eigenvectors.

    c         C` s0   t  j |  d i | d 6ƒ | |  _ | |  _ d  S(   Niÿÿÿÿ(   R   R*   t   eigenvaluest   eigenvectors(   R+   R.   R3   R4   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR*   '  s    	(   R/   R0   R1   R*   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR     s   c         C` s   t  d |  d d ƒ S(   sy   
    Choose number of lanczos vectors based on target number
    of singular/eigen values and vectors to compute, k.
    i   i   i   (   t   max(   t   k(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt
   choose_ncv-  s    t   _ArpackParamsc           B` s/   e  Z d  d d d d d d d „ Z d „  Z RS(   i   R   i    c         C` sÖ  | d k r t  d | ƒ ‚ n  | d  k r8 | d } n  | d k rW t  d | ƒ ‚ n  | d k rr t  d ƒ ‚ n  | d  k	 rŸ t j | d t ƒ|  _ d } n t j | | ƒ |  _ d } | d  k rÒ d |  _ n	 | |  _ | d  k rö t | ƒ } n  t	 | | ƒ } t j | | f | ƒ |  _
 t j d	 d
 ƒ |  _ d } | |  _ | |  j d <| |  j d <d |  j d <| |  j d <| |  _ |
 |  _ | |  _ | |  _ | |  _ |	 |  _ | |  _ | |  _ t |  _ d |  _ d  S(   Ni    s   k must be positive, k=%di
   s$   maxiter must be positive, maxiter=%dt   fdFDs)   matrix type must be 'f', 'd', 'F', or 'D't   copyi   i   t   inti   i   i   (   t
   ValueErrort   Nonet   npt   arrayt   Truet   residt   zerost   sigmaR7   t   mint   vt   iparamt   modet   nt   tolR6   t   maxitert   ncvt   whicht   tpR,   t   Falset	   convergedt   ido(   R+   RH   R6   RM   RG   RC   RK   t   v0RJ   RL   RI   R,   t   ishfts(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR*   6  sJ    												c         C` s²   d } |  j  d } |  j  d } y |  j t ƒ \ } } WnP t k
 r‹ } d | | f } t j d ƒ } t j |  j d f ƒ } d } n Xt | | | |  j f | | ƒ ‚ d  S(   Ns<   No convergence (%d iterations, %d/%d eigenvectors converged)i   i   s   %s [%s]i    (   i    (	   RF   t   extractR@   R   R>   RB   RH   R   R6   (   R+   R.   t   k_okt   num_itert   evt   vect   err(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   _raise_no_convergencem  s    
N(   R/   R0   R=   R*   RY   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR8   5  s   6t   _SymmetricArpackParamsc        
   B` s>   e  Z d  d d d d d d d d d „	 Z d „  Z d „  Z RS(   i   R   i    c         ` s‡  | d k r~ ˆ d  k r' t d ƒ ‚ n  ˆ  d  k	 rB t d ƒ ‚ n  ˆ d  k	 r] t d ƒ ‚ n  ˆ ˆ _ d „  ˆ _ d ˆ _ n¤| d k rˆ d  k r¥ t d ƒ ‚ n  ˆ  d  k rÀ t d	 ƒ ‚ n  ˆ d  k rÛ t d
 ƒ ‚ n  ‡ ‡ f d †  ˆ _ ˆ ˆ _ ˆ ˆ _ ˆ  ˆ _ d ˆ _ n| d k rÂˆ d  k	 r>t d ƒ ‚ n  ˆ d  k rYt d ƒ ‚ n  ˆ  d  k rˆ ˆ _ ˆ ˆ _ d „  ˆ _ d ˆ _ q"‡  ‡ f d †  ˆ _ ˆ ˆ _ ˆ  ˆ _ d ˆ _ n`| d k rRˆ d  k rét d ƒ ‚ n  ˆ  d  k	 rt d ƒ ‚ n  ˆ d  k rt d ƒ ‚ n  ˆ ˆ _ ‡ ‡ f d †  ˆ _ ˆ ˆ _ d ˆ _ nÐ | d k rˆ d  k ryt d ƒ ‚ n  ˆ d  k r”t d ƒ ‚ n  ˆ ˆ _ ˆ ˆ _ ˆ  d  k râ‡ ‡ ‡ f d †  ˆ _ d „  ˆ _ d ˆ _ q"‡  ‡ ‡ ‡ f d †  ˆ _ ˆ  ˆ _ d ˆ _ n t d | ƒ ‚ | t k rJt d d j	 t ƒ ƒ ‚ n  | | k rit d  | ƒ ‚ n  t
 j ˆ | | | | ˆ |	 |
 | | | ƒ ˆ j | k s²ˆ j | k rÈt d! ˆ j ƒ ‚ n  t d | ˆ j ƒ ˆ _ t ˆ j ˆ j d" ˆ j ƒ ˆ _ t ˆ j } | d* k r,t d% ƒ ‚ n  t j | d& ˆ _ t j | d' ˆ _ t | ˆ _ t | ˆ _ t j d( d) ƒ ˆ _ d  S(+   Ni   s#   matvec must be specified for mode=1s'   M_matvec cannot be specified for mode=1s*   Minv_matvec cannot be specified for mode=1c         S` s   |  S(   N(    (   t   x(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   <lambda>»  s    t   Ii   s#   matvec must be specified for mode=2s%   M_matvec must be specified for mode=2s(   Minv_matvec must be specified for mode=2c         ` s   ˆ  ˆ |  ƒ ƒ S(   N(    (   R[   (   t   Minv_matvect   matvec(    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   Å  s    t   Gi   s'   matvec must not be specified for mode=3s(   Minv_matvec must be specified for mode=3c         S` s   |  S(   N(    (   R[   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   Ó  s    c         ` s   ˆ ˆ  |  ƒ ƒ S(   N(    (   R[   (   t   M_matvecR^   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   Ö  s    i   s#   matvec must be specified for mode=4s)   M_matvec must not be specified for mode=4s(   Minv_matvec must be specified for mode=4c         ` s   ˆ j  ˆ  |  ƒ ƒ S(   N(   t   OPa(   R[   (   R_   R+   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   â  s    i   s#   matvec must be specified for mode=5s(   Minv_matvec must be specified for mode=5c         ` s   ˆ  ˆ |  ƒ ˆ |  ƒ S(   N(    (   R[   (   R^   R_   RC   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   ï  s    c         S` s   |  S(   N(    (   R[   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   ð  s    c         ` s   ˆ ˆ |  ƒ ˆ ˆ  |  ƒ ƒ S(   N(    (   R[   (   Ra   R^   R_   RC   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   ó  s   s   mode=%i not implementeds   which must be one of %st    s!   k must be less than ndim(A), k=%ds   ncv must be k<ncv<=n, ncv=%si   R   R   s    Input matrix is not real-valued.t   saupdt   seupdi   R;   (   R   R   (   R=   R<   t   OPt   Bt   bmatRb   t   OPbt   A_matvect   _SEUPD_WHICHt   joinR8   R*   RK   R   RM   t   workdt   worklt
   _type_convR   t   __dict__t   _arpack_solvert   _arpack_extractt   _SAUPD_ERRORSt   iterate_infodictt   _SEUPD_ERRORSt   extract_infodictR>   RB   t   ipntr(   R+   RH   R6   RM   R_   RG   Ra   R^   RC   RK   RQ   RJ   RL   RI   t   ltr(    (   Ra   R^   R_   R+   RC   sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR*   |  s¢    6													#c         C` s÷  |  j  |  j |  j |  j |  j |  j |  j |  j |  j |  j	 |  j
 |  j |  j ƒ \ |  _ |  _ |  _ |  _ |  _ |  _	 |  _ t |  j	 d d |  j	 d d |  j ƒ } t |  j	 d d |  j	 d d |  j ƒ } |  j d k r|  j |  j
 | ƒ |  j
 | <nî|  j d k rW|  j d k rC|  j |  j
 | ƒ |  j
 | <qó|  j d k r|  j |  j
 | ƒ |  j
 | <|  j |  j
 | ƒ |  j
 | <qó|  j d k rt |  j	 d d |  j	 d d |  j ƒ } |  j |  j
 | ƒ } |  j | |  j |  j
 | ƒ |  j
 | <qót |  j	 d d |  j	 d d |  j ƒ } |  j |  j
 | ƒ |  j
 | <nœ |  j d k r†|  j |  j
 | ƒ |  j
 | <nm |  j d k r¤t d ƒ ‚ nO t |  _ |  j d k r¿n4 |  j d k rÛ|  j ƒ  n t |  j d |  j ƒ‚ d  S(	   Ni    i   iÿÿÿÿi   i   i   s/   ARPACK requested user shifts.  Assure ISHIFT==0R-   (   Rq   RP   Rh   RL   R6   RI   RA   RE   RF   Rw   Rm   Rn   R,   t   sliceRH   Rf   RG   Ri   Rb   Rj   RC   Rg   R<   R@   RO   RY   R   Rt   (   R+   t   xslicet   yslicet   Bxslicet   Ax(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   iterate  s<    H,,   ,,  	c   	      C` s  | } d } d } t  j |  j d ƒ } |  j | | | |  j |  j |  j |  j |  j |  j	 |  j
 |  j d d !|  j |  j d d |  j !|  j | ƒ \ } } } | d k rÃ t | d |  j ƒ‚ n  |  j d } | |  } | d  d  … d  | … f } | r| | f S| Sd  S(   Ni    t   AR;   i   i   R-   i   (   R>   RB   RK   Rr   RC   Rh   RL   R6   RI   RA   RE   RF   Rw   Rm   RH   Rn   R   Rv   (	   R+   t   return_eigenvectorst   rvect   ierrt   howmnyt   sselectR   R   RT   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyRS   >  s$    

N(   R/   R0   R=   R*   R~   RS   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyRZ   {  s
   ˜	(t   _UnsymmetricArpackParamsc        
   B` s>   e  Z d  d d d d d d d d d „	 Z d „  Z d „  Z RS(   i   R   i    c         ` sÁ  | d k r~ ˆ d  k r' t d ƒ ‚ n  ˆ  d  k	 rB t d ƒ ‚ n  ˆ d  k	 r] t d ƒ ‚ n  ˆ ˆ _ d „  ˆ _ d ˆ _ n´| d k rˆ d  k r¥ t d ƒ ‚ n  ˆ  d  k rÀ t d	 ƒ ‚ n  ˆ d  k rÛ t d
 ƒ ‚ n  ‡ ‡ f d †  ˆ _ ˆ ˆ _ ˆ ˆ _ ˆ  ˆ _ d ˆ _ n| d! k r"ˆ d  k r>t d ƒ ‚ n  ˆ d  k rYt d ƒ ‚ n  ˆ ˆ _ | d k r•| d k r†ˆ ˆ _ qÈt d ƒ ‚ n3 | d k r¶‡ f d †  ˆ _ n ‡ f d †  ˆ _ ˆ  d  k rød „  ˆ _ d ˆ _ ˆ j ˆ _ q2ˆ  ˆ _ d ˆ _ ‡  ‡ f d †  ˆ _ n t d | ƒ ‚ | t k rZt d d j	 t ƒ ƒ ‚ n  | | d k r}t d | ƒ ‚ n  t
 j ˆ | | | | | |	 |
 | | | ƒ ˆ j | k sÊˆ j | d k ràt d ˆ j ƒ ‚ n  t d | ˆ j ƒ ˆ _ t d ˆ j ˆ j d ˆ j ƒ ˆ _ t ˆ j } t j | d ˆ _ t j | d ˆ _ t | ˆ _ t | ˆ _ t j d d ƒ ˆ _ ˆ j d  k r´t ˆ j ˆ j j ƒ  ƒ ˆ _ n	 d  ˆ _ d  S("   Ni   s#   matvec must be specified for mode=1s'   M_matvec cannot be specified for mode=1s*   Minv_matvec cannot be specified for mode=1c         S` s   |  S(   N(    (   R[   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   „  s    R]   i   s#   matvec must be specified for mode=2s%   M_matvec must be specified for mode=2s(   Minv_matvec must be specified for mode=2c         ` s   ˆ  ˆ |  ƒ ƒ S(   N(    (   R[   (   R^   R_   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   Ž  s    R`   i   i   s*   matvec must be specified for mode in (3,4)s/   Minv_matvec must be specified for mode in (3,4)t   DFs   mode=4 invalid for complex Ac         ` s   t  j ˆ  |  ƒ ƒ S(   N(   R>   t   real(   R[   (   R^   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   £  s    c         ` s   t  j ˆ  |  ƒ ƒ S(   N(   R>   t   imag(   R[   (   R^   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   ¥  s    c         S` s   |  S(   N(    (   R[   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   §  s    c         ` s   ˆ j  ˆ  |  ƒ ƒ S(   N(   Rb   (   R[   (   Ra   R+   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR\   ­  s    s   mode=%i not implementeds!   Parameter which must be one of %sRc   s#   k must be less than ndim(A)-1, k=%ds   ncv must be k+1<ncv<=n, ncv=%st   naupdt   neupdi   R;   t   FD(   i   i   (   R=   R<   Rf   Rg   Rh   Rb   Ri   R_   t   _NEUPD_WHICHRl   R8   R*   RK   R   RM   Rm   Rn   Ro   R   Rp   Rq   Rr   R2   Rt   t   _NEUPD_ERRORSRv   R>   RB   Rw   t   lowert   rwork(   R+   RH   R6   RM   R_   RG   Ra   R^   RC   RK   RQ   RJ   RL   RI   Rx   (    (   Ra   R^   R_   R+   sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR*   V  s~    %								"'!c         C` sÅ  |  j  d k r |  j |  j |  j |  j |  j |  j |  j |  j |  j	 |  j
 |  j |  j |  j ƒ \ |  _ |  _ |  _ |  _ |  _	 |  _
 |  _ n„ |  j |  j |  j |  j |  j |  j |  j |  j |  j	 |  j
 |  j |  j |  j |  j ƒ \ |  _ |  _ |  _ |  _ |  _	 |  _
 |  _ t |  j
 d d |  j
 d d |  j ƒ } t |  j
 d d |  j
 d d |  j ƒ } |  j d k r›|  j |  j | ƒ |  j | <n&|  j d k r%|  j d	 k rÙ|  j |  j | ƒ |  j | <qÁt |  j
 d d |  j
 d d |  j ƒ } |  j |  j | ƒ |  j | <nœ |  j d k rT|  j |  j | ƒ |  j | <nm |  j d k rrt d ƒ ‚ nO t |  _ |  j d k rn4 |  j d k r©|  j ƒ  n t |  j d |  j ƒ‚ d  S(
   Nt   fdi    i   iÿÿÿÿi   i   s/   ARPACK requested user shifts.  Assure ISHIFT==0R-   (   i   i   (   RM   Rq   RP   Rh   RL   R6   RI   RA   RE   RF   Rw   Rm   Rn   R,   R   Ry   RH   Rf   RG   Rb   Rg   R<   R@   RO   RY   R   Rt   (   R+   Rz   R{   R|   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR~   Ð  s8    9<,,  ,  	c         C` s¥  |  j  |  j } } d } d } t j |  j d ƒ } t j |  j ƒ } t j |  j ƒ } t j d |  j |  j ƒ }	 |  j d k rÍt j | d |  j ƒ }
 t j | d |  j ƒ } t j | | d f |  j ƒ } |  j	 | | | | | |	 |  j
 |  j | |  j |  j |  j |  j |  j |  j |  j |  j ƒ \ }
 } } } | d k rat | d |  j ƒ‚ n  |  j d } |
 d	 | } | j |  j j ƒ  ƒ } | d k rwd } x÷| | k rst | | j ƒ d k rf| | k  rY| d  d  … | f d	 | d  d  … | d f | d  d  … | f <| d  d  … | f j ƒ  | d  d  … | d f <| d 7} qf| d 8} n  | d 7} q©Wn)d } x | | k rŸt | | j ƒ d k rçt j | d  d  … | f |  j | d  d  … | f ƒ ƒ | | <n«| | k  rˆ| d  d  … | f d	 | d  d  … | d f | d  d  … | f <| d  d  … | f j ƒ  | d  d  … | d f <t j | d  d  … | f |  j | d  d  … | f ƒ ƒ t j | d  d  … | d f |  j | d  d  … | d f ƒ ƒ d	 t j | d  d  … | f |  j | d  d  … | d f ƒ ƒ t j | d  d  … | d f |  j | d  d  … | f ƒ ƒ | | <| | j ƒ  | | d <| d 7} n
 | d 8} | d 7} q€W| | k rÕ| |  } | d  d  … d  | … f } qt j | d
 t |  j ƒ} |  j d k rt j | j ƒ } n? |  j d k r?t j t | j ƒ ƒ } n t j t | ƒ ƒ } |  j d k r| | | } | d  d  … | | f } n  |  j d k r| | |  } | d  d  … | |  f } qnÀ |  j	 | | | |  j |	 |  j
 |  j | |  j |  j |  j |  j |  j |  j |  j |  j  | ƒ \ } } } | d k rZt | d |  j ƒ‚ n  |  j d } | |  } | d  d  … d  | … f } | r| | f S| Sd  S(   Ni    R   R;   i   R   i   R-   i   y              ð?t   decimalsR$   R%   R&   R'   R   R    (   R$   R%   (   R&   R'   (   R$   R   R&   (   R%   R    R'   (!   R6   RH   R>   RB   RK   R‡   RC   Rˆ   RM   Rr   Rh   RL   RI   RA   RE   RF   Rw   Rm   Rn   R,   R   Rv   t   astypet   uppert   abst	   conjugatet   dotR_   t   conjt   roundt   _ndigitst   argsortR   (   R+   R€   R6   RH   R‚   Rƒ   R„   t   sigmart   sigmait   workevt   drt   dit   zrt	   nreturnedR   R   t   it   rdt   indRT   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyRS   ø  sœ    	$B0BB0$#)

 	$

N(   R/   R0   R=   R*   R~   RS   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR…   U  s
   x	(c         C` sH   t  |  ƒ }  t |  d ƒ sD t j |  j d ƒ } |  | j |  _ n  |  S(   Nt   dtypei   (   R	   t   hasattrR>   RB   t   shapeR¥   (   t   mR[   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   _aslinearoperator_with_dtype}  s
    t   SpLuInvc           B` s    e  Z d  Z d „  Z d „  Z RS(   sl   
    SpLuInv:
       helper class to repeatedly solve M*x=b
       using a sparse LU-decopposition of M
    c         C` sG   t  | ƒ |  _ | j |  _ | j |  _ t j |  j t j ƒ |  _ d  S(   N(   R   t   M_luR§   R¥   R>   t
   issubdtypet   complexfloatingt   isreal(   R+   t   M(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR*   ‹  s    c         C` sž   t  j | ƒ } |  j r~ t  j | j t  j ƒ r~ |  j j t  j | ƒ j	 |  j ƒ ƒ d |  j j t  j
 | ƒ j	 |  j ƒ ƒ S|  j j | j	 |  j ƒ ƒ Sd  S(   Ny              ð?(   R>   t   asarrayR®   R¬   R¥   R­   R«   t   solveR‡   R’   Rˆ   (   R+   R[   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   _matvec‘  s
    !$*(   R/   R0   R1   R*   R²   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyRª   …  s   	t   LuInvc           B` s    e  Z d  Z d „  Z d „  Z RS(   sd   
    LuInv:
       helper class to repeatedly solve M*x=b
       using an LU-decomposition of M
    c         C` s+   t  | ƒ |  _ | j |  _ | j |  _ d  S(   N(   R   R«   R§   R¥   (   R+   R¯   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR*   ¢  s    c         C` s   t  |  j | ƒ S(   N(   R   R«   (   R+   R[   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR²   §  s    (   R/   R0   R1   R*   R²   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR³   œ  s   	c         C` sZ   t  j | ƒ } d t  j | j ƒ t  j | j ƒ j } t |  | d t | | ƒ d d ƒS(   s2   
    gmres with looser termination condition.
    iè  RI   t   atoli    (	   R>   R°   t   sqrtt   sizet   finfoR¥   t   epsR   R5   (   R   t   bRI   t   min_tol(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   gmres_loose«  s    )t   IterInvc           B` s&   e  Z d  Z e d d „ Z d „  Z RS(   sb   
    IterInv:
       helper class to repeatedly solve M*x=b
       using an iterative method.
    i    c         C` s—   | |  _  t | d ƒ r' | j |  _ n& t j | j d ƒ } | | j |  _ | j |  _ | d k r d t j |  j ƒ j } n  | |  _ | |  _	 d  S(   NR¥   i   i    i   (
   R¯   R¦   R¥   R>   RB   R§   R·   R¸   t   ifuncRI   (   R+   R¯   R½   RI   R[   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR*   º  s    		c         C` sS   |  j  |  j | d |  j ƒ\ } } | d k rO t d |  j  j | f ƒ ‚ n  | S(   NRI   i    s?   Error in inverting M: function %s did not converge (info = %i).(   R½   R¯   RI   R<   R/   (   R+   R[   R¹   R,   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR²   Ê  s
    $(   R/   R0   R1   R»   R*   R²   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR¼   ´  s   t	   IterOpInvc           B` s5   e  Z d  Z e d d „ Z d „  Z e d „  ƒ Z RS(   so   
    IterOpInv:
       helper class to repeatedly solve [A-sigma*M]*x = b
       using an iterative method
    i    c   
      ` s  ˆ  |  _  ˆ |  _ ˆ |  _ ‡  ‡ ‡ f d †  } ‡  ‡ f d †  } t j ˆ  j d ƒ } ˆ d  k r” | | ƒ j }	 t |  j  j | d |	 ƒ|  _	 n- | | ƒ j }	 t |  j  j | d |	 ƒ|  _	 ˆ  j |  _ | d k rø d t j
 |  j	 j ƒ j } n  | |  _ | |  _ d  S(   Nc         ` s   ˆ  j  |  ƒ ˆ ˆ j  |  ƒ S(   N(   R_   (   R[   (   R   R¯   RC   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt	   mult_funcÞ  s    c         ` s   ˆ  j  |  ƒ ˆ |  S(   N(   R_   (   R[   (   R   RC   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   mult_func_M_Noneá  s    i   R¥   i    i   (   R   R¯   RC   R>   RB   R§   R=   R¥   R
   Rf   R·   R¸   R½   RI   (
   R+   R   R¯   RC   R½   RI   R¿   RÀ   R[   R¥   (    (   R   R¯   RC   sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR*   Ù  s(    				c         C` sS   |  j  |  j | d |  j ƒ\ } } | d k rO t d |  j  j | f ƒ ‚ n  | S(   NRI   i    sI   Error in inverting [A-sigma*M]: function %s did not converge (info = %i).(   R½   Rf   RI   R<   R/   (   R+   R[   R¹   R,   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR²   ø  s
    $c         C` s
   |  j  j S(   N(   Rf   R¥   (   R+   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR¥      s    (   R/   R0   R1   R»   R*   R²   t   propertyR¥   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR¾   Ó  s   	c         C` sg   t  |  ƒ r t |  ƒ j St |  ƒ rP t |  ƒ rC | rC |  j }  n  t |  ƒ j St |  d | ƒj Sd  S(   NRI   (   R   R³   R_   R   R   t   TRª   R¼   (   R¯   t	   symmetricRI   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   get_inv_matvec  s    c         C` sú  | d k r" t  |  d | d | ƒS| d  k r1t |  ƒ r· t j |  j t j ƒ sg t j | ƒ d k ry t j |  ƒ }  n
 |  d }  |  j	 d  d  |  j
 d d … c | 8<t |  ƒ j St |  ƒ r|  | t |  j
 d ƒ }  | rü t |  ƒ rü |  j }  n  t |  j ƒ  ƒ j St t |  ƒ | | d | ƒj SnÅ t |  ƒ rKt |  ƒ set | ƒ rŠt | ƒ rŠt t |  ƒ t | ƒ | d | ƒj St |  ƒ s¢t | ƒ r·t |  | | ƒ j S|  | | } | rãt | ƒ rã| j } n  t | j ƒ  ƒ j Sd  S(   Ni    RÃ   RI   y                i   (   RÄ   R=   R   R>   R¬   R¥   R­   Rˆ   R:   t   flatR§   R³   R_   R   R   R   RÂ   Rª   t   tocscR¾   R©   (   R   R¯   RC   RÃ   RI   Rf   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   get_OPinv_matvec  s8    
'	s@   Nested calls to eigs/eighs not allowed: ARPACK is not re-entranti   c         C` sÿ  |  j  d |  j  d k r3 t d |  j  f ƒ ‚ n  | d k	 r¹ | j  |  j  k rp t d | j  |  j  f ƒ ‚ n  t j | j ƒ j j ƒ  t j |  j ƒ j j ƒ  k r¹ t j d ƒ q¹ n  |  j  d } | d k rå t d | ƒ ‚ n  | | d k rrt j d t	 ƒ t
 |  ƒ r t d ƒ ‚ n  t |  t ƒ r>t d	 ƒ ‚ n  t | t ƒ r\t d
 ƒ ‚ n  t |  d | d |	 ƒS| d k rSt |  ƒ j } | d k	 r¨t d ƒ ‚ n  | d k	 rÃt d ƒ ‚ n  | d k rÿd } d } d } |
 d k	 rPt d ƒ ‚ qPq‘d } |
 d k r,t | d t d | ƒ} n t |
 ƒ }
 |
 j } t | ƒ j } n>t j |  j t j ƒ r| d k	 r†t d ƒ ‚ n  d } nr | d k s­| j ƒ  d k r¶d } nK | j ƒ  d k rõt j | ƒ d k rìt d ƒ ‚ n  d } n t d ƒ ‚ t |  ƒ j } |
 d k	 r+t d ƒ ‚ n  | d k rXt |  | | d t d | ƒ} n t | ƒ } | j } | d k r‚d } n t | ƒ j } t | | |  j j | | | | | | | | | | ƒ } t , x | j sç| j ƒ  qÑW| j |	 ƒ SWd QXd S(   s3  
    Find k eigenvalues and eigenvectors of the square matrix A.

    Solves ``A * x[i] = w[i] * x[i]``, the standard eigenvalue problem
    for w[i] eigenvalues with corresponding eigenvectors x[i].

    If M is specified, solves ``A * x[i] = w[i] * M * x[i]``, the
    generalized eigenvalue problem for w[i] eigenvalues
    with corresponding eigenvectors x[i]

    Parameters
    ----------
    A : ndarray, sparse matrix or LinearOperator
        An array, sparse matrix, or LinearOperator representing
        the operation ``A * x``, where A is a real or complex square matrix.
    k : int, optional
        The number of eigenvalues and eigenvectors desired.
        `k` must be smaller than N-1. It is not possible to compute all
        eigenvectors of a matrix.
    M : ndarray, sparse matrix or LinearOperator, optional
        An array, sparse matrix, or LinearOperator representing
        the operation M*x for the generalized eigenvalue problem

            A * x = w * M * x.

        M must represent a real, symmetric matrix if A is real, and must
        represent a complex, hermitian matrix if A is complex. For best
        results, the data type of M should be the same as that of A.
        Additionally:

            If `sigma` is None, M is positive definite

            If sigma is specified, M is positive semi-definite

        If sigma is None, eigs requires an operator to compute the solution
        of the linear equation ``M * x = b``.  This is done internally via a
        (sparse) LU decomposition for an explicit matrix M, or via an
        iterative solver for a general linear operator.  Alternatively,
        the user can supply the matrix or operator Minv, which gives
        ``x = Minv * b = M^-1 * b``.
    sigma : real or complex, optional
        Find eigenvalues near sigma using shift-invert mode.  This requires
        an operator to compute the solution of the linear system
        ``[A - sigma * M] * x = b``, where M is the identity matrix if
        unspecified. This is computed internally via a (sparse) LU
        decomposition for explicit matrices A & M, or via an iterative
        solver if either A or M is a general linear operator.
        Alternatively, the user can supply the matrix or operator OPinv,
        which gives ``x = OPinv * b = [A - sigma * M]^-1 * b``.
        For a real matrix A, shift-invert can either be done in imaginary
        mode or real mode, specified by the parameter OPpart ('r' or 'i').
        Note that when sigma is specified, the keyword 'which' (below)
        refers to the shifted eigenvalues ``w'[i]`` where:

            If A is real and OPpart == 'r' (default),
              ``w'[i] = 1/2 * [1/(w[i]-sigma) + 1/(w[i]-conj(sigma))]``.

            If A is real and OPpart == 'i',
              ``w'[i] = 1/2i * [1/(w[i]-sigma) - 1/(w[i]-conj(sigma))]``.

            If A is complex, ``w'[i] = 1/(w[i]-sigma)``.

    v0 : ndarray, optional
        Starting vector for iteration.
        Default: random
    ncv : int, optional
        The number of Lanczos vectors generated
        `ncv` must be greater than `k`; it is recommended that ``ncv > 2*k``.
        Default: ``min(n, max(2*k + 1, 20))``
    which : str, ['LM' | 'SM' | 'LR' | 'SR' | 'LI' | 'SI'], optional
        Which `k` eigenvectors and eigenvalues to find:

            'LM' : largest magnitude

            'SM' : smallest magnitude

            'LR' : largest real part

            'SR' : smallest real part

            'LI' : largest imaginary part

            'SI' : smallest imaginary part

        When sigma != None, 'which' refers to the shifted eigenvalues w'[i]
        (see discussion in 'sigma', above).  ARPACK is generally better
        at finding large values than small values.  If small eigenvalues are
        desired, consider using shift-invert mode for better performance.
    maxiter : int, optional
        Maximum number of Arnoldi update iterations allowed
        Default: ``n*10``
    tol : float, optional
        Relative accuracy for eigenvalues (stopping criterion)
        The default value of 0 implies machine precision.
    return_eigenvectors : bool, optional
        Return eigenvectors (True) in addition to eigenvalues
    Minv : ndarray, sparse matrix or LinearOperator, optional
        See notes in M, above.
    OPinv : ndarray, sparse matrix or LinearOperator, optional
        See notes in sigma, above.
    OPpart : {'r' or 'i'}, optional
        See notes in sigma, above

    Returns
    -------
    w : ndarray
        Array of k eigenvalues.
    v : ndarray
        An array of `k` eigenvectors.
        ``v[:, i]`` is the eigenvector corresponding to the eigenvalue w[i].

    Raises
    ------
    ArpackNoConvergence
        When the requested convergence is not obtained.
        The currently converged eigenvalues and eigenvectors can be found
        as ``eigenvalues`` and ``eigenvectors`` attributes of the exception
        object.

    See Also
    --------
    eigsh : eigenvalues and eigenvectors for symmetric matrix A
    svds : singular value decomposition for a matrix A

    Notes
    -----
    This function is a wrapper to the ARPACK [1]_ SNEUPD, DNEUPD, CNEUPD,
    ZNEUPD, functions which use the Implicitly Restarted Arnoldi Method to
    find the eigenvalues and eigenvectors [2]_.

    References
    ----------
    .. [1] ARPACK Software, http://www.caam.rice.edu/software/ARPACK/
    .. [2] R. B. Lehoucq, D. C. Sorensen, and C. Yang,  ARPACK USERS GUIDE:
       Solution of Large Scale Eigenvalue Problems by Implicitly Restarted
       Arnoldi Methods. SIAM, Philadelphia, PA, 1998.

    Examples
    --------
    Find 6 eigenvectors of the identity matrix:

    >>> from scipy.sparse.linalg import eigs
    >>> id = np.eye(13)
    >>> vals, vecs = eigs(id, k=6)
    >>> vals
    array([ 1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j])
    >>> vecs.shape
    (13, 6)

    i    i   s!   expected square matrix (shape=%s)s#   wrong M dimensions %s, should be %ssZ   M does not have the same type precision as A. This may adversely affect ARPACK convergences   k=%d must be greater than 0.sO   k >= N - 1 for N * N square matrix. Attempting to use scipy.linalg.eig instead.sh   Cannot use scipy.linalg.eig for sparse A with k >= N - 1. Use scipy.linalg.eig(A.toarray()) or reduce k.sA   Cannot use scipy.linalg.eig for LinearOperator A with k >= N - 1.sA   Cannot use scipy.linalg.eig for LinearOperator M with k >= N - 1.R¹   t   rights0   OPinv should not be specified with sigma = None.s=   OPpart should not be specified with sigma = None or complex As+   Minv should not be specified with M = None.i   RÃ   RI   s;   OPpart should not be specified with sigma=None or complex Ai   t   rR¢   s%   OPpart cannot be 'i' if sigma is reali   s   OPpart must be one of ('r','i')s*   Minv should not be specified when sigma isN(   R§   R<   R=   R>   R¥   t   charRŽ   t   warningst   warnt   RuntimeWarningR   t	   TypeErrort
   isinstanceR
   R   R©   R_   RÄ   R@   R¬   R­   Rˆ   RÇ   RN   R…   t   _ARPACK_LOCKRO   R~   RS   (   R   R6   R¯   RC   RL   RQ   RK   RJ   RI   R€   t   Minvt   OPinvt   OPpartRH   R_   RG   Ra   R^   t   params(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR   ;  sˆ    ™6								t   normalc         C` s-  t  j |  j t  j ƒ rì | d k r7 t d | ƒ ‚ n  | d k rR t d ƒ ‚ n* | d k rg d } n | d k r| d } n  t |  | d	 | d
 | d | d | d | d | d | d |	 d |
 d | ƒ
} |	 râ | d j | d f S| j Sn  |  j d |  j d k rt d |  j f ƒ ‚ n  | d* k	 r¥| j |  j k r\t d | j |  j f ƒ ‚ n  t  j | j ƒ j	 j
 ƒ  t  j |  j ƒ j	 j
 ƒ  k r¥t j d ƒ q¥n  |  j d } | d k rÍt d ƒ ‚ n  | | k rWt j d t ƒ t |  ƒ rt d ƒ ‚ n  t |  t ƒ r"t d ƒ ‚ n  t | t ƒ r@t d ƒ ‚ n  t |  d | d |	 ƒS| d* k r#t |  ƒ }  |  j } | d* k	 r“t d ƒ ‚ n  | d* k rÏd } d* } d* } |
 d* k	 r t d  ƒ ‚ q q¿d! } |
 d* k rüt | d" t d | ƒ} n t |
 ƒ }
 |
 j } t | ƒ j } nœ|
 d* k	 r>t d# ƒ ‚ n  | d k rÅd$ } d* } | d* k rƒt |  | | d" t d | ƒ} n t | ƒ } | j } | d* k r­d* } q¿t | ƒ } | j } nú | d% k r+d& } | d* k rt |  | | d" t d | ƒ} n t | ƒ j } t |  ƒ j } d* } n” | d' k r¯d( } t |  ƒ j } | d* k ryt |  | | d" t d | ƒ} n t | ƒ j } | d* k rd* } q¿t | ƒ j } n t d) | ƒ ‚ t | | |  j j	 | | | | | | | | | | ƒ } t , x | j s| j ƒ  qÿW| j |	 ƒ SWd* QXd* S(+   sž  
    Find k eigenvalues and eigenvectors of the real symmetric square matrix
    or complex hermitian matrix A.

    Solves ``A * x[i] = w[i] * x[i]``, the standard eigenvalue problem for
    w[i] eigenvalues with corresponding eigenvectors x[i].

    If M is specified, solves ``A * x[i] = w[i] * M * x[i]``, the
    generalized eigenvalue problem for w[i] eigenvalues
    with corresponding eigenvectors x[i].

    Parameters
    ----------
    A : ndarray, sparse matrix or LinearOperator
        A square operator representing the operation ``A * x``, where ``A`` is
        real symmetric or complex hermitian. For buckling mode (see below)
        ``A`` must additionally be positive-definite.
    k : int, optional
        The number of eigenvalues and eigenvectors desired.
        `k` must be smaller than N. It is not possible to compute all
        eigenvectors of a matrix.

    Returns
    -------
    w : array
        Array of k eigenvalues.
    v : array
        An array representing the `k` eigenvectors.  The column ``v[:, i]`` is
        the eigenvector corresponding to the eigenvalue ``w[i]``.

    Other Parameters
    ----------------
    M : An N x N matrix, array, sparse matrix, or linear operator representing
        the operation ``M @ x`` for the generalized eigenvalue problem

            A @ x = w * M @ x.

        M must represent a real, symmetric matrix if A is real, and must
        represent a complex, hermitian matrix if A is complex. For best
        results, the data type of M should be the same as that of A.
        Additionally:

            If sigma is None, M is symmetric positive definite.

            If sigma is specified, M is symmetric positive semi-definite.

            In buckling mode, M is symmetric indefinite.

        If sigma is None, eigsh requires an operator to compute the solution
        of the linear equation ``M @ x = b``. This is done internally via a
        (sparse) LU decomposition for an explicit matrix M, or via an
        iterative solver for a general linear operator.  Alternatively,
        the user can supply the matrix or operator Minv, which gives
        ``x = Minv @ b = M^-1 @ b``.
    sigma : real
        Find eigenvalues near sigma using shift-invert mode.  This requires
        an operator to compute the solution of the linear system
        ``[A - sigma * M] x = b``, where M is the identity matrix if
        unspecified.  This is computed internally via a (sparse) LU
        decomposition for explicit matrices A & M, or via an iterative
        solver if either A or M is a general linear operator.
        Alternatively, the user can supply the matrix or operator OPinv,
        which gives ``x = OPinv @ b = [A - sigma * M]^-1 @ b``.
        Note that when sigma is specified, the keyword 'which' refers to
        the shifted eigenvalues ``w'[i]`` where:

            if mode == 'normal', ``w'[i] = 1 / (w[i] - sigma)``.

            if mode == 'cayley', ``w'[i] = (w[i] + sigma) / (w[i] - sigma)``.

            if mode == 'buckling', ``w'[i] = w[i] / (w[i] - sigma)``.

        (see further discussion in 'mode' below)
    v0 : ndarray, optional
        Starting vector for iteration.
        Default: random
    ncv : int, optional
        The number of Lanczos vectors generated ncv must be greater than k and
        smaller than n; it is recommended that ``ncv > 2*k``.
        Default: ``min(n, max(2*k + 1, 20))``
    which : str ['LM' | 'SM' | 'LA' | 'SA' | 'BE']
        If A is a complex hermitian matrix, 'BE' is invalid.
        Which `k` eigenvectors and eigenvalues to find:

            'LM' : Largest (in magnitude) eigenvalues.

            'SM' : Smallest (in magnitude) eigenvalues.

            'LA' : Largest (algebraic) eigenvalues.

            'SA' : Smallest (algebraic) eigenvalues.

            'BE' : Half (k/2) from each end of the spectrum.

        When k is odd, return one more (k/2+1) from the high end.
        When sigma != None, 'which' refers to the shifted eigenvalues ``w'[i]``
        (see discussion in 'sigma', above).  ARPACK is generally better
        at finding large values than small values.  If small eigenvalues are
        desired, consider using shift-invert mode for better performance.
    maxiter : int, optional
        Maximum number of Arnoldi update iterations allowed.
        Default: ``n*10``
    tol : float
        Relative accuracy for eigenvalues (stopping criterion).
        The default value of 0 implies machine precision.
    Minv : N x N matrix, array, sparse matrix, or LinearOperator
        See notes in M, above.
    OPinv : N x N matrix, array, sparse matrix, or LinearOperator
        See notes in sigma, above.
    return_eigenvectors : bool
        Return eigenvectors (True) in addition to eigenvalues. This value determines
        the order in which eigenvalues are sorted. The sort order is also dependent on the `which` variable.

            For which = 'LM' or 'SA':
                If `return_eigenvectors` is True, eigenvalues are sorted by algebraic value.

                If `return_eigenvectors` is False, eigenvalues are sorted by absolute value.

            For which = 'BE' or 'LA':
                eigenvalues are always sorted by algebraic value.

            For which = 'SM':
                If `return_eigenvectors` is True, eigenvalues are sorted by algebraic value.

                If `return_eigenvectors` is False, eigenvalues are sorted by decreasing absolute value.

    mode : string ['normal' | 'buckling' | 'cayley']
        Specify strategy to use for shift-invert mode.  This argument applies
        only for real-valued A and sigma != None.  For shift-invert mode,
        ARPACK internally solves the eigenvalue problem
        ``OP * x'[i] = w'[i] * B * x'[i]``
        and transforms the resulting Ritz vectors x'[i] and Ritz values w'[i]
        into the desired eigenvectors and eigenvalues of the problem
        ``A * x[i] = w[i] * M * x[i]``.
        The modes are as follows:

            'normal' :
                OP = [A - sigma * M]^-1 @ M,
                B = M,
                w'[i] = 1 / (w[i] - sigma)

            'buckling' :
                OP = [A - sigma * M]^-1 @ A,
                B = A,
                w'[i] = w[i] / (w[i] - sigma)

            'cayley' :
                OP = [A - sigma * M]^-1 @ [A + sigma * M],
                B = M,
                w'[i] = (w[i] + sigma) / (w[i] - sigma)

        The choice of mode will affect which eigenvalues are selected by
        the keyword 'which', and can also impact the stability of
        convergence (see [2] for a discussion).

    Raises
    ------
    ArpackNoConvergence
        When the requested convergence is not obtained.

        The currently converged eigenvalues and eigenvectors can be found
        as ``eigenvalues`` and ``eigenvectors`` attributes of the exception
        object.

    See Also
    --------
    eigs : eigenvalues and eigenvectors for a general (nonsymmetric) matrix A
    svds : singular value decomposition for a matrix A

    Notes
    -----
    This function is a wrapper to the ARPACK [1]_ SSEUPD and DSEUPD
    functions which use the Implicitly Restarted Lanczos Method to
    find the eigenvalues and eigenvectors [2]_.

    References
    ----------
    .. [1] ARPACK Software, http://www.caam.rice.edu/software/ARPACK/
    .. [2] R. B. Lehoucq, D. C. Sorensen, and C. Yang,  ARPACK USERS GUIDE:
       Solution of Large Scale Eigenvalue Problems by Implicitly Restarted
       Arnoldi Methods. SIAM, Philadelphia, PA, 1998.

    Examples
    --------
    >>> from scipy.sparse.linalg import eigsh
    >>> identity = np.eye(13)
    >>> eigenvalues, eigenvectors = eigsh(identity, k=6)
    >>> eigenvalues
    array([1., 1., 1., 1., 1., 1.])
    >>> eigenvectors.shape
    (13, 6)

    RÕ   s,   mode=%s cannot be used with complex matrix AR#   s/   which='BE' cannot be used with complex matrix AR!   R$   R"   R%   R¯   RC   RL   RQ   RK   RJ   RI   R€   RÑ   RÒ   i    i   s!   expected square matrix (shape=%s)s#   wrong M dimensions %s, should be %ssZ   M does not have the same type precision as A. This may adversely affect ARPACK convergences   k must be greater than 0.sL   k >= N for N * N square matrix. Attempting to use scipy.linalg.eigh instead.sf   Cannot use scipy.linalg.eigh for sparse A with k >= N. Use scipy.linalg.eigh(A.toarray()) or reduce k.s>   Cannot use scipy.linalg.eigh for LinearOperator A with k >= N.s>   Cannot use scipy.linalg.eigh for LinearOperator M with k >= N.R¹   t   eigvals_onlys0   OPinv should not be specified with sigma = None.s+   Minv should not be specified with M = None.i   RÃ   s*   Minv should not be specified when sigma isi   t   bucklingi   t   cayleyi   s   unrecognized mode '%s'N(   R>   R¬   R¥   R­   R<   R   R‡   R§   R=   RÊ   RŽ   RË   RÌ   RÍ   R   RÎ   RÏ   R
   R   R©   R_   RÄ   R@   RÇ   RZ   RÐ   RO   R~   RS   (   R   R6   R¯   RC   RL   RQ   RK   RJ   RI   R€   RÑ   RÒ   RG   t   retRH   R_   Ra   R^   RÔ   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR   9  s¾    Å		$	
6								c   	      C` sL  |  j  \ } } t j | | | f d |  j ƒ} |  | d  d  … d  | … f <xø t | ƒ D]ê } t j j | ƒ } t j |  ƒ rž | d t j j | ƒ } n  xd t | | ƒ D]R } | d  d  … | f } | t j | | j	 ƒ  ƒ t j | | j	 ƒ  ƒ | 8} q¯ W| t j
 t j | | j	 ƒ  ƒ ƒ } | | d  d  … | | f <qZ W| S(   NR¥   y              ð?(   R§   R>   t   emptyR¥   t   ranget   randomt   randnt   iscomplexobjR–   R—   Rµ   (	   R[   R6   RH   R¨   t   yR¢   RE   t   jt   u(    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   _augmented_orthonormal_colsˆ  s    ":%c         C` s   t  |  j | ƒ j S(   N(   Râ   RÂ   (   R[   R6   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   _augmented_orthonormal_rows   s    c         C` s   |  j  j ƒ  S(   N(   RÂ   R—   (   R[   (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   _herm¤  s    c         ` s2  t  ˆ  t ƒ p t ˆ  ƒ s- t j ˆ  ƒ ‰  n  ˆ  j \ } ‰ | d k s] | t | ˆ ƒ k rp t d | ƒ ‚ n  t  ˆ  t ƒ r| ˆ k r© ˆ  j ‰ ˆ  j	 }	 ˆ  j
 ‰ q\ˆ  j
 ‰ ˆ  j ‰ t ˆ  d d ƒ ‰ ˆ d k rý ˆ  j t j ˆ d g ƒ ƒ j ‰ n  ‡  ‡ ‡ f d †  }	 nG | ˆ k r@ˆ  j ‰ }	 t ˆ  ƒ j ‰ n ˆ  j ‰ t ˆ  ƒ j ‰ }	 ‡ ‡ f d †  }
 t d |
 d ˆ  j d t ˆ  j ƒ t ˆ  j ƒ f ƒ } t | d	 | d
 | d d | d | d | d | ƒ\ } } | d k r€t j | j d ƒ } | j j j ƒ  } i d d 6d d 6} | | t j | ƒ j } | t j | ƒ } | | k } | j ƒ  } | | } t j | | ƒ } t j | ƒ } | | | *| sª| S| ˆ k rý| d d … | f } | d k rè|	 | ƒ | n d } t | ƒ } n> | d d … | f } | d k r5t |	 | ƒ | ƒ n d } | d k	 rVt | | ƒ n d } | d k	 rwt | | ƒ n d } n¥ | d k rt j | ƒ } | s¥| S| ˆ k rè| } | d k rÓ|	 | ƒ | n d } t | ƒ } q%| } | d k rt |	 | ƒ | ƒ n d } n t d ƒ ‚ | | | f S(   s
  Compute the largest k singular values/vectors for a sparse matrix.

    Parameters
    ----------
    A : {sparse matrix, LinearOperator}
        Array to compute the SVD on, of shape (M, N)
    k : int, optional
        Number of singular values and vectors to compute.
        Must be 1 <= k < min(A.shape).
    ncv : int, optional
        The number of Lanczos vectors generated
        ncv must be greater than k+1 and smaller than n;
        it is recommended that ncv > 2*k
        Default: ``min(n, max(2*k + 1, 20))``
    tol : float, optional
        Tolerance for singular values. Zero (default) means machine precision.
    which : str, ['LM' | 'SM'], optional
        Which `k` singular values to find:

            - 'LM' : largest singular values
            - 'SM' : smallest singular values

        .. versionadded:: 0.12.0
    v0 : ndarray, optional
        Starting vector for iteration, of length min(A.shape). Should be an
        (approximate) left singular vector if N > M and a right singular
        vector otherwise.
        Default: random

        .. versionadded:: 0.12.0
    maxiter : int, optional
        Maximum number of iterations.

        .. versionadded:: 0.12.0
    return_singular_vectors : bool or str, optional
        - True: return singular vectors (True) in addition to singular values.

        .. versionadded:: 0.12.0

        - "u": only return the u matrix, without computing vh (if N > M).
        - "vh": only return the vh matrix, without computing u (if N <= M).

        .. versionadded:: 0.16.0

    Returns
    -------
    u : ndarray, shape=(M, k)
        Unitary matrix having left singular vectors as columns.
        If `return_singular_vectors` is "vh", this variable is not computed,
        and None is returned instead.
    s : ndarray, shape=(k,)
        The singular values.
    vt : ndarray, shape=(k, N)
        Unitary matrix having right singular vectors as rows.
        If `return_singular_vectors` is "u", this variable is not computed,
        and None is returned instead.


    Notes
    -----
    This is a naive implementation using ARPACK as an eigensolver
    on A.H * A or A * A.H, depending on which one is more efficient.

    Examples
    --------
    >>> from scipy.sparse import csc_matrix
    >>> from scipy.sparse.linalg import svds, eigs
    >>> A = csc_matrix([[1, 0, 0], [5, 0, 2], [0, -1, 0], [0, 0, 3]], dtype=float)
    >>> u, s, vt = svds(A, k=2)
    >>> s
    array([ 2.75193379,  5.6059665 ])
    >>> np.sqrt(eigs(A.dot(A.T), k=2)[0]).real
    array([ 5.6059665 ,  2.75193379])
    i    s*   k must be between 1 and min(A.shape), k=%dR¥   i   c         ` sw   t  j |  j d ˆ f d ˆ ƒ} xK t |  j ƒ D]: \ } } ˆ  j | j d d ƒ ƒ j | | d  d  … f <q2 W| j S(   Ni   R¥   iÿÿÿÿ(   R>   RÚ   R§   t	   enumerateRÂ   t   rmatvect   reshape(   t   Vt   outR¢   t   col(   R   R¥   R¨   (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   X_matmat  s    "2c         ` s   ˆ  ˆ |  ƒ ƒ S(   N(    (   R[   (   t   XH_dott   X_dot(    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   matvec_XH_X  s    R_   R§   R6   RI   i   RJ   RK   RL   RQ   R   g     @@R   g    €„.AR   Nt   vhRá   R    s"   which must be either 'LM' or 'SM'.(   RÏ   R
   R   R>   R°   R§   RD   R<   R_   t   matmatRæ   t   getattrR=   R–   RB   R¥   Rä   R   t   maximumR‡   RÊ   RŽ   R·   R¸   R5   t   sumRµ   t
   zeros_likeRâ   Rã   (   R   R6   RK   RI   RL   RQ   RJ   t   return_singular_vectorsRH   Rë   Rî   t   XH_Xt   eigvalst   eigvect   tt   factort   condt   cutofft   above_cutofft   nlarget   nsmallt   slargeR   t   vlarget   ularget   vhlargeRá   Rï   RE   (    (   R   Rì   Rí   R¥   R¨   sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyR   ¨  sx    L!				$	!

"(!$"+(Q   R1   t
   __future__R    R   R   t   __docformat__t   __all__t    R   t   numpyR>   RË   t   scipy.sparse.linalg.interfaceR	   R
   t   scipy.sparseR   R   R   R   t   scipy.linalgR   R   R   R   t   scipy.sparse.sputilsR   t   scipy.sparse.linalgR   R   t   scipy._lib._utilR   t   scipy._lib._threadsafetyR   Ro   R™   t   DNAUPD_ERRORSt   SNAUPD_ERRORSR:   t   ZNAUPD_ERRORSt   CNAUPD_ERRORSt   DSAUPD_ERRORSt   SSAUPD_ERRORSt   DNEUPD_ERRORSt   SNEUPD_ERRORSt   ZNEUPD_ERRORSt   CNEUPD_ERRORSt   DSEUPD_ERRORSt   SSEUPD_ERRORSRs   R2   Ru   R   Rk   RŒ   R)   R   R   R7   t   objectR8   RZ   R…   R©   Rª   R³   R»   R¼   R¾   RN   RÄ   RÇ   RÐ   R=   R@   R   R   Râ   Rã   Rä   R   (    (    (    sF   lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.pyt   <module>   s@   """"





















		FÚÿ )			2'üÿ N			