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— thecol_indicesbuffer (buffer 1) asuint64: the column of each non-zero, in row-major storage order (nnzentries).row_ptr— therow_ptrbuffer (buffer 2) asuint64:nrows + 1entries, whererow_ptr[i]is the first storage index of rowiandrow_ptr[nrows] = nnz.
§Errors
Error::IndexRankMismatch—query.len() != 2.Error::IndexOutOfRange—rowis not a valid row (row >= nrows).Error::InvalidLayout—row_ptris empty, or arow_ptrentry points outsidecol_indices/ is non-monotone for the queried row.
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