This interface provides different methods to construct a Diagonal
matrix. Only the diagonal elements of are being stored, i.e.
Diagonal matrix filled with zeros: integer, parameter :: n = 100
type(Diagonal) :: A
A = Diagonal(n)
Diagonal matrix from a vector. integer, parameter :: n = 100
real(dp), allocatable :: dv(:)
type(Diagonal) :: A
integer :: i
dv = [(i, i=1, n)]; A = Diagonal(dv)
Diagonal matrix with constant diagonal element. integer, parameter :: n = 100
real(dp), parameter :: d = 2.0_dp
type(Diagonal) :: A
A = Diagonal(d, n)
Diagonal matrix from a standard rank-2 array. integer, parameter :: n = 100
real(dp) :: B(n, n)
type(Diagonal) :: A
call random_number(B); A = Diagonal(B)
Note
Only double precision is currently supported for this matrix type.
Utility function to construct a Diagonal matrix from a rank-1
array.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | dv(:) |
Diagonal elements of the matrix. |
Corresponding diagonal matrix.
Utility function to construct a Diagonal matrix with constant
diagonal element.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | d |
Constant diagonal element of the matrix. |
||
| integer(kind=ilp), | intent(in) | :: | n |
Dimension of the matrix. |
Corresponding diagonal matrix.
Utility function to construct a Diagonal matrix from a rank-2
array. The resulting matrix is constructed from the diagonal
element of the input matrix, even if the latter is not diagonal.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | A(:,:) |
Dense matrix from which to construct the
|
Corresponding diagonal matrix.
Utility function to construct a Diagonal matrix filled with
zeros.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=ilp), | intent(in) | :: | n |
Dimension of the matrix. |
Corresponding diagonal matrix.
This interface provides methods to convert a Diagonal matrix to a
regular rank-2 array.
B = dense(A)
A : Matrix of Diagonal type.
It is an intent(in) argument.
B : Rank-2 array representation of the matrix .
Convert a Diagonal matrix to a rank-2 array.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input diagonal matrix. |
Output dense rank-2 array.
This interface overloads the det interface from stdlib_linag to
compute the determinant where is of type
Diagonal.
d = det(A)
A : Matrix of Diagonal type.
It is in an intent(in) argument.
d : Determinant of the matrix.
Compute the determinant of a Diagonal matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
Determinant of the matrix.
This interface overloads the eigh interface from stdlib_linalg
to compute the eigenvalues and eigenvectors of a real-valued matrix
whose type is Diagonal.
call eigh(A, lambda [, vectors])
A : real-valued matrix of Diagonal.
It is an intent(in) argument.
lambda : Rank-1 real array returning the eigenvalues of A
in increasing order. It is an intent(out) argument.
vectors (optional) : Rank-2 array of the same kind as A
returning the eigenvectors of A. It is
an intent(out) argument.
Utility function to compute the eigenvalues and eigenvectors of
a Diagonal matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
||
| real(kind=dp), | intent(out), | allocatable | :: | lambda(:) |
Eigenvalues. |
|
| real(kind=dp), | intent(out), | optional, | allocatable | :: | vectors(:,:) |
Eigenvectors. |
This interface overloads the eigvalsh interface from
stdlib_linalg to compute the eigenvalues of a real-valued matrix
whose type is Diagonal.
lambda = eigvalsh(A)
A : real-valued matrix of Diagonal type.
It is an intent(in) argument.
lambda : Vector of eigenvalues in increasing order.
Utility function to compute the eigenvalues of a real Diagonal
matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
Eigenvalues.
This interface overloads the Fortran intrinsic matmul for a
Diagonal matrix, both for matrix-vector and matrix-matrix
products. For a matrix-matrix product , only the matrix
has to be a Diagonal matrix. Both and
need to be standard Fortran rank-2 arrays. All the underlying
functions are defined as pure.
y = matmul(A, x)
Compute the matrix-vector product for a Diagonal
matrix . Both x and y are rank-1 arrays with the same
kind as A.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
||
| real(kind=dp), | intent(in) | :: | x(:) |
Input vector. |
Output vector.
Compute the matrix-matrix product for a Diagonal
matrix and a dense matrix (rank-2 array). is
also a rank-2 array with the same dimensions as .
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
||
| real(kind=dp), | intent(in) | :: | X(:,:) |
Input vectors. |
Output vectors.
Utility function to perform a scalar multiplication with a
Diagonal matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A | |||
| real(kind=dp), | intent(in) | :: | alpha |
Utility function to perform a scalar multiplication with a
Diagonal matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=dp), | intent(in) | :: | alpha | |||
| type(Diagonal), | intent(in) | :: | A |
Utility function to get the shape of a Diagonal matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
Shape of the matrix.
Utility function to return the size of Diagonal matrix along a
given dimension.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
||
| integer(kind=ilp), | intent(in), | optional | :: | dim |
Queried dimension. |
Size of the matrix along the dimension dim.
This interface overloads the solve interface from stdlib_linalg
for solving a linear system where is a
Diagonal matrix. It also enables to solve a linear system with
multiple right-hand sides.
x = solve(A, b)
A : Matrix of Diagonal type. It is an intent(in) argument.
b : Rank-1 or rank-2 array defining the right-hand side(s).
It is an intent(in) argument.
x : Solution of the linear system. It has the same type and
shape as b.
Solve the linear system where is of type
Diagonal and B a standard rank-2 array. The solution matrix
X has the same dimensions and kind as the right-hand side
matrix B.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Coefficient matrix. |
||
| real(kind=dp), | intent(in) | :: | B(:,:) |
Right-hand side vectors. |
Solution vectors.
Solve the linear system where is of type
Diagonal and b a standard rank-1 array. The solution vector
x has the same dimension and kind as the right-hand side
vector b.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Coefficient matrix. |
||
| real(kind=dp), | intent(in) | :: | b(:) |
Right-hand side vector. |
Solution vector.
This interface overloads the svd interface from stdlib_linalg
to compute the the singular value decomposition of a Diagonal
matrix .
call svd(A, s [, u] [, vt])
A : Matrix of Diagonal type.
It is an intent(in) argument.
s : Rank-1 real array returning the singular values
of A. It is an intent(out) argument.
u (optional) : Rank-2 array of the same kind as A returning
the left singular vectors of A as columns. Its
size should be [n, n]. It is an intent(out)
argument.
vt (optional) : Rank-2 array of the same kind as A returning
the right singular vectors of A as rows. Its
size should be [n, n]. It is an intent(out)
argument.
Compute the singular value decomposition of a Diagonal matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
||
| real(kind=dp), | intent(out), | optional, | allocatable | :: | u(:,:) |
Left singular vectors as columns. |
| real(kind=dp), | intent(out), | allocatable | :: | s(:) |
Singular values in descending order. |
|
| real(kind=dp), | intent(out), | optional, | allocatable | :: | vt(:,:) |
Right singular vectors as rows. |
This interface overloads the svdvals interface from
stdlib_linalg to compute the singular values of a Diagonal
matrix .
s = svdvals(A)
A : Matrix of Diagonal type.
It is an intent(in) argument.
s : Vector of singular values sorted in decreasing order.
Compute the singular values of a Diagonal matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
Singular values in descending order.
This interface overloads the trace interface from stdlib_linalg
to compute the trace of a matrix of type Diagonal.
tr = trace(A)
A : Matrix of Diagonal type.
It is an intent(in) argument.
tr: Trace of the matrix.
Compute the trace of a Diagonal matrix.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(Diagonal), | intent(in) | :: | A |
Input matrix. |
Trace of the matrix.
This interface overloads the Fortran intrinsic procedure to define
the transpose operation for a Diagonal matrix.
B = transpose(A)
A : Matrix of Diagonal type.
It is an intent(in) argument.
B : Resulting transposed matrix. It is of the same type as A.
Base type used to define a Diagonal matrix of size [n x n]
with diagonal elements given by the rank-1 array dv.
This interface provides different methods to construct a Diagonal
matrix. Only the diagonal elements of are being stored, i.e.
| private pure, module function construct (dv) | Utility function to construct a |
| private pure, module function construct_constant (d, n) | Utility function to construct a |
| private module function dense_to_diag (A) | Utility function to construct a |
| private pure, module function initialize (n) | Utility function to construct a |