Skip to main content

element_offset

Function element_offset 

Source
pub fn element_offset(
    query: &[u64],
    col_indices: &[u64],
    row_ptr: &[u64],
) -> Result<Option<u64>>
Expand description

Looks up the storage offset (values / col_indices buffer index) of logical index (row, col) in a CSR matrix, or returns None if the element is a structural zero.

§Arguments

  • query — logical index [row, col]; MUST have length 2 (CSR is rank-2).
  • col_indices — the col_indices buffer (buffer 1) as uint64: the column of each non-zero, in row-major storage order (nnz entries).
  • row_ptr — the row_ptr buffer (buffer 2) as uint64: nrows + 1 entries, where row_ptr[i] is the first storage index of row i and row_ptr[nrows] = nnz.

§Errors

The caller is responsible for validating col against shape[1]; an out-of-range column simply reports a structural zero (None).

§Examples

use hurray_core::layout::addressing::csr::element_offset;

// 3×3 matrix:
//   row 0: (0,0), (0,2)
//   row 1: —
//   row 2: (2,1)
let col_indices: &[u64] = &[0, 2, 1];
let row_ptr: &[u64] = &[0, 2, 2, 3];

assert_eq!(element_offset(&[0, 2], col_indices, row_ptr).unwrap(), Some(1));
assert_eq!(element_offset(&[2, 1], col_indices, row_ptr).unwrap(), Some(2));
assert_eq!(element_offset(&[1, 0], col_indices, row_ptr).unwrap(), None); // empty row