omnibias.keras.blocks.linear
Keras 3 operator layers and activation paths implemented with keras.ops for TensorFlow, JAX, or Torch.
import omnibias.keras.blocks.linearModule contract & mathematical conventions
Operator-typed dense layer: cmbDense.
A drop-in for keras.layers.Dense followed by an
OperatorBlock on the output features. Mirrors
omnibias.torch.blocks.linear.cmbLinear.
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.
cmbDense
omnibias.keras.cmbDenseSource ↗class cmbDense(layers.Layer)keras.layers.Dense + per-feature OperatorBlock.
Parameters
units : int Number of output features.
op : OpName, default "identity"
base : str or ActivationSpec, default "sigmoid"
use_bias : bool, default True Dense-layer bias (independent of the OMBU bias terms).
block_kwargs : dict, optional Extra keyword arguments passed to OperatorBlock.
Parameters
| Name | Type & default | Contract |
|---|---|---|
unitspositional-or-keyword | intRequired | int Number of output features. |
oppositional-or-keyword | OpNameDefault: 'identity' | OpName, default "identity" |
basepositional-or-keyword | str | ActivationSpec[Any]Default: 'sigmoid' | str or ActivationSpec, default "sigmoid" |
use_biaspositional-or-keyword | boolDefault: True | bool, default True Dense-layer bias (independent of the OMBU bias terms). |
block_kwargspositional-or-keyword | dict[str, Any] | NoneDefault: None | dict, optional Extra keyword arguments passed to OperatorBlock. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Executed regression · cmbdense shape and finite
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_cmbdense_shape_and_finite() -> None:
x = np.random.default_rng(5).normal(size=(8, 6))
layer = cmbDense(units=16, op="identity", base="tanh")
out = _np(layer(_t(x)))
assert out.shape == (8, 16)
assert np.all(np.isfinite(out))python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbdense_shape_and_finite" -qFields & methods
__init__method
__init__(self, units: int, op: OpName='identity', base: str | ActivationSpec[Any]='sigmoid', use_bias: bool=True, block_kwargs: dict[str, Any] | None=None, **kwargs: Any) -> NoneSee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
unitspositional-or-keyword | intRequired | See the operation contract and implementation below. |
oppositional-or-keyword | OpNameDefault: 'identity' | See the operation contract and implementation below. |
basepositional-or-keyword | str | ActivationSpec[Any]Default: 'sigmoid' | See the operation contract and implementation below. |
use_biaspositional-or-keyword | boolDefault: True | See the operation contract and implementation below. |
block_kwargspositional-or-keyword | dict[str, Any] | NoneDefault: None | See the operation contract and implementation below. |
kwargsvariadic keyword | AnyRequired | See the operation contract and implementation below. |
Returns: None
Executed regression · cmbdense shape and finite
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_cmbdense_shape_and_finite() -> None:
x = np.random.default_rng(5).normal(size=(8, 6))
layer = cmbDense(units=16, op="identity", base="tanh")
out = _np(layer(_t(x)))
assert out.shape == (8, 16)
assert np.all(np.isfinite(out))python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbdense_shape_and_finite" -qMethod implementation
def __init__(
self,
units: int,
op: OpName = "identity",
base: str | ActivationSpec[Any] = "sigmoid",
use_bias: bool = True,
block_kwargs: dict[str, Any] | None = None,
**kwargs: Any,
) -> None:
super().__init__(**kwargs)
self.units = units
self._op = op
self._base_name = base if isinstance(base, str) else base.name
self._use_bias = use_bias
self._block_kwargs = block_kwargs or {}
self.dense = layers.Dense(units, use_bias=use_bias)
self.block = OperatorBlock(
op=op, base=base, channels=units, **self._block_kwargs
)callmethod
call(self, x: Any) -> AnySee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | AnyRequired | See the operation contract and implementation below. |
Returns: Any
Executed regression · cmbdense shape and finite
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_cmbdense_shape_and_finite() -> None:
x = np.random.default_rng(5).normal(size=(8, 6))
layer = cmbDense(units=16, op="identity", base="tanh")
out = _np(layer(_t(x)))
assert out.shape == (8, 16)
assert np.all(np.isfinite(out))python -m pytest "packages/omnibias-keras/tests/test_blocks.py::test_cmbdense_shape_and_finite" -qMethod implementation
def call(self, x: Any) -> Any:
return self.block(self.dense(x))get_configmethod
get_config(self) -> dict[str, Any]See the class contract above and the exact method implementation below.
Returns: dict[str, Any]
Method implementation
def get_config(self) -> dict[str, Any]:
config = super().get_config()
config.update(
{
"units": self.units,
"op": self._op,
"base": self._base_name,
"use_bias": self._use_bias,
"block_kwargs": self._block_kwargs,
}
)
return configdenseattribute
dense = layers.Dense(units, use_bias=use_bias)Public instance attribute assigned by __init__. The source assignment is dense = layers.Dense(units, use_bias=use_bias); it describes instance state, not a literal constructor default.
blockattribute
block = OperatorBlock(op=op, base=base, channels=units, **self._block_kwargs)Public instance attribute assigned by __init__. The source assignment is block = OperatorBlock(op=op, base=base, channels=units, **self._block_kwargs); it describes instance state, not a literal constructor default.
Read the implementation
class cmbDense(layers.Layer):
"""``keras.layers.Dense`` + per-feature :class:`OperatorBlock`.
Parameters
----------
units : int
Number of output features.
op : :class:`OpName`, default ``"identity"``
base : str or :class:`ActivationSpec`, default ``"sigmoid"``
use_bias : bool, default True
Dense-layer bias (independent of the OMBU bias terms).
block_kwargs : dict, optional
Extra keyword arguments passed to :class:`OperatorBlock`.
"""
def __init__(
self,
units: int,
op: OpName = "identity",
base: str | ActivationSpec[Any] = "sigmoid",
use_bias: bool = True,
block_kwargs: dict[str, Any] | None = None,
**kwargs: Any,
) -> None:
super().__init__(**kwargs)
self.units = units
self._op = op
self._base_name = base if isinstance(base, str) else base.name
self._use_bias = use_bias
self._block_kwargs = block_kwargs or {}
self.dense = layers.Dense(units, use_bias=use_bias)
self.block = OperatorBlock(
op=op, base=base, channels=units, **self._block_kwargs
)
def call(self, x: Any) -> Any:
return self.block(self.dense(x))
def get_config(self) -> dict[str, Any]:
config = super().get_config()
config.update(
{
"units": self.units,
"op": self._op,
"base": self._base_name,
"use_bias": self._use_bias,
"block_kwargs": self._block_kwargs,
}
)
return configOther public import paths
omnibias.keras.cmbDenseomnibias.keras.blocks.cmbDenseomnibias.keras.blocks.linear.cmbDense