torch.eig
-
torch.eig(input, eigenvectors=False, *, out=None) -> (Tensor, Tensor) -
Computes the eigenvalues and eigenvectors of a real square matrix.
Note
Since eigenvalues and eigenvectors might be complex, backward pass is supported only if eigenvalues and eigenvectors are all real valued.
When
inputis on CUDA,torch.eig()causes host-device synchronization.- Parameters
- Keyword Arguments
-
out (tuple, optional) – the output tensors
- Returns
-
A namedtuple (eigenvalues, eigenvectors) containing
-
eigenvalues (Tensor): Shape . Each row is an eigenvalue of
input, where the first element is the real part and the second element is the imaginary part. The eigenvalues are not necessarily ordered. -
eigenvectors (Tensor): If
eigenvectors=False, it’s an empty tensor. Otherwise, this tensor of shape can be used to compute normalized (unit length) eigenvectors of corresponding eigenvalues as follows. If the correspondingeigenvalues[j]is a real number, columneigenvectors[:, j]is the eigenvector corresponding toeigenvalues[j]. If the correspondingeigenvalues[j]andeigenvalues[j + 1]form a complex conjugate pair, then the true eigenvectors can be computed as , .
-
eigenvalues (Tensor): Shape . Each row is an eigenvalue of
- Return type
Example:
Trivial example with a diagonal matrix. By default, only eigenvalues are computed: >>> a = torch.diag(torch.tensor([1, 2, 3], dtype=torch.double)) >>> e, v = torch.eig(a) >>> e tensor([[1., 0.], [2., 0.], [3., 0.]], dtype=torch.float64) >>> v tensor([], dtype=torch.float64) Compute also the eigenvectors: >>> e, v = torch.eig(a, eigenvectors=True) >>> e tensor([[1., 0.], [2., 0.], [3., 0.]], dtype=torch.float64) >>> v tensor([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]], dtype=torch.float64)
© 2019 Torch Contributors
Licensed under the 3-clause BSD License.
https://pytorch.org/docs/1.8.0/generated/torch.eig.html