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¶
|
Return whether the optional numpy dependency is available for the numeric helpers. |
|
Convert a single scalar value to a plain |
|
Present |
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_availableflag freshly on each call (the flag set whenhttk.core.vectorsconditionally imports/registers the numpy backend), so tests may monkeypatchhttk.core.vectors._numpy_availableto 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 scalarSurdVector) and a scalarFracVectorrender through their own exactto_float(); aFraction,int,float, or numericstrrender viaany_to_fraction(). A non-scalar shape raisesTypeError.Unlike
to_numeric(), this needs no numpy: a plainfloatconversion 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
objas plain numpy numbers: anumpy.ndarrayfor a tensor, afloatfor a scalar.A tensor becomes a base-class
float64numpy.ndarray(never a view subclass) viaVectorNumpyView; a scalar input (shape()) returns a plainfloatviato_numeric_scalar()(never a 0-d array).The numeric presentation is numpy-backed, so this always requires numpy: it raises
ImportError(naming thehttk-core[numpy]extra) when numpy is not installed, uniformly, so the contract is predictable regardless of the input shape. Useto_numeric_scalar()directly for a single float without a numpy requirement.