ptwm_core
ptwm_core::metadata
Tensor metadata convention for the .ptwm container.
ptwm_core::metadata
Tensor metadata convention for the .ptwm container.
ptwm_core::metadata
crates/ptwm-core/src/metadata.rs:1mod metadataTensor metadata convention for the `.ptwm` container.
`TensorRecord.tensor_metadata` is an opaque CBOR map.
This module defines and enforces the **shape convention** used by the
Python bindings:
```text
{
"shape": [u64, u64, ...], // tensor dimensions, row-major
"dtype": "<str>" // canonical dtype name (e.g. "bf16", "mxfp4")
}
```
A minimal hand-rolled CBOR encoder/decoder is used — we only need
unsigned integers, text strings, fixed-length arrays, and fixed-length
maps. No floats, tags, or indefinite-length items.
Keeping it dependency-free avoids pulling a CBOR crate for ~50 lines of
logic and guarantees the byte layout is exactly what the spec says.
ptwm_core::metadata::decode_shape_metadata
crates/ptwm-core/src/metadata.rs:141pub fn decode_shape_metadata(buf: &[u8]) -> Result<(Vec<u64>, String), PtwmCoreError>Decode a `{"shape": [...], "dtype": "..."}` CBOR map previously written by [`encode_shape_metadata`]. Any other map layout (missing keys, extra keys, wrong types) is rejected as `InvalidContainer`.
ptwm_core::metadata::encode_shape_metadata
crates/ptwm-core/src/metadata.rs:54pub fn encode_shape_metadata(shape: &[u64], dtype_name: &str) -> Vec<u8>Encode `{"shape": shape, "dtype": dtype_name}` as CBOR.