Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
Clojure
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Helion
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Yul (Solidity IR)
Zig
Javascript
GIMPLE
Ygen
sway
fortran source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
AARCH64 gfortran 10.5.0
AARCH64 gfortran 11.4.0
AARCH64 gfortran 12.1.0
AARCH64 gfortran 12.2.0
AARCH64 gfortran 12.3.0
AARCH64 gfortran 12.4.0
AARCH64 gfortran 12.5.0
AARCH64 gfortran 13.1.0
AARCH64 gfortran 13.2.0
AARCH64 gfortran 13.3.0
AARCH64 gfortran 13.4.0
AARCH64 gfortran 14.1.0
AARCH64 gfortran 14.2.0
AARCH64 gfortran 14.3.0
AARCH64 gfortran 15.1.0
AARCH64 gfortran 15.2.0
AARCH64 gfortran 4.9.4
AARCH64 gfortran 5.5.0
AARCH64 gfortran 6.4
AARCH64 gfortran 7.3
AARCH64 gfortran 8.2
ARM (32bit) gfortran 10.5.0
ARM (32bit) gfortran 11.4.0
ARM (32bit) gfortran 12.1.0
ARM (32bit) gfortran 12.2.0
ARM (32bit) gfortran 12.3.0
ARM (32bit) gfortran 12.4.0
ARM (32bit) gfortran 12.5.0
ARM (32bit) gfortran 13.1.0
ARM (32bit) gfortran 13.2.0
ARM (32bit) gfortran 13.3.0
ARM (32bit) gfortran 13.4.0
ARM (32bit) gfortran 14.1.0
ARM (32bit) gfortran 14.2.0
ARM (32bit) gfortran 14.3.0
ARM (32bit) gfortran 15.1.0
ARM (32bit) gfortran 15.2.0
ARM (32bit) gfortran 6.4
ARM (32bit) gfortran 7.3
ARM (32bit) gfortran 8.2
HPPA gfortran 14.2.0
HPPA gfortran 14.3.0
HPPA gfortran 15.1.0
HPPA gfortran 15.2.0
LFortran 0.42.0
LFortran 0.43.0
LFortran 0.44.0
LFortran 0.45.0
LFortran 0.46.0
LFortran 0.47.0
LFortran 0.48.0
LFortran 0.49.0
LFortran 0.50.0
LFortran 0.51.0
LFortran 0.52.0
LOONGARCH64 gfortran 12.2.0
LOONGARCH64 gfortran 12.3.0
LOONGARCH64 gfortran 12.4.0
LOONGARCH64 gfortran 12.5.0
LOONGARCH64 gfortran 13.1.0
LOONGARCH64 gfortran 13.2.0
LOONGARCH64 gfortran 13.3.0
LOONGARCH64 gfortran 13.4.0
LOONGARCH64 gfortran 14.1.0
LOONGARCH64 gfortran 14.2.0
LOONGARCH64 gfortran 14.3.0
LOONGARCH64 gfortran 15.1.0
LOONGARCH64 gfortran 15.2.0
MIPS gfortran 12.1.0
MIPS gfortran 12.2.0
MIPS gfortran 12.3.0
MIPS gfortran 12.4.0
MIPS gfortran 12.5.0
MIPS gfortran 13.1.0
MIPS gfortran 13.2.0
MIPS gfortran 13.3.0
MIPS gfortran 13.4.0
MIPS gfortran 14.1.0
MIPS gfortran 14.2.0
MIPS gfortran 14.3.0
MIPS gfortran 15.1.0
MIPS gfortran 15.2.0
MIPS gfortran 4.9.4
MIPS gfortran 5.5.0
MIPS gfortran 9.5.0
MIPS64 gfortran 12.1.0
MIPS64 gfortran 12.2.0
MIPS64 gfortran 12.3.0
MIPS64 gfortran 12.4.0
MIPS64 gfortran 12.5.0
MIPS64 gfortran 13.1.0
MIPS64 gfortran 13.2.0
MIPS64 gfortran 13.3.0
MIPS64 gfortran 13.4.0
MIPS64 gfortran 14.1.0
MIPS64 gfortran 14.2.0
MIPS64 gfortran 14.3.0
MIPS64 gfortran 15.1.0
MIPS64 gfortran 15.2.0
MIPS64 gfortran 4.9.4
MIPS64 gfortran 5.5.0
MIPS64 gfortran 9.5.0
MIPS64el gfortran 12.1.0
MIPS64el gfortran 12.2.0
MIPS64el gfortran 12.3.0
MIPS64el gfortran 12.4.0
MIPS64el gfortran 12.5.0
MIPS64el gfortran 13.1.0
MIPS64el gfortran 13.2.0
MIPS64el gfortran 13.3.0
MIPS64el gfortran 13.4.0
MIPS64el gfortran 14.1.0
MIPS64el gfortran 14.2.0
MIPS64el gfortran 14.3.0
MIPS64el gfortran 15.1.0
MIPS64el gfortran 15.2.0
MIPS64el gfortran 4.9.4
MIPS64el gfortran 5.5.0
MIPS64el gfortran 9.5.0
MIPSel gfortran 12.1.0
MIPSel gfortran 12.2.0
MIPSel gfortran 12.3.0
MIPSel gfortran 12.4.0
MIPSel gfortran 12.5.0
MIPSel gfortran 13.1.0
MIPSel gfortran 13.2.0
MIPSel gfortran 13.3.0
MIPSel gfortran 13.4.0
MIPSel gfortran 14.1.0
MIPSel gfortran 14.2.0
MIPSel gfortran 14.3.0
MIPSel gfortran 15.1.0
MIPSel gfortran 15.2.0
MIPSel gfortran 4.9.4
MIPSel gfortran 5.5.0
MIPSel gfortran 9.5.0
POWER gfortran 12.1.0
POWER gfortran 12.2.0
POWER gfortran 12.3.0
POWER gfortran 12.4.0
POWER gfortran 12.5.0
POWER gfortran 13.1.0
POWER gfortran 13.2.0
POWER gfortran 13.3.0
POWER gfortran 13.4.0
POWER gfortran 14.1.0
POWER gfortran 14.2.0
POWER gfortran 14.3.0
POWER gfortran 15.1.0
POWER gfortran 15.2.0
POWER64 gfortran 12.1.0
POWER64 gfortran 12.2.0
POWER64 gfortran 12.3.0
POWER64 gfortran 12.4.0
POWER64 gfortran 12.5.0
POWER64 gfortran 13.1.0
POWER64 gfortran 13.2.0
POWER64 gfortran 13.3.0
POWER64 gfortran 13.4.0
POWER64 gfortran 14.1.0
POWER64 gfortran 14.2.0
POWER64 gfortran 14.3.0
POWER64 gfortran 15.1.0
POWER64 gfortran 15.2.0
POWER64 gfortran trunk
POWER64le gfortran 12.1.0
POWER64le gfortran 12.2.0
POWER64le gfortran 12.3.0
POWER64le gfortran 12.4.0
POWER64le gfortran 12.5.0
POWER64le gfortran 13.1.0
POWER64le gfortran 13.2.0
POWER64le gfortran 13.3.0
POWER64le gfortran 13.4.0
POWER64le gfortran 14.1.0
POWER64le gfortran 14.2.0
POWER64le gfortran 14.3.0
POWER64le gfortran 15.1.0
POWER64le gfortran 15.2.0
POWER64le gfortran trunk
RISC-V 32-bits gfortran (trunk)
RISC-V 32-bits gfortran 12.1.0
RISC-V 64-bits gfortran (trunk)
RISC-V 64-bits gfortran 12.1.0
RISCV (32bit) gfortran 11.4.0
RISCV (32bit) gfortran 12.2.0
RISCV (32bit) gfortran 12.3.0
RISCV (32bit) gfortran 12.4.0
RISCV (32bit) gfortran 12.5.0
RISCV (32bit) gfortran 13.1.0
RISCV (32bit) gfortran 13.2.0
RISCV (32bit) gfortran 13.3.0
RISCV (32bit) gfortran 13.4.0
RISCV (32bit) gfortran 14.1.0
RISCV (32bit) gfortran 14.2.0
RISCV (32bit) gfortran 14.3.0
RISCV (32bit) gfortran 15.1.0
RISCV (32bit) gfortran 15.2.0
RISCV64 gfortran 11.4.0
RISCV64 gfortran 12.2.0
RISCV64 gfortran 12.3.0
RISCV64 gfortran 12.4.0
RISCV64 gfortran 12.5.0
RISCV64 gfortran 13.1.0
RISCV64 gfortran 13.2.0
RISCV64 gfortran 13.3.0
RISCV64 gfortran 13.4.0
RISCV64 gfortran 14.1.0
RISCV64 gfortran 14.2.0
RISCV64 gfortran 14.3.0
RISCV64 gfortran 15.1.0
RISCV64 gfortran 15.2.0
SPARC LEON gfortran 12.2.0
SPARC LEON gfortran 12.3.0
SPARC LEON gfortran 12.4.0
SPARC LEON gfortran 12.5.0
SPARC LEON gfortran 13.1.0
SPARC LEON gfortran 13.2.0
SPARC LEON gfortran 13.3.0
SPARC LEON gfortran 13.4.0
SPARC LEON gfortran 14.1.0
SPARC LEON gfortran 14.2.0
SPARC LEON gfortran 14.3.0
SPARC LEON gfortran 15.1.0
SPARC LEON gfortran 15.2.0
SPARC gfortran 12.2.0
SPARC gfortran 12.3.0
SPARC gfortran 12.4.0
SPARC gfortran 12.5.0
SPARC gfortran 13.1.0
SPARC gfortran 13.2.0
SPARC gfortran 13.3.0
SPARC gfortran 13.4.0
SPARC gfortran 14.1.0
SPARC gfortran 14.2.0
SPARC gfortran 14.3.0
SPARC gfortran 15.1.0
SPARC gfortran 15.2.0
SPARC64 gfortran 12.2.0
SPARC64 gfortran 12.3.0
SPARC64 gfortran 12.4.0
SPARC64 gfortran 12.5.0
SPARC64 gfortran 13.1.0
SPARC64 gfortran 13.2.0
SPARC64 gfortran 13.3.0
SPARC64 gfortran 13.4.0
SPARC64 gfortran 14.1.0
SPARC64 gfortran 14.2.0
SPARC64 gfortran 14.3.0
SPARC64 gfortran 15.1.0
SPARC64 gfortran 15.2.0
Tricore gfortran 11.3.0 (EEESlab)
flang-trunk
flang-trunk-fc1
power64 AT12.0
power64 AT13.0
power64le AT12.0
power64le AT13.0
s390x gfortran 12.1.0
s390x gfortran 12.2.0
s390x gfortran 12.3.0
s390x gfortran 12.4.0
s390x gfortran 12.5.0
s390x gfortran 13.1.0
s390x gfortran 13.2.0
s390x gfortran 13.3.0
s390x gfortran 13.4.0
s390x gfortran 14.1.0
s390x gfortran 14.2.0
s390x gfortran 14.3.0
s390x gfortran 15.1.0
s390x gfortran 15.2.0
x86 nvfortran 24.11
x86 nvfortran 24.9
x86 nvfortran 25.1
x86 nvfortran 25.3
x86 nvfortran 25.5
x86 nvfortran 25.7
x86 nvfortran 25.9
x86-64 gfortran (trunk)
x86-64 gfortran 10.1
x86-64 gfortran 10.2
x86-64 gfortran 10.3
x86-64 gfortran 10.3 (assertions)
x86-64 gfortran 10.4
x86-64 gfortran 10.4 (assertions)
x86-64 gfortran 10.5
x86-64 gfortran 10.5 (assertions)
x86-64 gfortran 11.1
x86-64 gfortran 11.1 (assertions)
x86-64 gfortran 11.2
x86-64 gfortran 11.2 (assertions)
x86-64 gfortran 11.3
x86-64 gfortran 11.3 (assertions)
x86-64 gfortran 11.4
x86-64 gfortran 11.4 (assertions)
x86-64 gfortran 12.1
x86-64 gfortran 12.1 (assertions)
x86-64 gfortran 12.2
x86-64 gfortran 12.2 (assertions)
x86-64 gfortran 12.3
x86-64 gfortran 12.3 (assertions)
x86-64 gfortran 12.4
x86-64 gfortran 12.4 (assertions)
x86-64 gfortran 12.5
x86-64 gfortran 12.5 (assertions)
x86-64 gfortran 13.1
x86-64 gfortran 13.1 (assertions)
x86-64 gfortran 13.2
x86-64 gfortran 13.2 (assertions)
x86-64 gfortran 13.3
x86-64 gfortran 13.3 (assertions)
x86-64 gfortran 13.4
x86-64 gfortran 13.4 (assertions)
x86-64 gfortran 14.1
x86-64 gfortran 14.1 (assertions)
x86-64 gfortran 14.2
x86-64 gfortran 14.2 (assertions)
x86-64 gfortran 14.3
x86-64 gfortran 14.3 (assertions)
x86-64 gfortran 15.1
x86-64 gfortran 15.1 (assertions)
x86-64 gfortran 15.2
x86-64 gfortran 15.2 (assertions)
x86-64 gfortran 4.9.4
x86-64 gfortran 5.5
x86-64 gfortran 6.3
x86-64 gfortran 7.1
x86-64 gfortran 7.2
x86-64 gfortran 7.3
x86-64 gfortran 8.1
x86-64 gfortran 8.2
x86-64 gfortran 8.3
x86-64 gfortran 8.4
x86-64 gfortran 8.5
x86-64 gfortran 9.1
x86-64 gfortran 9.2
x86-64 gfortran 9.3
x86-64 gfortran 9.4
x86-64 ifort 19.0.0
x86-64 ifort 2021.1.2
x86-64 ifort 2021.10.0
x86-64 ifort 2021.11.0
x86-64 ifort 2021.2.0
x86-64 ifort 2021.3.0
x86-64 ifort 2021.4.0
x86-64 ifort 2021.5.0
x86-64 ifort 2021.6.0
x86-64 ifort 2021.7.0
x86-64 ifort 2021.7.1
x86-64 ifort 2021.8.0
x86-64 ifort 2021.9.0
x86-64 ifx (latest)
x86-64 ifx 2021.1.2
x86-64 ifx 2021.2.0
x86-64 ifx 2021.3.0
x86-64 ifx 2021.4.0
x86-64 ifx 2022.0.0
x86-64 ifx 2022.1.0
x86-64 ifx 2022.2.0
x86-64 ifx 2022.2.1
x86-64 ifx 2023.0.0
x86-64 ifx 2023.1.0
x86-64 ifx 2023.2.1
x86-64 ifx 2024.0.0
Options
Source code
program test use stdlib_linalg, only: eig use stdlib_linalg_lapack, only: ggev use stdlib_linalg_constants use stdlib_linalg use stdlib_linalg_state use, intrinsic:: ieee_arithmetic, only: ieee_value, ieee_positive_inf, ieee_quiet_nan implicit none character(*), parameter :: this="eig" integer, parameter :: n=2 double complex, dimension(n,n) :: A_Z,S_Z double precision, dimension(n,n) :: A_D,S_D double complex, dimension(n,n) :: vecs_r double complex,dimension(n) :: eigs integer :: i ! Set matrix A_Z = reshape( [ [1, 6], & [9, 2] ], [n,n] ) S_Z = 0 do i= 1,2 S_Z(i,i) = i end do A_D = real(A_Z) S_D = real(S_Z) call stdlib_linalg_eig_generalized_z(A_Z,S_Z,eigs,right=vecs_r) !Fails !call eig(A_Z,S_Z,eigs,right=vecs_r) !Fails write(*,*) eigs write(*,*) vecs_r contains !> Process GGEV output flags pure subroutine handle_ggev_info(err,info,shapea,shapeb) !> Error handler type(linalg_state_type), intent(inout) :: err !> GEEV return flag integer(ilp), intent(in) :: info !> Input matrix size integer(ilp), intent(in) :: shapea(2),shapeb(2) select case (info) case (0) ! Success! err%state = LINALG_SUCCESS case (-1) err = linalg_state_type(this,LINALG_INTERNAL_ERROR,'Invalid task ID: left eigenvectors.') case (-2) err = linalg_state_type(this,LINALG_INTERNAL_ERROR,'Invalid task ID: right eigenvectors.') case (-5,-3) err = linalg_state_type(this,LINALG_VALUE_ERROR,'invalid matrix size: a=',shapea) case (-7) err = linalg_state_type(this,LINALG_VALUE_ERROR,'invalid matrix size: b=',shapeb) case (-12) err = linalg_state_type(this,LINALG_VALUE_ERROR,'insufficient left vector matrix size.') case (-14) err = linalg_state_type(this,LINALG_VALUE_ERROR,'insufficient right vector matrix size.') case (-16) err = linalg_state_type(this,LINALG_INTERNAL_ERROR,'Insufficient work array size.') case (1:) err = linalg_state_type(this,LINALG_ERROR,'Eigenvalue computation did not converge.') case default err = linalg_state_type(this,LINALG_INTERNAL_ERROR,'Unknown error returned by ggev.') end select end subroutine handle_ggev_info !> Request for eigenvector calculation elemental character function eigenvectors_task(required) logical, intent(in) :: required eigenvectors_task = merge('V','N',required) end function eigenvectors_task subroutine stdlib_linalg_eig_generalized_z(a,b,lambda,right,left,& overwrite_a,overwrite_b,err) !! Eigendecomposition of matrix A returning an array `lambda` of eigenvalues, !! and optionally right or left eigenvectors. !> Input matrix A[m,n] complex(dp), intent(inout), dimension(:,:), target :: a !> Generalized problem matrix B[n,n] complex(dp), intent(inout), dimension(:,:), target :: b !> Array of eigenvalues complex(dp), intent(out) :: lambda(:) !> [optional] RIGHT eigenvectors of A (as columns) complex(dp), optional, intent(out), target :: right(:,:) !> [optional] LEFT eigenvectors of A (as columns) complex(dp), optional, intent(out), target :: left(:,:) !> [optional] Can A data be overwritten and destroyed? (default: no) logical(lk), optional, intent(in) :: overwrite_a !> [optional] Can B data be overwritten and destroyed? (default: no) logical(lk), optional, intent(in) :: overwrite_b !> [optional] state return flag. On error if not requested, the code will stop type(linalg_state_type), optional, intent(out) :: err !> Local variables type(linalg_state_type) :: err0 integer(ilp) :: m,n,lda,ldu,ldv,info,k,lwork,neig,ldb,nb logical(lk) :: copy_a,copy_b character :: task_u,task_v complex(dp), target :: work_dummy(1),u_dummy(1,1),v_dummy(1,1) complex(dp), allocatable :: work(:) complex(dp), dimension(:,:), pointer :: amat,umat,vmat,bmat real(dp), allocatable :: rwork(:) complex(dp), allocatable :: beta(:) !> Matrix size m = size(a,1,kind=ilp) n = size(a,2,kind=ilp) k = min(m,n) neig = size(lambda,kind=ilp) lda = m if (k<=0 .or. m/=n) then err0 = linalg_state_type(this,LINALG_VALUE_ERROR,& 'invalid or matrix size a=',[m,n],', must be nonempty square.') call linalg_error_handling(err0,err) return elseif (neig<k) then err0 = linalg_state_type(this,LINALG_VALUE_ERROR,& 'eigenvalue array has insufficient size:',& ' lambda=',neig,', n=',n) call linalg_error_handling(err0,err) return endif ldb = size(b,1,kind=ilp) nb = size(b,2,kind=ilp) if (ldb/=n .or. nb/=n) then err0 = linalg_state_type(this,LINALG_VALUE_ERROR,& 'invalid or matrix size b=',[ldb,nb],', must be same as a=',[m,n]) call linalg_error_handling(err0,err) return end if ! Can A be overwritten? By default, do not overwrite copy_a = .true._lk if (present(overwrite_a)) copy_a = .not.overwrite_a ! Initialize a matrix temporary if (copy_a) then allocate(amat(m,n),source=a) else amat => a endif ! Can B be overwritten? By default, do not overwrite copy_b = .true._lk if (present(overwrite_b)) copy_b = .not.overwrite_b ! Initialize a matrix temporary if (copy_b) then allocate(bmat,source=b) else bmat => b endif allocate(beta(n)) ! Decide if U, V eigenvectors task_u = eigenvectors_task(present(left)) task_v = eigenvectors_task(present(right)) if (present(right)) then ! For a complex matrix, GEEV returns complex arrays. ! Point directly to output. vmat => right if (size(vmat,2,kind=ilp)<n) then err0 = linalg_state_type(this,LINALG_VALUE_ERROR,& 'right eigenvector matrix has insufficient size: ',& shape(vmat),', with n=',n) endif else vmat => v_dummy endif if (present(left)) then ! For a complex matrix, GEEV returns complex arrays. ! Point directly to output. umat => left if (size(umat,2,kind=ilp)<n) then err0 = linalg_state_type(this,LINALG_VALUE_ERROR,& 'left eigenvector matrix has insufficient size: ',& shape(umat),', with n=',n) endif else umat => u_dummy endif get_ggev: if (err0%ok()) then ldu = size(umat,1,kind=ilp) ldv = size(vmat,1,kind=ilp) ! Compute workspace size allocate(rwork(5*n)) lwork = -1_ilp call ggev(task_u,task_v,n,amat,lda,& bmat,ldb, & lambda, & beta, & umat,ldu,vmat,ldv,& work_dummy,lwork,rwork,info) call handle_ggev_info(err0,info,shape(amat),shape(bmat)) ! Compute eigenvalues if (info==0) then !> Prepare working storage lwork = nint(real(work_dummy(1),kind=dp), kind=ilp) allocate(work(lwork)) !> Compute eigensystem call ggev(task_u,task_v,n,amat,lda,& bmat,ldb, & lambda, & beta, & umat,ldu,vmat,ldv,& work,lwork,rwork,info) call handle_ggev_info(err0,info,shape(amat),shape(bmat)) endif ! Finalize storage and process output flag ! Scale generalized eigenvalues lambda(:n) = scale_general_eig(lambda(:n),beta) endif get_ggev if (copy_a) deallocate(amat) if (copy_b) deallocate(bmat) call linalg_error_handling(err0,err) end subroutine stdlib_linalg_eig_generalized_z !> Utility function: Scale generalized eigenvalue elemental complex(dp) function scale_general_eig(alpha,beta) result(lambda) !! A generalized eigenvalue for a pair of matrices (A,B) is a scalar lambda or a ratio !! alpha/beta = lambda, such that A - lambda*B is singular. It is usually represented as the !! pair (alpha,beta), there is a reasonable interpretation for beta=0, and even for both !! being zero. complex(dp), intent(in) :: alpha complex(dp), intent(in) :: beta real (dp), parameter :: rzero = 0.0_dp complex(dp), parameter :: czero = (0.0_dp,0.0_dp) if (beta==czero) then if (alpha/=czero) then lambda = cmplx(ieee_value(1.0_dp, ieee_positive_inf), & ieee_value(1.0_dp, ieee_positive_inf), kind=dp) else lambda = ieee_value(1.0_dp, ieee_quiet_nan) end if else lambda = alpha/beta end if end function scale_general_eig end program test
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree