Appearance
cellpack::store::ReadWorkspace
Module contract · All interfaces
At a glance
pub struct ReadWorkspace { /* private fields */ }Reusable private scratch: per-thread decode buffers by output element type and the row bookkeeping of CSR reads. It never holds outputs; one workspace serves one read at a time.
Keep one workspace per concurrent read and reuse it for later reads. clear releases retained scratch; it does not own or invalidate caller output arrays.
Try it
FIXED EXAMPLE RUST / CPU
Gather rows and map columns
Rows [3, 0, 3] preserve order and repetition. The source → output map keeps source column 2 first and column 0 second.
mod common;
use std::error::Error;
use cellpack::scans::UNMAPPED;
use cellpack::store::{CpkFile, ReadOptions, ReadWorkspace, RowSelection};
fn main() -> Result<(), Box<dyn Error>> {
let file = CpkFile::open(common::fixture()?)?;
let rows = [3, 0, 3];
// Each entry maps a source column to its output position.
let map = [1, UNMAPPED, 0, UNMAPPED];
let selection = file.prepare_selection(
RowSelection::List(&rows), Some(&map), 2, ReadOptions::default(),
)?;
let spec = selection.spec();
let mut workspace = ReadWorkspace::default();
let mut out = vec![0.0f64; spec.dense_len()?];
selection.read_dense_into(&mut out, &mut workspace, 1)?;
let mut offsets = vec![0u64; spec.rows + 1];
let mut columns = vec![0u32; spec.nnz];
let mut values = vec![0.0f64; spec.nnz];
let nnz = selection.read_csr_into(
&mut offsets, &mut columns, &mut values, &mut workspace, 1,
)?;
println!("rows: {rows:?}");
println!("output: {out:?}");
println!("CSR offsets: {offsets:?}");
println!("actual nnz: {nnz}");
Ok(())
}
rows: [3, 0, 3]
output: [0.0, 7.0, 0.0, 0.0, 0.0, 7.0]
CSR offsets: [0, 1, 1, 2]
actual nnz: 2Explore how row and column selection works
Explore the selectionInstant illustration in your browser
| Source row | Source col 2 | Source col 0 |
|---|---|---|
| 3 | 0 | 7 |
| 0 | 0 | 0 |
| 3 | 0 | 7 |
source → output: [1, UNMAPPED, 0, UNMAPPED]
This illustration runs in the browser. The fixed server example always uses rows [3, 0, 3].
Member index
1 of 1 members
clearReleases retained scratch.
Methods and associated constants
clear
pub fn clear(&mut self)Releases retained scratch.
Implemented traits
impl Default for ReadWorkspaceContract reference
See the module reference for semantic input/output rules, units, allocation, mutation, failure behavior, and lifetime requirements. Declarations and documented members are synchronized from the crate source.