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.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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=dp), | intent(inout), | target, contiguous | :: | h(:) |
k-th column of the Hessenberg matrix. |
|
| complex(kind=dp), | intent(inout) | :: | c(:) |
Cosine components of the Givens rotations. |
||
| complex(kind=dp), | intent(inout) | :: | s(:) |
Sine components of the Givens rotations. |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=sp), | intent(inout), | target, contiguous | :: | h(:) |
k-th column of the Hessenberg matrix. |
|
| complex(kind=sp), | intent(inout) | :: | c(:) |
Cosine components of the Givens rotations. |
||
| complex(kind=sp), | intent(inout) | :: | s(:) |
Sine components of the Givens rotations. |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout), | target, contiguous | :: | h(:) |
k-th column of the Hessenberg matrix. |
|
| real(kind=dp), | intent(inout) | :: | c(:) |
Cosine components of the Givens rotations. |
||
| real(kind=dp), | intent(inout) | :: | s(:) |
Sine components of the Givens rotations. |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(inout), | target, contiguous | :: | h(:) |
k-th column of the Hessenberg matrix. |
|
| real(kind=sp), | intent(inout) | :: | c(:) |
Cosine components of the Givens rotations. |
||
| real(kind=sp), | intent(inout) | :: | s(:) |
Sine components of the Givens rotations. |
This interface provides methods to assert tha thte shape of its input vector or matrix is as expected. It throws an error if not.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=dp), | intent(in) | :: | A(:,:) | |||
| integer, | intent(in) | :: | size(:) | |||
| character(len=*), | intent(in) | :: | matname | |||
| character(len=*), | intent(in) | :: | module | |||
| character(len=*), | intent(in) | :: | procedure |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=sp), | intent(in) | :: | A(:,:) | |||
| integer, | intent(in) | :: | size(:) | |||
| character(len=*), | intent(in) | :: | matname | |||
| character(len=*), | intent(in) | :: | module | |||
| character(len=*), | intent(in) | :: | procedure |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | A(:,:) | |||
| integer, | intent(in) | :: | size(:) | |||
| character(len=*), | intent(in) | :: | matname | |||
| character(len=*), | intent(in) | :: | module | |||
| character(len=*), | intent(in) | :: | procedure |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(in) | :: | A(:,:) | |||
| integer, | intent(in) | :: | size(:) | |||
| character(len=*), | intent(in) | :: | matname | |||
| character(len=*), | intent(in) | :: | module | |||
| character(len=*), | intent(in) | :: | procedure |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=dp), | intent(in) | :: | v(:) | |||
| integer, | intent(in) | :: | size(:) | |||
| character(len=*), | intent(in) | :: | vecname | |||
| character(len=*), | intent(in) | :: | module | |||
| character(len=*), | intent(in) | :: | procedure |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=sp), | intent(in) | :: | v(:) | |||
| integer, | intent(in) | :: | size(:) | |||
| character(len=*), | intent(in) | :: | vecname | |||
| character(len=*), | intent(in) | :: | module | |||
| character(len=*), | intent(in) | :: | procedure |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | v(:) | |||
| integer, | intent(in) | :: | size(:) | |||
| character(len=*), | intent(in) | :: | vecname | |||
| character(len=*), | intent(in) | :: | module | |||
| character(len=*), | intent(in) | :: | procedure |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(in) | :: | v(:) | |||
| integer, | intent(in) | :: | size(:) | |||
| character(len=*), | intent(in) | :: | vecname | |||
| character(len=*), | intent(in) | :: | module | |||
| character(len=*), | intent(in) | :: | procedure |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=dp), | intent(in) | :: | A(:,:) | |||
| complex(kind=dp), | intent(out) | :: | vecs(:,:) | |||
| complex(kind=dp), | intent(out) | :: | vals(:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=sp), | intent(in) | :: | A(:,:) | |||
| complex(kind=sp), | intent(out) | :: | vecs(:,:) | |||
| complex(kind=sp), | intent(out) | :: | vals(:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | A(:,:) | |||
| real(kind=dp), | intent(out) | :: | vecs(:,:) | |||
| complex(kind=dp), | intent(out) | :: | vals(:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(in) | :: | A(:,:) | |||
| real(kind=sp), | intent(out) | :: | vecs(:,:) | |||
| complex(kind=sp), | intent(out) | :: | vals(:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=dp), | intent(in) | :: | x(2) |
Vector whose second entry needs to be eliminated. |
Entries of the Givens rotation matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=sp), | intent(in) | :: | x(2) |
Vector whose second entry needs to be eliminated. |
Entries of the Givens rotation matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | x(2) |
Vector whose second entry needs to be eliminated. |
Entries of the Givens rotation matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(in) | :: | x(2) |
Vector whose second entry needs to be eliminated. |
Entries of the Givens rotation matrix.
Utility function to compute the base-2 logarithm of a real number.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | x |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(in) | :: | x |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=dp), | intent(inout) | :: | T(:,:) | |||
| complex(kind=dp), | intent(inout) | :: | Q(:,:) | |||
| logical, | intent(in) | :: | selected(:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=sp), | intent(inout) | :: | T(:,:) | |||
| complex(kind=sp), | intent(inout) | :: | Q(:,:) | |||
| logical, | intent(in) | :: | selected(:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout) | :: | T(:,:) | |||
| real(kind=dp), | intent(inout) | :: | Q(:,:) | |||
| logical, | intent(in) | :: | selected(:) |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(inout) | :: | T(:,:) | |||
| real(kind=sp), | intent(inout) | :: | Q(:,:) | |||
| logical, | intent(in) | :: | selected(:) |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=dp), | intent(inout) | :: | A(:,:) | |||
| complex(kind=dp), | intent(out) | :: | sqrtA(:,:) | |||
| integer, | intent(out) | :: | info |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| complex(kind=sp), | intent(inout) | :: | A(:,:) | |||
| complex(kind=sp), | intent(out) | :: | sqrtA(:,:) | |||
| integer, | intent(out) | :: | info |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(inout) | :: | A(:,:) | |||
| real(kind=dp), | intent(out) | :: | sqrtA(:,:) | |||
| integer, | intent(out) | :: | info |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=sp), | intent(inout) | :: | A(:,:) | |||
| real(kind=sp), | intent(out) | :: | sqrtA(:,:) | |||
| integer, | intent(out) | :: | info |
Abstract type for options from which all others are extended.