mixle.engines.precision module

Floating-point precision helpers for compute engines.

precision_name(precision)[source]

Return a readable canonical precision name.

Parameters:

precision (Any)

Return type:

str

normalize_numpy_dtype(precision)[source]

Normalize a precision specifier to a NumPy floating dtype.

Parameters:

precision (Any)

Return type:

dtype | None

normalize_torch_dtype(precision, torch_module)[source]

Normalize a precision specifier to a Torch floating dtype.

Parameters:
  • precision (Any)

  • torch_module (Any)

Return type:

Any

engine_with_precision(engine, precision)[source]

Return engine adjusted to the requested floating precision.

Parameters:
  • engine (Any)

  • precision (Any)

Return type:

Any

auto_precision(data=None, *, engine=None, sample_size=512)[source]

Recommend 'float32' or 'float64' from the data and the target hardware.

float32 only helps on a GPU Torch engine (on CPU/NumPy it is a no-op or slower), and even there only when the data is well conditioned for single precision. Sufficient-statistic accumulation is already float64-safe (see ComputeEngine.accumulator_dtype), so this guards the remaining risk – the ~7 significant digits of float32 scoring – by inspecting the data’s magnitude and dynamic range. Returns 'float64' whenever a numeric sample is unavailable or looks risky.

Parameters:
  • data (Any) – A representative sample of the raw observations (or an iterable of them).

  • engine (Any) – The target compute engine; float32 is only recommended for a GPU Torch engine.

  • sample_size (int) – How many leading observations to inspect.

Returns:

'float32' or 'float64'.

Return type:

str