httk.core.vectors.leaf_codecs¶
Leaf codecs: the element-domain axis of the Vector family.
The Vector backends model the container axis (frac/native/numpy); a leaf codec
models the orthogonal element-domain axis — how a single leaf value is presented (as an int,
a fractions.Fraction, a float, a decimal.Decimal, …). Every codec converts
FROM the canonical Fraction hub (a backend’s exact fractions interchange), so it is independent
of which backend holds the data.
Conversion policy (mirroring the CellParams lossiness philosophy): because a backend always retains
the exact original, a view that cannot represent the data exactly is still produced without raising
— each codec applies a documented default conversion, with options to choose alternatives. Only
configuration errors — an unknown codec name or invalid options — raise ValueError.
This registry mirrors the compression-codec registry in
httk.core.datastream.compression: a frozen LeafCodec dataclass plus
register_leaf_codec()/known_leaf_codecs() for extension.
Classes¶
A leaf codec: a documented conversion of one exact |
Functions¶
|
Register or replace a codec under its |
Return the registered leaf-codec names in registration order. |
|
|
Return the registered codec named |
|
Resolve and validate a leaf codec eagerly and return it. |
|
Map |
Module Contents¶
- class httk.core.vectors.leaf_codecs.LeafCodec¶
A leaf codec: a documented conversion of one exact
fractions.Fractionleaf into a presentation leaf.A codec is an orthogonal layer beside the vector backends: given a value already reduced to the canonical Fraction hub, it produces the requested element type. Its
from_fractiondocuments both its exactness contract (when the result is exact) and its default conversion (what it does when an exact result is impossible); on data it never raises.- Parameters:
name – The canonical name used to select the codec.
from_fraction – The conversion operation applied to each exact hub leaf.
check_options – The option-validation operation.
- from_fraction: collections.abc.Callable[Ellipsis, Any]¶
Convert
(value: fractions.Fraction, **options) -> leaffrom the canonical Fraction hub.
- check_options: collections.abc.Callable[[dict[str, Any]], None]¶
Validate an options mapping eagerly, raising
ValueErroron any invalid option.
- httk.core.vectors.leaf_codecs.register_leaf_codec(codec)¶
Register or replace a codec under its
name.- Parameters:
codec (LeafCodec) – The codec to register.
- httk.core.vectors.leaf_codecs.known_leaf_codecs()¶
Return the registered leaf-codec names in registration order.
- httk.core.vectors.leaf_codecs.leaf_codec_for_name(name)¶
Return the registered codec named
name.- Parameters:
name (str) – The codec name to resolve.
- Returns:
The registered codec.
- Raises:
ValueError – If
nameis not registered.- Return type:
- httk.core.vectors.leaf_codecs.validate_leaf_codec(name, options)¶
Resolve and validate a leaf codec eagerly and return it.
Raises
ValueErrorifnameis not a registered codec or ifoptionsare invalid for it (the two configuration-error cases). This is called where aleaf=hint is received so that mistakes surface at view construction, never mid-conversion.- Parameters:
- Returns:
The resolved and validated codec.
- Raises:
ValueError – If the codec name or options are invalid.
- Return type:
- httk.core.vectors.leaf_codecs.apply_leaf_codec(codec, node, **options)¶
Map
codecover a (possibly nested) tuple offractions.Fraction, returning the converted nested structure (a bare leaf for a scalarnode).- Parameters:
codec (LeafCodec) – The codec to apply.
node (Any) – The scalar or nested exact data to convert.
**options (Any) – Options passed to the codec for each leaf.
- Returns:
The converted scalar or nested structure.
- Return type:
Any