csr_is_valid Function

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

Check that the stored triple is structurally consistent.

Verifies non-negative dimensions, that all three arrays are allocated, that row_ptr has nrow + 1 elements, starts at 1, is monotonically non-decreasing and ends at nnz + 1, that col_idx and values have the same length, and that every column index lies in 1:ncol. When err is present it carries the first violation found as ERROR_VALIDATION.

Type Bound

csr_t

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


Calls

proc~~csr_is_valid~~CallsGraph proc~csr_is_valid csr_t%csr_is_valid proc~fail~3 fail proc~csr_is_valid->proc~fail~3 proc~error_set error_t%error_set proc~fail~3->proc~error_set

Called by

proc~~csr_is_valid~~CalledByGraph proc~csr_is_valid csr_t%csr_is_valid proc~check_graph check_graph proc~check_graph->proc~csr_is_valid proc~csr_matvec csr_t%csr_matvec proc~csr_matvec->proc~csr_is_valid proc~csr_row_slice csr_t%csr_row_slice proc~csr_row_slice->proc~csr_is_valid proc~csr_transpose csr_t%csr_transpose proc~csr_transpose->proc~csr_is_valid proc~a_star a_star proc~a_star->proc~check_graph proc~bfs bfs proc~bfs->proc~check_graph proc~connected_components connected_components proc~connected_components->proc~check_graph proc~dijkstra dijkstra proc~dijkstra->proc~check_graph proc~path_cost path_cost proc~path_cost->proc~check_graph

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: i
integer(kind=default_int), private :: n_entries

Source Code

   function csr_is_valid(self, err) result(ok)
      !! Check that the stored triple is structurally consistent.
      !!
      !! Verifies non-negative dimensions, that all three arrays are
      !! allocated, that `row_ptr` has `nrow + 1` elements, starts at 1, is
      !! monotonically non-decreasing and ends at `nnz + 1`, that `col_idx`
      !! and `values` have the same length, and that every column index lies
      !! in `1:ncol`. When `err` is present it carries the first violation
      !! found as `ERROR_VALIDATION`.
      class(csr_t), intent(in) :: self
      type(error_t), intent(out), optional :: err
      logical :: ok
         !! `.true.` when the matrix is structurally sound

      integer(default_int) :: i, n_entries

      ok = .false.

      if (self%nrow < 0 .or. self%ncol < 0) then
         call fail(err, "pic_csr: matrix has a negative dimension")
         return
      end if
      if (.not. allocated(self%row_ptr) .or. .not. allocated(self%col_idx) .or. .not. allocated(self%values)) then
         call fail(err, "pic_csr: matrix has unallocated storage arrays")
         return
      end if
      if (int(size(self%row_ptr), default_int) /= self%nrow + 1) then
         call fail(err, "pic_csr: row_ptr must have exactly n_rows + 1 elements")
         return
      end if
      n_entries = int(size(self%col_idx), default_int)
      if (int(size(self%values), default_int) /= n_entries) then
         call fail(err, "pic_csr: col_idx and values must have the same length")
         return
      end if
      if (self%row_ptr(1) /= 1) then
         call fail(err, "pic_csr: row_ptr must start at 1")
         return
      end if
      do i = 1, self%nrow
         if (self%row_ptr(i + 1) < self%row_ptr(i)) then
            call fail(err, "pic_csr: row_ptr must be monotonically non-decreasing")
            return
         end if
      end do
      if (self%row_ptr(self%nrow + 1) /= n_entries + 1) then
         call fail(err, "pic_csr: row_ptr must end at nnz + 1")
         return
      end if
      do i = 1, n_entries
         if (self%col_idx(i) < 1 .or. self%col_idx(i) > self%ncol) then
            call fail(err, "pic_csr: col_idx holds a column index outside 1:n_cols")
            return
         end if
      end do

      ok = .true.
   end function csr_is_valid