fn

eig

Tensor
eig(x: Tensor)
source

Eigenvalue decomposition of a general square matrix.

For a general (not necessarily symmetric) square matrix AA returns eigenvalues λi\lambda_i and right eigenvectors viv_i such that

Avi=λivi,A=VΛV1.A v_i \,=\, \lambda_i\, v_i, \qquad A \,=\, V\,\Lambda\,V^{-1}.

For matrices with complex eigenvalues, the result is in general complex-valued. When AA is known to be symmetric / Hermitian prefer eigh — it is faster, more stable, and produces real eigenvalues with orthogonal eigenvectors.

Parameters

xTensor
Square matrix of shape (*, n, n).

Returns

Tensor

Tensor of shape (*, n). Real for real-spectrum matrices, complex otherwise.

Notes

Backed by LAPACK geev. Cost is O(n3)O(n^3). This op currently has no autograd support — gradients through eigendecomposition of a general matrix are notoriously unstable near defective spectra and not implemented.

Examples

>>> import lucid
>>> from lucid.linalg import eig
>>> A = lucid.tensor([[2.0, 0.0], [0.0, 3.0]])
>>> w, V = eig(A)
>>> w
Tensor([2.0000, 3.0000])