pub fn element_offset(
query: &[u64],
is_sorted: bool,
indices: &[u64],
) -> Result<Option<u64>>Expand description
Looks up the storage offset (values buffer index) of a logical index in a COO
tensor, or returns None if the element is structurally absent (implicit zero).
§Arguments
query— logical index[i0, …, i_{rank-1}]; its length defines the rank.is_sorted— the COO descriptor’sis_sortedflag. Whentrue, the stored entries are in strictly increasing lexicographic order and a binary search is used; whenfalse, a linear scan is used.indices— theindicesbuffer (buffer 1) asuint64values:nnz × rankcoordinates in row-major order, so entryr’s coordinates areindices[r*rank .. r*rank + rank].
The returned offset indexes both the values buffer and the entry’s row in indices.
§Errors
Error::IndexRankMismatch—queryis empty (rank 0).Error::InvalidLayout—indices.len()is not a multiple of the rank.
The caller is responsible for validating each query coordinate against the tensor
shape; an out-of-bounds coordinate simply reports a structural zero (None).
§Examples
use hurray_core::layout::addressing::coo::element_offset;
// 4×4 matrix with three sorted non-zeros: (0,1), (2,0), (2,3).
let indices: &[u64] = &[0, 1, /* */ 2, 0, /* */ 2, 3];
assert_eq!(element_offset(&[2, 0], true, indices).unwrap(), Some(1));
assert_eq!(element_offset(&[2, 3], true, indices).unwrap(), Some(2));
assert_eq!(element_offset(&[1, 1], true, indices).unwrap(), None); // structural zero