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 | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(csr_t), | intent(in) | :: | self | |||
| type(error_t), | intent(out), | optional | :: | err |
.true. when the matrix is structurally sound
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | i | ||||
| integer(kind=default_int), | private | :: | n_entries |
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