httk.core.vectors.vector_api

The minimal canonical vector interface shared by all vector backends and views.

Attributes

Classes

VectorAPI

Abstract base class for the canonical vector interface.

Module Contents

type httk.core.vectors.vector_api.Fractions = fractions.Fraction | tuple[Fractions, ...]
class httk.core.vectors.vector_api.VectorAPI[source]

Bases: abc.ABC

Abstract base class for the canonical vector interface.

It declares the fractions accessor (a nested tuple of fractions.Fraction, or a bare Fraction for a scalar) that every vector backend produces from its own native representation and every vector view builds its presentation from, together with the dim shape tuple. The interchange is exact when fractions_exact is True; members such as irrational surds whose hub is a deterministic approximation report False, and exact construction paths refuse them. This is the single interchange format; there is no pairwise conversion between backends.

On top of the two abstract accessors it provides the guaranteed float renderings to_floats() and to_float(), derived from the fractions hub — so whatever object the family hands you, .to_floats() works. (The exact value types FracVector and SurdVector honor the same contract with their own implementations, while the numpy backend adds a dtype-guarded fast path with the hub as fallback. Surd values render floats at fixed high precision independent of the decimal context, unlike the hub’s context-precision reduction.

property fractions: Fractions
Abstractmethod:

Return the Fraction interchange representation.

property fractions_exact: bool

Return whether fractions reproduces this value exactly.

Members whose Fraction interchange may be a deterministic approximation override this property with False; exact construction paths must refuse those members.

property dim: tuple[int, ...]
Abstractmethod:

Return the tensor shape as a tuple of dimensions.

to_floats()[source]

Return the value as nested lists of floats.

The value as (possibly nested) plain lists of float — a bare float for a scalar.

Derived from the fractions hub; when fractions_exact is False, the result is the member’s deterministic approximation. Nested lists match the numpy.ndarray.tolist() convention and are directly JSON-serializable.

Returns:

The rendered value.

Return type:

Any

to_float()[source]

Return the scalar value as a plain float.

Raises TypeError on a non-scalar.

Returns:

The rendered scalar value.

Raises:

TypeError – If the value is not scalar.

Return type:

float