-
-
Notifications
You must be signed in to change notification settings - Fork 37
Description
The eigen / eigen! functions of the LinearAlgebra package fail with the Adjoint and Transposed types.
Given a square matrix A (e.g. a 10×10 Array{Float64,2}), both the following statements fail:
E = eigen(A')
E = eigen(transpose(A))
with errors
ERROR: MethodError: no method matching eigen(::Adjoint{Float64,Array{Float64,2}})
and
ERROR: MethodError: no method matching eigen(::Transpose{Float64,Array{Float64,2}})
respectively.
A simple fix could be to define the method
LinearAlgebra.eigen(x::Union{Transpose{T, A}, Adjoint{T, A}}) where {T, A<:AbstractMatrix} = eigen(copy(x)) (credit: Twan Koolen on discourse).
However, it could be more efficient to use LAPACK functions directly computing left eigenvectors (i.e. eigenvectors of the transposed) without making another copy of the matrix. It looks like the wrapper LinearAlgebra.LAPACK.geevx! has such a feature. In eigen.jl, the lower level LAPACK call (line 40 as of tag v1.0.0) is
A, WR, WI, VL, VR, _ = LAPACK.geevx!(permute ? (scale ? 'B' : 'P') : (scale ? 'S' : 'N'), 'N', 'V', 'N', A)
According to the documentation,
A, WR, WI, VL, VR, _ = LAPACK.geevx!(permute ? (scale ? 'B' : 'P') : (scale ? 'S' : 'N'), 'V', 'N', 'N', A)
should compute left eigenvectors instead.
I am very new to Julia (I have been mostly a Matlab programmer so far), so I am not quite sure what is a clean way to insert such a fix into eigen.jl. At least, duplicating the eigen! code in eigen.jl does not seem to be a very good idea. Also, adding this may not cover all eigen methods for special matrices. (The eigen! method in eigen.jl applies to StridedMatrix{T}, which I assume excludes at least sparse matrices.)
Note: this issue is similar to Issue #523 regarding svdfact (now svd) which was fixed in PR JuliaLang/julia#27916 . The fix for svd will not work here though.