Appearance
cellpack::loader::OutputSchema
Module contract · All interfaces
At a glance
pub struct OutputSchema { /* private fields */ }One output: its dims as standard ids, the element type and size of a cell, and either the built-in dense row or a process function.
The schema owns nothing borrowed: out_ids is shared by Arc, and a process function keeps its callbacks and user_data alive through its own owner. Building the loader composes the schema’s side of the panel with each matrix’s side, so changing a schema needs a new loader and, for plans, a new identity.
List standard-column IDs in output order. A missing dimension uses the default; a present dimension with an omitted sparse value is zero.
Try it
FIXED EXAMPLE RUST / CPU
Deliver ordered batches
Two output schemas share each requested position. Missing dimensions use the schema default; present sparse zeros stay zero.
mod common;
use std::error::Error;
use std::sync::Arc;
use cellpack::loader::{
DataSourceBuilder, Dtype, IoBackend, Loader, LoaderConfig,
OutputSchema, Planning, Replicate, Ring,
};
fn main() -> Result<(), Box<dyn Error>> {
let mut builder = DataSourceBuilder::new(5, 4096)?.direct_io(false);
builder.add_cpk(common::fixture()?, &[0, 1, 2, 3])?;
let source = Arc::new(builder.build()?);
let schemas = vec![
OutputSchema::dense(1, vec![3, 1, 4], Dtype::F32)?.with_default(f64::NAN),
OutputSchema::dense(2, vec![0, 2], Dtype::F64)?,
];
let loader = Loader::new(source, schemas, LoaderConfig {
workers: 2, backend: IoBackend::Pread, slot_cells: 2,
..LoaderConfig::default()
})?;
let cells = [3u32, 0, 2, 3, 1];
let accesses = Replicate::new(cells, 2)?;
let ring = Arc::new(Ring::allocate(loader.ring_layout(2, 1))?);
let run = loader.prepare(&accesses, ring, Planning::None)?;
let stats = run.for_each_batch(|batch| {
let panel: Vec<f32> = batch.region(0).chunks_exact(4)
.map(|v| f32::from_ne_bytes(v.try_into().unwrap())).collect();
println!("positions {}..{}: panel {panel:?}",
batch.first_position(), batch.first_position() + batch.rows() as u64);
Ok(())
})?;
println!("delivered: {} positions, {} accesses", cells.len(), stats.counters.accesses);
Ok(())
}
positions 0..2: panel [0.0, 8.0, NaN, 1.0, 2.0, NaN]
positions 2..4: panel [6.0, 0.0, NaN, 0.0, 8.0, NaN]
positions 4..5: panel [0.0, 0.0, NaN]
delivered: 5 positions, 10 accessesMember index
16 of 16 members
denseThe built-in output: each cell as a dense row of out_ids.len() values of dtype (CSR records are scattered into it).processA process function’s output of cell_bytes per cell, with scratch_bytes of private scratch per call. identity is a stable caller-chosen version of both callbacks and every setting their owner retains; changing semantics requires changing it.with_defaultSets the default value of missing output dims in dense rows: dims whose standard id the cell’s matrix has no column for. Present dims the record stores no value for are 0, whatever the default. Zero unless set; converted to the schema’s dtype with as .with_default_bytesSets the exact little-endian value, including integers above 2^53.namedAttaches a label, for reports and debugging only: names never enter a fingerprint and are not resolved against anything.idThe schema’s id.nameThe label from Self::named , if any.out_idsThe standard id of every output dim, in output-column order.out_dimOutput dims, i.e. the length of a built-in dense row.dtypeThe element type of the output.default_bitsLittle-endian bytes of the default value in a word.cell_bytesBytes of one cell’s output.scratch_bytesScratch bytes a process call of this schema may use, per call.process_fnThe process function, or none for the built-in dense row.is_builtinWhether the loader writes this schema’s output itself.row_formatThe row format the schema’s process function receives (the built-in output writes dense rows).
Methods and associated constants
dense
The built-in output: each cell as a dense row of out_ids.len() values of dtype (CSR records are scattered into it).
process
pub fn process(
id: SchemaId,
out_ids: impl Into<Arc<[u32]>>,
dtype: Dtype,
cell_bytes: usize,
process: ProcessFn,
identity: u64,
scratch_bytes: usize,
) -> Result<Self>A process function’s output of cell_bytes per cell, with scratch_bytes of private scratch per call. identity is a stable caller-chosen version of both callbacks and every setting their owner retains; changing semantics requires changing it.
with_default
pub fn with_default(self, value: f64) -> SelfSets the default value of missing output dims in dense rows: dims whose standard id the cell’s matrix has no column for. Present dims the record stores no value for are 0, whatever the default. Zero unless set; converted to the schema’s dtype with as.
with_default_bytes
pub fn with_default_bytes(self, value: &[u8]) -> Result<Self>Sets the exact little-endian value, including integers above 2^53.
named
Attaches a label, for reports and debugging only: names never enter a fingerprint and are not resolved against anything.
id
The schema’s id.
name
The label from Self::named, if any.
out_ids
The standard id of every output dim, in output-column order.
out_dim
Output dims, i.e. the length of a built-in dense row.
dtype
The element type of the output.
default_bits
pub fn default_bits(&self) -> u64Little-endian bytes of the default value in a word.
cell_bytes
pub fn cell_bytes(&self) -> usizeBytes of one cell’s output.
scratch_bytes
pub fn scratch_bytes(&self) -> usizeScratch bytes a process call of this schema may use, per call.
process_fn
pub fn process_fn(&self) -> Option<&ProcessFn>The process function, or none for the built-in dense row.
is_builtin
pub fn is_builtin(&self) -> boolWhether the loader writes this schema’s output itself.
row_format
pub fn row_format(&self) -> RowFormatThe row format the schema’s process function receives (the built-in output writes dense rows).
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.