csr_t Derived Type

type, public :: csr_t

Compressed sparse row matrix with real(dp) values.


Components

Type Visibility Attributes Name Initial
integer(kind=default_int), public, allocatable :: col_idx(:)

Column index of every stored entry, ascending within each row

integer(kind=default_int), public :: ncol = 0

Number of columns; prefer the n_cols accessor when reading

integer(kind=default_int), public :: nrow = 0

Number of rows; prefer the n_rows accessor when reading

integer(kind=default_int), public, allocatable :: row_ptr(:)

Row start offsets, size nrow + 1, one-based

real(kind=dp), public, allocatable :: values(:)

Value of every stored entry, parallel to col_idx


Type-Bound Procedures

procedure, public :: build_from_coo => csr_build_from_coo

  • private subroutine csr_build_from_coo(self, n_rows, n_cols, rows, cols, vals, err)

    Build the matrix from coordinate (COO) triplets.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(csr_t), intent(inout) :: self
    integer(kind=default_int), intent(in) :: n_rows

    Number of rows of the assembled matrix

    integer(kind=default_int), intent(in) :: n_cols

    Number of columns of the assembled matrix

    integer(kind=default_int), intent(in) :: rows(:)

    Row coordinate of each triplet

    integer(kind=default_int), intent(in) :: cols(:)

    Column coordinate of each triplet

    real(kind=dp), intent(in) :: vals(:)

    Value of each triplet

    type(error_t), intent(out), optional :: err

procedure, public :: destroy => csr_destroy

  • private subroutine csr_destroy(self)

    Release all storage and reset the matrix to an empty 0 by 0 one.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_t), intent(inout) :: self

procedure, public :: is_valid => csr_is_valid

  • private function csr_is_valid(self, err) result(ok)

    Check that the stored triple is structurally consistent.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(csr_t), intent(in) :: self
    type(error_t), intent(out), optional :: err

    Return Value logical

    .true. when the matrix is structurally sound

procedure, public :: matvec => csr_matvec

  • private subroutine csr_matvec(self, x, y, err)

    Sparse matrix-vector product y = A*x.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(csr_t), intent(in) :: self
    real(kind=dp), intent(in) :: x(:)

    Input vector of length n_cols

    real(kind=dp), intent(out) :: y(:)

    Output vector of length n_rows

    type(error_t), intent(out), optional :: err

procedure, public :: n_cols => csr_n_cols

  • private pure function csr_n_cols(self) result(n)

    Number of columns of the matrix.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_t), intent(in) :: self

    Return Value integer(kind=default_int)

procedure, public :: n_rows => csr_n_rows

  • private pure function csr_n_rows(self) result(n)

    Number of rows of the matrix.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_t), intent(in) :: self

    Return Value integer(kind=default_int)

procedure, public :: nnz => csr_nnz

  • private pure function csr_nnz(self) result(n)

    Number of stored entries, including any explicitly stored zeros.

    Arguments

    Type IntentOptional Attributes Name
    class(csr_t), intent(in) :: self

    Return Value integer(kind=default_int)

procedure, public :: row_slice => csr_row_slice

  • private subroutine csr_row_slice(self, i, cols, vals, err)

    Copy out the column indices and values stored in row i.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(csr_t), intent(in) :: self
    integer(kind=default_int), intent(in) :: i

    Row to read, in 1:nrow

    integer(kind=default_int), intent(out), allocatable :: cols(:)

    Column indices of row i, ascending

    real(kind=dp), intent(out), allocatable :: vals(:)

    Values of row i, parallel to cols

    type(error_t), intent(out), optional :: err

procedure, public :: transpose => csr_transpose

  • private subroutine csr_transpose(self, at, err)

    Build the transpose of this matrix into at.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(csr_t), intent(in) :: self
    type(csr_t), intent(out) :: at

    Receives the transpose

    type(error_t), intent(out), optional :: err

Source Code

   type :: csr_t
      !! Compressed sparse row matrix with `real(dp)` values.
      integer(default_int) :: nrow = 0
         !! Number of rows; prefer the `n_rows` accessor when reading
      integer(default_int) :: ncol = 0
         !! Number of columns; prefer the `n_cols` accessor when reading
      integer(default_int), allocatable :: row_ptr(:)
         !! Row start offsets, size `nrow + 1`, one-based
      integer(default_int), allocatable :: col_idx(:)
         !! Column index of every stored entry, ascending within each row
      real(dp), allocatable :: values(:)
         !! Value of every stored entry, parallel to `col_idx`
   contains
      procedure :: build_from_coo => csr_build_from_coo
      procedure :: n_rows => csr_n_rows
      procedure :: n_cols => csr_n_cols
      procedure :: nnz => csr_nnz
      procedure :: row_slice => csr_row_slice
      procedure :: matvec => csr_matvec
      procedure :: transpose => csr_transpose
      procedure :: is_valid => csr_is_valid
      procedure :: destroy => csr_destroy
   end type csr_t