Skip to content

lazymatrix::ReadBlock ​

LazyMatrix for Rust · 0.8.1

Source

rust
pub trait ReadBlock<F: Scalar>: MatrixShape + MatrixErrorType

Experimental fallible access to raw rectangular matrix blocks.

Unlike borrowed column and row capabilities, this capability may perform decoding and I/O. Callers choose rectangles and provide initialized buffer storage. Implementations overwrite exactly the first rows.len() * columns.len() elements and return a packed row-major view of that prefix. The unused tail remains unchanged, including after an error. Empty rectangles return empty views without storage reads.

A returned view borrows only the buffer, preventing its reuse while the view remains live. Backends may require additional chunk and codec workspace; the buffer length is not a bound on total working memory. Reading multiple rectangles in the same storage chunk may decode that chunk repeatedly.

rust
use lazymatrix::{ReadBlock, MatrixShape};
fn overlapping_reads<M: ReadBlock<f64>>(matrix: &M, buffer: &mut [f64]) {
    let first = matrix.read_block(0..1, 0..1, buffer).unwrap();
    let second = matrix.read_block(0..1, 0..1, buffer).unwrap();
    assert_eq!(first.values(), second.values());
}

Methods ​

read_block ​

rust
fn read_block<'buf>(
    &self,
    rows: Range<usize>,
    columns: Range<usize>,
    buffer: &'buf mut [F]
) -> Result<DenseBlock<'buf, F>, <Self as MatrixErrorType>::Error>

Source

Read an in-bounds rectangle into caller-owned storage.

Errors ​

Returns the backend's error on a read or decoding failure. No view is returned; the entire requested prefix is unspecified and must be discarded. A successful retry overwrites that prefix completely.

Panics ​

Panics for reversed or out-of-bounds ranges, dimension overflow, or a buffer shorter than the requested number of elements. Implementations must validate these conditions before accessing storage.

Implementation of ReadBlock ​

Source

rust
impl<A, F> ReadBlock<F> for ZarrMatrix<A, F> where A: ZarrArray<F>, F: Scalar

Released under the MIT and Apache 2.0 licenses.