linalg.decomp

Module Contents

Functions

_make_complex_eigvecs(w,vin,dtype) Produce complex-valued eigenvectors from LAPACK DGGEV real-valued output
_make_eigvals(alpha,beta,homogeneous_eigvals)
_geneig(a1,b1,left,right,overwrite_a,overwrite_b,homogeneous_eigvals)
eig(a,b=None,left=False,right=True,overwrite_a=False,overwrite_b=False,check_finite=True,homogeneous_eigvals=False) Solve an ordinary or generalized eigenvalue problem of a square matrix.
eigh(a,b=None,lower=True,eigvals_only=False,overwrite_a=False,overwrite_b=False,turbo=True,eigvals=None,type=1,check_finite=True) Solve an ordinary or generalized eigenvalue problem for a complex
_check_select(select,select_range,max_ev,max_len) Check that select is valid, convert to Fortran style.
eig_banded(a_band,lower=False,eigvals_only=False,overwrite_a_band=False,select=”a”,select_range=None,max_ev=0,check_finite=True) Solve real symmetric or complex hermitian band matrix eigenvalue problem.
eigvals(a,b=None,overwrite_a=False,check_finite=True,homogeneous_eigvals=False) Compute eigenvalues from an ordinary or generalized eigenvalue problem.
eigvalsh(a,b=None,lower=True,overwrite_a=False,overwrite_b=False,turbo=True,eigvals=None,type=1,check_finite=True) Solve an ordinary or generalized eigenvalue problem for a complex
eigvals_banded(a_band,lower=False,overwrite_a_band=False,select=”a”,select_range=None,check_finite=True) Solve real symmetric or complex hermitian band matrix eigenvalue problem.
eigvalsh_tridiagonal(d,e,select=”a”,select_range=None,check_finite=True,tol=0.0,lapack_driver=”auto”) Solve eigenvalue problem for a real symmetric tridiagonal matrix.
eigh_tridiagonal(d,e,eigvals_only=False,select=”a”,select_range=None,check_finite=True,tol=0.0,lapack_driver=”auto”) Solve eigenvalue problem for a real symmetric tridiagonal matrix.
_check_info(info,driver,positive=”did not converge (LAPACK info=%d)”) Check info return value.
hessenberg(a,calc_q=False,overwrite_a=False,check_finite=True) Compute Hessenberg form of a matrix.
_make_complex_eigvecs(w, vin, dtype)

Produce complex-valued eigenvectors from LAPACK DGGEV real-valued output

_make_eigvals(alpha, beta, homogeneous_eigvals)
_geneig(a1, b1, left, right, overwrite_a, overwrite_b, homogeneous_eigvals)
eig(a, b=None, left=False, right=True, overwrite_a=False, overwrite_b=False, check_finite=True, homogeneous_eigvals=False)

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.

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.

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.
LinAlgError
If eigenvalue computation does not converge.

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
eigh(a, b=None, lower=True, eigvals_only=False, overwrite_a=False, overwrite_b=False, turbo=True, eigvals=None, type=1, check_finite=True)

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
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.
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

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.

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
_check_select(select, select_range, max_ev, max_len)

Check that select is valid, convert to Fortran style.

eig_banded(a_band, lower=False, eigvals_only=False, overwrite_a_band=False, select="a", select_range=None, max_ev=0, check_finite=True)

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.

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.
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].
LinAlgError
If eigenvalue computation does not converge.

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
eigvals(a, b=None, overwrite_a=False, check_finite=True, homogeneous_eigvals=False)

Compute eigenvalues from an ordinary or generalized eigenvalue problem.

Find eigenvalues of a general matrix:

a   vr[:,i] = w[i]        b   vr[:,i]
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.

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.
LinAlgError
If eigenvalue computation does not converge

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
eigvalsh(a, b=None, lower=True, overwrite_a=False, overwrite_b=False, turbo=True, eigvals=None, type=1, check_finite=True)

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
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.
w : (N,) float ndarray
The N (1<=N<=M) selected eigenvalues, in ascending order, each repeated according to its multiplicity.
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.

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
eigvals_banded(a_band, lower=False, overwrite_a_band=False, select="a", select_range=None, check_finite=True)

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.

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.
w : (M,) ndarray
The eigenvalues, in ascending order, each repeated according to its multiplicity.
LinAlgError
If eigenvalue computation does not converge.
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

eigvalsh_tridiagonal(d, e, select="a", select_range=None, check_finite=True, tol=0.0, lapack_driver="auto")

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.

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'.
w : (M,) ndarray
The eigenvalues, in ascending order, each repeated according to its multiplicity.
LinAlgError
If eigenvalue computation does not converge.
eigh_tridiagonal : eigenvalues and right eiegenvectors for
symmetric/Hermitian tridiagonal matrices
eigh_tridiagonal(d, e, eigvals_only=False, select="a", select_range=None, check_finite=True, tol=0.0, lapack_driver="auto")

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.

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'.
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].
LinAlgError
If eigenvalue computation does not converge.
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

This function makes use of LAPACK S/DSTEMR routines.

_check_info(info, driver, positive="did not converge (LAPACK info=%d)")

Check info return value.

hessenberg(a, calc_q=False, overwrite_a=False, check_finite=True)

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.

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.
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.