I'm looking for an efficient algorithm (preferred for Julia) to calculate the eigenvectors of a 4x4 non-Hermitian matrix having a structure of
a b 0 c
0 0 -1 0
d e 0 f
g h 0 i
I know that I can in principle use the build-in function of Julia or python. However, although Julia is mentioned as fast being quite fast, the calculations are a factor 2 slower than if I would use the C++ eigen library (with fastmath option). So I’m wondering, which algorithm the eigen library is using in this case and if one can be transferred to Julia or Python.
Thanks for any hints and comments
Update
Thanks for the comments and not being accurate enough. Here is an example, which works in Julia
using BenchmarkTools
using LinearAlgebra
using StaticArrays
function foo(A)
eigen(A)
return
end
function foo2(A)
@fastmath eigen(A)
return
end
function foo3(A)
LinearAlgebra.LAPACK.geevx!('B', 'N', 'V', 'N', copy(A))
return
end
A = rand(4,4) + im*rand(4,4);
A[:,3] .= 0;
A[2,:] .= 0;
A[2,3] = 1;
AStatic = SMatrix{4,4, ComplexF64}(A)
@benchmark eigen($A)
@benchmark eigen($AStatic)
@benchmark foo($AStatic)
@benchmark foo2($AStatic)
@benchmark foo3($A)
@AboAmmar Actually I need the eigenvalues and the eigenvectors. The julia version I used, uses OpenBlas. However, even using MKL (MKL.jl) the performance gain is very small
Also the usage of the fastmath option does not change anything. Maybe, the functions which I'm calling are already compiled so that this option does not work here.
Also the use StaticArrays might be useful in some cases. But for non-hermitian matrices the function calls the build-in function of Julia. The QR and LU decomposition can be used, but they will not provide me the eigenvalues. Even eigenvals() is not applicable for non-Hermitian matrices
@Jérôme Richard thanks for the link to the post. I'm afraid that a manual determinnation, e.g., by using Ferraris method requieres a lot computation and the speed will be the same.