I have to calculate the eigenvector and eigenvalues for many (more than 60.000) non-Hermitian 4x4 matrices. I know that this can be slightly speed up by means of using LinearAlgebra.LAPACK.geevx! instead of using the eigen() function itself. However, if I would do this in C++ and use the eigen library for C++ (using the compiling option O3 and fastmath) I can even speed up this calculation by a factor 2 … 3. Is there an opportunity to reach the same speed like the C++ eigen library by a Package for instance? Using the option @fastmath in Julia does not change the performance.
StaticArrays
should be better.
Thanks for the answer. But if I haven’t overseen it, StaticArrays
has no eigen()
function for non-Hermitian matrices and use than the built-in function of julia, so that result is the same. E.g.,
using BenchmarkTools
using LinearAlgebra
using StaticArraysm = rand(4,4) + im*rand(4,4);
M = SMatrix{4,4, ComplexF64}(m)
@benchmark eigen($m)
@benchmark eigen($M)
Thanks for the link. But this seems to be quite limited to hermitian matrices and only for size of 3x3
Are you perhaps missing a parameter in the SMatrix declaration?
SMatrix{4,4,ComplexF64,16}
Is needed I think?
The above mentioned example still works on my PC (julia 1.7.3) even without the 16 in the declaration. Anyway, even if I add this in the declaration, the evaluation time is roughly the same.
@benchmark eigen($m)
leads to
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 12.680 μs … 258.653 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 14.110 μs ┊ GC (median): 0.00%
Time (mean ± σ): 16.117 μs ± 7.016 μs ┊ GC (mean ± σ): 0.00% ± 0.00%
Memory estimate: 10.23 KiB, allocs estimate: 22.
while for StaticArrays
, i.e. @benchmark eigen($M)
was used I get
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 12.849 μs … 11.458 ms ┊ GC (min … max): 0.00% … 99.67%
Time (median): 14.216 μs ┊ GC (median): 0.00%
Time (mean ± σ): 16.555 μs ± 114.533 μs ┊ GC (mean ± σ): 6.90% ± 1.00%
Memory estimate: 10.89 KiB, allocs estimate: 24.
which is quite similar