
    g9                    @   d Z ddlZddlZddlmZm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 ddlmZmZ ddlmZ dd	lmZ d
dlmZ ej8                  j:                  j<                  ZdZ g dZ!dddddZ"dddddZ#i ddd
ddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6iZ$e$Z%e$jM                         Z'd7e'd-<   e'Z(i ddd
d8dddddddddd9d!d"d#d:d%d&d'd(d)d;d+d,d-d<d/d0d1d2d3d=d5d6iZ)e)Z*i ddd
d>dddddd d#d?d%d&d'd@d)dAd+dBd-d.d/d0d1dCd3dDdEdFdGdHZ+e+jM                         Z,dIe,d
<   dJe,dE<   dKe,dG<   i ddd
dLddddddMd#d?d%d&d'd@d)dNd+dOd-dPd/d0d1dCd3dDdEdQdGdRZ-e-jM                         Z.dSe.dE<   dTe.dG<   i dddddddd9d#d:d%d&d'd@d)dUd+d,d-d<d/d0d1d4dEdVdGdWdXdCdYdZZ/e/jM                         Z0d[e0dE<   d\e0dY<   e)e*d]Z1e$e%e'e(d^Z2e/e0d]Z3e+e,e-e.d^Z4g d_Z5g d`Z6 G da dbe7      Z8 G dc dde8      Z9de Z: G df dg      Z; G dh die;      Z< G dj dke;      Z= G dl dme      Z> G dn doe      Z?dp Z@ G dq dre      ZA G ds dte      ZBd{duZCd|dvZDd|dwZE edx      ZF	 	 	 d}dyZG	 	 	 d~dzZHy)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                       e Zd ZdZefdZy)r   z
    ARPACK error
    c                 ^    |j                  |d      }t        j                  | d||fz         y )NzUnknown errorzARPACK error %d: %s)getRuntimeError__init__)selfinfoinfodictmsgs       [/var/www/html/venv/lib/python3.12/site-packages/scipy/sparse/linalg/_eigen/arpack/arpack.pyr5   zArpackError.__init__  s,    ll41d$9T3K$GH    N)__name__
__module____qualname____doc___NAUPD_ERRORSr5    r;   r:   r   r     s     '4 Ir;   r   c                       e Zd ZdZd Zy)r   z
    ARPACK iteration did not converge

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

    c                 R    t         j                  | dd|i       || _        || _        y )Nr#   )r   r5   eigenvalueseigenvectors)r6   r9   rD   rE   s       r:   r5   zArpackNoConvergence.__init__*  s(    T2Cy1&(r;   N)r<   r=   r>   r?   r5   rA   r;   r:   r   r     s    
)r;   r   c                 &    t        d| z  dz   d      S )zy
    Choose number of lanczos vectors based on target number
    of singular/eigen values and vectors to compute, k.
    r!   r      )max)ks    r:   
choose_ncvrJ   0  s    
 q1uqy"r;   c                       e Zd Z	 	 ddZd Zy)_ArpackParamsNc                    |dk  rt        d|z        ||dz  }|dk  rt        d|z        |dvr$t        j                  |d      rd}nt        d      |t        j                  |d	      | _        d
}nt        j
                  ||      | _        d}|d| _        n|| _        |t        |      }t        ||      }t        j
                  ||f|      | _	        t        j
                  dt              | _        d
}|| _        || j                  d<   || j                  d<   d
| j                  d<   || j                  d<   || _        |
| _        || _        || _        || _        |	| _        || _        || _        d| _        d| _        y )Nr   zk must be positive, k=%d
   z$maxiter must be positive, maxiter=%dfdFDr   z)matrix type must be 'f', 'd', 'F', or 'D'T)copyr      r!   r"      F)
ValueErrornpcan_castarrayresidzerossigmarJ   minv
arpack_intiparammodentolrI   maxiterncvwhichtpr7   	convergedido)r6   r_   rI   rd   r^   rY   rb   v0ra   rc   r`   r7   ishftss                r:   r5   z_ArpackParams.__init__9  sw   67!;<<?"fGa<CgMNNV{{2s# !LMM>"40DJD !RDJD=DJDJ;Q-C#qk1c(B'hhr:. 	A AAA
	r;   c                 R   d}| j                   d   }| j                   d   }	 | j                  d      \  }}t        |||| j                  fz  ||      # t        $ rJ}| d| d}t        j                  d      }t        j                  | j
                  df      }d}Y d }~kd }~ww xY w)	Nz<No convergence (%d iterations, %d/%d eigenvectors converged)   r!   Tz [])r   r   )r]   extractr   rT   rX   r_   r   rI   )r6   r9   k_oknum_iterevvecerrs          r:   _raise_no_convergencez#_ArpackParams._raise_no_convergencet  s    L{{1~;;q>	ll4(GB "#4(@"@"cJJ  	EC5"C$B((DFFA;'CD		s   A 	B&A B!!B&)r   NNNNr(   r   )r<   r=   r>   r5   rr   rA   r;   r:   rL   rL   8  s    /3BC9vKr;   rL   c                   &    e Zd Z	 	 	 ddZd Zd Zy)_SymmetricArpackParamsNc                 r    |dk(  r?t        d      t        d      t        d       _        d  _        d _        nw|dk(  rPt        d      t        d	      t        d
      fd _         _         _         _        d _        n"|dk(  r[t        d      t        d       _         _        d  _        d _        nfd _         _         _        d _        n|dk(  rHt        d      t        d      t        d       _         fd _         _        d _        nu|dk(  rbt        d      t        d       _         _        fd _        d  _        d _        n*fd _         _        d _        nt        d|z        |t        vr!t        ddj                  t                     ||k\  rt        d |z        t        j                   |||||	|
|||        j                  |kD  s j                  |k  rt        d! j                         t        d|z   j                         _        t         j                   j                  d"z   z   j                         _        t          j                     }|d#vrt        d$      t"        j$                  |d%z       _        t"        j$                  |d&z       _        t*        |    _        t.        |    _        t3        j4                  d't6               _        y )(Nr   #matvec must be specified for mode=1'M_matvec cannot be specified for mode=1*Minv_matvec cannot be specified for mode=1c                     | S NrA   xs    r:   <lambda>z1_SymmetricArpackParams.__init__.<locals>.<lambda>      q r;   Ir!   #matvec must be specified for mode=2%M_matvec must be specified for mode=2(Minv_matvec must be specified for mode=2c                        |             S rz   rA   r|   Minv_matvecmatvecs    r:   r}   z1_SymmetricArpackParams.__init__.<locals>.<lambda>      F1I 6 r;   Gr"   z'matvec must not be specified for mode=3z(Minv_matvec must be specified for mode=3c                     | S rz   rA   r{   s    r:   r}   z1_SymmetricArpackParams.__init__.<locals>.<lambda>      1 r;   c                        |             S rz   rA   )r|   M_matvecr   s    r:   r}   z1_SymmetricArpackParams.__init__.<locals>.<lambda>  s    K$< r;   rj   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    j                   |             S rz   OPa)r|   r   r6   s    r:   r}   z1_SymmetricArpackParams.__init__.<locals>.<lambda>  s     3 r;   r   z#matvec must be specified for mode=5z(Minv_matvec must be specified for mode=5c                 ,      |       | z  z         S rz   rA   )r|   r   r   rY   s    r:   r}   z1_SymmetricArpackParams.__init__.<locals>.<lambda>  s    Kq	EAI0E$F r;   c                     | S rz   rA   r{   s    r:   r}   z1_SymmetricArpackParams.__init__.<locals>.<lambda>  r   r;   c                 8      |        |       z  z         S rz   rA   )r|   r   r   r   rY   s    r:   r}   z1_SymmetricArpackParams.__init__.<locals>.<lambda>  s%    Kq	27(1+2E1F %G r;   mode=%i not implementedzwhich must be one of  z!k must be less than ndim(A), k=%dzncv must be k<ncv<=n, ncv=   )r   r   z Input matrix is not real-valued.saupdseupdrQ   )rS   OPBbmatr   OPbA_matvec_SEUPD_WHICHjoinrL   r5   rb   r   rd   workdworkl
_type_convr   __dict___arpack_solver_arpack_extract_SAUPD_ERRORSiterate_infodict_SEUPD_ERRORSextract_infodictrT   rX   r\   ipntrr6   r_   rI   rd   r   r^   r   r   rY   rb   rg   ra   rc   r`   ltrs   `   ` ```      r:   r5   z_SymmetricArpackParams.__init__  s:   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!	6=>>$4SXXl5K4LMNN6@1DEEtQ2tU"B	= 88a<488q=9$((DEE $AE4773
#DHH1$=twwG
!j ?@@%..sW}=&//g> -c 2 -c 2XXb*-
r;   c                    | j                  | j                  | j                  | j                  | j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                        \  | _        | _        | _        | _        | _        | _	        | _        t        | j                  d   dz
  | j                  d   dz
  | j                  z         }t        | j                  d   dz
  | j                  d   dz
  | j                  z         }| j                  dk(  r,| j                  | j                  |         | j                  |<   y | j                  dk(  r| j                   dk(  r,| j                  | j                  |         | j                  |<   y | j                   dk(  rW| j#                  | j                  |         | j                  |<   | j%                  | j                  |         | j                  |<   y | j                   dk(  rt        | j                  d   dz
  | j                  d   dz
  | j                  z         }| j'                  | j                  |         }| j%                  || j(                  | j                  |   z  z         | j                  |<   y t        | j                  d   dz
  | j                  d   dz
  | j                  z         }| j%                  | j                  |         | j                  |<   y | j                  dk(  r,| j+                  | j                  |         | j                  |<   y | j                  dk(  rt-        d      d| _        | j                  dk(  ry | j                  dk(  r| j1                          y t3        | j                  | j4                  	      )
Nr   r   r#   r!   r   r"   /ARPACK requested user shifts.  Assure ISHIFT==0Tr8   )r   rf   r   rc   rI   r`   rW   r[   r]   r   r   r   r7   slicer_   r   r^   r   r   r   rY   r   rS   re   rr   r   r   )r6   xsliceysliceBxsliceAxs        r:   iteratez_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%)XXbDJJ48JJw4G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                    |}d}d}t        j                  | j                  d      }| j                  |||| j                  | j
                  | j                  | j                  | j                  | j                  | j                  | j                  dd | j                  | j                  dd| j                  z   | j                  |      \  }}}|dk7  rt!        || j"                        | j                  d   }|d | }|d d d |f   }|r||fS |S )Nr   Aint   r!   r   rj   )rT   rX   rb   r   rY   r   rc   rI   r`   rW   r[   r]   r   r   r_   r   r   r   )	r6   return_eigenvectorsrvecierrhowmnysselectr   r   rm   s	            r:   rl   z_SymmetricArpackParams.extractD  s    "((488U+))$*.))TZZ*.((DJJ*.++a*:DJJ*.**Qq466z*B*.**d<
1d 19dT-B-BCC{{1~etHa$hKa4KHr;   	r   NNNNNNr(   r   r<   r=   r>   r5   r   rl   rA   r;   r:   rt   rt     s    :>)-BCW.r&MPr;   rt   c                   &    e Zd Z	 	 	 ddZd Zd Zy)_UnsymmetricArpackParamsNc                     |dk(  r>t        d      t        d      t        d       _        d  _        d _        n|dk(  rOt        d      t        d	      t        d
      fd _         _         _         _        d _        n|dv rt        d      t        d       _        |dv r|dk(  r _        n%t        d      |dk(  rfd _        n
fd _        !d  _        d _         j                   _        n( _        d _         fd _        nt        d|z        |t        vr!t        ddj                  t                     ||dz
  k\  rt        d|z        t        j                   ||||||	|
|||        j                  |kD  s j                  |dz   k  rt        d j                         t        d|z   j                         _        t        d j                  z   j                  dz   z   j                         _        t          j                     }t"        j$                  |dz       _        t"        j$                  |dz       _        t*        |    _        t.        |    _        t3        j4                  dt6               _         j                  dv r4t         j                   j                  j;                                _        y d  _        y ) Nr   rv   rw   rx   c                     | S rz   rA   r{   s    r:   r}   z3_UnsymmetricArpackParams.__init__.<locals>.<lambda>  r~   r;   r   r!   r   r   r   c                        |             S rz   rA   r   s    r:   r}   z3_UnsymmetricArpackParams.__init__.<locals>.<lambda>  r   r;   r   r"   rj   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                 :    t        j                   |             S rz   )rT   realr|   r   s    r:   r}   z3_UnsymmetricArpackParams.__init__.<locals>.<lambda>      Q)@ r;   c                 :    t        j                   |             S rz   )rT   imagr   s    r:   r}   z3_UnsymmetricArpackParams.__init__.<locals>.<lambda>  r   r;   c                     | S rz   rA   r{   s    r:   r}   z3_UnsymmetricArpackParams.__init__.<locals>.<lambda>  r   r;   c                 2    j                   |             S rz   r   )r|   r   r6   s    r:   r}   z3_UnsymmetricArpackParams.__init__.<locals>.<lambda>  s    DHHXa[$9 r;   r   zParameter which must be one of r   z#k must be less than ndim(A)-1, k=%dzncv must be k+1<ncv<=n, ncv=naupdneupd   FD)rS   r   r   r   r   r   r   _NEUPD_WHICHr   rL   r5   rb   r   rd   r   r   r   r   r   r   r   r@   r   _NEUPD_ERRORSr   rT   rX   r\   r   lowerrworkr   s   `   ` ``       r:   r5   z!_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6=>>$>sxx?U>VWXXA:BQFGGtQ2tU"B	= 88a<488q1u,;DHH:FGG $AE4773
#ALDHHqL$A477K
!%..sW}=&//g> -c 2 -c 2XXb*-
77d?'$''--/BDJDJr;   c                 J   | j                   dv 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z
  | j                  d   dz
  | j                   z         }t        | j                  d   dz
  | j                  d   dz
  | j                   z         }| j                  dk(  r,| j#                  | j                  |         | j                  |<   y | j                  dk(  r| j$                  dv r,| j#                  | j                  |         | j                  |<   y t        | j                  d   dz
  | j                  d   dz
  | j                   z         }| j'                  | j                  |         | j                  |<   y | j                  dk(  r,| j)                  | j                  |         | j                  |<   y | j                  dk(  rt+        d      d	| _        | j                  dk(  ry | j                  dk(  r| j/                          y t1        | j                  | j2                  
      )Nfdr   r   r#   r   r!   r!   r"   r   Tr   )rd   r   rf   r   rc   rI   r`   rW   r[   r]   r   r   r   r7   r   r   r_   r   r^   r   r   rS   re   rr   r   r   )r6   resultsr   r   r   s        r:   r   z _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                 >   | j                   | j                  }}d}d}t        j                  | j                  d      }t        j
                  | j                        }t        j                  | j                        }t        j                  d| j                  z  | j                        }	| j                  dv rt        j                  |dz   | j                        }
t        j                  |dz   | j                        }t        j                  ||dz   f| j                        }| j                  ||||||	| j                  | j                  || j                  | j                  | j                  | j                  | j                   | j"                  | j$                  | j&                        \  }
}}}|dk7  rt)        || j*                        | j                  d   }|
d	|z  z   }|j-                  | j                  j/                               }|dk(  rd}||k  r,t1        ||   j                        dk7  rQ||k  rG|d d |f   d	|d d |dz   f   z  z   |d d |f<   |d d |f   j3                         |d d |dz   f<   |dz  }n|dz  }|dz  }||k  rwnd}||k  rt1        ||   j                        dk(  r8t        j4                  |d d |f   | j7                  |d d |f               ||<   nL||k  rA|d d |f   d	|d d |dz   f   z  z   |d d |f<   |d d |f   j3                         |d d |dz   f<   t        j4                  |d d |f   | j7                  |d d |f               t        j4                  |d d |dz   f   | j7                  |d d |dz   f               z   d	t        j4                  |d d |f   | j7                  |d d |dz   f               t        j4                  |d d |dz   f   | j7                  |d d |f               z
  z  z   ||<   ||   j9                         ||dz   <   |dz  }n|dz  }|dz  }||k  r||k  r|d | }|d d d |f   }n| j:                  d
v r|}n | j:                  dv rd|| j                  z
  z  }| j                  dv r t        j<                  j
                        }nU| j                  dv r)t        j<                  t1        j                              }nt        j<                  t1                    }| j                  dv r|| d  d d d   }n| j                  dv r|d | }||   }|d d |f   }n| j                  |||| j                  |	| j                  | j                  || j                  | j                  | j                  | j                  | j                   | j"                  | j$                  | j>                  |      \  }}}|dk7  rt)        || j*                        | j                  d   }|d | }|d d d |f   }|r||fS |S )Nr   r   r   r"   r   r   r   rj                 ?r   r   )r-   r.   )r/   r0   )r-   r(   r/   r#   )r.   r)   r0   ) rI   r_   rT   rX   rb   r   rY   r   rd   r   r   rc   r`   rW   r[   r]   r   r   r   r7   r   r   astypeupperabs	conjugatedotr   conjr^   argsortr   )r6   r   rI   r_   r   r   r   sigmarsigmaiworkevdrdizr	nreturnedr   r   irdindrm   s                       r:   rl   z _UnsymmetricArpackParams.extract   s   vvtvv1((488U+$$!dhh,077d?!a%)B!a%)B1a!e*dgg.B$$%8wyy$**a4::vvt{{DJJzz4::tyy	: BB 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 A~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 (()<!7DJJ99djj!TXXtzz664;;

::tzz4::t	E Aq$ qy!$1F1FGG;;q>D%4A!UdU(Aa4KHr;   r   r   rA   r;   r:   r   r   [  s    :>)-BCwr)MVGr;   r   c                       e Zd ZdZd Zd Zy)SpLuInvzl
    SpLuInv:
       helper class to repeatedly solve M*x=b
       using a sparse LU-decomposition of M
    c                     t        |      | _        |j                  | _        |j                  | _        t	        j
                  | j                  t        j                         | _        y rz   )r   M_lushapedtyperT   
issubdtypecomplexfloatingisrealr6   Ms     r:   r5   zSpLuInv.__init__  sB    G	WW
WW
--

B4F4FGGr;   c                 ,   t        j                  |      }| j                  rt        j                  |j                  t         j
                        r| j                  j                  t        j                  |      j                  | j                              d| j                  j                  t        j                  |      j                  | j                              z  z   S | j                  j                  |j                  | j                              S )Nr   )rT   asarrayr   r   r   r   r   solver   r   r   r6   r|   s     r:   _matveczSpLuInv._matvec  s     JJqM;;2=="2D2DEIIOOBGGAJ$5$5djj$AB499??2771:+<+<TZZ+HIIJ K 99??188DJJ#788r;   Nr<   r=   r>   r?   r5   r   rA   r;   r:   r   r     s    H9r;   r   c                       e Zd ZdZd Zd Zy)LuInvzd
    LuInv:
       helper class to repeatedly solve M*x=b
       using an LU-decomposition of M
    c                 h    t        |      | _        |j                  | _        |j                  | _        y rz   )r	   r   r   r   r   s     r:   r5   zLuInv.__init__  s#    aL	WW
WW
r;   c                 .    t        | j                  |      S rz   )r
   r   r   s     r:   r   zLuInv._matvec  s    		1%%r;   Nr   rA   r;   r:   r   r     s    
&r;   r   c                     t        j                  |      }dt        j                  |j                        z  t        j                  |j
                        j                  z  }t        | |t        ||      d      S )z2
    gmres with looser termination condition.
    i  r   )rtolatol)	rT   r   sqrtsizefinfor   epsr   rH   )r   br`   min_tols       r:   gmres_looser    sW     	

1ARWWQVV_$rxx'8'<'<<GACW-A66r;   c                   "    e Zd ZdZedfdZd Zy)IterInvzb
    IterInv:
       helper class to repeatedly solve M*x=b
       using an iterative method.
    r   c                 Z   || _         t        |d      r|j                  | _        n6t        j                  |j
                  d         }||z  j                  | _        |j
                  | _        |dk  r,dt        j                  | j                        j                  z  }|| _        || _	        y )Nr   r   r   r!   )
r   hasattrr   rT   rX   r   r  r	  ifuncr`   )r6   r   r  r`   r|   s        r:   r5   zIterInv.__init__  s    1gDJ$Aa%DJWW
!8 bhhtzz*...C
r;   c                     | j                  | j                  || j                        \  }}|dk7  r$t        d| j                   j                  |fz        |S )Nr`   r   z?Error in inverting M: function %s did not converge (info = %i).)r  r   r`   rS   r<   r6   r|   r
  r7   s       r:   r   zIterInv._matvec  sZ    **TVVQDHH*5419 @ $

 3 3T:; < < r;   N)r<   r=   r>   r?   r  r5   r   rA   r;   r:   r  r    s     !,  r;   r  c                   2    e Zd ZdZedfdZd Zed        Zy)	IterOpInvzo
    IterOpInv:
       helper class to repeatedly solve [A-sigma*M]*x = b
       using an iterative method
    r   c                 0   | _         | _        | _        fd}fd}t        j                  j
                  d         }: ||      j                  }	t        | j                   j
                  ||	      | _        n9 ||      j                  }	t        | j                   j
                  ||	      | _        j
                  | _        |dk  r6dt        j                  | j                  j                        j                  z  }|| _        || _        y )Nc                 P    j                  |       j                  |       z  z
  S rz   r   )r|   r   r   rY   s    r:   	mult_funcz%IterOpInv.__init__.<locals>.mult_func  s#    88A;!!444r;   c                 2    j                  |       | z  z
  S rz   r  )r|   r   rY   s    r:   mult_func_M_Nonez,IterOpInv.__init__.<locals>.mult_func_M_None  s    88A;**r;   r   )r   r   r!   )r   r   rY   rT   rX   r   r   r   r   r  r	  r  r`   )
r6   r   r   rY   r  r`   r  r  r|   r   s
    ```      r:   r5   z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                     | j                  | j                  || j                        \  }}|dk7  r$t        d| j                   j                  |fz        |S )Nr  r   zIError in inverting [A-sigma*M]: function %s did not converge (info = %i).)r  r   r`   rS   r<   r  s       r:   r   zIterOpInv._matvec   sZ    **TWWaTXX*6419 @ $

 3 3T:; < < r;   c                 .    | j                   j                  S rz   )r   r   )r6   s    r:   r   zIterOpInv.dtype  s    ww}}r;   N)	r<   r=   r>   r?   r  r5   r   propertyr   rA   r;   r:   r  r    s,     +61 >  r;   r  c                     | j                   dk(  r<|r:t        j                  | j                  t        j                        s| j
                  S t        |       r| S | j                         S )z:Convert sparse matrix to CSC (by transposing, if possible)csr)formatrT   r   r   r   Tr   tocsc)r   	hermitians     r:   _fast_spmatrix_to_cscr&    sJ    	EiMM!''2+=+=>ss
	A	wwyr;   c                     t        |       rt        |       j                  S t        |       st	        |       r"t        | |      } t        |       j                  S t        | |      j                  S )Nr%  r  )r   r   r   r   r   r&  r   r  )r   r%  r`   s      r:   get_inv_matvecr)    sU    qzQx	!*1-!!y9qz   qc")))r;   c                    |dk(  rt        | ||      S |#t        |       rt        j                  | j                  t        j
                        st        j                  |      dk(  rt        j                  |       } n| dz   } | j                  d d | j                  d   dz   xx   |z  cc<   t        |       j                  S t        |       st        |       r@| |t        | j                  d         z  z
  } t        | |      } t!        |       j                  S t#        t%        |       |||      j                  S t        |       st        |       st        |       r!t        |      sAt        |      s6t        |       s+t#        t%        |       t%        |      ||      j                  S t        |       st        |      rt        | ||z  z
        j                  S | ||z  z
  }t        ||      }t!        |      j                  S )Nr   r%  r`   y                r   r(  r  )r)  r   rT   r   r   r   r   rP   flatr   r   r   r   r   r   r&  r   r  r   )r   r   rY   r%  r`   r   s         r:   get_OPinv_matvecr-  #  s   za9#>>y1:aggr'9'9:wwu~*GGAJFFF#QWWQZ!^#$-$8??"a[.q1EC
O++A%a9=A1:$$$-a030067 HQK8J18MQZ<Nq<Q-a0-a0"--3V4 QZ71:UQY'...UQYB&rY?B2;%%%r;   z@Nested calls to eigs/eighs not allowed: ARPACK is not re-entrantc                 |   t        |       } t        |      }| j                  d   | j                  d   k7  rt        d| j                   d      ||j                  | j                  k7  r%t        d|j                   d| j                         t        j                  |j                        j
                  j                         t        j                  | j                        j
                  j                         k7  rt        j                  dd	
       | j                  d   }|dk  rt        d|z        ||dz
  k\  rvt        j                  dt        d	
       t        |       rt        d      t        | t              rt        d      t        |t              rt        d      t        | ||	      S |t        |       j                   }|t        d      |t        d      |d}d}d}|
Lt        d      d	}|
t#        |d|      }nt        |
      }
|
j                   }t        |      j                   }n t        j$                  | j                  t        j&                        r|t        d      d}n\||j                         dk(  rd}nD|j                         dk(  r&t        j(                  |      dk(  rt        d      d}nt        d      t        |       j                   }|
t        d      |t+        | ||d|      }nt        |      }|j                   }|d}nt        |      j                   }t-        ||| j                  j
                  ||||||||||      }t.        5  |j0                  s|j3                          |j0                  s|j5                  |	      cddd       S # 1 sw Y   yxY w)aJ  
    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=%d 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.Tr+  z;OPpart should not be specified with sigma=None or complex Ar"   rr   z%OPpart cannot be 'i' if sigma is realrj   zOPpart must be one of ('r','i')*Minv should not be specified when sigma isF)r   r   rS   rT   r   charr   warningswarnRuntimeWarningr   	TypeError
isinstancer   r   r   r   r)  r   r   r   r-  r   _ARPACK_LOCKre   r   rl   )r   rI   r   rY   rc   rg   rb   ra   r`   r   MinvOPinvOPpartr_   r   r^   r   r   paramss                      r:   r   r   L  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7!;<<A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!  "@ A AD^v||~4D\\^s"wwu~" !HIID>??!!$++IJJ=*1a5:EK %U+E,,K9H'*11H%aAGGLL&$&.U&)2wsDF 
 3""NN "" ~~12	3 3 3s   .)N2N22N;c                    t        j                  | j                  t         j                        rl|dk7  rt	        d| d      |dk(  rt	        d      |dk(  rd}n|dk(  rd	}t        | |||||||||	|
|
      }|	r|d   j                  |d   fS |j                  S | j                  d   | j                  d   k7  rt	        d| j                   d      ||j                  | j                  k7  r%t	        d|j                   d| j                         t        j                  |j                        j                  j                         t        j                  | j                        j                  j                         k7  rt        j                  dd       | j                  d   }|dk  rt	        d      ||k\  rwt        j                  dt        d       t        |       rt        d      t        | t               rt        d      t        |t               rt        d      t#        | ||	       S |{t%        |       } | j&                  }|t	        d      |d}d}d}|
^t	        d      d}|
t)        |d|      }nt%        |
      }
|
j&                  }t%        |      j&                  }n|
t	        d      |dk(  rKd }d}|t+        | ||d|      }nt%        |      }|j&                  }|d}nt%        |      }|j&                  }n|d!k(  rBd"}|t+        | ||d|      }nt%        |      j&                  }t%        |       j&                  }d}nn|d#k(  rZd$}t%        |       j&                  }|t+        | ||d|      }nt%        |      j&                  }|d}n%t%        |      j&                  }nt	        d%| d&      t-        ||| j                  j                  ||||||||||      }t.        5  |j0                  s|j3                          |j0                  s|j5                  |	      cddd       S # 1 sw Y   yxY w)'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``.
        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)

    normalzmode=z% cannot be used with complex matrix Ar,   z/which='BE' cannot be used with complex matrix Ar*   r-   r+   r.   )
r   rY   rc   rg   rb   ra   r`   r   rB  rC  r   r   r/  r0  Nr1  r2  r3  r!   r4  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_onlyr7  r8  Tr+  r:  r"   bucklingrj   cayleyr   zunrecognized mode '')rT   r   r   r   rS   r   r   r   r;  r   r<  r=  r>  r   r?  r@  r   r   r   r   r)  r-  rt   rA  re   r   rl   )r   rI   r   rY   rc   rg   rb   ra   r`   r   rB  rC  r^   retr_   r   r   r   rE  s                      r:   r   r   M  sg   ^ 
}}QWWb0018uTF*OPQQD=NOOd]Ed]E1a1E2G': 
 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Av 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}.q!U9=3H )/#lly$Q'88 ZD}.q!U9=3H /u5<<%a(//FH XD%a(//F}.q!U9=3H /u5<<y+A.55 24&:;;#Aq!'',,$,k5$'WeSBF 
 3""NN "" ~~12	3 3 3s   4)P8P88Q)F)Fr   )rR   NNr(   NNNr   TNNN)rR   NNr(   NNNr   TNNrG  )Ir?   numpyrT   r<  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   r\   __docformat____all__r   _ndigitsDNAUPD_ERRORSSNAUPD_ERRORSrP   ZNAUPD_ERRORSCNAUPD_ERRORSDSAUPD_ERRORSSSAUPD_ERRORSDNEUPD_ERRORSSNEUPD_ERRORSZNEUPD_ERRORSCNEUPD_ERRORSDSEUPD_ERRORSSSEUPD_ERRORSr   r@   r   r   r   r   r4   r   r   rJ   rL   rt   r   r   r   r  r  r  r&  r)  r-  rA  r   r   rA   r;   r:   <module>rg     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I, I)+ )&GK GKTV] Vrl} l\	9n 90&N & 7n @0 0f	* &J  9 : 59<@'+~3B 6:=A&.U3r;   