mixle.engines.jax_engine module¶
JAX implementation of the ComputeEngine protocol – XLA arrays, functional autograd, GPU/TPU.
JAX’s jax.numpy mirrors the NumPy API, so most ops alias straight through (no axis->``dim``
translation as Torch needs). Two JAX-isms are handled here:
float64 is opt-in. JAX defaults to float32; mixle accumulates in float64, so this module enables
jax_enable_x64at import (and the engine’saccumulator_dtypeis float64).arrays are immutable.
index_adduses the functionalarr.at[idx].add(...)update and returns the new array (return-value-only, like the Torch engine).
Autograd is functional in JAX (jax.grad / value_and_grad), not tensor-tagged, so
requires_grad() is always False even though supports_autograd is True. Like every non-host
engine it keeps resident_estep=True / supports_numba=False: scoring runs on JAX arrays, and the
E-step round-trips through host NumPy unless an engine-resident kernel is registered.
- class JaxEngine(device=None, dtype=None, compile=False)[source]
Bases:
ComputeEngineJAX array engine: XLA-compiled ops, float64, optional
jax.jitcompilation, GPU/TPU via JAX.- name = 'jax'
- supports_autograd = True
- property accumulator_dtype: Any
High-precision dtype for sufficient-statistic reductions (always float64).
- with_precision(precision)[source]
Return a JAX engine with the same placement and a new dtype policy.
- Parameters:
precision (Any)
- Return type:
JaxEngine
- asarray(x, dtype=None)[source]
Convert
xto a JAX array. Float inputs are force-cast to the engine dtype (float64 by default) unlessdtypeis given – matching the Torch engine’s contract, not NumPy’s.
- zeros(shape, dtype=None)[source]
Allocate a zero array with this engine’s dtype.
- empty(shape, dtype=None)[source]
Allocate an array (JAX has no uninitialized
empty; zeros is the safe equivalent).
- arange(*args, **kwargs)[source]
Return
jnp.arange; float arguments select the engine float dtype.
- to_numpy(x)[source]
Move a JAX array back to a host NumPy array.
- stack(arrays, axis=0)[source]
Stack arrays with
jnp.stack.
- requires_grad(x)[source]
Always False: JAX autograd is functional (
jax.grad), not tensor-tagged.
- compile(fn)[source]
Compile
fnwithjax.jitwhen enabled.
- static log(x)
- static exp(x)
- static sqrt(x)
- static abs(x)
- static where(*args)
- static maximum(x, y)
- static clip(x, a_min=None, a_max=None)
- static floor(x)
- static isnan(x)
- static isinf(x)
- static sum(x, *args, **kwargs)
- static max(x, *args, **kwargs)
- static dot(x, y)
- static matmul(x, y)
- static cumsum(x, *args, **kwargs)
- static logsumexp(x, *args, **kwargs)
- static bincount(x, *args, **kwargs)
- static unique(x, *args, **kwargs)
- static searchsorted(x, y, *args, **kwargs)
- static gammaln(x)
- static digamma(x)
- static betaln(x, y)
- static erf(x)
- static cos(x)
- static sin(x)
- static arctan2(x, y)
- static i0e(x)
- index_add(out, index, values)[source]
Add
valuesintooutalong axis 0 via the functional.at[idx].addupdate.Contract: return-value-only – JAX arrays are immutable, so this returns a new array; callers must use the return value (the same contract the Torch engine documents).