httk.core.vectors.vector_api¶
The minimal canonical vector interface shared by all vector backends and views.
Attributes¶
Classes¶
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.ABCAbstract base class for the canonical vector interface.
It declares the
fractionsaccessor (a nested tuple offractions.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 thedimshape tuple. The interchange is exact whenfractions_exactis 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()andto_float(), derived from thefractionshub — so whatever object the family hands you,.to_floats()works. (The exact value typesFracVectorandSurdVectorhonor 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_exact: bool¶
Return whether
fractionsreproduces this value exactly.Members whose Fraction interchange may be a deterministic approximation override this property with
False; exact construction paths must refuse those members.
- to_floats()[source]¶
Return the value as nested lists of floats.
The value as (possibly nested) plain lists of
float— a barefloatfor a scalar.Derived from the
fractionshub; whenfractions_exactis False, the result is the member’s deterministic approximation. Nested lists match thenumpy.ndarray.tolist()convention and are directly JSON-serializable.- Returns:
The rendered value.
- Return type:
Any