Skip to content

torch.eig should return complex tensor #43081

@zasdfgbnm

Description

@zasdfgbnm

Currently the return value of torch.eig is:

eigenvalues (Tensor):

Shape (n \times 2)(n×2) . 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 (n \times n)(n×n) can be used to compute normalized (unit length)
eigenvectors of corresponding eigenvalues as follows. If the corresponding eigenvalues[j]
is a real number, column eigenvectors[:, j] is the eigenvector corresponding to eigenvalues[j].
If the corresponding eigenvalues[j] and eigenvalues[j + 1] form a complex conjugate pair,
then the true eigenvectors can be computed as
\text{true eigenvector}[j] = eigenvectors[:, j] + i \times eigenvectors[:, j + 1]true eigenvector[j]=eigenvectors[:,j]+i×eigenvectors[:,j+1] ,
\text{true eigenvector}[j + 1] = eigenvectors[:, j] - i \times eigenvectors[:, j + 1]true eigenvector[j+1]=eigenvectors[:,j−i×eigenvectors[:,j+1] .

This behavior is because of historical reason when complex tensors was not a thing. Since complex tensor is now supported,
the return value of eigenvalues should then be a complex tensor of shape (n,), and eigenvectors should also be a complex tensor of shape (n,n) where eignvectors[:,j] is the jth eigen vector.

cc @ezyang @anjali411 @dylanbespalko @mruberry @gchanan @vincentqb @vishwakftw @jianyuh @nikitaved @pearu

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNot as big of a feature, but technically not a bug. Should be easy to fixmodule: bc-breakingRelated to a BC-breaking changemodule: complexRelated to complex number support in PyTorchmodule: linear algebraIssues related to specialized linear algebra operations in PyTorch; includes matrix multiply matmultriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions