Appearance
cellpack::store::ReadSpec
Module contract · All interfaces
At a glance
Output dimensions of a prepared selection: nnz is the CSR capacity and dtype the stored dtype.
Use rows × columns to size dense elements and nnz to reserve CSR capacity. Byte sizes describe the stored dtype, which may differ from a requested typed output.
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].
Fields and variants
rows
rows: usizeSelected output rows, including repeats in a gather.
columns
columns: usizeOutput panel width after the optional column map.
nnz
nnz: usizeSource-based CSR entry capacity, before mapped columns are dropped.
dtype
dtype: DtypeStored dtype, not the generic output type of a converted read.
Member index
3 of 3 members
dense_lenElements of the dense output.dense_bytesDense byte count at the stored dtype width, with overflow checks. For converted typed output, use Self::dense_len elements of T .value_bytesCSR value capacity in bytes at the stored dtype width. Actual mapped nnz may be smaller, and converted T may have another width.
Methods and associated constants
dense_len
Elements of the dense output.
dense_bytes
pub fn dense_bytes(&self) -> Result<usize>Dense byte count at the stored dtype width, with overflow checks. For converted typed output, use Self::dense_len elements of T.
value_bytes
pub fn value_bytes(&self) -> Result<usize>CSR value capacity in bytes at the stored dtype width. Actual mapped nnz may be smaller, and converted T may have another width.
Implemented traits
Contract 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.