Skip to content
API REFERENCEUsage guides →

Data contracts ​

Use this reference before connecting external arrays, sampling callbacks, or shared output buffers. Shapes, units, id spaces, and ownership are part of the API contract; a successful compilation alone does not establish them.

Which layer accepts what? ​

LayerInputOutputAllocation and ownership
scansBorrowed matrix/record bytes, metadata and caller workspaceEncoded bytes, decoded arrays, or borrowed PartsCaller owns outputs and scratch; borrowed views retain dependencies
store writerCSR/dense row batches or packed chunksA finalized .cpk streamWriter owns staging and encoding buffers
store prepared readerA file region, ordered row selection, optional column mapCaller-owned typed dense/CSR arraysSelection owns prepared metadata; workspace owns scratch
loaderImmutable registered files, schemas, deterministic accessesLeased native output bytes per schema and batchProducer owns ring writes; consumer lease delays slot reuse
optLoader graph, accesses, frame budget and costsResidency plan or online compiler statePlan binds to input, schema and sequence identity

Matrix inputs ​

Let R be rows, C columns, E stored entries, and W bytes per stored value.

TypeRequired representation
DenseRefRow-major data; a whole number of rows of C × W bytes
CsrRefR + 1 u64 row offsets; index and value arrays covering every row interval
CsrViewThe same row model with borrowed integer offsets through Offsets
CellRefOne sparse row, strictly ascending unique column ids; indices.len() × W value bytes
RowRefOne sparse or dense row, interpreted with its declared dimensions and value width

Values are little-endian bytes, with W ∈ {1, 2, 4, 8}. Chunk encoders require 1 <= C <= i32::MAX. Within every CSR row, indices must be nonnegative, strictly increasing, distinct, and below C. Row offsets must describe readable index/value intervals and must not decrease. A complete standalone CSR normally starts at offset zero; views can describe intervals into larger backing arrays.

Indices accepts u16, u32, i32, i64, or u64 storage. Signed negatives and ids outside the supported range are invalid. Offsets accepts u32, u64, i32, or i64; signed offsets must be nonnegative. Wider host storage does not expand the codec's column-id space.

Dense and CSR source layouts do not force each encoded record's layout. With automatic layout selection, individual records can be sparse or dense. Explicit sparse zeros are stored entries. In loader semantics, an omitted value of a present column is zero, rather than a missing dimension.

Numeric types and conversion ​

File dtypes are U8/U16/U32/U64/I8/I16/I32/I64/F32/F64. Codec compression preserves stored value bit patterns. It does not normalize, quantize, replace NaNs, or attach biological meanings to values.

Typed storage reads and scans::CastInto use Rust as semantics for their supported numeric element types. The loader admits a narrower set of pairs:

Stored → outputLoader support
Same dtypeYes
Unsigned → wider unsigned or wider signedYes
Signed → wider signedYes
Signed → same-width or wider unsignedYes; negative values are not checked before casting
Any integer → f32 or f64Yes; large integers can lose precision
f32 → f64Yes
Other narrowing, float → integer, f64 → f32Rejected by loader construction

Use loader::allowed(source, output) for the actual pair check. The low-level cast API and loader admission rules are distinct. Native loader output is typed host representation; file/codec byte streams are little-endian representation.

Shapes and capacity ​

OperationOutput extent
Storage dense readExactly ReadSpec.rows × ReadSpec.columns elements
Storage CSR readExactly rows + 1 offsets; index/value capacity at least ReadSpec.nnz
Codec chunk CSR decodeselected_rows + 1 offsets and sufficient entry/value capacity
Codec dense decodeByte count from scans::dense_len
Dense loader schemaout_ids.len() × dtype.width() bytes per cell
Process schemaExactly declared cell_bytes per cell
Leased schema regionbatch.rows() × cell_bytes(schema) bytes

ReadSpec.nnz is source-based capacity. Column filtering can reduce the returned actual nnz. Ignore unused index/value capacity. A tail batch can have fewer than slot_cells positions; use rows(), not the configured slot size.

Encoding and decoding sizing APIs distinguish byte capacity from u64 workspace words. Do not multiply or divide units implicitly.

Column and row identities ​

NameMeaningImportant limit
Source columnPosition in one input matrixCodec dimension range
Coded columnChunk-local compression orderRequires the matching chunk permutation
Standard columnApplication-owned vocabulary idLoader builder's vocab
Output columnPosition in one schema's panelout_ids.len()
CellIdGlobal source row, assigned in registration orderu32; constructors check representable counts
PositionLogical output row in the sequenceCan repeat the same cell
AccessOne schema delivery at a positionk / S is position; k % S is schema

Storage RowSelection::List uses u64 file rows. Codec Rows::List uses u32 chunk-local rows. Loader Accesses produces global CellId values. These selectors are not interchangeable.

A storage gene map is source → output. A data-source map is source → standard. A schema lists standard ids in output order. Maps must cover their required input domain, and kept targets must be distinct. UNMAPPED = u32::MAX means dropped, not a valid output or standard id.

Missing dimensions ​

A source matrix either has a standard column or does not. A present column whose sparse record omits a value produces zero. A dimension absent from that matrix produces the schema default. Defaults never replace present zeros. CSR process rows cannot distinguish these two omitted cases; dense process rows can distinguish them when the default is a sentinel no valid value takes.

File and page identity ​

A stream is valid after CpkWriter::finish succeeds. A writer may truncate an existing path. Its success is not an atomic publication or fsync guarantee. Keep files immutable while prepared selections, sources, loaders, and plans use them. Loader construction/preparation verifies recorded file identity.

Packed page sizes are powers of two in [512, 65536] bytes. All matrices of one data source use the builder's page size. Embedded stream offsets and lengths are supplied by the application. O_DIRECT additionally requires filesystem and physical-offset alignment support.

Borrowing and concurrency ​

ResourceLifetime rule
Borrowed encoder inputKeep immutable through the call or the entire PreparedEncoder borrow
MetaKeep its backing metadata bytes alive
Decode/encode tablesUse only with their matching metadata
PartsBorrows workspace, record, and possibly metadata; consume before reusing them
ReadWorkspaceExclusive to one read at a time; can be reused afterward
Loader runBorrows loader and sequence; one run holds a loader at a time
Batch regionValid only while its lease is held and backing memory remains alive
Native callbackCode/context must outlive every call, be thread-safe, and retain no input pointers

External ring constructors are unsafe: backing storage must be stable, correctly aligned, sufficiently large, and governed by the slot protocol. An asynchronous device copy is still a reader; release its source lease only after completion.

Failure and validation boundary ​

Entry points check declared shapes, capacities, option ranges, and metadata compatibility where documented. Inner record bytes are trusted. Malformed trusted data can cause undefined behavior in optimized paths; the decoder is not an untrusted-data validator.

A read/decode/process failure can leave partial output. Discard that operation's output. Loader failure cancels the run and wakes participants. An aborted ring cannot start another run. Report the original non-Aborted error when available.

See errors for exact variants and recovery scope.

Definition