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_float in 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.0 clipped at low=0.0 becomes 0.0 exactly as np.clip does.

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_number to 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.