Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Data Types

The dtype field in an object descriptor names the element type of the tensor. It is stored as a lowercase text string in CBOR.

Type Table

CBOR stringRust variantBytes per elementNotes
float16Dtype::Float162IEEE 754 half-precision
bfloat16Dtype::Bfloat162Brain float — same exponent range as float32, less mantissa precision
float32Dtype::Float324IEEE 754 single-precision
float64Dtype::Float648IEEE 754 double-precision
complex64Dtype::Complex648Pair of float32 (real, imaginary)
complex128Dtype::Complex12816Pair of float64 (real, imaginary)
int8Dtype::Int81Signed
int16Dtype::Int162Signed
int32Dtype::Int324Signed
int64Dtype::Int648Signed
uint8Dtype::Uint81Unsigned
uint16Dtype::Uint162Unsigned
uint32Dtype::Uint324Unsigned
uint64Dtype::Uint648Unsigned
bitmaskDtype::Bitmask0*Packed bits

*bitmask returns 0 from byte_width() — see the edge case note below.

Byte Order

The byte_order field in the payload descriptor specifies whether multi-byte elements are stored in big-endian ("big") or little-endian ("little") order. This applies to the stored payload bytes after encoding.

Single-byte types (int8, uint8, bitmask) are unaffected by byte order.

Bitmask Edge Case

Dtype::Bitmask is for packing boolean or categorical data sub-byte. The payload size is ceil(num_elements / 8) bytes. The byte_width() method returns 0 as a sentinel; callers that need the actual payload size must compute it:

#![allow(unused)]
fn main() {
let payload_bytes = if dtype == Dtype::Bitmask {
    (num_elements + 7) / 8
} else {
    num_elements * dtype.byte_width()
};
}

Choosing a dtype

SituationRecommended dtype
Temperature, wind speed, pressure (weather)float32
High-precision scientific analysisfloat64
ML model weightsbfloat16 or float16
Integer indices, countsint32 or int64
Land-sea masks, validity flagsuint8 or bitmask
Complex wave spectracomplex64