csr_row_slice Subroutine

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

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

Both outputs are allocated to the number of stored entries in that row, which is zero for an empty row. A row index outside 1:nrow reports ERROR_VALIDATION and yields zero-size outputs.

Type Bound

csr_t

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

Calls

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

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: hi
integer(kind=default_int), private :: k
integer(kind=default_int), private :: lo
integer(kind=default_int), private :: n

Source Code

   subroutine csr_row_slice(self, i, cols, vals, err)
      !! Copy out the column indices and values stored in row `i`.
      !!
      !! Both outputs are allocated to the number of stored entries in that
      !! row, which is zero for an empty row. A row index outside `1:nrow`
      !! reports `ERROR_VALIDATION` and yields zero-size outputs.
      class(csr_t), intent(in) :: self
      integer(default_int), intent(in) :: i
         !! Row to read, in `1:nrow`
      integer(default_int), allocatable, intent(out) :: cols(:)
         !! Column indices of row `i`, ascending
      real(dp), allocatable, intent(out) :: vals(:)
         !! Values of row `i`, parallel to `cols`
      type(error_t), intent(out), optional :: err

      integer(default_int) :: lo, hi, n, k

      if (.not. self%is_valid(err)) then
         allocate (cols(0))
         allocate (vals(0))
         return
      end if

      if (i < 1 .or. i > self%nrow) then
         call fail(err, "pic_csr: row_slice got a row index outside 1:n_rows")
         allocate (cols(0))
         allocate (vals(0))
         return
      end if

      lo = self%row_ptr(i)
      hi = self%row_ptr(i + 1) - 1
      n = hi - lo + 1
      allocate (cols(n))
      allocate (vals(n))
      do k = 1, n
         cols(k) = self%col_idx(lo + k - 1)
         vals(k) = self%values(lo + k - 1)
      end do
   end subroutine csr_row_slice