lazymatrix::MatrixTraversal
LazyMatrix for Rust · 0.12.0
pub trait MatrixTraversal<F: Scalar>: MatrixShape + MatrixErrorTypeExplicit traversal of raw matrix entries within a rectangle.
Unlike borrowing capabilities, traversal may gather, decode, or read data. Full traversal visits every selected cell exactly once. Sparse traversal omits implicit zeros, sums duplicate entries at each cell in their storage order, and visits unique cells in the order declared by TraversalLayout. Explicitly stored zeros, including sums that cancel to zero, remain visits. Visitor indices always refer to the original matrix, rather than the selected rectangle. The backing matrix must remain unchanged during a scan and between repeated scans used by fitting.
Implementations restrict outer storage scans and chunk reads to the selection. Sparse coalescing may use workspace proportional to the selected inner dimension; full storage must not materialize the selected rectangle. Chunk and codec buffers may include a whole intersecting storage chunk.
Methods
dense_for_each_entry
fn dense_for_each_entry(
&self,
rows: Range<usize>,
columns: Range<usize>,
visitor: impl FnMut(usize, usize, F)
) -> Result<(), <Self as MatrixErrorType>::Error> where Self: MatrixRead<F>Traverse dense indexed storage without allocating or gathering entries.
Custom dense implementations can delegate Self::for_each_entry to this helper and declare TraversalLayout::Full.
Panics
Panics for reversed or out-of-bounds ranges before reading entries.
for_each_entry
fn for_each_entry(
&self,
rows: Range<usize>,
columns: Range<usize>,
visitor: impl FnMut(usize, usize, F)
) -> Result<(), <Self as MatrixErrorType>::Error>Visit raw entries in a selected rectangle.
Empty rectangles perform no reads or callbacks.
Errors
Returns the backend's error if traversal fails. Earlier callbacks may already have run; callers must discard incomplete statistics or honor the partial-output contract of the operation using this traversal.
Panics
Panics for reversed or out-of-bounds ranges. Implementations must validate both ranges before reads or callbacks, even for empty ranges.
traversal_layout
fn traversal_layout(&self) -> TraversalLayoutDescribe which entries are visited and their native ordering.
Implementation of MatrixTraversal
impl<A: ZarrArray<F>, F: Scalar> MatrixTraversal<F> for ZarrMatrix<A, F>Implementation of MatrixTraversal
impl<M: lazymatrix::MatrixTraversal<F>, F: Scalar> MatrixTraversal<F> for SprsCsc<M>Implementation of MatrixTraversal
impl<M: lazymatrix::MatrixTraversal<F>, F: Scalar> MatrixTraversal<F> for SprsCsr<M>
