httk.core.vectors.vector_numpy_backend

Backend wrapping a numpy ndarray (numpy is an optional dependency, imported lazily).

Classes

VectorNumpyBackend

Backend for a vector backed by a numpy.ndarray.

Module Contents

class httk.core.vectors.vector_numpy_backend.VectorNumpyBackend(obj, **hints)[source]

Bases: httk.core.vectors.vector_backend.VectorBackend

Backend for a vector backed by a numpy.ndarray.

numpy is an optional dependency (httk-core[numpy]) and is imported lazily; if numpy is not installed, this backend’s _backend_adopt returns None so it is simply never selected.

numpy float64 values are themselves binary rationals, so the fractions interchange is produced exactly from the array (each float becomes its exact rational value). Only the reverse direction (building a numpy view) is lossy. unwrap returns the wrapped array.

Parameters:
  • obj (Any) – The source data to wrap.

  • **hints (Any) – Optional backend-selection hints.

property fractions: httk.core.vectors.vector_api.Fractions[source]

Return the array in the exact Fraction interchange format.

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

Return the array shape.

to_floats()[source]

Return floats through a numpy fast path for real numeric dtypes.

Other dtypes fall back to to_floats() so the exact hub conversion and its error semantics are preserved.

Returns:

The rendered value.

Return type:

Any

to_float()[source]

Return a scalar float through numpy for real numeric 0-D arrays.

Non-scalar arrays raise the same TypeError as the hub implementation. Other scalar dtypes fall back to to_float() for its exact conversion and error semantics.

Returns:

The rendered scalar value.

Raises:

TypeError – If the value is not scalar.

Return type:

float

unwrap()[source]

Return the wrapped numpy array.