citylearn.internal.scalars module
Scalar helpers for per-step hot paths.
- citylearn.internal.scalars.as_float(value: Any) Any[source]
Return a Python float for a NumPy floating scalar or 0-d array; anything else unchanged.
NumPy 1 evaluated
float32_scalar <op> python_floatin float64; NumPy 2 (NEP 50) keeps it in float32. Reading float32 storage through this helper keeps such arithmetic in float64 under both, so results do not depend on the installed NumPy version.
- citylearn.internal.scalars.clip_scalar(value: float, low: float | None = None, high: float | None = None) float[source]
Return
float(np.clip(value, low, high))for a single value without NumPy call overhead.Follows NumPy’s
min(max(x, low), high)order, so NaN propagates and-0.0clipped atlow=0.0becomes0.0exactly asnp.clipdoes.
- citylearn.internal.scalars.numpy1_scalar(value: Any) Any[source]
Return a Python int or float as
np.float64; anything else unchanged.NumPy 1 promoted
float32_scalar <op> python_numberto float64, but kept arithmetic between two float32 scalars in float32. NumPy 2 (NEP 50) treats the Python number as weak and stays in float32. Wrapping only the Python operand reproduces NumPy 1 under both versions without changing arithmetic between two NumPy scalars.