pub fn element_offset(
query: &[u64],
row_indices: &[u64],
col_ptr: &[u64],
) -> Result<Option<u64>>Expand description
Looks up the storage offset (values / row_indices buffer index) of logical index
(row, col) in a CSC matrix, or returns None if the element is a structural zero.
§Arguments
query— logical index[row, col]; MUST have length 2 (CSC is rank-2).row_indices— therow_indicesbuffer (buffer 1) asuint64: the row of each non-zero, in column-major storage order (nnzentries).col_ptr— thecol_ptrbuffer (buffer 2) asuint64:ncols + 1entries, wherecol_ptr[j]is the first storage index of columnjandcol_ptr[ncols] = nnz.
§Errors
Error::IndexRankMismatch—query.len() != 2.Error::IndexOutOfRange—colis not a valid column (col >= ncols).Error::InvalidLayout—col_ptris empty, or acol_ptrentry points outsiderow_indices/ is non-monotone for the queried column.
The caller is responsible for validating row against shape[0]; an out-of-range row
simply reports a structural zero (None).
§Examples
use hurray_core::layout::addressing::csc::element_offset;
// 3×3 matrix, stored column-major:
// col 0: (0,0)
// col 1: (2,1)
// col 2: (0,2)
let row_indices: &[u64] = &[0, 2, 0];
let col_ptr: &[u64] = &[0, 1, 2, 3];
assert_eq!(element_offset(&[2, 1], row_indices, col_ptr).unwrap(), Some(1));
assert_eq!(element_offset(&[0, 2], row_indices, col_ptr).unwrap(), Some(2));
assert_eq!(element_offset(&[1, 1], row_indices, col_ptr).unwrap(), None); // structural zero