Skip to content
API REFERENCEUsage guides →

Matrix storage: store ​

cellpack::store owns the file-level workflow: streaming matrix writes, prepared reads, physical read planning, and decoding into caller-owned outputs. It does not own sampling, a shared gene vocabulary, or an asynchronous training queue. For those tasks, use loader.

Start at the level you need

Input and output model ​

Operation familyTakesProduces
WriterDeclared matrix dtype/layout and row batchesOne finalized .cpk matrix stream
File inspectionPath or embedded regionDimensions, dtype, superblock, directory and chunk bytes
Prepared selectionFile rows, optional source-to-output map, read policyReadSelection with shape, capacity and I/O plan
Borrowed-output readSelection, typed buffers, workspace, worker countDense values or canonical CSR plus actual nnz
Panel-row helperChunk metadata/tables, panel and mapperMapped rows in caller buffers

See the shared matrix, conversion, and lifetime contracts.

CpkWriter ​

MethodInputsReturn and postcondition
createpath, n_cols, dtype, source_layout, CpkOptionsResult<CpkWriter>; creates/truncates the path, which is not yet a valid stream
appendBorrowed MatrixRef-convertible rowsResult<()>; appends in order, buffering a partial chunk
set_threadsDesired thread count(); counts below one become one; complete chunks can encode concurrently
end_chunkWriter's staged rowsResult<()>; flushes them so the next append starts a new chunk
append_packedOne encoded and page-packed chunkResult<()>; appends without re-encoding after compatibility checks
finishConsumes writerResult<()>; writes tail, directory and final superblock

append requires matching column count and value width. If the incoming form differs from the declared source layout, the writer converts CSR/dense form. CSR columns remain canonical. append_packed requires no staged rows and a chunk with matching dimensions, value width, page size and total byte length.

source_layout chooses the form staged by the writer. It does not promise that every encoded record will be dense or sparse; chunk encoding options decide that. The supplied dtype interprets input bytes: matching byte width is not numeric conversion. For example, writing four-byte integer values with Dtype::F32 declares them to be float bit patterns. Convert values before appending if needed. Borrowed append inputs may be reused after the call returns.

CpkOptions::new(encode) defaults to 4096 rows per chunk and 4096-byte pages. chunk_rows is a target; early chunk endings and appended packed chunks may produce different chunk lengths. Codec choices live in EncodeOptions.

CpkFile ​

MethodInputsReturn
openPathOpened matrix handle
open_regionPath, byte offset, optional bounded byte lengthHandle to an embedded stream
n_rows / n_cols / dtypeHandleMatrix shape and stored type
superblock / chunksHandleBorrowed stream metadata and directory entries
byte_offsetHandleStream's offset in its outer file
identityOpen descriptorDevice and inode, independent of later path replacement
read_meta / read_chunkChunk indexOwned metadata bytes or complete chunk bytes
read_chunk_intoChunk index, metadata-only flag, exact-size byte bufferWrites chunk bytes into the supplied buffer
read_dense / read_csrHalf-open Range<u64>Allocated stored-dtype bytes or Csr
prepare_readHalf-open row rangePrepared selection of every source column
prepare_selectionRowSelection, optional map, output width, ReadOptionsPrepared ordered selection

open_region interprets format offsets relative to the stream. read_dense returns Vec<u8>, not Vec<f32>. Allocated Csr stores u64 offsets, u32 indices and value bytes. Obtain its value dtype and source column count from the file; Csr has no dtype/shape fields. Prepared typed reads are the route for conversion or buffer reuse.

Opening reads the superblock and directory; chunk metadata and record payloads are read later as requested. A successfully opened handle is not a full-file record verification. identity() describes the opened descriptor, so replacing the path does not retarget an existing handle.

ReadSelection and ReadWorkspace ​

MethodInputsOutput and mutation
specPrepared selectionReadSpec { rows, columns, nnz, dtype }
io_summaryPrepared physical readsPlanned payload/read bytes and request counts
read_dense_into<T>Exact rows × columns buffer, exclusive workspace, workersResult<()>; fills every output element
read_csr_into<P,I,T>Exact row-offset array, index/value capacities, workspace, workersResult<usize>; returns actual nnz and canonical output indices
ReadWorkspace::clearWorkspaceReleases retained scratch

RowSelection::Range uses half-open file rows. List preserves arbitrary order and repetitions. The optional map covers every source column, maps kept columns to distinct output positions, and uses UNMAPPED for drops. Missing output positions are zero. Without a map, output width must equal file width.

ReadSpec::dense_len is an element count; dense_bytes and value_bytes use the stored dtype width, not a requested converted output type. Allocate typed output using element counts and size_of::<T>(). nnz is capacity, not post-filter actual nnz. Narrow index types must hold the largest output column and every needed row offset.

Preparing a selection reads metadata. Each read invocation performs record I/O. The selection owns its prepared state; output is owned by the caller. Concurrent reads need separate mutable workspaces and outputs. Failures can leave partial writes.

Validation and failure scope ​

BoundaryChecked contractOn failure
create / appendEncoding options, page/chunk sizes; input column count and value widthReturns an error; an unfinished file must not be published
open / open_regionStream bounds, superblock and directoryNo usable handle is returned
prepare_selectionRow bounds, full source map, distinct/in-range targets, metadata and addressable capacitiesNo usable selection is returned
Typed output entryExact dense length; CSR lengths/capacities and index widthsOutput dimensions are rejected before decoding
Record I/O / decodingI/O and supported record checksTreat that invocation's output as incomplete

Canonical CSR inputs and chunk/record consistency remain part of the shared trusted-data contract. These interfaces are not an untrusted-file sanitizer. After a writer error, do not assume that retrying an append resumes at a transactional checkpoint.

Physical reads and panel helpers ​

RecordReadPlan::new(meta, cells, options) plans one chunk's records from metadata. ranges returns disjoint read ranges; summary returns byte/request totals. read_into(file, base, out) resizes a byte vector and reads each range relative to the records-region base. record(out, position) returns a borrowed record slice for the corresponding requested position, including repeated/empty records.

ReadOptions defaults to Auto, zero merge gap, and 4096 equivalent bytes per request. WholeChunk means the complete records region, excluding metadata. ReadSummary describes application reads, not physical device traffic.

compose_panel combines a chunk permutation and an optional source map. PanelRows<S,T> binds metadata, tables, a panel and a mapper; bind prepares RowScratch<T>; dense and csr decode/map individual records. These helpers share the codec's trusted-record contract. Returned CSR column slices borrow scratch and must be consumed before its reuse.

Complete interface index ​

Each entry opens a searchable page with its declaration, parameter/return types, fields, methods, and source documentation.

Structs ​

InterfaceResponsibility
CpkFileAn opened .cpk file.
CpkOptionsHow a file is chunked and coded.
CpkWriterWrites one matrix to a .cpk file. Rows are appended in order; the file is valid only after CpkWriter::finish .
CsrOwned CSR rows with ascending source column ids within each row. Values are little-endian bytes interpreted with CpkFile::dtype ; this object does not carry a separate dtype or shape descriptor.
PanelRowsDecodes records of one chunk into panel rows of T , reading stored values as S (the chunk’s value width).
ReadOptionsRead planning: strategy, merge threshold and the estimated cost of a read.
ReadRangeOne read: length bytes at offset (from the records region start) land at buffer_offset in the read buffer.
ReadSelectionMetadata 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.
ReadSpecOutput dimensions of a prepared selection: nnz is the CSR capacity and dtype the stored dtype.
ReadSummaryI/O a plan performs, counted in bytes and requests.
ReadWorkspaceReusable 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.
RecordReadPlanReads for a list of cells and the buffer slice each cell’s record occupies.
RowScratchPrivate per-thread scratch for PanelRows and file selections. It grows on demand, is reusable across chunks and never holds outputs.

Enums ​

InterfaceResponsibility
ReadStrategyWhen to read the whole records region instead of the selected ranges.
RowSelectionCells to read: a contiguous range, or a gather in output order whose ids may repeat.

Traits ​

InterfaceResponsibility
OutputElementElement types a selection reads into, from any stored dtype.

Functions ​

InterfaceResponsibility
compose_panelComposes a chunk’s coded gene order with a source → panel map (identity when None ) into out , indexed by coded id.
Definition