Computes the eigenvalue decomposition of a square matrix if it exists.
Source:R/linalg.R
linalg_eig.Rd
Letting be or , the eigenvalue decomposition of a square matrix (if it exists) is defined as
Arguments
- A
(Tensor): tensor of shape
(*, n, n)
where*
is zero or more batch dimensions consisting of diagonalizable matrices.
Value
A list (eigenvalues, eigenvectors)
which corresponds to and above.
eigenvalues
and eigenvectors
will always be complex-valued, even when A
is real. The eigenvectors
will be given by the columns of eigenvectors
.
Details
This decomposition exists if and only if is diagonalizable
_.
This is the case when all its eigenvalues are different.
Supports input of float, double, cfloat and cdouble dtypes.
Also supports batches of matrices, and if A
is a batch of matrices then
the output has the same batch dimensions.
Warning
This function assumes that
A
isdiagonalizable
_ (for example, when all the eigenvalues are different). If it is not diagonalizable, the returned eigenvalues will be correct but .The eigenvectors of a matrix are not unique, nor are they continuous with respect to
A
. Due to this lack of uniqueness, different hardware and software may compute different eigenvectors. This non-uniqueness is caused by the fact that multiplying an eigenvector by a non-zero number produces another set of valid eigenvectors of the matrix. In this implmentation, the returned eigenvectors are normalized to have norm1
and largest real component.Gradients computed using
V
will only be finite whenA
does not have repeated eigenvalues. Furthermore, if the distance between any two eigenvalues is close to zero, the gradient will be numerically unstable, as it depends on the eigenvalues through the computation of .
See also
linalg_eigvals()
computes only the eigenvalues. Unlikelinalg_eig()
, the gradients oflinalg_eigvals()
are always numerically stable.linalg_eigh()
for a (faster) function that computes the eigenvalue decomposition for Hermitian and symmetric matrices.linalg_svd()
for a function that computes another type of spectral decomposition that works on matrices of any shape.linalg_qr()
for another (much faster) decomposition that works on matrices of any shape.
Other linalg:
linalg_cholesky_ex()
,
linalg_cholesky()
,
linalg_det()
,
linalg_eigh()
,
linalg_eigvalsh()
,
linalg_eigvals()
,
linalg_householder_product()
,
linalg_inv_ex()
,
linalg_inv()
,
linalg_lstsq()
,
linalg_matrix_norm()
,
linalg_matrix_power()
,
linalg_matrix_rank()
,
linalg_multi_dot()
,
linalg_norm()
,
linalg_pinv()
,
linalg_qr()
,
linalg_slogdet()
,
linalg_solve_triangular()
,
linalg_solve()
,
linalg_svdvals()
,
linalg_svd()
,
linalg_tensorinv()
,
linalg_tensorsolve()
,
linalg_vector_norm()
Examples
if (torch_is_installed()) {
a <- torch_randn(2, 2)
wv <- linalg_eig(a)
}