torch.Tensor.Tensor.eigvalsh
Tensor.eigvalsh(options?: EighOptions): Tensor<DynamicShape, D, Dev>Tensor.eigvalsh(UPLO: 'L' | 'U', options?: EighOptions): Tensor<DynamicShape, D, Dev>Computes only the eigenvalues of a Hermitian (symmetric) matrix (without eigenvectors).
Fast eigenvalue computation for symmetric matrices, returning real eigenvalues in
ascending order. Faster than eigh() when you don't need eigenvectors. Essential
for quick spectral analysis of covariance matrices, Gram matrices, and optimization
problems where you need condition numbers or stability checks.
Use Cases:
- Quick condition number estimation
- Positive-definite verification
- Spectral radius estimation
- Stability analysis without eigenvectors
- Performance-critical eigenvalue-only computations
- Real eigenvalues: Always returns real values
- Sorted order: Returns eigenvalues in ascending order
- UPLO usage: Only specified triangle is used
- Efficiency: Faster than eigh() when eigenvectors not needed
- Batch support: Works with batched matrices
Parameters
optionsEighOptionsoptional
Returns
Tensor<DynamicShape, D, Dev>– Real eigenvalues in ascending orderExamples
// Fast eigenvalue computation
const A = torch.tensor([[4, 1], [1, 3]]);
const eigenvalues = A.eigvalsh(); // [2.38, 4.62] (real, sorted)
// Condition number from eigenvalues
const { eigenvalues: eigs } = A.eigh();
const condition_number = eigs[-1] / eigs[0];
// Check positive-definite
const eigs = A.eigvalsh();
const is_spd = eigs.min() > 0;See Also
- PyTorch torch.eigvalsh() (or tensor.eigvalsh())
- eigh - Full eigendecomposition for Hermitian matrices
- eigvals - Eigenvalues for general matrices
- eig - General eigendecomposition
- svd - Singular value decomposition