fn

eigh

Tensor
eigh(x: Tensor, UPLO: str = 'L')
source

Eigendecomposition of a Hermitian / symmetric matrix.

Returns the eigenvalues and orthonormal eigenvectors of a real symmetric (or complex Hermitian) matrix AA. Eigenvalues are returned in ascending order and eigenvectors form an orthogonal matrix VV such that

A=VΛV,A \,=\, V \,\Lambda\, V^\top,

where Λ=diag(λ1,,λn)\Lambda = \mathrm{diag}(\lambda_1, \ldots, \lambda_n) with λ1λn\lambda_1 \le \cdots \le \lambda_n.

Parameters

xTensor
Square Hermitian / symmetric matrix of shape (*, n, n).
UPLOstr= 'L'
"L" (default) reads only the lower triangle of x; "U" reads only the upper triangle. The other triangle is ignored, so a non-Hermitian input is accepted as long as the chosen triangle holds the correct values.

Returns

Tensor

Real-valued tensor of shape (*, n) in ascending order.

Notes

Prefer this over eig whenever A is symmetric / Hermitian — it is faster, numerically more stable, and guarantees real eigenvalues with orthogonal eigenvectors (VV=IV^\top V = I).

Backward uses the Loewner-matrix formula Fij=1/(λiλj)F_{ij} = 1/(\lambda_i - \lambda_j):

LA=V(diag(Gλ)+F(VGV))V,\frac{\partial \mathcal{L}}{\partial A} \,=\, V\,\big(\mathrm{diag}(G_\lambda) + F \odot (V^\top G_V)\big)\,V^\top,

symmetrised to enforce the symmetry of AA. Gradients blow up near repeated eigenvalues.

Implementation: LAPACK syevd on the CPU stream (via Apple Accelerate); MLX on the GPU stream. Both run in O(n3)O(n^3).

Examples

>>> import lucid
>>> from lucid.linalg import eigh
>>> A = lucid.tensor([[2.0, 1.0], [1.0, 3.0]])
>>> w, V = eigh(A)
>>> w
Tensor([1.3820, 3.6180])