Computes the eigenvalue decomposition of a square matrix if it exists.
Computes the eigenvalue decomposition of a square matrix if it exists.
Letting be or , the eigenvalue decomposition of a square matrix (if it exists) is defined as
linalg_eig(A)
Arguments
A: (Tensor): tensor of shape (*, n, n) where * is zero or more batch dimensions consisting of diagonalizable matrices.
Returns
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
torch:::math_to_rd(" A = V \operatorname{diag}(\Lambda)V^{-1}\mathrlap{\qquad V \in \mathbb{C}^{n \times n}, \Lambda\in \mathbb{C}^n} ")
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.
Note
The eigenvalues and eigenvectors of a real matrix may be complex.
Warning
This function assumes that A is diagonalizable_ (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 norm 1 and largest real component.
Gradients computed using V will only be finite when A 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 .