Diagonal Interface

public interface Diagonal

This interface provides different methods to construct a Diagonal matrix. Only the diagonal elements of are being stored, i.e.

Syntax

  • Construct a Diagonal matrix filled with zeros:
   integer, parameter :: n = 100
   type(Diagonal) :: A

   A = Diagonal(n)
  • Construct a 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)
  • Construct a Diagonal matrix with constant diagonal element.
   integer, parameter :: n = 100
   real(dp), parameter :: d = 2.0_dp
   type(Diagonal) :: A

   A = Diagonal(d, n)
  • Construct a 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.


Functions

private pure module function construct(dv) result(A)

Utility function to construct a Diagonal matrix from a rank-1 array.

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: dv(:)

Diagonal elements of the matrix.

Return Value type(Diagonal)

Corresponding diagonal matrix.

private pure module function construct_constant(d, n) result(A)

Utility function to construct a Diagonal matrix with constant diagonal element.

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: d

Constant diagonal element of the matrix.

integer(kind=ilp), intent(in) :: n

Dimension of the matrix.

Return Value type(Diagonal)

Corresponding diagonal matrix.

private module function dense_to_diag(A) result(B)

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.

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in) :: A(:,:)

Dense matrix from which to construct the Diagonal one.

Return Value type(Diagonal)

Corresponding diagonal matrix.

private pure module function initialize(n) result(A)

Utility function to construct a Diagonal matrix filled with zeros.

Arguments

Type IntentOptional Attributes Name
integer(kind=ilp), intent(in) :: n

Dimension of the matrix.

Return Value type(Diagonal)

Corresponding diagonal matrix.