httk.core.vectors.numeric

The numeric presentation of vectors: plain numpy numbers for callers who just want floats.

Where the backend/view family (see httk.core.vectors.vector_view) lets the same tensor be seen as the exact FracVector, an exact SurdVector, a nested tuple, or a numpy.ndarray, the numeric concept is a convenience presentation one level above that: it is for users who do not care which representation carries the numbers and simply want plain numpy floats to compute with.

The numeric presentation is numpy-backed, so a caller always knows the concrete type it gets: to_numeric() returns a base-class float64 numpy.ndarray for a tensor and a plain float for a scalar — never a view subclass, never a 0-d array. NumericVector is the generic name for what comes out.

numpy is an optional dependency of httk-core (the httk-core[numpy] extra). to_numeric() therefore requires numpy and raises ImportError when it is not installed. The scalar helper to_numeric_scalar() is the exception: converting a single value to a float needs no numpy, so it works unconditionally and never raises for a missing numpy.

Use the numeric helpers when you just want numpy numbers; reach for a specific view (VectorNumpyView, VectorNativeView) when you need control over the exact container type, dtype, or leaf codec.

Attributes

Functions

numpy_available(→ bool)

Return whether the optional numpy dependency is available for the numeric helpers.

to_numeric_scalar(→ float)

Convert a single scalar value to a plain float, deterministically.

to_numeric(→ NumericVector)

Present obj as plain numpy numbers: a numpy.ndarray for a tensor, a float for a

Module Contents

type httk.core.vectors.numeric.NumericVector = float | numpy.ndarray[source]
httk.core.vectors.numeric.numpy_available() bool[source]

Return whether the optional numpy dependency is available for the numeric helpers.

This reads the vectors package’s _numpy_available flag freshly on each call (the flag set when httk.core.vectors conditionally imports/registers the numpy backend), so tests may monkeypatch httk.core.vectors._numpy_available to exercise the numpy-absent path.

httk.core.vectors.numeric.to_numeric_scalar(obj: Any) float[source]

Convert a single scalar value to a plain float, deterministically.

A SurdScalar (or scalar SurdVector) and a scalar FracVector render through their own exact to_float(); a Fraction, int, float, or numeric str render via any_to_fraction(). A non-scalar shape raises TypeError.

Unlike to_numeric(), this needs no numpy: a plain float conversion has no numpy dependency, so it works unconditionally and never raises for a missing numpy.

httk.core.vectors.numeric.to_numeric(obj: httk.core.vectors.vector_like.VectorLike) NumericVector[source]

Present obj as plain numpy numbers: a numpy.ndarray for a tensor, a float for a scalar.

A tensor becomes a base-class float64 numpy.ndarray (never a view subclass) via VectorNumpyView; a scalar input (shape ()) returns a plain float via to_numeric_scalar() (never a 0-d array).

The numeric presentation is numpy-backed, so this always requires numpy: it raises ImportError (naming the httk-core[numpy] extra) when numpy is not installed, uniformly, so the contract is predictable regardless of the input shape. Use to_numeric_scalar() directly for a single float without a numpy requirement.