PTWM
transforms

ptwm_core::transforms::source

Source op — graph entry node that describes the raw input tensor.

ptwm_core::transforms::source

Source op — graph entry node that describes the raw input tensor.

rsmod

ptwm_core::transforms::source

crates/ptwm-core/src/transforms/source.rs:1
mod source

`Source` op — graph entry node that describes the raw input tensor.

rsfn

ptwm_core::transforms::source::bound_source_params

crates/ptwm-core/src/transforms/source.rs:95
pub fn bound_source_params(shape: &[u64], dtype_code: u16) -> Option<Vec<u8>>

Source params for a tensor's own shape and public dtype code: the params a *bound* Source stands for in the compact chain wire (`chain::wire_compact`). Same layout as [`Source::write_params`]: `u8` ndim, `u32` LE dims, `u16` LE chain dtype.

`None` when the tensor cannot bind a Source: more than [`MAX_SOURCE_DIMS`] dimensions, a dimension above `u32::MAX`, or a dtype without a chain dtype.
rsfn

ptwm_core::transforms::source::chain_dtype_for_public

crates/ptwm-core/src/transforms/source.rs:69
pub fn chain_dtype_for_public(dtype_code: u16) -> Option<u16>

Chain-internal Source dtype for a public dtype code (`Dtype` registry), mirroring `_CHAIN_DTYPE` in `python/ptwm/preprocessing/_chains.py`. `None` for codes without a chain dtype (for example `bool`).

rsfn

ptwm_core::transforms::source::element_width_for

crates/ptwm-core/src/transforms/source.rs:18
pub fn element_width_for(dtype_code: u16) -> ElementWidth

Element width inferred from a chain-internal dtype code. The chain's Source params use a different code space than `Dtype::from_code` (the public registry); see `_CHAIN_DTYPE` in `python/ptwm/preprocessing/_chains.py`. This is the one owner of the mapping: `compressor::source_descriptor_for` calls it rather than restating it.

rsfn

ptwm_core::transforms::source::is_nibble_packed_dtype

crates/ptwm-core/src/transforms/source.rs:39
pub fn is_nibble_packed_dtype(dtype_code: u16) -> bool

Whether a chain-internal dtype stores two values per byte.

Kept separate from element width on purpose: nibble width says how wide an element is, this says that elements share a byte. Codecs that read packed nibbles (`PerGroupCodebook`) require both, and transforms that cannot handle sharing (`BurrowsWheeler`, `IndexPack`) reject on this one.
rsconst

ptwm_core::transforms::source::MAX_SOURCE_DIMS

crates/ptwm-core/src/transforms/source.rs:125
pub const MAX_SOURCE_DIMS

Maximum number of dimensions the wire format supports. Encoded as a single `u8` length prefix in `write_params`.

rsfn

ptwm_core::transforms::source::read_source_params

crates/ptwm-core/src/transforms/source.rs:243
pub fn read_source_params(buf: &[u8]) -> Result<(Source, usize), PtwmCoreError>

Parse `Source` params from a raw byte buffer. Returns `(Source, bytes_consumed)`.

rstype

ptwm_core::transforms::source::Source

crates/ptwm-core/src/transforms/source.rs:118
pub struct Source

Mandatory entry node of every PPG chain. Takes no inputs (the runtime injects raw tensor bytes externally) and emits one `Role::Raw` plane whose descriptor follows from the tensor `shape` and `dtype_code`.

### forward / inverse semantics The runtime wires tensor bytes into the graph, so `forward` expects a **single synthetic input** carrying the raw tensor bytes (the runtime wraps them in a `Plane` before calling). It validates the descriptor and forwards the plane unchanged. `inverse` is symmetric: takes one plane, returns it unchanged.
rsfn

ptwm_core::transforms::source::storage_bytes

crates/ptwm-core/src/transforms/source.rs:53
pub fn storage_bytes(dtype_code: u16, n_elements: u64) -> Option<u64>

Storage bytes for `n_elements` of a chain-internal dtype.

A packed dtype's shape counts storage units, not values: one `Float4E2M1FNx2` element is one byte carrying two fp4 values, which is what `Dtype::element_size` reports and what a packed tensor's own shape counts. Element width describes the *value* width for such a dtype, so deriving the byte count from it would halve the length and leave the decompressor rebuilding every packed plane at half its size. Returns `None` when the byte count does not fit in `u64`.
rsfn

ptwm_core::transforms::source::storage_bytes_per_element

crates/ptwm-core/src/transforms/source.rs:59
pub fn storage_bytes_per_element(dtype_code: u16) -> u64

Storage bytes of one element of a chain-internal dtype. Packed FP4 is one byte per element (two values).