# torch.linalg.eigvalsh¶

torch.linalg.eigvalsh(A, UPLO='L', *, out=None) → Tensor

Computes the eigenvalues of a complex Hermitian or real symmetric matrix.

Letting $\mathbb{K}$ be $\mathbb{R}$ or $\mathbb{C}$, the eigenvalues of a complex Hermitian or real symmetric matrix $A \in \mathbb{K}^{n \times n}$ are defined as the roots (counted with multiplicity) of the polynomial p of degree n given by

$p(\lambda) = \operatorname{det}(A - \lambda \mathrm{I}_n)\mathrlap{\qquad \lambda \in \mathbb{R}}$

where $\mathrm{I}_n$ is the n-dimensional identity matrix. The eigenvalues of a real symmetric or complex Hermitian matrix are always real.

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.

The eigenvalues are returned in ascending order.

A is assumed to be Hermitian (resp. symmetric), but this is not checked internally, instead:

• If UPLO= ‘L’ (default), only the lower triangular part of the matrix is used in the computation.

• If UPLO= ‘U’, only the upper triangular part of the matrix is used.

Note

When inputs are on a CUDA device, this function synchronizes that device with the CPU.

torch.linalg.eigh() computes the full eigenvalue decomposition.

Parameters
• A (Tensor) – tensor of shape (*, n, n) where * is zero or more batch dimensions consisting of symmetric or Hermitian matrices.

• UPLO ('L', 'U', optional) – controls whether to use the upper or lower triangular part of A in the computations. Default: ‘L’.

Keyword Arguments

out (Tensor, optional) – output tensor. Ignored if None. Default: None.

Returns

A real-valued tensor cointaining the eigenvalues even when A is complex. The eigenvalues are returned in ascending order.

Examples:

>>> a = torch.randn(2, 2, dtype=torch.complex128)
>>> a = a + a.t().conj()  # creates a Hermitian matrix
>>> a
tensor([[2.9228+0.0000j, 0.2029-0.0862j],
[0.2029+0.0862j, 0.3464+0.0000j]], dtype=torch.complex128)
>>> w = torch.linalg.eigvalsh(a)
>>> w
tensor([0.3277, 2.9415], dtype=torch.float64)

>>> a = torch.randn(3, 2, 2, dtype=torch.float64)
>>> a = a + a.transpose(-2, -1)  # creates a symmetric matrix
>>> a
tensor([[[ 2.8050, -0.3850],
[-0.3850,  3.2376]],

[[-1.0307, -2.7457],
[-2.7457, -1.7517]],

[[ 1.7166,  2.2207],
[ 2.2207, -2.0898]]], dtype=torch.float64)
>>> w = torch.linalg.eigvalsh(a)
>>> w
tensor([[ 2.5797,  3.4629],
[-4.1605,  1.3780],
[-3.1113,  2.7381]], dtype=torch.float64)