omnibias.keras.activations.registry
Keras 3 operator layers and activation paths implemented with keras.ops for TensorFlow, JAX, or Torch.
import omnibias.keras.activations.registryModule contract & mathematical conventions
Activation registry (Keras backend): ActivationSpec and lookup.
The ActivationSpec dataclass is defined generically in
omnibias.core.spec; this module re-exports it and maintains a
process-wide registry so get_activation can resolve string names
like "tanh" to their full spec. The kernels stored in each spec are
written against keras.ops so they run on any Keras backend.
Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.
Imports & aliases
These names share a definition with another public module. Follow a name for its full contract, parameters, and examples.
| Import from this module | Canonical reference |
|---|---|
ActivationSpec | omnibias.core.ActivationSpec |
get_activation
omnibias.keras.get_activationSource ↗get_activation(name: str | ActivationSpec[Any]) -> ActivationSpec[Any]Resolve a name (or pass-through spec) to an ActivationSpec.
Parameters
| Name | Type & default | Contract |
|---|---|---|
namepositional-or-keyword | str | ActivationSpec[Any]Required | See the operation contract and implementation below. |
ActivationSpec[Any]Explicit validation & failure cases
- When
not isinstance(name, str), raisesTypeError(f'Expected str or ActivationSpec, got {type(name).__name__}: {name!r}'). - When
key not in _REGISTRY, raisesKeyError(f'Unknown activation {name!r}. Known: {known}.').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · tempered rejects bad scale
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_tempered_rejects_bad_scale() -> None:
with pytest.raises(ValueError):
TemperedActivation("softplus", beta=1.0, scale="bogus")python -m pytest "packages/omnibias-keras/tests/test_tempered_blocks.py::test_tempered_rejects_bad_scale" -qRegression example · fastpath negative order raises
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_fastpath_negative_order_raises() -> None:
z = ops.convert_to_tensor(np.zeros(3))
with pytest.raises(ValueError):
get_activation("tanh").fastpath(z, -1)python -m pytest packages/omnibias-keras/tests/test_activations.py -k test_fastpath_negative_order_raises -qRead the implementation
def get_activation(name: str | ActivationSpec[Any]) -> ActivationSpec[Any]:
"""Resolve a name (or pass-through spec) to an :class:`ActivationSpec`."""
if isinstance(name, ActivationSpec):
return name
if not isinstance(name, str):
raise TypeError(
f"Expected str or ActivationSpec, got {type(name).__name__}: {name!r}"
)
key = name.lower()
if key not in _REGISTRY:
known = ", ".join(sorted(set(_REGISTRY.keys())))
raise KeyError(f"Unknown activation {name!r}. Known: {known}.")
return _REGISTRY[key]Other public import paths
omnibias.keras.get_activationomnibias.keras.activations.get_activationomnibias.keras.activations.registry.get_activation
is_registered
omnibias.keras.is_registeredSource ↗is_registered(name: str) -> boolTrue if name (or one of its aliases) is in the registry.
Parameters
| Name | Type & default | Contract |
|---|---|---|
namepositional-or-keyword | strRequired | See the operation contract and implementation below. |
boolRead the implementation
def is_registered(name: str) -> bool:
"""True if ``name`` (or one of its aliases) is in the registry."""
return isinstance(name, str) and name.lower() in _REGISTRYOther public import paths
omnibias.keras.is_registeredomnibias.keras.activations.is_registeredomnibias.keras.activations.registry.is_registered
list_activations
omnibias.keras.list_activationsSource ↗list_activations() -> list[str]Return the canonical (non-alias) activation names, sorted.
list[str]Executed regression · all piecewise registered
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_all_piecewise_registered() -> None:
registered = set(list_activations())
for name in _PIECEWISE_NAMES:
assert name in registered, f"{name!r} not registered"python -m pytest "packages/omnibias-keras/tests/test_piecewise.py::test_all_piecewise_registered" -qRegression example · all expected activations registered
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_all_expected_activations_registered() -> None:
registered = set(list_activations())
for name in _NAMES:
assert name in registered, f"{name!r} not registered"python -m pytest packages/omnibias-keras/tests/test_activations.py -k test_all_expected_activations_registered -qRead the implementation
def list_activations() -> list[str]:
"""Return the canonical (non-alias) activation names, sorted."""
return sorted({spec.name for spec in _REGISTRY.values()})Other public import paths
omnibias.keras.list_activationsomnibias.keras.activations.list_activationsomnibias.keras.activations.registry.list_activations
register_activation
omnibias.keras.register_activationSource ↗register_activation(spec: ActivationSpec[Any]) -> ActivationSpec[Any]Register an ActivationSpec under its name and aliases.
Parameters
| Name | Type & default | Contract |
|---|---|---|
specpositional-or-keyword | ActivationSpec[Any]Required | See the operation contract and implementation below. |
ActivationSpec[Any]Explicit validation & failure cases
- When
not spec.name, raisesValueError('ActivationSpec.name must be a non-empty string.'). - When
name in _REGISTRY and _REGISTRY[name] is not spec, raisesValueError(f'Activation {name!r} is already registered with a different spec.'). - When
akey in _REGISTRY and _REGISTRY[akey] is not spec, raisesValueError(f'Alias {alias!r} for activation {name!r} clashes with an existing entry.').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Read the implementation
def register_activation(spec: ActivationSpec[Any]) -> ActivationSpec[Any]:
"""Register an :class:`ActivationSpec` under its name and aliases."""
if not spec.name:
raise ValueError("ActivationSpec.name must be a non-empty string.")
name = spec.name.lower()
if name in _REGISTRY and _REGISTRY[name] is not spec:
raise ValueError(
f"Activation {name!r} is already registered with a different spec."
)
_REGISTRY[name] = spec
for alias in spec.aliases:
akey = alias.lower()
if akey in _REGISTRY and _REGISTRY[akey] is not spec:
raise ValueError(
f"Alias {alias!r} for activation {name!r} clashes with an existing entry."
)
_REGISTRY[akey] = spec
return specOther public import paths
omnibias.keras.register_activationomnibias.keras.activations.register_activationomnibias.keras.activations.registry.register_activation