torch.linalg.eigh
- torch.linalg.eigh(A, UPLO='L', *, out=None)
Computes the eigenvalue decomposition of a complex Hermitian or real symmetric matrix.
Letting be or , the of a complex Hermitian or real symmetric matrix is defined as
Computes the eigenvalue decomposition of a complex Hermitian or real symmetric matrix.
Letting be or , the of a complex Hermitian or real symmetric matrix is defined as
where is the conjugate transpose when is complex, and the transpose when is real-valued. is orthogonal in the real case and unitary in the complex case.
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.
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.
The eigenvalues are returned in ascending order.
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’.
out (tuple, optional) – output tuple of two tensors. Ignored if None. Default: None.
A named tuple (eigenvalues, eigenvectors) which corresponds to and above.
eigenvalues will always be real-valued, even when A is complex.
It will also be ordered in ascending order.
eigenvectors will have the same dtype as A and will contain the eigenvectors as its columns.
>>> 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)
>>> L, Q = torch.linalg.eigh(A)
>>> L
tensor([0.3277, 2.9415], dtype=torch.float64)
>>> Q
tensor([[-0.0846+-0.0000j, -0.9964+0.0000j],
[ 0.9170+0.3898j, -0.0779-0.0331j]], dtype=torch.complex128)
>>> torch.dist(Q @ torch.diag(L.cdouble()) @ Q.T.conj(), A)
tensor(6.1062e-16, dtype=torch.float64)
>>> A = torch.randn(3, 2, 2, dtype=torch.float64)
>>> A = A + A.mT # creates a batch of symmetric matrices
>>> L, Q = torch