omnibias.torch.activations.registry
PyTorch activation derivatives, trainable operator layers, network jets, and direct differential-operator contractions.
import omnibias.torch.activations.registryModule contract & mathematical conventions
Activation registry (PyTorch backend): ActivationSpec and global lookup.
The ActivationSpec dataclass itself is defined generically in
omnibias.core.spec; this module specialises it to torch.Tensor
and maintains a process-wide registry so get_activation can resolve
string names like "sigmoid" to their full spec at construction time.
The activation modules (smooth, proximal, classical,
trigonometric, nqs) are imported by
omnibias.torch.activations.__init__ for side-effect registration.
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 |
IntegralFn
omnibias.torch.activations.registry.IntegralFnSource ↗IntegralFn = Callable[[Tensor], Tensor]This exported constant is defined by the expression above. Its exact value and annotation come from the pinned source; use it with the module contract.
Read the implementation
IntegralFn = Callable[[Tensor], Tensor]NthDerivativeFn
omnibias.torch.activations.registry.NthDerivativeFnSource ↗NthDerivativeFn = Callable[[Tensor, int], Tensor]This exported constant is defined by the expression above. Its exact value and annotation come from the pinned source; use it with the module contract.
Read the implementation
NthDerivativeFn = Callable[[Tensor, int], Tensor]TensorFn
omnibias.torch.activations.registry.TensorFnSource ↗TensorFn = Callable[[Tensor], Tensor]Public alias so callers do not need to import torch.Tensor directly
when only the type signature matters.
Read the implementation
TensorFn = Callable[[Tensor], Tensor]TorchActivationSpec
omnibias.torch.activations.registry.TorchActivationSpecSource ↗TorchActivationSpec: TypeAlias = ActivationSpec[Tensor]Type alias documenting that the torch backend pins TensorT to
class:torch.Tensor. Equivalent to ActivationSpec[torch.Tensor].
Read the implementation
TorchActivationSpec: TypeAlias = ActivationSpec[Tensor]get_activation
omnibias.torch.get_activationSource ↗get_activation(name: str | ActivationSpec[Tensor]) -> ActivationSpec[Tensor]Resolve a name (or pass-through spec) to an ActivationSpec.
Resolve a registered activation name or pass through an existing ActivationSpec. Use the returned specification to inspect whether a derivative or other specialized path is available before invoking it. A non-None fastpath does not remove the individual activation’s order and numerical-domain restrictions. The first-derivative example compares tanh against an independent analytic identity.
Parameters
| Name | Type & default | Contract |
|---|---|---|
namepositional-or-keyword | str | ActivationSpec[Tensor]Required | Registered name or alias, or an existing ActivationSpec object. Unknown strings fail lookup rather than silently choosing a default activation. |
ActivationSpec[Tensor]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.
Complete runnable example · first derivative
This is the complete downloadable script, tested against the pinned installed distribution. It includes initialization and assertions.
import torch
from omnibias.torch import get_activation
x = torch.linspace(-2, 2, 9, dtype=torch.float64)
spec = get_activation("tanh")
first = spec.fastpath(x, 1)
expected = 1 - torch.tanh(x).square()
torch.testing.assert_close(first, expected)
print(first.shape) # torch.Size([9])python first_derivative.pyExecuted regression · heaviside alias resolves
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_heaviside_alias_resolves() -> None:
assert get_activation("heaviside").name == "step"python -m pytest "packages/omnibias-torch/tests/test_piecewise.py::test_heaviside_alias_resolves" -qRead the implementation
def get_activation(name: str | ActivationSpec[Tensor]) -> ActivationSpec[Tensor]:
"""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.torch.get_activationomnibias.torch.activations.get_activationomnibias.torch.activations.registry.get_activation
is_registered
omnibias.torch.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.torch.is_registeredomnibias.torch.activations.is_registeredomnibias.torch.activations.registry.is_registered
list_activations
omnibias.torch.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-torch/tests/test_piecewise.py::test_all_piecewise_registered" -qRegression example · keras registers same activations
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_keras_registers_same_activations() -> None:
from omnibias.torch.activations.registry import list_activations as torch_list
assert sorted(keras_list()) == sorted(torch_list())python -m pytest tests/test_keras_parity.py -k test_keras_registers_same_activations -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.torch.list_activationsomnibias.torch.activations.list_activationsomnibias.torch.activations.registry.list_activations
register_activation
omnibias.torch.register_activationSource ↗register_activation(spec: ActivationSpec[Tensor]) -> ActivationSpec[Tensor]Register an ActivationSpec under its name and aliases.
Returns the spec unchanged so this can be used as a decorator-style expression.
Parameters
| Name | Type & default | Contract |
|---|---|---|
specpositional-or-keyword | ActivationSpec[Tensor]Required | See the operation contract and implementation below. |
ActivationSpec[Tensor]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[Tensor]) -> ActivationSpec[Tensor]:
"""Register an :class:`ActivationSpec` under its name and aliases.
Returns the spec unchanged so this can be used as a decorator-style
expression.
"""
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.torch.register_activationomnibias.torch.activations.register_activationomnibias.torch.activations.registry.register_activation