mixle.engines.arithmetic module

Backend-dispatched arithmetic helpers used by mixle classes.

Array operations dispatch on their arguments’ engine (engine_of); scalar constants have no arguments to dispatch on, so they resolve from the active engine instead – NUMPY_ENGINE by default (plain floats, the historical behaviour). Select a different one to make the constants come from it, e.g. the symbolic engine, so that pi stays a symbolic pi and half an exact 1/2 instead of collapsing to floats during exact arithmetic:

import mixle.engines.arithmetic as arith
with arith.using_engine("symbolic"):
    arith.pi      # SymbolicExpression "pi", not 3.141592...

This is the extension point for letting users control the arithmetic backend without switching mixle to a full computer-algebra system. maxint / maxrandint / eps are implementation limits and tolerances (not mathematical constants), so they stay engine-independent.

asarray(*args, **kwargs)
zeros(*args, **kwargs)
empty(*args, **kwargs)
arange(*args, **kwargs)
to_numpy(*args, **kwargs)
log(*args, **kwargs)
exp(*args, **kwargs)
sqrt(*args, **kwargs)
abs(*args, **kwargs)
where(*args, **kwargs)
maximum(*args, **kwargs)
clip(*args, **kwargs)
floor(*args, **kwargs)
isnan(*args, **kwargs)
isinf(*args, **kwargs)
dot(*args, **kwargs)
matmul(*args, **kwargs)
cumsum(*args, **kwargs)
logsumexp(*args, **kwargs)
stack(*args, **kwargs)
bincount(*args, **kwargs)
index_add(*args, **kwargs)
unique(*args, **kwargs)
searchsorted(*args, **kwargs)
gammaln(*args, **kwargs)
digamma(*args, **kwargs)
betaln(*args, **kwargs)
erf(*args, **kwargs)
constant(value)[source]

Wrap value in the active engine’s scalar representation (identity for numeric engines).

Parameters:

value (Any)

Return type:

Any

get_default_engine()[source]

Return the engine that supplies scalar constants and the operation-dispatch default.

Return type:

ComputeEngine

set_default_engine(engine)[source]

Set the active engine (a ComputeEngine or "numpy"/"symbolic"); return the previous one.

Parameters:

engine (ComputeEngine | str)

Return type:

ComputeEngine

using_engine(engine)[source]

Context manager that makes engine the active engine for its block, then restores the previous one.

Parameters:

engine (ComputeEngine | str)