Skip to main content

element_offset

Function element_offset 

Source
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 — the row_indices buffer (buffer 1) as uint64: the row of each non-zero, in column-major storage order (nnz entries).
  • col_ptr — the col_ptr buffer (buffer 2) as uint64: ncols + 1 entries, where col_ptr[j] is the first storage index of column j and col_ptr[ncols] = nnz.

§Errors

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