Skip to content
fn

eigh

→Tensor
eigh(input: Tensor, UPLO: str = 'L')

Implementing kernel

C++ engine symbols that back this Python API.

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

inputTensor
Square Hermitian / symmetric matrix of shape (*, n, n).
UPLOstr= 'L'
"L" (default) reads only the lower triangle of input; "U" reads only the upper triangle; case does not matter. 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 (V⊤V=IV^\top V = I).

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

∂L∂A = V (diag(Gλ)+F⊙(V⊤GV)) 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.382, 3.618])

Used by 1