mixle.engines.base module¶
Compute-engine protocol and active-engine context management.
The protocol defines the array operations that backend-neutral scoring and estimation kernels may rely on, while the context helper lets nested M-step code discover the engine driving the current estimation pass.
- active_engine()[source]
Return the compute engine driving the current EM step, or
Noneoutside one.- Return type:
ComputeEngine | None
- using_active_engine(engine)[source]
Mark
engineactive for the duration of the block (used by the estimation loop).- Parameters:
engine (Any)
- class ComputeEngine[source]
Bases:
ABCSmall array-backend interface for numpy/torch/etc.
Engines own arithmetic policy: array library, device, dtype, and optional compilation. Distribution and kernel code should depend only on this surface when it wants backend-neutral arrays.
- constant(value)[source]
Return
valuein this engine’s scalar representation (identity for numeric engines).
- property accumulator_dtype: Any
High-precision dtype for sufficient-statistic reductions, or
Nonewhen not applicable.Numeric engines override this with their float64 accumulator so a reduced-precision fit does not drift on large N (see
NumpyEngine/TorchEngine). The base returnsNone: meaning “no separate accumulator dtype”, which is the correct policy for engines that never drive the numeric accumulate path (e.g. the symbolic engine, where reductions are exact expression trees).Noneis also a validdtype=argument tosum(NumPy’s default).
- property precision: str
Return the engine dtype policy as a stable user-facing name.
- with_precision(precision)[source]
Return an equivalent engine with a different floating-point policy.
- Parameters:
precision (Any)
- Return type:
ComputeEngine
- abstractmethod asarray(x, dtype=None)[source]
Convert
xinto this engine’s array/tensor representation.
- abstractmethod zeros(shape, dtype=None)[source]
Allocate a zero-filled array on this engine.
- abstractmethod empty(shape, dtype=None)[source]
Allocate an uninitialized array on this engine.
- abstractmethod arange(*args, **kwargs)[source]
Return an evenly spaced one-dimensional array on this engine.
- abstractmethod to_numpy(x)[source]
Move an engine array back to a NumPy/host representation.
- abstractmethod stack(arrays, axis=0)[source]
Stack a sequence of arrays along
axis.
- requires_grad(x)[source]
Return whether
xparticipates in this engine’s autograd graph.
- compile(fn)[source]
Optionally compile
fn; engines without a compiler return it unchanged.
- replicate(x)[source]
Return
xin the engine’s replicated placement, when applicable.