Appearance
cellpack::store::ReadSelection
Module contract · All interfaces
At a glance
pub struct ReadSelection { /* private fields */ }Metadata prepared once for repeated reads into independently owned outputs. spec().nnz is the CSR capacity: the stored entries of the selected cells, which dropped genes can reduce in the result.
Prepare once, allocate from spec(), then read into your own buffers. Separate concurrent reads need separate mutable workspaces and outputs.
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
4 of 4 members
io_summaryAggregates this selection’s planned application read bytes and requests. These values exclude metadata reads and do not measure device traffic.specOutput rows and columns, the CSR capacity and the stored dtype.read_dense_intoWrites rows × columns values of T , converting from the stored dtype. Dimensions are validated before any I/O; codec or I/O failures may leave the output partially written. Chunks are split over up to workers threads, each with its own workspace scratch.read_csr_intoWrites canonical CSR (ascending output columns per row) into caller arrays: indptr of rows + 1 entries, indices and values of at least ReadSpec::nnz entries. Rows are decoded at their capacity offsets, then compacted in place when genes were dropped; capacity past the returned nnz is unspecified. Dimensions and index widths are validated before any write. Returns the nnz.
Methods and associated constants
io_summary
pub fn io_summary(&self) -> ReadSummaryAggregates this selection’s planned application read bytes and requests. These values exclude metadata reads and do not measure device traffic.
spec
Output rows and columns, the CSR capacity and the stored dtype.
read_dense_into
pub fn read_dense_into<T: OutputElement>(
&self,
out: &mut [T],
ws: &mut ReadWorkspace,
workers: usize,
) -> Result<()>Writes rows × columns values of T, converting from the stored dtype. Dimensions are validated before any I/O; codec or I/O failures may leave the output partially written. Chunks are split over up to workers threads, each with its own workspace scratch.
Parameters
| Parameter | Meaning and constraints |
|---|---|
out | Exactly spec().dense_len() typed elements; the entire output is filled. |
ws | Exclusive reusable scratch for this call. |
workers | Read/decode worker count; at least one worker is used. |
Result
Fills the caller's output. On failure discard the output because it may be partially written.
read_csr_into
pub fn read_csr_into<P: IndptrOut, I: IndexOut + 'static, T: OutputElement>(
&self,
indptr: &mut [P],
indices: &mut [I],
values: &mut [T],
ws: &mut ReadWorkspace,
workers: usize,
) -> Result<usize>Writes canonical CSR (ascending output columns per row) into caller arrays: indptr of rows + 1 entries, indices and values of at least ReadSpec::nnz entries. Rows are decoded at their capacity offsets, then compacted in place when genes were dropped; capacity past the returned nnz is unspecified. Dimensions and index widths are validated before any write. Returns the nnz.
Parameters
| Parameter | Meaning and constraints |
|---|---|
indptr | Exactly spec().rows + 1 output row offsets. The integer type must represent every required offset. |
indices | At least spec().nnz output column IDs; the type must represent the largest output column. |
values | At least spec().nnz typed values. Only the returned actual-nnz prefix is meaningful. |
ws | Exclusive reusable scratch for this call. |
workers | Read/decode worker count. |
Result
Actual stored-entry count after mapping. Only this prefix of indices and values is meaningful; spec().nnz is an allocation capacity.
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.