Skip to main content

element_offset

Function element_offset 

Source
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’s is_sorted flag. When true, the stored entries are in strictly increasing lexicographic order and a binary search is used; when false, a linear scan is used.
  • indices — the indices buffer (buffer 1) as uint64 values: nnz × rank coordinates in row-major order, so entry r’s coordinates are indices[r*rank .. r*rank + rank].

The returned offset indexes both the values buffer and the entry’s row in indices.

§Errors

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