ó
î&]\c        
   @` s£  d  d l  m Z m Z m Z d d d d d d d d	 d
 d g
 Z d  d l Z d  d l m Z m Z m Z m	 Z	 m
 Z
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z d  d l m Z d  d l m Z d d l m Z m Z m Z d d l  m! Z! m" Z" e d d ƒ Z# d „  Z$ d „  Z% d „  Z& d e( e) e( e( e) e( d „ Z* d e) e( e( e( e) d d e) d „	 Z+ i	 d  d  6d d 6d d 6d  d 6d d 6d d 6d  d 6d d  6d d! 6Z, d" „  Z- e( e( e( d d d  e) d# „ Z. d e( e) e( d$ „ Z/ d e) e( e( e) d d e) d% „ Z0 e( e( d d e) d& „ Z1 d d e) d' d( d) „ Z2 e( d d e) d' d( d* „ Z3 d+ d, „ Z4 e( e( e) d- „ Z5 d. „  Z6 d S(/   i    (   t   divisiont   print_functiont   absolute_importt   eigt   eigvalst   eight   eigvalsht
   eig_bandedt   eigvals_bandedt   eigh_tridiagonalt   eigvalsh_tridiagonalt
   hessenbergt   cdf2rdfN(   t   arrayt   isfinitet   inexactt   nonzerot   iscomplexobjt   castt   flatnonzerot   conjt   asarrayt   argsortt   emptyt   newaxist   argwheret	   iscomplext   eyet   zerost   einsum(   t   xrange(   t   _asarray_validated(   t   string_typesi   (   t   LinAlgErrort   _datacopiedt   norm(   t   get_lapack_funcst   _compute_lworkt   Fy              ð?c         C` sº   t  j | d | ƒ} |  j d k } | d c  |  j d d k  O*xr t | ƒ D]d } | d d … | d f | j d d … | f <t | d d … | f | d d … | d f ƒ qN W| S(   sR   
    Produce complex-valued eigenvectors from LAPACK DGGEV real-valued output
    t   dtypei    iÿÿÿÿi   N(   t   numpyR   t   imagR   R   (   t   wt   vinR'   t   vt   mt   i(    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyt   _make_complex_eigvecs$   s    -5c         C` sû   | rD | d  k r. t j |  t j |  ƒ f ƒ St j |  | f ƒ Sn³ | d  k rT |  St j |  ƒ } |  d k } | d k } | } |  | | | | | <t j | | | @<t j |  j d k ƒ rÖ t j | | | @<n t	 t j t j ƒ | | | @<| Sd  S(   Ni    (
   t   NoneR(   t   vstackt	   ones_liket
   empty_liket   inft   allR)   t   nant   complex(   t   alphat   betat   homogeneous_eigvalsR*   t
   alpha_zerot	   beta_zerot   beta_nonzero(    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyt   _make_eigvals2   s     c         C` sN  t  d	 |  | f ƒ \ } | | } }	 | |  | d d ƒ}
 |
 d d j j t j ƒ } | j d k r« | |  | | |	 | | | ƒ \ } } } } } } t | | | ƒ } nS | |  | | |	 | | | ƒ \ } } } } } } } | t | } t | | | ƒ } t | d ƒ t j	 | j
 d k ƒ } | j d k p5| s}| j j } | r_t | | | ƒ } n  | r}t | | | ƒ } q}n  x‘ t | j d ƒ D]| } | rÒ| d  d  … | f c t | d  d  … | f ƒ <n  | r‘| d  d  … | f c t | d  d  … | f ƒ <q‘q‘W| p| s!| S| rD| r:| | | f S| | f S| | f S(
   Nt   ggevt   lworkiÿÿÿÿiþÿÿÿi    t   czs    generalized eig algorithm (ggev)g        (   R?   (   R$   t   realt   astypeR(   t   intt   typecodeR>   t   _It   _check_infoR5   R)   R'   t   charR/   R   t   shapeR#   (   t   a1t   b1t   leftt   rightt   overwrite_at   overwrite_bR:   R?   t   cvlt   cvrt   resR@   R8   R9   t   vlt   vrt   workt   infoR*   t   alphart   alphait	   only_realt   tR.   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyt   _geneigL   sB    59
c      
   C` sá  t  |  d | ƒ} t | j ƒ d k sA | j d | j d k rP t d ƒ ‚ n  | pb t | |  ƒ } | d k	 rt  | d | ƒ}	 | p• t |	 | ƒ } t |	 j ƒ d k sÇ |	 j d |	 j d k rÖ t d ƒ ‚ n  |	 j | j k r÷ t d ƒ ‚ n  t | |	 | | | | | ƒ St d | f ƒ \ }
 } | | } } t | | j d d	 | d
 | ƒ} |
 j	 d k r®|
 | d | d	 | d
 | d | ƒ\ } } } } t
 | d | ƒ } nq |
 | d | d	 | d
 | d | ƒ\ } } } } } i d d 6d d 6| j j } | t | } t
 | d | ƒ } t | d d d ƒt j | j d k ƒ } |
 j	 d k p\| s¤| j j } | r†t | | | ƒ } n  | r¤t | | | ƒ } q¤n  | p­| s´| S| r×| rÍ| | | f S| | f S| | f S(   sô  
    Solve an ordinary or generalized eigenvalue problem of a square matrix.

    Find eigenvalues w and right or left eigenvectors of a general matrix::

        a   vr[:,i] = w[i]        b   vr[:,i]
        a.H vl[:,i] = w[i].conj() b.H vl[:,i]

    where ``.H`` is the Hermitian conjugation.

    Parameters
    ----------
    a : (M, M) array_like
        A complex or real matrix whose eigenvalues and eigenvectors
        will be computed.
    b : (M, M) array_like, optional
        Right-hand side matrix in a generalized eigenvalue problem.
        Default is None, identity matrix is assumed.
    left : bool, optional
        Whether to calculate and return left eigenvectors.  Default is False.
    right : bool, optional
        Whether to calculate and return right eigenvectors.  Default is True.
    overwrite_a : bool, optional
        Whether to overwrite `a`; may improve performance.  Default is False.
    overwrite_b : bool, optional
        Whether to overwrite `b`; may improve performance.  Default is False.
    check_finite : bool, optional
        Whether to check that the input matrices contain only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.
    homogeneous_eigvals : bool, optional
        If True, return the eigenvalues in homogeneous coordinates.
        In this case ``w`` is a (2, M) array so that::

            w[1,i] a vr[:,i] = w[0,i] b vr[:,i]

        Default is False.

    Returns
    -------
    w : (M,) or (2, M) double or complex ndarray
        The eigenvalues, each repeated according to its
        multiplicity. The shape is (M,) unless
        ``homogeneous_eigvals=True``.
    vl : (M, M) double or complex ndarray
        The normalized left eigenvector corresponding to the eigenvalue
        ``w[i]`` is the column vl[:,i]. Only returned if ``left=True``.
    vr : (M, M) double or complex ndarray
        The normalized right eigenvector corresponding to the eigenvalue
        ``w[i]`` is the column ``vr[:,i]``.  Only returned if ``right=True``.

    Raises
    ------
    LinAlgError
        If eigenvalue computation does not converge.

    See Also
    --------
    eigvals : eigenvalues of general arrays
    eigh : Eigenvalues and right eigenvectors for symmetric/Hermitian arrays.
    eig_banded : eigenvalues and right eigenvectors for symmetric/Hermitian
        band matrices
    eigh_tridiagonal : eigenvalues and right eiegenvectors for
        symmetric/Hermitian tridiagonal matrices

    Examples
    --------
    >>> from scipy import linalg
    >>> a = np.array([[0., -1.], [1., 0.]])
    >>> linalg.eigvals(a)
    array([0.+1.j, 0.-1.j])

    >>> b = np.array([[0., 1.], [1., 1.]])
    >>> linalg.eigvals(a, b)
    array([ 1.+0.j, -1.+0.j])

    >>> a = np.array([[3., 0., 0.], [0., 8., 0.], [0., 0., 7.]])
    >>> linalg.eigvals(a, homogeneous_eigvals=True)
    array([[3.+0.j, 8.+0.j, 7.+0.j],
           [1.+0.j, 1.+0.j, 1.+0.j]])

    >>> a = np.array([[0., -1.], [1., 0.]])
    >>> linalg.eigvals(a) == linalg.eig(a)[0]
    array([ True,  True])
    >>> linalg.eig(a, left=True, right=False)[1] # normalized left eigenvector
    array([[-0.70710678+0.j        , -0.70710678-0.j        ],
           [-0.        +0.70710678j, -0.        -0.70710678j]])
    >>> linalg.eig(a, left=False, right=True)[1] # normalized right eigenvector
    array([[0.70710678+0.j        , 0.70710678-0.j        ],
           [0.        -0.70710678j, 0.        +0.70710678j]])



    t   check_finitei   i    i   s   expected square matrixs    a and b must have the same shapet   geevt
   geev_lworkt
   compute_vlt
   compute_vrRA   R@   RN   R&   t   ft   Dt   ds   eig algorithm (geev)t   positivesC   did not converge (only eigenvalues with order >= %d have converged)g        N(   R]   R^   (   R   t   lenRI   t
   ValueErrorR"   R0   R[   R$   R%   RE   R>   R'   RH   RF   RG   R(   R5   R)   R/   (   t   at   bRL   RM   RN   RO   R\   R:   RJ   RK   R]   R^   R_   R`   R@   R*   RS   RT   RV   t   wrt   wiRZ   RY   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR   v   s^    `//	
c
         C` s   t  |  d |	 ƒ}
 t |
 j ƒ d k sA |
 j d |
 j d k rP t d ƒ ‚ n  | pb t |
 |  ƒ } t |
 ƒ rz t } n t } | d! k	 rRt  | d |	 ƒ} | p° t | | ƒ } t | j ƒ d k sâ | j d | j d k rñ t d ƒ ‚ n  | j |
 j k r.t d t	 | j ƒ t	 |
 j ƒ f ƒ ‚ n  t | ƒ rCt } qX| pLt } n d! } | rdd pgd } | d! k	 rè| \ } } | d k  s¡| |
 j d k rÅt d	 d |
 j d d f ƒ ‚ n  | d 7} | d 7} | | f } n  | r÷d
 } n d } | rd } n d } | d! k rì| d } t
 | f |
 f ƒ \ } | d! k r| |
 d | d | d d d d d |
 j d d | ƒ\ } } } qE| \ } } | |
 d | d | d d d | d | d | ƒ\ } } } | d | | d !} nY| d! k	 r†| d } t
 | f |
 | f ƒ \ } | \ } } | |
 | d | d | d | d | d | d | d | ƒ\ } } } } | d | | d !} n¿ | rê| d } t
 | f |
 | f ƒ \ } | |
 | d | d | d | d | d | ƒ\ } } } n[ | d } t
 | f |
 | f ƒ \ } | |
 | d | d | d | d | d | ƒ\ } } } | d k rh| r[| S| | f Sn  t | | d t ƒ| d k r¢| d! k r¢t d ƒ ‚ nz d | k  oÀ| j d k n r| d! k	 rît d t | ƒ d ƒ ‚ qt d | ƒ ‚ n t d  | | j d ƒ ‚ d! S("   sw  
    Solve an ordinary or generalized eigenvalue problem for a complex
    Hermitian or real symmetric matrix.

    Find eigenvalues w and optionally eigenvectors v of matrix `a`, where
    `b` is positive definite::

                      a v[:,i] = w[i] b v[:,i]
        v[i,:].conj() a v[:,i] = w[i]
        v[i,:].conj() b v[:,i] = 1

    Parameters
    ----------
    a : (M, M) array_like
        A complex Hermitian or real symmetric matrix whose eigenvalues and
        eigenvectors will be computed.
    b : (M, M) array_like, optional
        A complex Hermitian or real symmetric definite positive matrix in.
        If omitted, identity matrix is assumed.
    lower : bool, optional
        Whether the pertinent array data is taken from the lower or upper
        triangle of `a`. (Default: lower)
    eigvals_only : bool, optional
        Whether to calculate only eigenvalues and no eigenvectors.
        (Default: both are calculated)
    turbo : bool, optional
        Use divide and conquer algorithm (faster but expensive in memory,
        only for generalized eigenvalue problem and if eigvals=None)
    eigvals : tuple (lo, hi), optional
        Indexes of the smallest and largest (in ascending order) eigenvalues
        and corresponding eigenvectors to be returned: 0 <= lo <= hi <= M-1.
        If omitted, all eigenvalues and eigenvectors are returned.
    type : int, optional
        Specifies the problem type to be solved:

           type = 1: a   v[:,i] = w[i] b v[:,i]

           type = 2: a b v[:,i] = w[i]   v[:,i]

           type = 3: b a v[:,i] = w[i]   v[:,i]
    overwrite_a : bool, optional
        Whether to overwrite data in `a` (may improve performance)
    overwrite_b : bool, optional
        Whether to overwrite data in `b` (may improve performance)
    check_finite : bool, optional
        Whether to check that the input matrices contain only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.

    Returns
    -------
    w : (N,) float ndarray
        The N (1<=N<=M) selected eigenvalues, in ascending order, each
        repeated according to its multiplicity.
    v : (M, N) complex ndarray
        (if eigvals_only == False)

        The normalized selected eigenvector corresponding to the
        eigenvalue w[i] is the column v[:,i].

        Normalization:

            type 1 and 3: v.conj() a      v  = w

            type 2: inv(v).conj() a  inv(v) = w

            type = 1 or 2: v.conj() b      v  = I

            type = 3: v.conj() inv(b) v  = I

    Raises
    ------
    LinAlgError
        If eigenvalue computation does not converge,
        an error occurred, or b matrix is not definite positive. Note that
        if input matrices are not symmetric or hermitian, no error is reported
        but results will be wrong.

    See Also
    --------
    eigvalsh : eigenvalues of symmetric or Hermitian arrays
    eig : eigenvalues and right eigenvectors for non-symmetric arrays
    eigh : eigenvalues and right eigenvectors for symmetric/Hermitian arrays
    eigh_tridiagonal : eigenvalues and right eiegenvectors for
        symmetric/Hermitian tridiagonal matrices

    Notes
    -----
    This function does not check the input array for being hermitian/symmetric
    in order to allow for representing arrays with only their upper/lower
    triangular parts.

    Examples
    --------
    >>> from scipy.linalg import eigh
    >>> A = np.array([[6, 3, 1, 5], [3, 0, 5, 1], [1, 5, 6, 2], [5, 1, 2, 2]])
    >>> w, v = eigh(A)
    >>> np.allclose(A @ v - v @ np.diag(w), np.zeros((4, 4)))
    True

    R\   i   i    i   s   expected square matrixs#   wrong b dimensions %s, should be %st   Nt   VsC   The eigenvalue range specified is not valid.
Valid range is [%s,%s]t   Lt   Ut   het   syt   evrt   uplot   jobzt   ranget   At   ilt   iuRN   t   It   gvxt   itypeRO   t   gvdt   gvRd   s   unrecoverable internal error.s'   the eigenvectors %s failed to converge.sƒ   internal fortran routine failed to converge: %i off-diagonal elements of an intermediate tridiagonal form did not converge to zero.s    the leading minor of order %i of 'b' is not positive definite. The factorization of 'b' could not be completed and no eigenvalues or eigenvectors were computed.N(   R   Re   RI   Rf   R"   R   t   Truet   FalseR0   t   strR$   RG   R!   R   (   Rg   Rh   t   lowert   eigvals_onlyRN   RO   t   turboR   t   typeR\   RJ   t   cplxRK   t   _jobt   lot   hiRr   t   pfxt   driverRq   R*   R,   RV   t   w_totRy   t   ifailR{   R|   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR     sž    h/	/%	

		
!"


#i   R5   t   valuet   indexRg   R,   R.   c   	      C` s•  t  |  t ƒ r |  j ƒ  }  n  y t |  }  Wn t k
 rK t d ƒ ‚ n Xd \ } } d } } |  d k rt | ƒ } | j d k s¬ | j d k s¬ | d | d k  r» t d ƒ ‚ n  |  d k rë | \ } } | d k r|| } q|q| j	 j
 j ƒ  d k r%t d	 | j	 | j	 j
 f ƒ ‚ n  | d \ } } t | | ƒ d k  s_t | | ƒ | k rnt d
 ƒ ‚ n  | | d } n  |  | | | | | f S(   s5   Check that select is valid, convert to Fortran style.s   invalid argument for selectg        g      ð?i   i    i   sB   select_range must be a 2-element array-like in nondecreasing ordert   hilqpsL   when using select="i", select_range must contain integers, got dtype %s (%s)s   select_range out of bounds(   g        g      ð?(   t
   isinstanceR    R€   t
   _conv_dictt   KeyErrorRf   R   t   ndimt   sizeR'   RH   t   mint   max(	   t   selectt   select_ranget   max_evt   max_lenRS   t   vuRv   Rw   t   sr(    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyt   _check_selectõ  s0    
2*c         C` s  | s | r6 t  |  d | ƒ} | p0 t | |  ƒ } nI t |  ƒ } t | j j t ƒ ry t | ƒ j ƒ  ry t	 d ƒ ‚ n  d } t
 | j ƒ d k r£ t	 d ƒ ‚ n  t | | | | j d ƒ \ } }	 }
 } } } ~ | d k rD| j j d k rû d } n d	 } t | f | f ƒ \ } | | d
 | d | d | ƒ\ } } } n*| rSd } n  | j j d k r‰t d t d d d ƒf ƒ \ } n! t d t d d d ƒf ƒ \ } d | d ƒ } | j j d k rÕd } n d } t | f | f ƒ \ } | | |	 |
 | | d
 | d | d | d | d | d | ƒ\ } } } } } | |  } | sn| d d … d | … f } n  t | | ƒ | r…| S| | f S(   s  
    Solve real symmetric or complex hermitian band matrix eigenvalue problem.

    Find eigenvalues w and optionally right eigenvectors v of a::

        a v[:,i] = w[i] v[:,i]
        v.H v    = identity

    The matrix a is stored in a_band either in lower diagonal or upper
    diagonal ordered form:

        a_band[u + i - j, j] == a[i,j]        (if upper form; i <= j)
        a_band[    i - j, j] == a[i,j]        (if lower form; i >= j)

    where u is the number of bands above the diagonal.

    Example of a_band (shape of a is (6,6), u=2)::

        upper form:
        *   *   a02 a13 a24 a35
        *   a01 a12 a23 a34 a45
        a00 a11 a22 a33 a44 a55

        lower form:
        a00 a11 a22 a33 a44 a55
        a10 a21 a32 a43 a54 *
        a20 a31 a42 a53 *   *

    Cells marked with * are not used.

    Parameters
    ----------
    a_band : (u+1, M) array_like
        The bands of the M by M matrix a.
    lower : bool, optional
        Is the matrix in the lower form. (Default is upper form)
    eigvals_only : bool, optional
        Compute only the eigenvalues and no eigenvectors.
        (Default: calculate also eigenvectors)
    overwrite_a_band : bool, optional
        Discard data in a_band (may enhance performance)
    select : {'a', 'v', 'i'}, optional
        Which eigenvalues to calculate

        ======  ========================================
        select  calculated
        ======  ========================================
        'a'     All eigenvalues
        'v'     Eigenvalues in the interval (min, max]
        'i'     Eigenvalues with indices min <= i <= max
        ======  ========================================
    select_range : (min, max), optional
        Range of selected eigenvalues
    max_ev : int, optional
        For select=='v', maximum number of eigenvalues expected.
        For other values of select, has no meaning.

        In doubt, leave this parameter untouched.

    check_finite : bool, optional
        Whether to check that the input matrix contains only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.

    Returns
    -------
    w : (M,) ndarray
        The eigenvalues, in ascending order, each repeated according to its
        multiplicity.
    v : (M, M) float or complex ndarray
        The normalized eigenvector corresponding to the eigenvalue w[i] is
        the column v[:,i].

    Raises
    ------
    LinAlgError
        If eigenvalue computation does not converge.

    See Also
    --------
    eigvals_banded : eigenvalues for symmetric/Hermitian band matrices
    eig : eigenvalues and right eigenvectors of general arrays.
    eigh : eigenvalues and right eigenvectors for symmetric/Hermitian arrays
    eigh_tridiagonal : eigenvalues and right eiegenvectors for
        symmetric/Hermitian tridiagonal matrices

    Examples
    --------
    >>> from scipy.linalg import eig_banded
    >>> A = np.array([[1, 5, 2, 0], [5, 2, 5, 2], [2, 5, 3, 5], [0, 2, 5, 4]])
    >>> Ab = np.array([[1, 2, 3, 4], [5, 5, 5, 0], [2, 2, 0, 0]])
    >>> w, v = eig_banded(Ab, lower=True)
    >>> np.allclose(A @ v - v @ np.diag(w), np.zeros((4, 4)))
    True
    >>> w = eig_banded(Ab, lower=True, eigvals_only=True)
    >>> w
    array([-4.26200532, -2.22987175,  3.95222349, 12.53965359])

    Request only the eigenvalues between ``[-3, 4]``

    >>> w, v = eig_banded(Ab, lower=True, select='v', select_range=[-3, 4])
    >>> w
    array([-2.22987175,  3.95222349])

    R\   s#   array must not contain infs or NaNsi   i   s   expected two-dimensional arrayi    t   GFDt   hbevdt   sbevdt	   compute_vR€   t   overwrite_abt   fFt   lamchR'   Ra   Rc   t   st   hbevxt   sbevxt   mmaxRt   t   abstolN(   R£   (   R£   (   R   R"   R   t
   issubclassR'   Rƒ   R   R   R5   Rf   Re   RI   Rœ   RH   R$   RG   (   t   a_bandR€   R   t   overwrite_a_bandR–   R—   R˜   R\   RJ   RS   Rš   Rv   Rw   t   internal_namet   bevdR*   R,   RV   R£   R¨   t   bevxR-   R‹   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR     sP    k(+		$!	
c         C` s.   t  |  d | d d d d d | d | d | ƒS(   s  
    Compute eigenvalues from an ordinary or generalized eigenvalue problem.

    Find eigenvalues of a general matrix::

        a   vr[:,i] = w[i]        b   vr[:,i]

    Parameters
    ----------
    a : (M, M) array_like
        A complex or real matrix whose eigenvalues and eigenvectors
        will be computed.
    b : (M, M) array_like, optional
        Right-hand side matrix in a generalized eigenvalue problem.
        If omitted, identity matrix is assumed.
    overwrite_a : bool, optional
        Whether to overwrite data in a (may improve performance)
    check_finite : bool, optional
        Whether to check that the input matrices contain only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities
        or NaNs.
    homogeneous_eigvals : bool, optional
        If True, return the eigenvalues in homogeneous coordinates.
        In this case ``w`` is a (2, M) array so that::

            w[1,i] a vr[:,i] = w[0,i] b vr[:,i]

        Default is False.

    Returns
    -------
    w : (M,) or (2, M) double or complex ndarray
        The eigenvalues, each repeated according to its multiplicity
        but not in any specific order. The shape is (M,) unless
        ``homogeneous_eigvals=True``.

    Raises
    ------
    LinAlgError
        If eigenvalue computation does not converge

    See Also
    --------
    eig : eigenvalues and right eigenvectors of general arrays.
    eigvalsh : eigenvalues of symmetric or Hermitian arrays
    eigvals_banded : eigenvalues for symmetric/Hermitian band matrices
    eigvalsh_tridiagonal : eigenvalues of symmetric/Hermitian tridiagonal
        matrices

    Examples
    --------
    >>> from scipy import linalg
    >>> a = np.array([[0., -1.], [1., 0.]])
    >>> linalg.eigvals(a)
    array([0.+1.j, 0.-1.j])

    >>> b = np.array([[0., 1.], [1., 1.]])
    >>> linalg.eigvals(a, b)
    array([ 1.+0.j, -1.+0.j])

    >>> a = np.array([[3., 0., 0.], [0., 8., 0.], [0., 0., 7.]])
    >>> linalg.eigvals(a, homogeneous_eigvals=True)
    array([[3.+0.j, 8.+0.j, 7.+0.j],
           [1.+0.j, 1.+0.j, 1.+0.j]])

    Rh   RL   i    RM   RN   R\   R:   (   R   (   Rg   Rh   RN   R\   R:   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR   º  s    E!c	   	      C` s@   t  |  d | d | d t d | d | d | d | d | d	 | ƒ	S(
   s  
    Solve an ordinary or generalized eigenvalue problem for a complex
    Hermitian or real symmetric matrix.

    Find eigenvalues w of matrix a, where b is positive definite::

                      a v[:,i] = w[i] b v[:,i]
        v[i,:].conj() a v[:,i] = w[i]
        v[i,:].conj() b v[:,i] = 1


    Parameters
    ----------
    a : (M, M) array_like
        A complex Hermitian or real symmetric matrix whose eigenvalues and
        eigenvectors will be computed.
    b : (M, M) array_like, optional
        A complex Hermitian or real symmetric definite positive matrix in.
        If omitted, identity matrix is assumed.
    lower : bool, optional
        Whether the pertinent array data is taken from the lower or upper
        triangle of `a`. (Default: lower)
    turbo : bool, optional
        Use divide and conquer algorithm (faster but expensive in memory,
        only for generalized eigenvalue problem and if eigvals=None)
    eigvals : tuple (lo, hi), optional
        Indexes of the smallest and largest (in ascending order) eigenvalues
        and corresponding eigenvectors to be returned: 0 <= lo < hi <= M-1.
        If omitted, all eigenvalues and eigenvectors are returned.
    type : int, optional
        Specifies the problem type to be solved:

           type = 1: a   v[:,i] = w[i] b v[:,i]

           type = 2: a b v[:,i] = w[i]   v[:,i]

           type = 3: b a v[:,i] = w[i]   v[:,i]
    overwrite_a : bool, optional
        Whether to overwrite data in `a` (may improve performance)
    overwrite_b : bool, optional
        Whether to overwrite data in `b` (may improve performance)
    check_finite : bool, optional
        Whether to check that the input matrices contain only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.

    Returns
    -------
    w : (N,) float ndarray
        The N (1<=N<=M) selected eigenvalues, in ascending order, each
        repeated according to its multiplicity.

    Raises
    ------
    LinAlgError
        If eigenvalue computation does not converge,
        an error occurred, or b matrix is not definite positive. Note that
        if input matrices are not symmetric or hermitian, no error is reported
        but results will be wrong.

    See Also
    --------
    eigh : eigenvalues and right eigenvectors for symmetric/Hermitian arrays
    eigvals : eigenvalues of general arrays
    eigvals_banded : eigenvalues for symmetric/Hermitian band matrices
    eigvalsh_tridiagonal : eigenvalues of symmetric/Hermitian tridiagonal
        matrices

    Notes
    -----
    This function does not check the input array for being hermitian/symmetric
    in order to allow for representing arrays with only their upper/lower
    triangular parts.

    Examples
    --------
    >>> from scipy.linalg import eigvalsh
    >>> A = np.array([[6, 3, 1, 5], [3, 0, 5, 1], [1, 5, 6, 2], [5, 1, 2, 2]])
    >>> w = eigvalsh(A)
    >>> w
    array([-3.74637491, -0.76263923,  6.08502336, 12.42399079])

    Rh   R€   R   RN   RO   R‚   R   Rƒ   R\   (   R   R}   (	   Rg   Rh   R€   RN   RO   R‚   R   Rƒ   R\   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR     s    Vc         C` s.   t  |  d | d d d | d | d | d | ƒS(   s  
    Solve real symmetric or complex hermitian band matrix eigenvalue problem.

    Find eigenvalues w of a::

        a v[:,i] = w[i] v[:,i]
        v.H v    = identity

    The matrix a is stored in a_band either in lower diagonal or upper
    diagonal ordered form:

        a_band[u + i - j, j] == a[i,j]        (if upper form; i <= j)
        a_band[    i - j, j] == a[i,j]        (if lower form; i >= j)

    where u is the number of bands above the diagonal.

    Example of a_band (shape of a is (6,6), u=2)::

        upper form:
        *   *   a02 a13 a24 a35
        *   a01 a12 a23 a34 a45
        a00 a11 a22 a33 a44 a55

        lower form:
        a00 a11 a22 a33 a44 a55
        a10 a21 a32 a43 a54 *
        a20 a31 a42 a53 *   *

    Cells marked with * are not used.

    Parameters
    ----------
    a_band : (u+1, M) array_like
        The bands of the M by M matrix a.
    lower : bool, optional
        Is the matrix in the lower form. (Default is upper form)
    overwrite_a_band : bool, optional
        Discard data in a_band (may enhance performance)
    select : {'a', 'v', 'i'}, optional
        Which eigenvalues to calculate

        ======  ========================================
        select  calculated
        ======  ========================================
        'a'     All eigenvalues
        'v'     Eigenvalues in the interval (min, max]
        'i'     Eigenvalues with indices min <= i <= max
        ======  ========================================
    select_range : (min, max), optional
        Range of selected eigenvalues
    check_finite : bool, optional
        Whether to check that the input matrix contains only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.

    Returns
    -------
    w : (M,) ndarray
        The eigenvalues, in ascending order, each repeated according to its
        multiplicity.

    Raises
    ------
    LinAlgError
        If eigenvalue computation does not converge.

    See Also
    --------
    eig_banded : eigenvalues and right eigenvectors for symmetric/Hermitian
        band matrices
    eigvalsh_tridiagonal : eigenvalues of symmetric/Hermitian tridiagonal
        matrices
    eigvals : eigenvalues of general arrays
    eigh : eigenvalues and right eigenvectors for symmetric/Hermitian arrays
    eig : eigenvalues and right eigenvectors for non-symmetric arrays

    Examples
    --------
    >>> from scipy.linalg import eigvals_banded
    >>> A = np.array([[1, 5, 2, 0], [5, 2, 5, 2], [2, 5, 3, 5], [0, 2, 5, 4]])
    >>> Ab = np.array([[1, 2, 3, 4], [5, 5, 5, 0], [2, 2, 0, 0]])
    >>> w = eigvals_banded(Ab, lower=True)
    >>> w
    array([-4.26200532, -2.22987175,  3.95222349, 12.53965359])
    R€   R   i   R«   R–   R—   R\   (   R   (   Rª   R€   R«   R–   R—   R\   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR   `  s    Wg        t   autoc         C` s1   t  |  | d t d | d | d | d | d | ƒS(   sH
  
    Solve eigenvalue problem for a real symmetric tridiagonal matrix.

    Find eigenvalues `w` of ``a``::

        a v[:,i] = w[i] v[:,i]
        v.H v    = identity

    For a real symmetric matrix ``a`` with diagonal elements `d` and
    off-diagonal elements `e`.

    Parameters
    ----------
    d : ndarray, shape (ndim,)
        The diagonal elements of the array.
    e : ndarray, shape (ndim-1,)
        The off-diagonal elements of the array.
    select : {'a', 'v', 'i'}, optional
        Which eigenvalues to calculate

        ======  ========================================
        select  calculated
        ======  ========================================
        'a'     All eigenvalues
        'v'     Eigenvalues in the interval (min, max]
        'i'     Eigenvalues with indices min <= i <= max
        ======  ========================================
    select_range : (min, max), optional
        Range of selected eigenvalues
    check_finite : bool, optional
        Whether to check that the input matrix contains only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.
    tol : float
        The absolute tolerance to which each eigenvalue is required
        (only used when ``lapack_driver='stebz'``).
        An eigenvalue (or cluster) is considered to have converged if it
        lies in an interval of this width. If <= 0. (default),
        the value ``eps*|a|`` is used where eps is the machine precision,
        and ``|a|`` is the 1-norm of the matrix ``a``.
    lapack_driver : str
        LAPACK function to use, can be 'auto', 'stemr', 'stebz',  'sterf',
        or 'stev'. When 'auto' (default), it will use 'stemr' if ``select='a'``
        and 'stebz' otherwise. 'sterf' and 'stev' can only be used when
        ``select='a'``.

    Returns
    -------
    w : (M,) ndarray
        The eigenvalues, in ascending order, each repeated according to its
        multiplicity.

    Raises
    ------
    LinAlgError
        If eigenvalue computation does not converge.

    See Also
    --------
    eigh_tridiagonal : eigenvalues and right eiegenvectors for
        symmetric/Hermitian tridiagonal matrices

    Examples
    --------
    >>> from scipy.linalg import eigvalsh_tridiagonal, eigvalsh
    >>> d = 3*np.ones(4)
    >>> e = -1*np.ones(3)
    >>> w = eigvalsh_tridiagonal(d, e)
    >>> A = np.diag(d) + np.diag(e, k=1) + np.diag(e, k=-1)
    >>> w2 = eigvalsh(A)  # Verify with other eigenvalue routines
    >>> np.allclose(w - w2, np.zeros(4))
    True
    R   R–   R—   R\   t   tolt   lapack_driver(   R	   R}   (   Rc   t   eR–   R—   R\   R°   R±   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR
   ¼  s    Kc         C` s%  t  |  d | ƒ}  t  | d | ƒ} xS |  | f D]E } | j d k rU t d ƒ ‚ n  | j j d k r1 t d ƒ ‚ q1 q1 W|  j | j d k r¯ t d |  j | j f ƒ ‚ n  t | | d |  j ƒ \ } }	 }
 } } } t | t	 ƒ s÷ t d ƒ ‚ n  d } | | k r"t d | | f ƒ ‚ n  | d	 k rI| d k r@d
 n d } n  t
 | f |  | f ƒ \ } | } | d k rË| d k r’t d ƒ ‚ n  | s§t d ƒ ‚ n  | |  | ƒ \ } } t | ƒ } n†| d k r| d k ròt d ƒ ‚ n  | |  | d | ƒ\ } } } t | ƒ } n2| d k r t | ƒ } d } t
 | f |  | f ƒ \ } | rdd n d } | |  | | |	 |
 | | | | ƒ	 \ } } } } } n± t | j d | j ƒ } | | d *t
 d  |  | f ƒ \ } | |  | | |	 |
 | | d | ƒ\ } } } t | d ƒ | |  | | |	 |
 | | d | d | d | ƒ\ } } } } t | | d ƒ | |  } | rv| S| d k rût
 d! |  | f ƒ \ } | |  | | | | ƒ \ } } t | d d d ƒt | ƒ } | | | d d … | f } } n | d d … d | … f } | | f Sd S("   sä  
    Solve eigenvalue problem for a real symmetric tridiagonal matrix.

    Find eigenvalues `w` and optionally right eigenvectors `v` of ``a``::

        a v[:,i] = w[i] v[:,i]
        v.H v    = identity

    For a real symmetric matrix ``a`` with diagonal elements `d` and
    off-diagonal elements `e`.

    Parameters
    ----------
    d : ndarray, shape (ndim,)
        The diagonal elements of the array.
    e : ndarray, shape (ndim-1,)
        The off-diagonal elements of the array.
    select : {'a', 'v', 'i'}, optional
        Which eigenvalues to calculate

        ======  ========================================
        select  calculated
        ======  ========================================
        'a'     All eigenvalues
        'v'     Eigenvalues in the interval (min, max]
        'i'     Eigenvalues with indices min <= i <= max
        ======  ========================================
    select_range : (min, max), optional
        Range of selected eigenvalues
    check_finite : bool, optional
        Whether to check that the input matrix contains only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.
    tol : float
        The absolute tolerance to which each eigenvalue is required
        (only used when 'stebz' is the `lapack_driver`).
        An eigenvalue (or cluster) is considered to have converged if it
        lies in an interval of this width. If <= 0. (default),
        the value ``eps*|a|`` is used where eps is the machine precision,
        and ``|a|`` is the 1-norm of the matrix ``a``.
    lapack_driver : str
        LAPACK function to use, can be 'auto', 'stemr', 'stebz', 'sterf',
        or 'stev'. When 'auto' (default), it will use 'stemr' if ``select='a'``
        and 'stebz' otherwise. When 'stebz' is used to find the eigenvalues and
        ``eigvals_only=False``, then a second LAPACK call (to ``?STEIN``) is
        used to find the corresponding eigenvectors. 'sterf' can only be
        used when ``eigvals_only=True`` and ``select='a'``. 'stev' can only
        be used when ``select='a'``.

    Returns
    -------
    w : (M,) ndarray
        The eigenvalues, in ascending order, each repeated according to its
        multiplicity.
    v : (M, M) ndarray
        The normalized eigenvector corresponding to the eigenvalue ``w[i]`` is
        the column ``v[:,i]``.

    Raises
    ------
    LinAlgError
        If eigenvalue computation does not converge.

    See Also
    --------
    eigvalsh_tridiagonal : eigenvalues of symmetric/Hermitian tridiagonal
        matrices
    eig : eigenvalues and right eigenvectors for non-symmetric arrays
    eigh : eigenvalues and right eigenvectors for symmetric/Hermitian arrays
    eig_banded : eigenvalues and right eigenvectors for symmetric/Hermitian
        band matrices

    Notes
    -----
    This function makes use of LAPACK ``S/DSTEMR`` routines.

    Examples
    --------
    >>> from scipy.linalg import eigh_tridiagonal
    >>> d = 3*np.ones(4)
    >>> e = -1*np.ones(3)
    >>> w, v = eigh_tridiagonal(d, e)
    >>> A = np.diag(d) + np.diag(e, k=1) + np.diag(e, k=-1)
    >>> np.allclose(A @ v - v @ np.diag(w), np.zeros((4, 4)))
    True
    R\   i   s   expected one-dimensional arrayR   s$   Only real arrays currently supporteds-   d (%s) must have one more element than e (%s)i    s   lapack_driver must be strR¯   t   stemrt   sterft   stebzt   stevs'   lapack_driver must be one of %s, got %ss)   sterf can only be used when select == "a"s0   sterf can only be used when eigvals_only is Trues(   stev can only be used when select == "a"R    t   Et   Biÿÿÿÿt   stemr_lworkR@   t   liworks    (eigh_tridiagonal)t   steins   stein (eigh_tridiagonal)Rd   s"   %d eigenvectors failed to convergeN(   R¯   R³   R´   Rµ   R¶   (   R¹   (   R»   (   R   R’   Rf   R'   RH   t	   TypeErrorR“   Rœ   R   R    R$   Re   t   floatR   RG   R   (   Rc   R²   R   R–   R—   R\   R°   R±   t   checkRS   Rš   Rv   Rw   t   _t   driverst   funcR    R*   RV   R-   R,   R¬   Rµ   t   ordert   iblockt   isplitt   e_R¹   R@   Rº   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR	     s|    X'
!
$s!   did not converge (LAPACK info=%d)c         C` sY   |  d k  r& t  d |  | f ƒ ‚ n  |  d k rU | rU t d | | |  f ƒ ‚ n  d S(   s   Check info return value.i    s+   illegal value in argument %d of internal %ss   %s N(   Rf   R!   (   RV   R‰   Rd   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyRG   ­  s
    c         C` sþ  t  |  d | ƒ} t | j ƒ d k sA | j d | j d k rP t d ƒ ‚ n  | pb t | |  ƒ } | j d d k rœ | r˜ | t j | j d ƒ f S| St d | f ƒ \ } } } | | d	 d d
 | ƒ\ } }	 }
 } } t | d d t	 ƒt | ƒ } t
 | | j d d |	 d |
 ƒ} | | d |	 d |
 d | d
 d ƒ\ } } } t | d d t	 ƒt j | d ƒ } | s{| St d | f ƒ \ } } t
 | | d |	 d |
 ƒ} | d | d | d |	 d |
 d | d
 d ƒ \ } } t | d d t	 ƒ| | f S(   s  
    Compute Hessenberg form of a matrix.

    The Hessenberg decomposition is::

        A = Q H Q^H

    where `Q` is unitary/orthogonal and `H` has only zero elements below
    the first sub-diagonal.

    Parameters
    ----------
    a : (M, M) array_like
        Matrix to bring into Hessenberg form.
    calc_q : bool, optional
        Whether to compute the transformation matrix.  Default is False.
    overwrite_a : bool, optional
        Whether to overwrite `a`; may improve performance.
        Default is False.
    check_finite : bool, optional
        Whether to check that the input matrix contains only finite numbers.
        Disabling may give a performance gain, but may result in problems
        (crashes, non-termination) if the inputs do contain infinities or NaNs.

    Returns
    -------
    H : (M, M) ndarray
        Hessenberg form of `a`.
    Q : (M, M) ndarray
        Unitary/orthogonal similarity transformation matrix ``A = Q H Q^H``.
        Only returned if ``calc_q=True``.

    Examples
    --------
    >>> from scipy.linalg import hessenberg
    >>> A = np.array([[2, 5, 8, 7], [5, 2, 2, 8], [7, 5, 6, 6], [5, 4, 4, 8]])
    >>> H, Q = hessenberg(A, calc_q=True)
    >>> H
    array([[  2.        , -11.65843866,   1.42005301,   0.25349066],
           [ -9.94987437,  14.53535354,  -5.31022304,   2.43081618],
           [  0.        ,  -1.83299243,   0.38969961,  -0.51527034],
           [  0.        ,   0.        ,  -3.83189513,   1.07494686]])
    >>> np.allclose(Q @ H @ Q.conj().T - A, np.zeros((4, 4)))
    True
    R\   i   i    i   s   expected square matrixt   gehrdt   gebalt   gehrd_lworkt   permuteRN   s   gebal (hessenberg)Rd   R†   R‡   R@   s   gehrd (hessenberg)iÿÿÿÿt   orghrt   orghr_lworkRg   t   taus   orghr (hessenberg)(   RÆ   RÇ   RÈ   (   RÊ   RË   (   R   Re   RI   Rf   R"   R(   R   R$   RG   R~   R%   t   triu(   Rg   t   calc_qRN   R\   RJ   RÆ   RÇ   RÈ   t   baR†   R‡   t   pivscaleRV   t   nR@   t   hqRÌ   t   hRÊ   RË   t   q(    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR   ¶  s0    ./'"-3c         C` sú  t  |  ƒ t  | ƒ }  } |  j d k  r7 t d ƒ ‚ n  | j d k  rU t d ƒ ‚ n  | j |  j d k rz t d ƒ ‚ n  |  j d } |  j d  } | j d | j d k r½ t d ƒ ‚ n  | j d | k rß t d	 ƒ ‚ n  t |  ƒ } | j d
 d ƒ } | d d k j ƒ  s"t d ƒ ‚ n  t | ƒ } | d  } | d } | d d d … }	 | d d d … }
 d } x` | D]X } | d d d … | d d d … k j ƒ  s³t d ƒ ‚ | | d d d … f 7} quWt	 | | | f d |  j
 j ƒ} t | ƒ } |  j
 | d | | f <|  | |	 f j | | |	 |
 f <|  | |
 f j | | |
 |	 f <t	 | | | f d t j ƒ} d | d | | f <d | | |	 |	 f <d | | |	 |
 f <d | | |
 |	 f <d | | |
 |
 f <t d | | ƒ j
 } | | f S(   sº	  
    Converts complex eigenvalues ``w`` and eigenvectors ``v`` to real
    eigenvalues in a block diagonal form ``wr`` and the associated real
    eigenvectors ``vr``, such that::

        vr @ wr = X @ vr

    continues to hold, where ``X`` is the original array for which ``w`` and
    ``v`` are the eigenvalues and eigenvectors.

    .. versionadded:: 1.1.0

    Parameters
    ----------
    w : (..., M) array_like
        Complex or real eigenvalues, an array or stack of arrays

        Conjugate pairs must not be interleaved, else the wrong result
        will be produced. So ``[1+1j, 1, 1-1j]`` will give a correct result, but
        ``[1+1j, 2+1j, 1-1j, 2-1j]`` will not.

    v : (..., M, M) array_like
        Complex or real eigenvectors, a square array or stack of square arrays.

    Returns
    -------
    wr : (..., M, M) ndarray
        Real diagonal block form of eigenvalues
    vr : (..., M, M) ndarray
        Real eigenvectors associated with ``wr``

    See Also
    --------
    eig : Eigenvalues and right eigenvectors for non-symmetric arrays
    rsf2csf : Convert real Schur form to complex Schur form

    Notes
    -----
    ``w``, ``v`` must be the eigenstructure for some *real* matrix ``X``.
    For example, obtained by ``w, v = scipy.linalg.eig(X)`` or
    ``w, v = numpy.linalg.eig(X)`` in which case ``X`` can also represent
    stacked arrays.

    .. versionadded:: 1.1.0

    Examples
    --------
    >>> X = np.array([[1, 2, 3], [0, 4, 5], [0, -5, 4]])
    >>> X
    array([[ 1,  2,  3],
           [ 0,  4,  5],
           [ 0, -5,  4]])

    >>> from scipy import linalg
    >>> w, v = linalg.eig(X)
    >>> w
    array([ 1.+0.j,  4.+5.j,  4.-5.j])
    >>> v
    array([[ 1.00000+0.j     , -0.01906-0.40016j, -0.01906+0.40016j],
           [ 0.00000+0.j     ,  0.00000-0.64788j,  0.00000+0.64788j],
           [ 0.00000+0.j     ,  0.64788+0.j     ,  0.64788-0.j     ]])

    >>> wr, vr = linalg.cdf2rdf(w, v)
    >>> wr
    array([[ 1.,  0.,  0.],
           [ 0.,  4.,  5.],
           [ 0., -5.,  4.]])
    >>> vr
    array([[ 1.     ,  0.40016, -0.01906],
           [ 0.     ,  0.64788,  0.     ],
           [ 0.     ,  0.     ,  0.64788]])

    >>> vr @ wr
    array([[ 1.     ,  1.69593,  1.9246 ],
           [ 0.     ,  2.59153,  3.23942],
           [ 0.     , -3.23942,  2.59153]])
    >>> X @ vr
    array([[ 1.     ,  1.69593,  1.9246 ],
           [ 0.     ,  2.59153,  3.23942],
           [ 0.     , -3.23942,  2.59153]])
    i   s)   expected w to be at least one-dimensionali   s)   expected v to be at least two-dimensionalsU   expected eigenvectors array to have exactly one dimension more than eigenvalues arrayiÿÿÿÿiþÿÿÿsV   expected v to be a square matrix or stacked square matrices: v.shape[-2] = v.shape[-1]s7   expected the same number of eigenvalues as eigenvectorst   axisi    s/   expected complex-conjugate pairs of eigenvaluesNs(   Conjugate pair spanned different arrays!R'   .g      ð?y              à?g      à?y              à¿s   ...ij,...jk->...ik(    (   R   R’   Rf   RI   R   t   sumR5   R   t   AssertionErrorR   RB   R'   Rt   R)   R(   t   cdoubleR   (   R*   R,   RÑ   t   Mt   complex_maskt	   n_complext   idxt	   idx_stackt   idx_elemt   jt   kt	   stack_indR.   Ri   t   dit   uRT   (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyR     sN    R

8"""(7   t
   __future__R    R   R   t   __all__R(   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   scipy._lib.sixR   t   scipy._lib._utilR   R    t   miscR!   R"   R#   t   lapackR$   R%   RF   R/   R>   R[   R0   R~   R}   R   R   R   Rœ   R   R   R   R   R
   R	   RG   R   R   (    (    (    s2   lib/python2.7/site-packages/scipy/linalg/decomp.pyt   <module>   sN   p			*—à	 	¤	I	Z[O	 	P