
    -i                    J   S r SSKrSSKrSSKJrJr  SSKJrJ	r	  SSK
JrJrJrJr  SSKJrJrJr  SSKJrJr  SSKJr  SS	KJr  S
SKJr  \R8                  R:                  R<                  rSr / SQr!SSSSS.r"SSSSS.r#0 SS_S
S_SS_SS_SS_SS_SS _S!S"_S#S$_S%S&_S'S(_S)S*_S+S,_S-S._S/S0_S1S2_S3S4_S5S60Er$\$r%\$RM                  5       r'S7\'S-'   \'r(0 SS_S
S8_SS_SS_SS_SS_SS9_S!S"_S#S:_S%S&_S'S(_S)S;_S+S,_S-S<_S/S0_S1S2_S3S=_S5S60Er)\)r*0 SS_S
S>_SS_SS_SS _S#S?_S%S&_S'S@_S)SA_S+SB_S-S._S/S0_S1SC_S3SD_SESF_SGSH_r+\+RM                  5       r,SI\,S
'   SJ\,SE'   SK\,SG'   0 SS_S
SL_SS_SS_SSM_S#S?_S%S&_S'S@_S)SN_S+SO_S-SP_S/S0_S1SC_S3SD_SESQ_SGSR_r-\-RM                  5       r.SS\.SE'   ST\.SG'   0 SS_SS_SS_SS9_S#S:_S%S&_S'S@_S)SU_S+S,_S-S<_S/S0_S1S4_SESV_SGSW_SXSC_SYSZ_r/\/RM                  5       r0S[\0SE'   S\\0SY'   \)\*S].r1\$\%\'\(S^.r2\/\0S].r3\+\,\-\.S^.r4/ S_Qr5/ S`Qr6 " Sa Sb\75      r8 " Sc Sd\85      r9Se r: " Sf Sg5      r; " Sh Si\;5      r< " Sj Sk\;5      r= " Sl Sm\5      r> " Sn So\5      r?Sp r@ " Sq Sr\5      rA " Ss St\5      rBS{Su jrCS|Sv jrDS|Sw jrE\" Sx5      rF   S}Sy jrG   S~Sz jrHg)zn
Find a few eigenvectors and eigenvalues of a matrix.


Uses ARPACK: https://github.com/opencollab/arpack-ng

    N)aslinearoperatorLinearOperator)eyeissparse)eigeigh	lu_factorlu_solve)convert_pydata_sparse_to_scipyisdenseis_pydata_spmatrix)gmressplu)_aligned_zeros)ReentrancyLock   )_arpackzrestructuredtext en)eigseigshArpackErrorArpackNoConvergencesdcz)fr   FD      zNormal exit.zMaximum number of iterations taken. All possible eigenvalues of OP has been found. IPARAM(5) returns the number of wanted converged Ritz values.   zONo longer an informational error. Deprecated starting with release 2 of ARPACK.   zNo 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. zN must be positive.zNEV must be positive.z)NCV-NEV >= 2 and less than or equal to N.zRThe maximum number of Arnoldi update iterations allowed must be greater than zero.z8 WHICH must be one of 'LM', 'SM', 'LR', 'SR', 'LI', 'SI'izBMAT must be one of 'I' or 'G'.iz5Length of private work array WORKL is not sufficient.iz0Error return from LAPACK eigenvalue calculation;izStarting vector is zero.izIPARAM(7) must be 1,2,3,4.iz.IPARAM(7) = 1 and BMAT = 'G' are incompatible.iz"IPARAM(1) must be equal to 0 or 1.iz&NEV and WHICH = 'BE' are incompatible.izCould 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.zIPARAM(7) must be 1,2,3.zRMaximum number of iterations taken. All possible eigenvalues of OP has been found.z9NCV must be greater than NEV and less than or equal to N.z4WHICH must be one of 'LM', 'SM', 'LA', 'SA' or 'BE'.z`Error return from trid. eigenvalue calculation; Informational error from LAPACK routine dsteqr .zIPARAM(7) must be 1,2,3,4,5.z'NEV and WHICH = 'BE' are incompatible. as  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.z7WHICH must be one of 'LM', 'SM', 'LR', 'SR', 'LI', 'SI'z5Length of private work WORKL array is not sufficient.zdError return from calculation of a real Schur form. Informational error from LAPACK routine dlahqr .z^Error return from calculation of eigenvectors. Informational error from LAPACK routine dtrevc.z HOWMNY = 'S' not yet implementedz1HOWMNY must be one of 'A' or 'P' if RVEC = .true.iz<DNAUPD  did not find any eigenvalues to sufficient accuracy.izDNEUPD 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 DNEUPDav  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.z;SNAUPD did not find any eigenvalues to sufficient accuracy.zSNEUPD 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 SNEUPDak  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.z)NCV-NEV >= 1 and less than or equal to N.zLError return from LAPACK eigenvalue calculation. This should never happened.z^Error return from calculation of eigenvectors. Informational error from LAPACK routine ztrevc.zIPARAM(7) must be 1,2,3z;ZNAUPD did not find any eigenvalues to sufficient accuracy.zZNEUPD 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 ZNEUPDz;CNAUPD did not find any eigenvalues to sufficient accuracy.zCNEUPD 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 CNEUPDz]Error return from trid. eigenvalue calculation; Information error from LAPACK routine dsteqr.z<DSAUPD  did not find any eigenvalues to sufficient accuracy.z1HOWMNY must be one of 'A' or 'S' if RVEC = .true.iizDSEUPD  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.z<SSAUPD  did not find any eigenvalues to sufficient accuracy.zSSEUPD  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.)r   r   )r   r   r   r   )LMSMLASABE)r(   r)   LRSRLISIc                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   i  z
ARPACK error
c                 f   > Uc  [         nUR                  US5      n[        TU ]  SU SU 35        g )NzUnknown errorzARPACK error z: )_NAUPD_ERRORSgetsuper__init__)selfinfoinfodictmsg	__class__s       [/var/www/html/venv/lib/python3.13/site-packages/scipy/sparse/linalg/_eigen/arpack/arpack.pyr6   ArpackError.__init__  s8    $Hll41=b67     N)__name__
__module____qualname____firstlineno____doc__r6   __static_attributes____classcell__)r;   s   @r<   r   r     s    8 8r>   r   c                       \ rS rSrSrS rSrg)r   i   z
ARPACK iteration did not converge

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

c                 N    [         R                  U SSU05        X l        X0l        g )Nr#   )r   r6   eigenvalueseigenvectors)r7   r:   rJ   rK   s       r<   r6   ArpackNoConvergence.__init__-  s$    T2Cy1&(r>   )rJ   rK   N)rA   rB   rC   rD   rE   r6   rF   r?   r>   r<   r   r      s    
)r>   r   c                 &    [        SU -  S-   S5      $ )zm
Choose number of lanczos vectors based on target number
of singular/eigen values and vectors to compute, k.
r!   r      )max)ks    r<   
choose_ncvrQ   3  s    
 q1uqy"r>   c                   (    \ rS rSr  SS jrS rSrg)_ArpackParamsi;  Nc                 
   US::  a  [        SU 35      eUc  US-  nUS::  a  [        SU 35      eUS;  a*  [        R                  " US5      (       a  SnO[        S5      eUb  [        R                  " USS	9U l        S
nO[        R
                  " X5      U l        SnUc  SU l        OXPl        Uc  [        U5      n[        Xa5      n[        R
                  " X4U5      U l	        [        R
                  " S[        5      U l        S
nX@l        XR                  S'   XR                  S'   S
U R                  S'   X@R                  S'   Xl        Xl        X l        Xl        X`l        Xl        X0l        Xl        SU l        SU l        g )Nr   zk must be positive, k=
   z"maxiter must be positive, maxiter=fdFDr   z)matrix type must be 'f', 'd', 'F', or 'D'T)copyr      r!   r"      F)
ValueErrornpcan_castarrayresidzerossigmarQ   minv
arpack_intiparammodentolrP   maxiterncvwhichtpr8   	convergedido)r7   rf   rP   rk   re   r`   ri   v0rh   rj   rg   r8   ishftss                r<   r6   _ArpackParams.__init__<  s^   65aS9::?"fGa<A'KLLV{{2s## !LMM>"40DJD !DJD=DJJ;Q-C#k1(B'hhr:. 	A AAA
	r>   c                 P   SnU R                   S   nU R                   S   n U R                  S5      u  pE[        XX R                  4-  XE5      e! [         aL  nU SU S3n[        R                  " S5      n[        R                  " U R
                  S45      nSn S nANkS nAff = f)	Nz<No convergence (%d iterations, %d/%d eigenvectors converged)   r!   Tz [])r   r   )rd   extractr   r[   r_   rf   r   rP   )r7   r:   k_oknum_iterevvecerrs          r<   _raise_no_convergence#_ArpackParams._raise_no_convergencew  s    L{{1~;;q>	ll4(GB "#4(@"@"JJ  	EC5"C$B((DFFA;'CD		s   A 
B%AB  B%)rl   rm   r8   rd   rP   rh   re   rf   ri   r^   r`   rg   rk   rb   rj   )r   NNNNr(   r   )rA   rB   rC   rD   r6   rz   rF   r?   r>   r<   rS   rS   ;  s    /3BC9vKr>   rS   c                   0    \ rS rSr   SS jrS rS rSrg)_SymmetricArpackParamsi  Nc                   ^ ^^^^ US:X  aB  Tc  [        S5      eTb  [        S5      eTb  [        S5      eTT l        S T l        ST l        GOUS:X  aT  Tc  [        S5      eTc  [        S	5      eTc  [        S
5      eUU4S jT l        TT l        TT l        TT l        ST l        GO3US:X  a_  Tb  [        S5      eTc  [        S5      eTc  TT l        TT l        S T l        ST l        OUU4S jT l        TT l        TT l        ST l        OUS:X  aL  Tc  [        S5      eTb  [        S5      eTc  [        S5      eTT l        UU 4S jT l        TT l        ST l        O|US:X  ag  Tc  [        S5      eTc  [        S5      eTT l        TT l        Tc  UUU4S jT l        S T l        ST l        O,UUUU4S jT l        TT l        ST l        O[        SU S35      eU[        ;  a!  [        SS R                  [        5       35      eX!:  a  [        S!U 35      e[        R                  T XX5TXXU5        T R                  U:  d  T R                  U::  a  [        S"T R                   35      e[        SU-  T R                  5      T l        [        T R                  T R                  S#-   -  T R                  5      T l        [         T R                     nUS$;  a  [        S%5      e["        R$                  US&-      T l        ["        R$                  US'-      T l        [*        U   T l        [.        U   T l        [2        R4                  " S([6        5      T l        g ))Nr   #matvec must be specified for mode=1'M_matvec cannot be specified for mode=1*Minv_matvec cannot be specified for mode=1c                     U $ r@   r?   xs    r<   <lambda>1_SymmetricArpackParams.__init__.<locals>.<lambda>      qr>   Ir!   #matvec must be specified for mode=2%M_matvec must be specified for mode=2(Minv_matvec must be specified for mode=2c                     > T" T" U 5      5      $ r@   r?   r   Minv_matvecmatvecs    r<   r   r         F1I 6r>   Gr"   z'matvec must not be specified for mode=3z(Minv_matvec must be specified for mode=3c                     U $ r@   r?   r   s    r<   r   r         1r>   c                     > T" T" U 5      5      $ r@   r?   )r   M_matvecr   s    r<   r   r     s    K$<r>   rr   z#matvec must be specified for mode=4z)M_matvec must not be specified for mode=4z(Minv_matvec must be specified for mode=4c                 2   > TR                  T" U 5      5      $ r@   OPa)r   r   r7   s    r<   r   r     s     3r>   r   z#matvec must be specified for mode=5z(Minv_matvec must be specified for mode=5c                 ,   > T" T" U 5      TU -  -   5      $ r@   r?   )r   r   r   r`   s    r<   r   r     s    Kq	EAI0E$Fr>   c                     U $ r@   r?   r   s    r<   r   r     r   r>   c                 8   > T" T" U 5      TT" U 5      -  -   5      $ r@   r?   )r   r   r   r   r`   s    r<   r   r     s#    Kq	27(1+2E1F %Gr>   mode= not implementedzwhich must be one of  zk must be less than ndim(A), k=zncv must be k<ncv<=n, ncv=   )r   r   z Input matrix is not real-valued.saupdseupdrX   )rZ   OPBbmatr   OPbA_matvec_SEUPD_WHICHjoinrS   r6   ri   r   rk   workdworkl
_type_convr   __dict___arpack_solver_arpack_extract_SAUPD_ERRORSiterate_infodict_SEUPD_ERRORSextract_infodictr[   r_   rc   ipntrr7   rf   rP   rk   r   re   r   r   r`   ri   rn   rh   rj   rg   ltrs   `   ` ```      r<   r6   _SymmetricArpackParams.__init__  s6   l 19~ !FGG# !JKK& !MNNDG DFDIQY~ !FGG !HII" !KLL6DG"DHDHDFDIQY! !JKK" !KLL%&$	<&!	QY~ !FGG# !LMM" !KLL"DH3DGDFDIQY~ !FGG" !KLL"DH"DMF$	G!	uTF*:;<<$4SXXl5K4LMNN6>qcBCCtQ2U"	= 88a<488q=9$((DEE $AE4773
#DHH1$=twwG
!j ?@@%..sW}=&//g> -c 2 -c 2XXb*-
r>   c                    U R                  U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  5      u  U l        U l        U l        U l        U l        U l	        U l        [        U R                  S   S-
  U R                  S   S-
  U R                  -   5      n[        U R                  S   S-
  U R                  S   S-
  U R                  -   5      nU R                  S:X  a,  U R                  U R                  U   5      U R                  U'   g U R                  S:X  Ga  U R                   S:X  a,  U R                  U R                  U   5      U R                  U'   g U R                   S:X  aW  U R#                  U R                  U   5      U R                  U'   U R%                  U R                  U   5      U R                  U'   g U R                   S:X  a  [        U R                  S   S-
  U R                  S   S-
  U R                  -   5      nU R'                  U R                  U   5      nU R%                  X@R(                  U R                  U   -  -   5      U R                  U'   g [        U R                  S   S-
  U R                  S   S-
  U R                  -   5      nU R%                  U R                  U   5      U R                  U'   g U R                  S:X  a,  U R+                  U R                  U   5      U R                  U'   g U R                  S:X  a  [-        S5      eSU l        U R                  S:X  a  g U R                  S:X  a  U R1                  5         g [3        U R                  U R4                  S	9e)
Nr   r   r#   r!   r   r"   /ARPACK requested user shifts.  Assure ISHIFT==0Tr9   )r   rm   r   rj   rP   rg   r^   rb   rd   r   r   r   r8   slicerf   r   re   r   r   r   r`   r   rZ   rl   rz   r   r   )r7   xsliceysliceBxsliceAxs        r<   iterate_SymmetricArpackParams.iterate  s   $))TZZ $$**dffdkk $

DJJ

DIIO 	S$(DJTZ
 tzz!}q($**Q-!*;dff*DEtzz!}q($**Q-!*;dff*DE88r>!%F);!<DJJvXX]yyA~%)WWTZZ-?%@

6"a%)XXdjj.@%A

6"%)XXdjj.@%A

6"a

1 14::a=13Dtvv3MN]]4::f#56%)XXbJJ48JJw4G5H /I &J

6"  

1 14::a=13Dtvv3MN%)XXdjj.A%B

6"XX]!%

6(:!;DJJvXX]NOO!DNyyA~a**,!$))d6K6KLLr>   c                    UnSnSn[         R                  " U R                  S5      nU R                  X$XPR                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  SS U R                  U R                  SSU R                  -   U R                  U5      u  pgnUS:w  a  [!        X0R"                  S9eU R                  S   nUS U nUS S 2S U24   nU(       a  Xg4$ U$ )Nr   Aint   r!   r   rr   )r[   r_   ri   r   r`   r   rj   rP   rg   r^   rb   rd   r   r   rf   r   r   r   )	r7   return_eigenvectorsrvecierrhowmnysselectr   r   ru   s	            r<   rt   _SymmetricArpackParams.extractG  s    "((488U+))$*.))TZZ*.((DJJ*.++a*:DJJ*.**Qq466z*B*.**d<
d 19d-B-BCC{{1~etHa$hK4KHr>   )r   r   r   r   r   r   r   r   rl   r   rm   r8   rd   r   r   r^   rg   rb   r   r   	r   NNNNNNr(   r   rA   rB   rC   rD   r6   r   rt   rF   r?   r>   r<   r}   r}     s    :>)-BCW.r&MPr>   r}   c                   0    \ rS rSr   SS jrS rS rSrg)_UnsymmetricArpackParamsi^  Nc                 .  ^ ^^^ US:X  aB  Tc  [        S5      eTb  [        S5      eTb  [        S5      eTT l        S T l        ST l        GOUS:X  aS  Tc  [        S5      eTc  [        S	5      eTc  [        S
5      eUU4S jT l        TT l        TT l        TT l        ST l        OUS;   a  Tc  [        S5      eTc  [        S5      eTT l        US;   a  US:X  a  TT l        O([        S5      eUS:X  a  U4S jT l        OU4S jT l        Tc!  S T l        ST l        T R                  T l        O*TT l        ST l        UU 4S jT l        O[        SU S35      eU[        ;  a!  [        SSR                  [        5       35      eX!S-
  :  a  [        SU 35      e[        R                  T XX5UXXU5        T R                  U:  d  T R                  US-   ::  a  [        ST R                   35      e[        SU-  T R                  5      T l        [        ST R                  -  T R                  S-   -  T R                  5      T l        [         T R                     n["        R$                  US-      T l        ["        R$                  US-      T l        [*        U   T l        [.        U   T l        [2        R4                  " S[6        5      T l        T R                  S ;   a4  [        T R                  T R                  R;                  5       5      T l        g S T l        g )!Nr   r   r   r   c                     U $ r@   r?   r   s    r<   r   3_UnsymmetricArpackParams.__init__.<locals>.<lambda>  r   r>   r   r!   r   r   r   c                     > T" T" U 5      5      $ r@   r?   r   s    r<   r   r     r   r>   r   r"   rr   z*matvec must be specified for mode in (3,4)z/Minv_matvec must be specified for mode in (3,4)DFr"   zmode=4 invalid for complex Ac                 <   > [         R                  " T" U 5      5      $ r@   )r[   realr   r   s    r<   r   r         Q)@r>   c                 <   > [         R                  " T" U 5      5      $ r@   )r[   imagr   s    r<   r   r     r   r>   c                     U $ r@   r?   r   s    r<   r   r     r   r>   c                 2   > TR                  T" U 5      5      $ r@   r   )r   r   r7   s    r<   r   r     s    DHHXa[$9r>   r   r   zParameter which must be one of r   z!k must be less than ndim(A)-1, k=zncv must be k+1<ncv<=n, ncv=naupdneupd   FD)rZ   r   r   r   r   r   r   _NEUPD_WHICHr   rS   r6   ri   r   rk   r   r   r   r   r   r   r   r3   r   _NEUPD_ERRORSr   r[   r_   rc   r   lowerrworkr   s   `   ` ``       r<   r6   !_UnsymmetricArpackParams.__init___  s   J 19~ !FGG# !JKK& !MNNDG DFDIQY~ !FGG !HII" !KLL6DG"DHDHDFDIV^~  "5 6 6"  "5 6 6 !DKTz19*DH$%CDD19@DH@DH$	((!	9uTF*:;<<$>sxx?U>VWXXA:@DEEtQ2U"	= 88a<488q1u,;DHH:FGG $AE4773
#ALDHHqL$A477K
!%..sW}=&//g> -c 2 -c 2XXb*-
77d?'$''--/BDJDJr>   c                 X   U R                   S;   a  U R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  5      nUu  U l        U l        U l        U l        U l	        U l
        U l        OU R                  U R                  U R                  U R                  U R
                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  U R                  5      nUu  U l        U l        U l        U l        U l	        U l
        U l        [        U R                  S   S-
  U R                  S   S-
  U R                   -   5      n[        U R                  S   S-
  U R                  S   S-
  U R                   -   5      nU R                  S:X  a,  U R#                  U R                  U   5      U R                  U'   g U R                  S:X  a  U R$                  S;   a,  U R#                  U R                  U   5      U R                  U'   g [        U R                  S   S-
  U R                  S   S-
  U R                   -   5      nU R'                  U R                  U   5      U R                  U'   g U R                  S:X  a,  U R)                  U R                  U   5      U R                  U'   g U R                  S:X  a  [+        S5      eS	U l        U R                  S:X  a  g U R                  S:X  a  U R/                  5         g [1        U R                  U R2                  S
9e)Nfdr   r   r#   r   r!   r!   r"   r   Tr   )rk   r   rm   r   rj   rP   rg   r^   rb   rd   r   r   r   r8   r   r   rf   r   re   r   r   rZ   rl   rz   r   r   )r7   resultsr   r   r   s        r<   r    _UnsymmetricArpackParams.iterate  s   77d?))$((DIItzz466*.((DJJ*.**djj$**diiYG 6=3DHdh
DFTZ ))$((DIItzz466*.((DJJ*.**djj$***.**diiAG
 6=3DHdh
DFTZ tzz!}q($**Q-!*;dff*DEtzz!}q($**Q-!*;dff*DE88r>!%F);!<DJJvXX]yyF"%)WWTZZ-?%@

6"

1 14::a=13Dtvv3MN%)XXdjj.A%B

6"XX]!%

6(:!;DJJvXX]NOO!DNyyA~a**,!$))d6K6KLLr>   c                 r   U R                   U R                  p2SnSn[        R                  " U R                  S5      n[        R
                  " U R                  5      n[        R                  " U R                  5      n[        R                  " SU R                  -  U R                  5      n	U R                  S;   Ga  [        R                  " US-   U R                  5      n
[        R                  " US-   U R                  5      n[        R                  " X2S-   4U R                  5      nU R                  UXVXxU	U R                  U R                  X R                  U R                  U R                  U R                  U R                   U R"                  U R$                  U R&                  5      u  ppUS:w  a  [)        X@R*                  S9eU R                  S   nU
S	U-  -   nUR-                  U R                  R/                  5       5      nUS:X  a  SnUU::  a{  [1        UU   R                  5      S:w  aR  UU:  aG  US S 2U4   S	US S 2US-   4   -  -   US S 2U4'   US S 2U4   R3                  5       US S 2US-   4'   US-  nOUS-  nUS-  nUU::  a  M{  GOSnUU::  Ga  [1        UU   R                  5      S:X  a9  [        R4                  " US S 2U4   U R7                  US S 2U4   5      5      UU'   GOQUU:  GaE  US S 2U4   S	US S 2US-   4   -  -   US S 2U4'   US S 2U4   R3                  5       US S 2US-   4'   [        R4                  " US S 2U4   U R7                  US S 2U4   5      5      [        R4                  " US S 2US-   4   U R7                  US S 2US-   4   5      5      -   S	[        R4                  " US S 2U4   U R7                  US S 2US-   4   5      5      [        R4                  " US S 2US-   4   U R7                  US S 2U4   5      5      -
  -  -   UU'   UU   R9                  5       UUS-   '   US-  nOUS-  nUS-  nUU::  a  GM  X::  a  US U nUS S 2S U24   nGOU R:                  S
;   a  UnO!U R:                  S;   a  SXR                  -
  -  nU R                  S;   a!  [        R<                  " WR
                  5      nOYU R                  S;   a*  [        R<                  " [1        WR                  5      5      nO[        R<                  " [1        W5      5      nU R                  S;   a  UU* S  S S S2   nOU R                  S;   a  US U nUU   nUS S 2U4   nOU R                  UXVU R                  U	U R                  U R                  X R                  U R                  U R                  U R                  U R                   U R"                  U R$                  U R>                  U5      u  pnUS:w  a  [)        X@R*                  S9eU R                  S   nUS U nUS S 2S U24   nU(       a  X4$ U$ )Nr   r   r   r"   r   r   r   rr                 ?r   r   )r-   r.   )r/   r0   )r-   r(   r/   r#   )r.   r)   r0   ) rP   rf   r[   r_   ri   r   r`   r   rk   r   r   rj   rg   r^   rb   rd   r   r   r   r8   r   r   astypeupperabs	conjugatedotr   conjre   argsortr   )r7   r   rP   rf   r   r   r   sigmarsigmaiworkevdrdizr	nreturnedr   r   irdindru   s                       r<   rt    _UnsymmetricArpackParams.extract  s   vvtvv1((488U+$$!dhh,077d?!a%)B!a%)B1!e*dgg.B$$%8yy$**a4::vvt{{DJJzz4::tyy	: BB qy!$1F1FGGAI TBYA 		$''--/*A {1f1Q499~* q5&(Ah1a!e81D&DAadG*+AqD'*;*;*=AaQhKFA &NIFA 1f* 1f1Q499~*!vvbAhBq!tH0EF!q5&(Ah1a!e81D&DAadG*+AqD'*;*;*=AaQhK%'VVBq!tH,0KK1a4,A&C')vvbAEl.2kk"QAX,.G(I&I ')BFF2ad837;;r!QU(|3L-N.0ffR1q5\59[[AqD5J/L-L 'M	%MAaD ()tyy{Aa!eHFA &NIFA/ 1f8 ~jyMa)m$ 99&BYY&(a**n-B::-**RWW-CZZ</ **S\2C**SW-C::!33qbc(4R4.CZZ#55bq'CcFafI (()<!DJJ99djj!XXtzz664;;

::tzz4::t	E A$ qy!$1F1FGG;;q>D%4A!UdU(A4KHr>   )r   r   r   r   r   r   r   rl   r   rm   r8   rd   r   r   r   r^   r   rg   rb   r   r   r   r   r?   r>   r<   r   r   ^  s    :>)-BCwr)MVGr>   r   c                   $    \ rS rSrSrS rS rSrg)SpLuInvi  z\
SpLuInv:
   helper class to repeatedly solve M*x=b
   using a sparse LU-decomposition of M
c                     [        U5      U l        UR                  U l        UR                  U l        [        R
                  " U R                  [        R                  5      (       + U l        g r@   )r   M_lushapedtyper[   
issubdtypecomplexfloatingisrealr7   Ms     r<   r6   SpLuInv.__init__  sB    G	WW
WW
--

B4F4FGGr>   c                 H   [         R                  " U5      nU R                  (       a  [         R                  " UR                  [         R
                  5      (       a  U R                  R                  [         R                  " U5      R                  U R                  5      5      SU R                  R                  [         R                  " U5      R                  U R                  5      5      -  -   $ U R                  R                  UR                  U R                  5      5      $ )Nr   )r[   asarrayr  r  r  r  r  solver   r   r   r7   r   s     r<   _matvecSpLuInv._matvec  s     JJqM;;2=="2D2DEEIIOOBGGAJ$5$5djj$AB499??2771:+<+<TZZ+HIIJ K 99??188DJJ#788r>   )r  r  r  r  NrA   rB   rC   rD   rE   r6   r  rF   r?   r>   r<   r   r     s    H9r>   r   c                   $    \ rS rSrSrS rS rSrg)LuInvi  zT
LuInv:
   helper class to repeatedly solve M*x=b
   using an LU-decomposition of M
c                 h    [        U5      U l        UR                  U l        UR                  U l        g r@   )r	   r  r  r  r  s     r<   r6   LuInv.__init__  s#    aL	WW
WW
r>   c                 .    [        U R                  U5      $ r@   )r
   r  r  s     r<   r  LuInv._matvec  s    		1%%r>   )r  r  r  Nr  r?   r>   r<   r  r    s    
&r>   r  c                     [         R                  " U5      nS[         R                  " UR                  5      -  [         R                  " UR
                  5      R                  -  n[        X[        X#5      SS9$ )z*
gmres with looser termination condition.
i  r   )rtolatol)	r[   r  sqrtsizefinfor  epsr   rO   )r   brg   min_tols       r<   gmres_looser!    sS     	

1ARWWQVV_$rxx'8'<'<<GC-A66r>   c                   ,    \ rS rSrSr\S4S jrS rSrg)IterInvi  zR
IterInv:
   helper class to repeatedly solve M*x=b
   using an iterative method.
r   c                 b   Xl         [        US5      (       a  UR                  U l        O6[        R                  " UR
                  S   5      nX-  R                  U l        UR
                  U l        US::  a-  S[        R                  " U R                  5      R                  -  nX l        X0l	        g )Nr  r   r   r!   )
r	  hasattrr  r[   r_   r  r  r  ifuncrg   )r7   r	  r&  rg   r   s        r<   r6   IterInv.__init__  s}    1gDJ$A%DJWW
!8 bhhtzz*...C
r>   c                     U R                  U R                  XR                  S9u  p#US:w  a&  [        SU R                   R                   SU S35      eU$ )Nrg   r   zError in inverting M: function  did not converge (info = ).)r&  r	  rg   rZ   rA   r7   r   r  r8   s       r<   r  IterInv._matvec  s]    **TVVQHH*5191$**2E2E1F G,,065  r>   )r	  r  r&  r  rg   N)	rA   rB   rC   rD   rE   r!  r6   r  rF   r?   r>   r<   r#  r#    s     !,  r>   r#  c                   <    \ rS rSrSr\S4S jrS r\S 5       r	Sr
g)		IterOpInvi  z_
IterOpInv:
   helper class to repeatedly solve [A-sigma*M]*x = b
   using an iterative method
r   c                 ,  ^^^ TU l         TU l        TU l        UUU4S jnUU4S jn[        R                  " TR
                  S   5      nTc7  U" U5      R                  n	[        U R                   R
                  UU	S9U l        O6U" U5      R                  n	[        U R                   R
                  UU	S9U l        TR
                  U l        US::  a7  S[        R                  " U R                  R                  5      R                  -  nX@l        XPl        g )Nc                 P   > TR                  U 5      TTR                  U 5      -  -
  $ r@   r   )r   r   r	  r`   s    r<   	mult_func%IterOpInv.__init__.<locals>.mult_func  s#    88A;!!444r>   c                 2   > TR                  U 5      TU -  -
  $ r@   r2  )r   r   r`   s    r<   mult_func_M_None,IterOpInv.__init__.<locals>.mult_func_M_None  s    88A;**r>   r   )r  r   r!   )r   r	  r`   r[   r_   r  r  r   r   r  r  r&  rg   )
r7   r   r	  r`   r&  rg   r3  r6  r   r  s
    ```      r<   r6   IterOpInv.__init__  s    
	5	+ HHQWWQZ 9$Q'--E$TVV\\%5+02DG aL&&E$TVV\\%.+02DG WW
!8 bhhtww}}-111C
r>   c                     U R                  U R                  XR                  S9u  p#US:w  a&  [        SU R                   R                   SU S35      eU$ )Nr)  r   z)Error in inverting [A-sigma*M]: function r*  r+  )r&  r   rg   rZ   rA   r,  s       r<   r  IterOpInv._matvec  s]    **TWWaXX*619;DJJ<O<O;P Q,,065  r>   c                 .    U R                   R                  $ r@   )r   r  )r7   s    r<   r  IterOpInv.dtype  s    ww}}r>   )r   r	  r   r&  r  r`   rg   N)rA   rB   rC   rD   rE   r!  r6   r  propertyr  rF   r?   r>   r<   r/  r/    s,     +61 >  r>   r/  c                     U R                   S:X  aG  U(       a@  [        R                  " U R                  [        R                  5      (       d  U R
                  $ [        U 5      (       a  U $ U R                  5       $ )z:Convert sparse matrix to CSC (by transposing, if possible)csr)formatr[   r  r  r  Tr   tocsc)r   	hermitians     r<   _fast_spmatrix_to_cscrD    sP    	EiMM!''2+=+=>>ss
	A		wwyr>   c                     [        U 5      (       a  [        U 5      R                  $ [        U 5      (       d  [	        U 5      (       a  [        XS9n [        U 5      R                  $ [        XS9R                  $ )NrC  r)  )r   r  r   r   r   rD  r   r#  )r	  rC  rg   s      r<   get_inv_matvecrG    sX    qzzQx	!*1--!!9qz   q")))r>   c                 Z   US:X  a
  [        XUS9$ UGc2  [        U 5      (       a  [        R                  " U R                  [        R
                  5      (       d  [        R                  " U5      S:X  a  [        R                  " U 5      n OU S-   n U R                  S S U R                  S   S-   2==   U-  ss'   [        U 5      R                  $ [        U 5      (       d  [        U 5      (       a;  X[        U R                  S   5      -  -
  n [        XS9n [!        U 5      R                  $ [#        [%        U 5      XUS9R                  $ [        U 5      (       d   [        U 5      (       d  [        U 5      (       a0  [        U5      (       dG  [        U5      (       d7  [        U 5      (       d'  [#        [%        U 5      [%        U5      X$S9R                  $ [        U 5      (       d  [        U5      (       a  [        XU-  -
  5      R                  $ XU-  -
  n[        XSS9n[!        U5      R                  $ )Nr   rC  rg   y                r   rF  r)  )rG  r   r[   r  r  r  r   rW   flatr  r  r   r   r   r   rD  r   r/  r   )r   r	  r`   rC  rg   r   s         r<   get_OPinv_matvecrK  (  s   za#>>y1::aggr'9'9::wwu~*GGAJFFF#QWWQZ!^#$-$8??"a[[.q11C
O++A%a=A1:$$$-a030067 HQKK8J18M8MQZZ<Nq<Q<Q-a0-a0"--3V4 QZZ71::QY'...QYB&r?B2;%%%r>   z@Nested calls to eigs/eighs not allowed: ARPACK is not re-entrantc                    [        U 5      n [        U5      nU R                  S   U R                  S   :w  a  [        SU R                   S35      eUb  UR                  U R                  :w  a%  [        SUR                   SU R                   35      e[        R                  " UR                  5      R
                  R                  5       [        R                  " U R                  5      R
                  R                  5       :w  a  [        R                  " SS	S
9  U R                  S   nUS::  a  [        SU S35      eXS-
  :  a  [        R                  " S[        S	S
9  [        U 5      (       a  [        S5      e[        U [        5      (       a  [        S5      e[        U[        5      (       a  [        S5      e[        XU	S9$ Uc  [        U 5      R                   nUb  [        S5      eUb  [        S5      eUc  SnSnSnU
b  [        S5      eGOJS	nU
c  [#        USUS9nO[        U
5      n
U
R                   n[        U5      R                   nGO[        R$                  " U R                  [        R&                  5      (       a  Ub  [        S5      eSnOaUb  UR                  5       S:X  a  SnOGUR                  5       S:X  a(  [        R(                  " U5      S:X  a  [        S5      eSnO[        S5      e[        U 5      R                   nU
b  [        S5      eUc  [+        XUSUS9nO[        U5      nUR                   nUc  SnO[        U5      R                   n[-        XU R                  R
                  XUUUXeXtU5      n[.           UR0                  (       d#  UR3                  5         UR0                  (       d  M#  UR5                  U	5      sSSS5        $ ! , (       d  f       g= f) a^  
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, https://github.com/opencollab/arpack-ng
.. [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:

>>> import numpy as np
>>> 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)

r   r   expected square matrix (shape=)Nwrong M dimensions , should be ZM does not have the same type precision as A. This may adversely affect ARPACK convergencer!   
stacklevelzk=z must be greater than 0.zOk >= N - 1 for N * N square matrix. Attempting to use scipy.linalg.eig instead.zhCannot use scipy.linalg.eig for sparse A with k >= N - 1. Use scipy.linalg.eig(A.toarray()) or reduce k.zACannot use scipy.linalg.eig for LinearOperator A with k >= N - 1.zACannot use scipy.linalg.eig for LinearOperator M with k >= N - 1.)r  right0OPinv should not be specified with sigma = None.z=OPpart should not be specified with sigma = None or complex A+Minv should not be specified with M = None.TrI  z;OPpart should not be specified with sigma=None or complex Ar"   rr   z%OPpart cannot be 'i' if sigma is realrr   zOPpart must be one of ('r','i')*Minv should not be specified when sigma isF)r   r  rZ   r[   r  charr   warningswarnRuntimeWarningr   	TypeError
isinstancer   r   r   r   rG  r  r  r   rK  r   _ARPACK_LOCKrl   r   rt   )r   rP   r	  r`   rj   rn   ri   rh   rg   r   MinvOPinvOPpartrf   r   re   r   r   paramss                      r<   r   r   Q  s   t 	'q)A&q)AwwqzQWWQZ9!''!DEE}77agg2177)<yQRR88AGG!!'')RXXagg->-C-C-I-I-KKMM I%&( 	

AAv2aS 89::Ez D$	4 A;; ) * * a(( 1 2 2a(( 1 2 2 1!455}!!$++ 2 3 3 9 : : 9DHK  "< = =  
 D|,Q$CH'-"kk'*11H ==""4"455!  "@ A AD^v||~4D\\^s"wwu~" !HIID>??!!$++IJJ=*15:EK %U+E,,K9H'*11H%aAGGLL&&.U&)wsDF 
""NN """ ~~12	 
s   3O=O
O%c                    [         R                  " U R                  [         R                  5      (       am  US:w  a  [	        SU S35      eUS:X  a  [	        S5      eUS:X  a  SnOUS:X  a  S	n[        XX#XEXgUXUS
9nU	(       a  US   R                  US   4$ UR                  $ U R                  S   U R                  S   :w  a  [	        SU R                   S35      eUb  UR                  U R                  :w  a%  [	        SUR                   SU R                   35      e[         R                  " UR                  5      R                  R                  5       [         R                  " U R                  5      R                  R                  5       :w  a  [        R                  " SSS9  U R                  S   nUS::  a  [	        S5      eX:  a  [        R                  " S[        SS9  [        U 5      (       a  [        S5      e[        U [         5      (       a  [        S5      e[        U[         5      (       a  [        S5      e[#        XU	(       + S9$ Uc}  [%        U 5      n U R&                  nUb  [	        S5      eUc  SnSnSnU
b  [	        S5      eGONSnU
c  [)        USUS9nO[%        U
5      n
U
R&                  n[%        U5      R&                  nGOU
b  [	        S5      eUS:X  aI  S nSnUc  [+        XUSUS9nO[%        U5      nUR&                  nUc  SnO[%        U5      nUR&                  nOUS!:X  a?  S"nUc  [+        XUSUS9nO[%        U5      R&                  n[%        U 5      R&                  nSnOmUS#:X  aX  S$n[%        U 5      R&                  nUc  [+        XUSUS9nO[%        U5      R&                  nUc  SnO%[%        U5      R&                  nO[	        S%U S&35      e[-        XU R                  R                  XUUUXeXtU5      n[.           UR0                  (       d#  UR3                  5         UR0                  (       d  M#  UR5                  U	5      sSSS5        $ ! , (       d  f       g= f)'a  
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].

Note that there is no specialized routine for the case when A is a complex
Hermitian matrix. In this case, ``eigsh()`` will call ``eigs()`` and return the
real parts of the eigenvalues thus obtained.

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``.
    Regardless of the selected mode (normal, cayley, or buckling),
    `OPinv` should always be supplied as ``OPinv = [A - sigma * M]^-1``.

    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, https://github.com/opencollab/arpack-ng
.. [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
--------
>>> import numpy as np
>>> 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)

normalr   z% cannot be used with complex matrix Ar,   z/which='BE' cannot be used with complex matrix Ar*   r-   r+   r.   )
r	  r`   rj   rn   ri   rh   rg   r   r`  ra  r   r   rM  rN  NrO  rP  rQ  r!   rR  zk must be greater than 0.zLk >= N for N * N square matrix. Attempting to use scipy.linalg.eigh instead.zfCannot use scipy.linalg.eigh for sparse A with k >= N. Use scipy.linalg.eigh(A.toarray()) or reduce k.z>Cannot use scipy.linalg.eigh for LinearOperator A with k >= N.z>Cannot use scipy.linalg.eigh for LinearOperator M with k >= N.)r  eigvals_onlyrU  rV  TrI  rX  r"   bucklingrr   cayleyr   zunrecognized mode '')r[   r  r  r  rZ   r   r   r  rY  r   rZ  r[  r\  r   r]  r^  r   r   r   r   rG  rK  r}   r_  rl   r   rt   )r   rP   r	  r`   rj   rn   ri   rh   rg   r   r`  ra  re   retrf   r   r   r   rc  s                      r<   r   r   R  sS   d 
}}QWWb00118uTF*OPQQD=NOOd]Ed]E11': 
 q6;;A&&88OwwqzQWWQZ9!''!DEE}77agg2177)<yQRR88AGG!!'')RXXagg->-C-C-I-I-KKMM I%&( 	

AAv455v E$	4 A;; ) * * a(( - . .a(( - . . A-@)@AA}Q 2 3 39DHK  "< = =  
 D|,Q$CH'-"kk'*11H IJJ 8DF}.qU9=3H )/#lly$Q'88 ZD}.qU9=3H /u5<<%a(//FH XD%a(//F}.qU9=3H /u5<<y+A.55 24&:;;#A!'',,$,k5$'WSBF 
""NN """ ~~12	 
s   	3Q>Q
Q&)F)Fr   )rY   NNr(   NNNr   TNNN)rY   NNr(   NNNr   TNNre  )IrE   numpyr[   rZ  scipy.sparse.linalg._interfacer   r   scipy.sparser   r   scipy.linalgr   r   r	   r
   scipy.sparse._sputilsr   r   r   scipy.sparse.linalgr   r   scipy._lib._utilr   scipy._lib._threadsafetyr    r   timingnbxr  rc   __docformat____all__r   _ndigitsDNAUPD_ERRORSSNAUPD_ERRORSrW   ZNAUPD_ERRORSCNAUPD_ERRORSDSAUPD_ERRORSSSAUPD_ERRORSDNEUPD_ERRORSSNEUPD_ERRORSZNEUPD_ERRORSCNEUPD_ERRORSDSEUPD_ERRORSSSEUPD_ERRORSr   r3   r   r   r   r   RuntimeErrorr   r   rQ   rS   r}   r   r   r  r!  r#  r/  rD  rG  rK  r_  r   r   r?   r>   r<   <module>r     s  J   K & 7 7  , + 3 ^^%%
%
A Ss5
!"-~ =
  #  :   3  	% B  )!" ?#$ :%& "'( 	%)* 	9+, 	--. 	1/0 
 D1< ""$/c ~ 8  	  +   C  	% > )  ?!"  	;#& "'( 	')* 	9+, 	--. 	2/0 
 D1< ~    3 A ) ?   	;!$  	:%( 	%)* 	9+, 	+-. 	</0  
14  
5B ""$a "c (c N   * , @ N 6 L  3"  G#& /'( F)* 8+, I-.  "/2  83@ ""$"c (c ~  C	
 > ) ?  
9 " 	' 	9 	1 	G 	<  	+!"  #0 ""$0c  c  $#%####% $#%####% . 4
8, 
8)+ )&GK GKTV] Vrl} l\	9n 90&N & 7n B1 1h	* &J  9 : 59<@'+~3B 6:=A&.X3r>   