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[source]¶
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.- from_fraction: collections.abc.Callable[Ellipsis, Any][source]¶
Convert
(value: fractions.Fraction, **options) -> leaffrom the canonical Fraction hub.
- check_options: collections.abc.Callable[[dict[str, Any]], None][source]¶
Validate an options mapping eagerly, raising
ValueErroron any invalid option.
- httk.core.vectors.leaf_codecs.register_leaf_codec(codec: LeafCodec) None[source]¶
Register (or replace) a codec under its
name.
- httk.core.vectors.leaf_codecs.known_leaf_codecs() list[str][source]¶
Return the registered leaf-codec names, in registration order.
- httk.core.vectors.leaf_codecs.leaf_codec_for_name(name: str) LeafCodec[source]¶
Return the registered codec named
name, or raiseValueErrorlisting the known codecs.
- httk.core.vectors.leaf_codecs.validate_leaf_codec(name: str, options: dict[str, Any]) LeafCodec[source]¶
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.
- httk.core.vectors.leaf_codecs.apply_leaf_codec(codec: LeafCodec, node: Any, **options: Any) Any[source]¶
Map
codecover a (possibly nested) tuple offractions.Fraction, returning the converted nested structure (a bare leaf for a scalarnode).