Skip to content

linalg: Eigenvalues and Eigenvectors #816

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7d390f7
add source
perazz May 16, 2024
430c89c
remove `goto`s
perazz May 16, 2024
7645a45
exclude unsupported `xdp`
perazz May 16, 2024
6ce5172
submodule
perazz May 16, 2024
2d58c68
add tests
perazz May 16, 2024
15b73fc
test: remove `xdp`
perazz May 16, 2024
b5f7f21
add examples: `eig`, `eigh`, `eigvals`, `eigvalsh`
perazz May 16, 2024
892308f
fix: `module` procedures
perazz May 16, 2024
1ebf374
add documentation
perazz May 16, 2024
f9279b3
specs: `eig`, `eigh`
perazz May 16, 2024
56d89a8
specs: `eigvals`, `eigvalsh`
perazz May 16, 2024
f13e75d
clarify svd
perazz Jun 5, 2024
34bb7d7
Update doc/specs/stdlib_linalg.md
perazz Jun 5, 2024
cdef45f
remove `(sp)` from the examples
perazz Jun 5, 2024
fe1c89e
Update doc/specs/stdlib_linalg.md
perazz Jun 5, 2024
65099e3
Update doc/specs/stdlib_linalg.md
perazz Jun 5, 2024
0e13fe5
kind -> precision
perazz Jun 5, 2024
d0f385a
Update doc/specs/stdlib_linalg.md
perazz Jun 5, 2024
acd93b9
Merge branch 'eigenvalues' of github.com:perazz/stdlib into eigenvalues
perazz Jun 5, 2024
36c8d5a
fix `sp` in example
perazz Jun 5, 2024
e6aa0f5
Option to output `real` eigenvalues only
perazz Jun 5, 2024
17ebed2
reorganize `if(present(x))`
perazz Jun 21, 2024
bac3187
no negated checks
perazz Jun 21, 2024
4f503f7
copy_a: simplify
perazz Jun 21, 2024
34284cb
Merge branch 'master' into eigenvalues
perazz Jun 21, 2024
f232a76
typo
perazz Jun 21, 2024
d19425a
fix intel `module subroutine` error
perazz Jun 21, 2024
cc95fc4
Update doc/specs/stdlib_linalg.md
perazz Jun 26, 2024
18b95af
Update doc/specs/stdlib_linalg.md
perazz Jun 26, 2024
1fb2ba9
Update doc/specs/stdlib_linalg.md
perazz Jun 26, 2024
f5303bf
Update doc/specs/stdlib_linalg.md
perazz Jun 26, 2024
66f1f17
Update doc/specs/stdlib_linalg.md
perazz Jun 26, 2024
5501b83
example_eigh: v->vectors
perazz Jun 26, 2024
59f3b34
Merge branch 'eigenvalues' of github.com:perazz/stdlib into eigenvalues
perazz Jun 26, 2024
d433869
fix vectors
perazz Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add documentation
  • Loading branch information
perazz committed May 16, 2024
commit 1ebf374111365804a60b70fec83ce245511f1873
90 changes: 85 additions & 5 deletions src/stdlib_linalg.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,27 @@ module stdlib_linalg
#:endfor
end interface

interface eig
!! Eigendecomposition of a square matrix: return eigenvalues, and optionally eigenvectors
! Eigendecomposition of a square matrix: eigenvalues, and optionally eigenvectors
interface eig
!! version: experimental
!!
!! Solves the eigendecomposition \( A \cdot \bar{v} - \lambda \cdot \bar{v} \) for square matrix \( A \).
!! ([Specification](../page/specs/stdlib_linalg.html#eig-eigenvalues-and-eigenvectors-of-a-square-matrix))
!!
!!### Summary
!! Subroutine interface for computing eigenvalues and eigenvectors of a square matrix.
!!
!!### Description
!!
!! This interface provides methods for computing the eigenvalues, and optionally eigenvectors,
!! of a general square matrix. Supported data types include `real` and `complex`, and no assumption is
!! made on the matrix structure. The user may request either left, right, or both
!! eigenvectors to be returned. They are returned as columns of a square matrix with the same size as `A`.
!! Preallocated space for both eigenvalues `lambda` and the eigenvector matrices must be user-provided.
!!
!!@note The solution is based on LAPACK's general eigenproblem solvers `*GEEV`.
!!@note BLAS/LAPACK backends do not currently support extended precision (``xdp``).
!!
#:for rk,rt,ri in RC_KINDS_TYPES
#:if rk!="xdp"
module subroutine stdlib_linalg_eig_${ri}$(a,lambda,right,left,overwrite_a,err)
Expand All @@ -580,8 +599,26 @@ module stdlib_linalg
#:endfor
end interface eig

! Eigenvalues of a square matrix
interface eigvals
!! Eigenvalues of a square matrix
!! version: experimental
!!
!! Returns the eigenvalues \( lambda \), \( A \cdot \bar{v} - \lambda \cdot \bar{v} \), for square matrix \( A \).
!! ([Specification](../page/specs/stdlib_linalg.html#eigvals-eigenvalues-of-a-square-matrix))
!!
!!### Summary
!! Function interface for computing the eigenvalues of a square matrix.
!!
!!### Description
!!
!! This interface provides functions for returning the eigenvalues of a general square matrix.
!! Supported data types include `real` and `complex`, and no assumption is made on the matrix structure.
!! An `error stop` is thrown in case of failure; otherwise, error information can be returned
!! as an optional `type(linalg_state_type)` output flag.
!!
!!@note The solution is based on LAPACK's general eigenproblem solvers `*GEEV`.
!!@note BLAS/LAPACK backends do not currently support extended precision (``xdp``).
!!
#:for rk,rt,ri in RC_KINDS_TYPES
#:if rk!="xdp"
module function stdlib_linalg_eigvals_${ri}$(a,err) result(lambda)
Expand All @@ -605,8 +642,30 @@ module stdlib_linalg
#:endfor
end interface eigvals

! Eigendecomposition of a real symmetric or complex hermitian matrix
interface eigh
!! Eigendecomposition of a real symmetric or complex hermitian matrix
!! version: experimental
!!
!! Solves the eigendecomposition \( A \cdot \bar{v} - \lambda \cdot \bar{v} \) for a real symmetric
!! \( A = A^T \) or complex Hermitian \( A = A^H \) square matrix.
!! ([Specification](../page/specs/stdlib_linalg.html#eigh-eigenvalues-and-eigenvectors-of-a-real-symmetric-or-complex-hermitian-square-matrix))
!!
!!### Summary
!! Subroutine interface for computing eigenvalues and eigenvectors of a real symmetric or complex Hermitian square matrix.
!!
!!### Description
!!
!! This interface provides methods for computing the eigenvalues, and optionally eigenvectors,
!! of a real symmetric or complex Hermitian square matrix. Supported data types include `real` and `complex`.
!! The matrix must be symmetric (if `real`) or Hermitian (if `complex`). Only the lower or upper
!! half of the matrix is accessed, and the user can select which using the optional `upper_a`
!! flag (default: use lower half). The vectors are orthogonal, and may be returned as columns of an optional
!! matrix `vectors` with the same kind and size as `A`.
!! Preallocated space for both eigenvalues `lambda` and the eigenvector matrix must be user-provided.
!!
!!@note The solution is based on LAPACK's eigenproblem solvers `*SYEV`/`*HEEV`.
!!@note BLAS/LAPACK backends do not currently support extended precision (``xdp``).
!!
#:for rk,rt,ri in RC_KINDS_TYPES
#:if rk!="xdp"
module subroutine stdlib_linalg_eigh_${ri}$(a,lambda,vectors,upper_a,overwrite_a,err)
Expand All @@ -629,8 +688,29 @@ module stdlib_linalg
#:endfor
end interface eigh

! Eigenvalues of a real symmetric or complex hermitian matrix
interface eigvalsh
!! Eigenvalues of a real symmetric or complex hermitian matrix
!! version: experimental
!!
!! Returns the eigenvalues \( lambda \), \( A \cdot \bar{v} - \lambda \cdot \bar{v} \), for a real
!! symmetric \( A = A^T \) or complex Hermitian \( A = A^H \) square matrix.
!! ([Specification](../page/specs/stdlib_linalg.html#eigvalsh-eigenvalues-of-a-real-symmetric-or-complex-hermitian-square-matrix))
!!
!!### Summary
!! Function interface for computing the eigenvalues of a real symmetric or complex hermitian square matrix.
!!
!!### Description
!!
!! This interface provides functions for returning the eigenvalues of a real symmetric or complex Hermitian
!! square matrix. Supported data types include `real` and `complex`. The matrix must be symmetric
!! (if `real`) or Hermitian (if `complex`). Only the lower or upper half of the matrix is accessed,
!! and the user can select which using the optional `upper_a` flag (default: use lower half).
!! An `error stop` is thrown in case of failure; otherwise, error information can be returned
!! as an optional `type(linalg_state_type)` output flag.
!!
!!@note The solution is based on LAPACK's eigenproblem solvers `*SYEV`/`*HEEV`.
!!@note BLAS/LAPACK backends do not currently support extended precision (``xdp``).
!!
#:for rk,rt,ri in RC_KINDS_TYPES
#:if rk!="xdp"
module function stdlib_linalg_eigvalsh_${ri}$(a,upper_a,err) result(lambda)
Expand Down
16 changes: 8 additions & 8 deletions src/stdlib_linalg_eigenvalues.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ submodule (stdlib_linalg) stdlib_linalg_eigenvalues
${rt}$, intent(in), target :: a(:,:)
!> [optional] state return flag. On error if not requested, the code will stop
type(linalg_state_type), intent(out) :: err
!> Array of singular values
!> Array of eigenvalues
complex(${rk}$), allocatable :: lambda(:)

!> Create
Expand All @@ -125,7 +125,7 @@ submodule (stdlib_linalg) stdlib_linalg_eigenvalues
!! Return an array of eigenvalues of matrix A.
!> Input matrix A[m,n]
${rt}$, intent(in), target :: a(:,:)
!> Array of singular values
!> Array of eigenvalues
complex(${rk}$), allocatable :: lambda(:)

!> Create
Expand Down Expand Up @@ -154,9 +154,9 @@ submodule (stdlib_linalg) stdlib_linalg_eigenvalues
${rt}$, intent(inout), target :: a(:,:)
!> Array of eigenvalues
complex(${rk}$), intent(out) :: lambda(:)
!> The columns of RIGHT contain the right eigenvectors of A
!> [optional] RIGHT eigenvectors of A (as columns)
complex(${rk}$), optional, intent(out), target :: right(:,:)
!> The columns of LEFT contain the left eigenvectors of A
!> [optional] LEFT eigenvectors of A (as columns)
complex(${rk}$), optional, intent(out), target :: left(:,:)
!> [optional] Can A data be overwritten and destroyed?
logical(lk), optional, intent(in) :: overwrite_a
Expand Down Expand Up @@ -323,7 +323,7 @@ submodule (stdlib_linalg) stdlib_linalg_eigenvalues
logical(lk), optional, intent(in) :: upper_a
!> [optional] state return flag. On error if not requested, the code will stop
type(linalg_state_type), intent(out) :: err
!> Array of singular values
!> Array of eigenvalues
real(${rk}$), allocatable :: lambda(:)

${rt}$, pointer :: amat(:,:)
Expand All @@ -348,9 +348,9 @@ submodule (stdlib_linalg) stdlib_linalg_eigenvalues
!! Return an array of eigenvalues of real symmetric / complex hermitian A
!> Input matrix A[m,n]
${rt}$, intent(in), target :: a(:,:)
!> [optional] Should the upper/lower half of A be used? Default: lower
!> [optional] Should the upper/lower half of A be used? Default: use lower
logical(lk), optional, intent(in) :: upper_a
!> Array of singular values
!> Array of eigenvalues
real(${rk}$), allocatable :: lambda(:)

${rt}$, pointer :: amat(:,:)
Expand Down Expand Up @@ -382,7 +382,7 @@ submodule (stdlib_linalg) stdlib_linalg_eigenvalues
${rt}$, optional, intent(out), target :: vectors(:,:)
!> [optional] Can A data be overwritten and destroyed?
logical(lk), optional, intent(in) :: overwrite_a
!> [optional] Should the upper/lower half of A be used? Default: lower
!> [optional] Should the upper/lower half of A be used? Default: use lower
logical(lk), optional, intent(in) :: upper_a
!> [optional] state return flag. On error if not requested, the code will stop
type(linalg_state_type), optional, intent(out) :: err
Expand Down