Appearance
cellpack::store::CpkOptions
Module contract · All interfaces
At a glance
pub struct CpkOptions {
pub encode: EncodeOptions,
pub chunk_rows: usize,
pub page_size: u32,
}How a file is chunked and coded.
Choose page size in bytes and a target number of rows per chunk. The new constructor uses 4096-byte pages and a 4096-row target. Source layout and encoded layout are separate choices.
Try it
FIXED EXAMPLE RUST / CPU
Write and reopen a matrix
Write a small matrix and inspect the decoded dense rows and CSR structure. The file becomes readable after finish succeeds.
mod common;
use std::error::Error;
use cellpack::format::{Dtype, SourceLayout};
use cellpack::scans::DenseRef;
use cellpack::store::{CpkFile, CpkWriter, ReadWorkspace};
fn main() -> Result<(), Box<dyn Error>> {
let path = common::directory()?.join("example.cpk");
let values = [0.0f32, 2.0, 0.0, 1.0, 0.0, 3.0];
let bytes: Vec<u8> = values.iter().flat_map(|v| v.to_le_bytes()).collect();
let mut writer = CpkWriter::create(
&path, 3, Dtype::F32, SourceLayout::Dense, common::options(),
)?;
writer.append(DenseRef { n_genes: 3, value_width: 4, data: &bytes })?;
writer.finish()?;
let file = CpkFile::open(&path)?;
let selection = file.prepare_read(0..2)?;
let mut out = vec![0.0f32; selection.spec().dense_len()?];
selection.read_dense_into(&mut out, &mut ReadWorkspace::default(), 1)?;
let csr = file.read_csr(0..2)?;
println!("shape: {} × {}", file.n_rows(), file.n_cols());
println!("dense: {out:?}");
println!("CSR offsets: {:?}", csr.indptr);
println!("CSR columns: {:?}", csr.indices);
Ok(())
}
shape: 2 × 3
dense: [0.0, 2.0, 0.0, 1.0, 0.0, 3.0]
CSR offsets: [0, 1, 3]
CSR columns: [1, 0, 2]Fields and variants
encode
encode: EncodeOptionsPer-chunk column ordering, layout candidates, value coding and rANS settings.
chunk_rows
chunk_rows: usizeRows per chunk; each chunk has its own models and column order.
page_size
page_size: u32Records are packed so each reads its minimum number of these pages.
Member index
1 of 1 members
new4096-row chunks packed to 4 KiB pages.
Methods and associated constants
new
pub fn new(encode: EncodeOptions) -> Self4096-row chunks packed to 4 KiB pages.
Implemented traits
impl Clone for CpkOptionsimpl Debug for CpkOptionsContract 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.