We don’t have a high-level API for that yet (only SciPy has it afaict), but it’s not a problem as you can just use the generalized LAPACK interface, see this example:
program example_dggev
use iso_fortran_env, only: dp => real64
use stdlib_linalg_lapack, only: ggev ! generic-type wrapper to *GGEV functions
implicit none
real(dp), allocatable :: A(:,:), B(:,:), ALPHAR(:), ALPHAI(:), BETA(:), VL(:,:), VR(:,:), WORK(:)
integer :: N, LDA, LDB, LDVL, LDVR, INFO, LWORK, i
! Define matrix sizes
N = 2
! Allocate matrices and vectors
allocate(A(N, N), B(N, N), ALPHAR(N), ALPHAI(N), BETA(N), VL(N, N), VR(N, N))
! Define matrices A and B
A = reshape([1.0_dp, 2.0_dp, 3.0_dp, 4.0_dp], shape=[N, N]) ! Example matrix A
B = reshape([2.0_dp, 0.0_dp, 0.0_dp, 2.0_dp], shape=[N, N]) ! Example matrix B
! Leading dimensions
LDA = N
LDB = N
LDVL = N
LDVR = N
! Query workspace (LWORK)
LWORK = -1
allocate(WORK(1))
call ggev('N', 'V', N, A, LDA, B, LDB, ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO)
LWORK = nint(WORK(1))
deallocate(WORK); allocate(WORK(LWORK))
print *, 'LWORK = ',LWORK
! Solve the generalized eigenvalue problem A*x = λ*B*x
call ggev('N', 'V', N, A, LDA, B, LDB, ALPHAR, ALPHAI, BETA, VL, LDVL, VR, LDVR, WORK, LWORK, INFO)
! Check for success
if (INFO == 0) then
print *, "Generalized eigenvalues (lam = ALPHAR/BETA):"
print *, (ALPHAR(i)/BETA(i), ALPHAI(i)/BETA(i), i=1, N)
print *, "Right eigenvectors (VR):"
print *, VR
else
print *, "Error: ggev failed with INFO =", INFO
end if
! Deallocate arrays
deallocate(A, B, ALPHAR, ALPHAI, BETA, VL, VR)
end program example_dggev
Note the correct LAPACK function is GGEV
, not the simpler GEEV
.
Please open an Issue on the stdlib page and I’m happy to help add handling of the non-identity eigenvector case!