Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eigen decomposition of Diagonal matrix returns Dense eigenvectors #53007

Open
jecs opened this issue Jan 22, 2024 · 3 comments
Open

Eigen decomposition of Diagonal matrix returns Dense eigenvectors #53007

jecs opened this issue Jan 22, 2024 · 3 comments
Labels
good first issue Indicates a good issue for first-time contributors to Julia linear algebra Linear algebra

Comments

@jecs
Copy link

jecs commented Jan 22, 2024

Hello. I noticed today that if you have a matrix of Diagonal type, then the eigenvector matrix (from eigvecs or eigen) is not of type Diagonal. Wouldn't it make more sense for the eigenvectors to match the type of the input matrix, when possible?

For example, if I have A = Diagonal(rand(10)), then eigvecs(A;kwarg...) should return a Diagonal (e.g. one(A)), but eigvecs(Matrix(A);kwarg...) should return a Matrix (e.g. one(Matrix(A))), and so on. The same changes would be needed for eigen(...).

@dkarrasch dkarrasch added the linear algebra Linear algebra label Jan 22, 2024
@MasonProtter MasonProtter added the good first issue Indicates a good issue for first-time contributors to Julia label Jan 23, 2024
@fredrikekre
Copy link
Member

This would be incompatible with the sortby kwarg since the return type would have to depend on the value of sortby then.

@jecs
Copy link
Author

jecs commented Jan 24, 2024

Maybe for Diagonal, using sortby could return view(one(A),:,p) where p is the permutation? Or would this introduce type instability?

@eschnett
Copy link
Contributor

Isn't eigenvector calculation type unstable anyway? eigvecs checks whether the matrix is symmetric (by checking the values in the matrix), and if so, returns a real-valued result. Thus a dependence on a keyword argument shouldn't matter.

julia> A = randn(4,4);

julia> typeof(eigvecs(A))
Matrix{ComplexF64} (alias for Array{Complex{Float64}, 2})

julia> typeof(eigvecs(A+A'))
Matrix{Float64} (alias for Array{Float64, 2})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Indicates a good issue for first-time contributors to Julia linear algebra Linear algebra
Projects
None yet
Development

No branches or pull requests

5 participants