This module provides a set of utility functions used throughout LightKrylov
.
It includes:
assert_shape
: Assert that the shape of the argument is the expected shape.eig
: Compute the eigenvalue decomposition of a general matrix.sqrtm
: Compute the non-negative square root of a symmetric positive definite matrix using its SVD.sqrtm_eig
: Compute the non-negative square root of a symmetric positive definite matrix using its eigenvalue decomposition.schur
: Compute the Schur factorization of a general square matrix.ordschur
: Re-order the Schur factorization to have the selected eigenvalues in the upper left block.Note that as the development of stdlib
progresses, some of these functions
will be deprecated in favor of the stdlib
implementations.
This interface provides methods to assert that the shape of its input vector or matrix is the expected shape. It throws an error if not.
Utility function to assert the shape of a vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | v(:) |
Vector whose dimension need to be asserted. |
||
integer, | intent(in) | :: | size(:) |
Expected dimensions of v. |
||
character(len=*), | intent(in) | :: | vecname |
Name of the asserted vector. |
||
character(len=*), | intent(in) | :: | module |
Name of the module where assertion is done. |
||
character(len=*), | intent(in) | :: | procedure |
Name of the routine where assertion is done. |
Utility function to assert the shape of a matrix.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | A(:,:) |
Matrix whose dimension need to be asserted. |
||
integer, | intent(in) | :: | size(:) |
Expected dimensions of A. |
||
character(len=*), | intent(in) | :: | matname |
Name of the asserted matrix. |
||
character(len=*), | intent(in) | :: | module |
Name of the module where assertion is done. |
||
character(len=*), | intent(in) | :: | procedure |
Name of the routine where assertion is done. |
Utility function to assert the shape of a vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | v(:) |
Vector whose dimension need to be asserted. |
||
integer, | intent(in) | :: | size(:) |
Expected dimensions of v. |
||
character(len=*), | intent(in) | :: | vecname |
Name of the asserted vector. |
||
character(len=*), | intent(in) | :: | module |
Name of the module where assertion is done. |
||
character(len=*), | intent(in) | :: | procedure |
Name of the routine where assertion is done. |
Utility function to assert the shape of a matrix.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | A(:,:) |
Matrix whose dimension need to be asserted. |
||
integer, | intent(in) | :: | size(:) |
Expected dimensions of A. |
||
character(len=*), | intent(in) | :: | matname |
Name of the asserted matrix. |
||
character(len=*), | intent(in) | :: | module |
Name of the module where assertion is done. |
||
character(len=*), | intent(in) | :: | procedure |
Name of the routine where assertion is done. |
Utility function to assert the shape of a vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=sp), | intent(in) | :: | v(:) |
Vector whose dimension need to be asserted. |
||
integer, | intent(in) | :: | size(:) |
Expected dimensions of v. |
||
character(len=*), | intent(in) | :: | vecname |
Name of the asserted vector. |
||
character(len=*), | intent(in) | :: | module |
Name of the module where assertion is done. |
||
character(len=*), | intent(in) | :: | procedure |
Name of the routine where assertion is done. |
Utility function to assert the shape of a matrix.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=sp), | intent(in) | :: | A(:,:) |
Matrix whose dimension need to be asserted. |
||
integer, | intent(in) | :: | size(:) |
Expected dimensions of A. |
||
character(len=*), | intent(in) | :: | matname |
Name of the asserted matrix. |
||
character(len=*), | intent(in) | :: | module |
Name of the module where assertion is done. |
||
character(len=*), | intent(in) | :: | procedure |
Name of the routine where assertion is done. |
Utility function to assert the shape of a vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=dp), | intent(in) | :: | v(:) |
Vector whose dimension need to be asserted. |
||
integer, | intent(in) | :: | size(:) |
Expected dimensions of v. |
||
character(len=*), | intent(in) | :: | vecname |
Name of the asserted vector. |
||
character(len=*), | intent(in) | :: | module |
Name of the module where assertion is done. |
||
character(len=*), | intent(in) | :: | procedure |
Name of the routine where assertion is done. |
Utility function to assert the shape of a matrix.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=dp), | intent(in) | :: | A(:,:) |
Matrix whose dimension need to be asserted. |
||
integer, | intent(in) | :: | size(:) |
Expected dimensions of A. |
||
character(len=*), | intent(in) | :: | matname |
Name of the asserted matrix. |
||
character(len=*), | intent(in) | :: | module |
Name of the module where assertion is done. |
||
character(len=*), | intent(in) | :: | procedure |
Name of the routine where assertion is done. |
Computes the eigenvalue decomposition of a general square matrix.
This interface provides methods to compute the solution to the eigenproblem
, where $\mathbf{A}$ is a square real
or complex
matrix.
Result array lambda
returns the eigenvalues of , while vecs
returns the corresponding eigenvectors. Note that it follows the LAPACK convention
when is real
. The solver is based on LAPACK's *GEEV
backends.
call eig(A, vecs, lambda)
A
: real
or complex
square array containing the coefficient matrix. It is an intent(in)
argument.
vecs
: Square array of the same size, type, and kind as A
containing the eigenvectors
(following LAPACK's convention for real
matrices). It is an intent(out)
argument.
lambda
: complex
rank-1 array of the same kind as A
containing the eigenvalues.
It is an intent(out)
argument.
Note
Due to the abstrct nature of the vector types defined in LightKrylov
, it is unlikely
that this implementation will be superseeded in favor of the stdlib
one as the latter
does not follow the LAPACK's convention.
Eigenvalue decomposition of a dense matrix using LAPACK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | A(:,:) |
Matrix to be factorized. |
||
real(kind=sp), | intent(out) | :: | vecs(:,:) |
Eigenvectors. |
||
complex(kind=sp), | intent(out) | :: | vals(:) |
Eigenvalue decomposition of a dense matrix using LAPACK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | A(:,:) |
Matrix to be factorized. |
||
real(kind=dp), | intent(out) | :: | vecs(:,:) |
Eigenvectors. |
||
complex(kind=dp), | intent(out) | :: | vals(:) |
Eigenvalue decomposition of a dense matrix using LAPACK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=sp), | intent(in) | :: | A(:,:) |
Matrix to be factorized. |
||
complex(kind=sp), | intent(out) | :: | vecs(:,:) |
Eigenvectors. |
||
complex(kind=sp), | intent(out) | :: | vals(:) |
Eigenvalue decomposition of a dense matrix using LAPACK.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=dp), | intent(in) | :: | A(:,:) |
Matrix to be factorized. |
||
complex(kind=dp), | intent(out) | :: | vecs(:,:) |
Eigenvectors. |
||
complex(kind=dp), | intent(out) | :: | vals(:) |
Utility function to compute the base-2 logarithm of a real number.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | x |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | x |
This interface provides methods to compute the infinity norm of a matrix.
Note that it'll eventually be superseeded by the stdlib
implementation.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | A(:,:) |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | A(:,:) |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=sp), | intent(in) | :: | A(:,:) |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=dp), | intent(in) | :: | A(:,:) |
Given the Schur factorization and basis of a matrix, reorders it to have the selected eigenvalues in the upper left block.
This interface provides methods to re-order the Schur factorization of a real
or
complex
square matrix. Note that, if is real
, it returns the
real Schur form.
call ordschur(T, Q, selected)
T
: real
or complex
square array containing the Schur factorization of a matrix.
On exit, it is overwritten with its re-ordered counterpart. It is an intent(inout)
argument.
Q
: Two-dimensional square array of the same size, type and kind as A
. It contains
the original Schur basis on entry and the re-ordered one on exit.
It is an intent(inout)
argument.
selected
: logical
rank-1 array selecting which eigenvalues need to be moved in the
upper left block of the Schur factorization.
It is an intent(in)
arguement.
Re-order the Schur factorization from schur
such that the selected eigenvalues
are in the upper-left block.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(inout) | :: | T(:,:) |
Schur matrix to be re-ordered. |
||
real(kind=sp), | intent(inout) | :: | Q(:,:) |
Schur vectors to be re-ordered. |
||
logical, | intent(in) | :: | selected(:) |
Boolean array defining the selected eigenvalues. |
Re-order the Schur factorization from schur
such that the selected eigenvalues
are in the upper-left block.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(inout) | :: | T(:,:) |
Schur matrix to be re-ordered. |
||
real(kind=dp), | intent(inout) | :: | Q(:,:) |
Schur vectors to be re-ordered. |
||
logical, | intent(in) | :: | selected(:) |
Boolean array defining the selected eigenvalues. |
Re-order the Schur factorization from schur
such that the selected eigenvalues
are in the upper-left block.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=sp), | intent(inout) | :: | T(:,:) |
Schur matrix to be re-ordered. |
||
complex(kind=sp), | intent(inout) | :: | Q(:,:) |
Schur vectors to be re-ordered. |
||
logical, | intent(in) | :: | selected(:) |
Boolean array defining the selected eigenvalues. |
Re-order the Schur factorization from schur
such that the selected eigenvalues
are in the upper-left block.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=dp), | intent(inout) | :: | T(:,:) |
Schur matrix to be re-ordered. |
||
complex(kind=dp), | intent(inout) | :: | Q(:,:) |
Schur vectors to be re-ordered. |
||
logical, | intent(in) | :: | selected(:) |
Boolean array defining the selected eigenvalues. |
Computes the Schur factorization of a general square matrix.
This interface provides methods to compute the Schur factorization of a real
or
complex
square matrix. Note that, if is real
, it returns the
real Schur form.
Result array eigvals
returns the eigenvalues of while Z
contains the Schur basis.
call schur(A, Z, eigvals)
A
: real
or complex
square array containing the coefficient matrix. On exit, it
is overwritten with its (real) Schur factorization. It is an intent(inout)
argument.
Z
: Two-dimensional square array of the same size, type and kind as A
. It contains
the Schur basis. It is an intent(out)
argument.
eigvals
: complex
rank-1 array of the same kind as A
containing the eigenvalues.
It is an intent(out)
arguement.
Compute the Schur form (in-place) and Schur vectors of the matrix A
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(inout) | :: | A(:,:) |
Matrix to be factorized. |
||
real(kind=sp), | intent(out) | :: | Z(:,:) |
Schur basis. |
||
complex(kind=sp), | intent(out) | :: | eigvals(:) |
Eigenvalues. |
Compute the Schur form (in-place) and Schur vectors of the matrix A
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(inout) | :: | A(:,:) |
Matrix to be factorized. |
||
real(kind=dp), | intent(out) | :: | Z(:,:) |
Schur basis. |
||
complex(kind=dp), | intent(out) | :: | eigvals(:) |
Eigenvalues. |
Compute the Schur form (in-place) and Schur vectors of the matrix A
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=sp), | intent(inout) | :: | A(:,:) |
Matrix to be factorized. |
||
complex(kind=sp), | intent(out) | :: | Z(:,:) |
Schur basis. |
||
complex(kind=sp), | intent(out) | :: | eigvals(:) |
Eigenvalues. |
Compute the Schur form (in-place) and Schur vectors of the matrix A
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=dp), | intent(inout) | :: | A(:,:) |
Matrix to be factorized. |
||
complex(kind=dp), | intent(out) | :: | Z(:,:) |
Schur basis. |
||
complex(kind=dp), | intent(out) | :: | eigvals(:) |
Eigenvalues. |
Computes the non-negative square root of a symmetric positive definite matrix using its singular value decomposition.
This interface provides methods to compute the non-negative square root of a symmetric (hermitian) positive definite matrix .
call sqrtm(A, sqrtmA, info)
A
: Symmetric (hermitian) positive definite matrix whose non-negative square root
needs to be computed. It is an intent(in)
argument.
sqrtmA
: Non-negative square root of A
. It has the same size, kind and type as A
.
It is an intent(out)
argument.
info
: Information flag. It is an intent(out)
argument.
Matrix-valued sqrt function for dense symmetric/hermitian positive (semi-)definite matrices
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(inout) | :: | X(:,:) |
Matrix of which to compute the sqrt |
||
real(kind=sp), | intent(out) | :: | sqrtmX(size(X,1),size(X,1)) |
Return matrix |
||
integer, | intent(out) | :: | info |
Information flag |
Matrix-valued sqrt function for dense symmetric/hermitian positive (semi-)definite matrices
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(inout) | :: | X(:,:) |
Matrix of which to compute the sqrt |
||
real(kind=dp), | intent(out) | :: | sqrtmX(size(X,1),size(X,1)) |
Return matrix |
||
integer, | intent(out) | :: | info |
Information flag |
Matrix-valued sqrt function for dense symmetric/hermitian positive (semi-)definite matrices
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=sp), | intent(inout) | :: | X(:,:) |
Matrix of which to compute the sqrt |
||
complex(kind=sp), | intent(out) | :: | sqrtmX(size(X,1),size(X,1)) |
Return matrix |
||
integer, | intent(out) | :: | info |
Information flag |
Matrix-valued sqrt function for dense symmetric/hermitian positive (semi-)definite matrices
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=dp), | intent(inout) | :: | X(:,:) |
Matrix of which to compute the sqrt |
||
complex(kind=dp), | intent(out) | :: | sqrtmX(size(X,1),size(X,1)) |
Return matrix |
||
integer, | intent(out) | :: | info |
Information flag |
Computes the non-negative square root of a symmetric positive definite matrix using its eigenvalue decomposition.
This interface provides methods to compute the non-negative square root of a symmetric (hermitian) positive definite matrix .
call sqrtm_eig(A, sqrtmA, info)
A
: Symmetric (hermitian) positive definite matrix whose non-negative square root
needs to be computed. It is an intent(in)
argument.
sqrtmA
: Non-negative square root of A
. It has the same size, kind and type as A
.
It is an intent(out)
argument.
info
: Information flag. It is an intent(out)
argument.
Matrix-valued sqrt function for dense symmetric/hermitian positive (semi-)definite matrices
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=sp), | intent(in) | :: | X(:,:) |
Matrix of which to compute the sqrt |
||
real(kind=sp), | intent(out) | :: | sqrtmX(size(X,1),size(X,1)) |
Return matrix |
||
integer, | intent(out) | :: | info |
Information flag |
Matrix-valued sqrt function for dense symmetric/hermitian positive (semi-)definite matrices
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=dp), | intent(in) | :: | X(:,:) |
Matrix of which to compute the sqrt |
||
real(kind=dp), | intent(out) | :: | sqrtmX(size(X,1),size(X,1)) |
Return matrix |
||
integer, | intent(out) | :: | info |
Information flag |
Matrix-valued sqrt function for dense symmetric/hermitian positive (semi-)definite matrices
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=sp), | intent(in) | :: | X(:,:) |
Matrix of which to compute the sqrt |
||
complex(kind=sp), | intent(out) | :: | sqrtmX(size(X,1),size(X,1)) |
Return matrix |
||
integer, | intent(out) | :: | info |
Information flag |
Matrix-valued sqrt function for dense symmetric/hermitian positive (semi-)definite matrices
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
complex(kind=dp), | intent(in) | :: | X(:,:) |
Matrix of which to compute the sqrt |
||
complex(kind=dp), | intent(out) | :: | sqrtmX(size(X,1),size(X,1)) |
Return matrix |
||
integer, | intent(out) | :: | info |
Information flag |
Abstract type container for options from which all others are being extended.
Conjugate gradient options.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | maxiter | = | 100 |
Maximum number of |
Conjugate gradient options.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | maxiter | = | 100 |
Maximum number of |
GMRES options.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | kdim | = | 30 |
Dimension of the Krylov subspace (default: 30). |
|
integer, | public | :: | maxiter | = | 10 |
Maximum number of |
GMRES options.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | public | :: | kdim | = | 30 |
Dimension of the Krylov subspace (default: 30). |
|
integer, | public | :: | maxiter | = | 10 |
Maximum number of |
Options for Newton-Krylov fixed-point iteration.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | public | :: | ifbisect | = | .false. |
Bisection toggle to enforce residual reduction (default = .false.) |
|
integer, | public | :: | maxiter | = | 100 |
Maximum number of Newton iterations (default = 100) |
|
integer, | public | :: | maxstep_bisection | = | 5 |
Maximum number of bisections (evaluations of F) for step selection (default = 5) Ignored if ifbisect = .false. |
Options for Newton-Krylov fixed-point iteration.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | public | :: | ifbisect | = | .false. |
Bisection toggle to enforce residual reduction (default = .false.) |
|
integer, | public | :: | maxiter | = | 100 |
Maximum number of Newton iterations (default = 100) |
|
integer, | public | :: | maxstep_bisection | = | 5 |
Maximum number of bisections (evaluations of F) for step selection (default = 5) Ignored if ifbisect = .false. |