omnibias.torch.blocks.linear
PyTorch activation derivatives, trainable operator layers, network jets, and direct differential-operator contractions.
import omnibias.torch.blocks.linearModule contract & mathematical conventions
Operator-typed linear layer: cmbLinear.
A drop-in for torch.nn.Linear followed by an
OperatorBlock on the output channels.
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.
cmbLinear
omnibias.torch.cmbLinearSource ↗class cmbLinear(nn.Module)nn.Linear + per-channel OperatorBlock.
Parameters
in_features : int
out_features : int
op : OpName, default "identity" Operator role for the output activation.
base : str or ActivationSpec, default "sigmoid"
bias : bool, default True Linear-layer bias (independent of the OMBU bias terms).
block_kwargs : dict, optional Extra keyword arguments passed to OperatorBlock.
Parameters
| Name | Type & default | Contract |
|---|---|---|
in_featurespositional-or-keyword | intRequired | int |
out_featurespositional-or-keyword | intRequired | int |
oppositional-or-keyword | OpNameDefault: 'identity' | OpName, default "identity" Operator role for the output activation. |
basepositional-or-keyword | str | ActivationSpec[Tensor]Default: 'sigmoid' | str or ActivationSpec, default "sigmoid" |
biaspositional-or-keyword | boolDefault: True | bool, default True Linear-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. |
Executed regression · cmblinear forward shape
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_cmblinear_forward_shape() -> None:
layer = cmbLinear(5, 3, op="identity", base="tanh")
out = layer(torch.randn(2, 5))
assert out.shape == (2, 3)python -m pytest "packages/omnibias-torch/tests/test_blocks.py::test_cmblinear_forward_shape" -qRegression example · cmblinear uses default dtype
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_cmblinear_uses_default_dtype(torch_default_float64) -> None:
fc = cmbLinear(in_features=8, out_features=4, op="grad", base="tanh")
assert fc.linear.weight.dtype == torch.float64
assert fc.block.ombu.biases.dtype == torch.float64python -m pytest packages/omnibias-torch/tests/test_audit_regressions.py -k test_cmblinear_uses_default_dtype -qFields & methods
__init__method
__init__(self, in_features: int, out_features: int, op: OpName='identity', base: str | ActivationSpec[Tensor]='sigmoid', bias: bool=True, block_kwargs: dict[str, Any] | None=None) -> NoneSee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
in_featurespositional-or-keyword | intRequired | See the operation contract and implementation below. |
out_featurespositional-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[Tensor]Default: 'sigmoid' | See the operation contract and implementation below. |
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. |
Returns: None
Executed regression · cmblinear forward shape
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_cmblinear_forward_shape() -> None:
layer = cmbLinear(5, 3, op="identity", base="tanh")
out = layer(torch.randn(2, 5))
assert out.shape == (2, 3)python -m pytest "packages/omnibias-torch/tests/test_blocks.py::test_cmblinear_forward_shape" -qMethod implementation
def __init__(
self,
in_features: int,
out_features: int,
op: OpName = "identity",
base: str | ActivationSpec[Tensor] = "sigmoid",
bias: bool = True,
block_kwargs: dict[str, Any] | None = None,
) -> None:
super().__init__()
self.in_features = in_features
self.out_features = out_features
self.linear = nn.Linear(in_features, out_features, bias=bias)
self.block = OperatorBlock(
op=op,
base=base,
channels=out_features,
**(block_kwargs or {}),
)forwardmethod
forward(self, x: Tensor) -> TensorSee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | TensorRequired | See the operation contract and implementation below. |
Returns: Tensor
Executed regression · cmblinear forward shape
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_cmblinear_forward_shape() -> None:
layer = cmbLinear(5, 3, op="identity", base="tanh")
out = layer(torch.randn(2, 5))
assert out.shape == (2, 3)python -m pytest "packages/omnibias-torch/tests/test_blocks.py::test_cmblinear_forward_shape" -qMethod implementation
def forward(self, x: Tensor) -> Tensor:
out: Tensor = self.block(self.linear(x))
return outextra_reprmethod
extra_repr(self) -> strSee the class contract above and the exact method implementation below.
Returns: str
Method implementation
def extra_repr(self) -> str:
return (
f"in_features={self.in_features}, out_features={self.out_features}, "
f"op={self.block.op!r}, base={self.block.base_name!r}"
)linearattribute
linear = nn.Linear(in_features, out_features, bias=bias)Public instance attribute assigned by __init__. The source assignment is linear = nn.Linear(in_features, out_features, bias=bias); it describes instance state, not a literal constructor default.
Regression example · cmblinear uses default dtype
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_cmblinear_uses_default_dtype(torch_default_float64) -> None:
fc = cmbLinear(in_features=8, out_features=4, op="grad", base="tanh")
assert fc.linear.weight.dtype == torch.float64
assert fc.block.ombu.biases.dtype == torch.float64python -m pytest packages/omnibias-torch/tests/test_audit_regressions.py -k test_cmblinear_uses_default_dtype -qblockattribute
block = OperatorBlock(op=op, base=base, channels=out_features, **block_kwargs or {})Public instance attribute assigned by __init__. The source assignment is block = OperatorBlock(op=op, base=base, channels=out_features, **block_kwargs or {}); it describes instance state, not a literal constructor default.
Regression example · cmblinear uses default dtype
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_cmblinear_uses_default_dtype(torch_default_float64) -> None:
fc = cmbLinear(in_features=8, out_features=4, op="grad", base="tanh")
assert fc.linear.weight.dtype == torch.float64
assert fc.block.ombu.biases.dtype == torch.float64python -m pytest packages/omnibias-torch/tests/test_audit_regressions.py -k test_cmblinear_uses_default_dtype -qRead the implementation
class cmbLinear(nn.Module):
"""``nn.Linear`` + per-channel :class:`OperatorBlock`.
Parameters
----------
in_features : int
out_features : int
op : :class:`OpName`, default ``"identity"``
Operator role for the output activation.
base : str or :class:`ActivationSpec`, default ``"sigmoid"``
bias : bool, default True
Linear-layer bias (independent of the OMBU bias terms).
block_kwargs : dict, optional
Extra keyword arguments passed to :class:`OperatorBlock`.
"""
def __init__(
self,
in_features: int,
out_features: int,
op: OpName = "identity",
base: str | ActivationSpec[Tensor] = "sigmoid",
bias: bool = True,
block_kwargs: dict[str, Any] | None = None,
) -> None:
super().__init__()
self.in_features = in_features
self.out_features = out_features
self.linear = nn.Linear(in_features, out_features, bias=bias)
self.block = OperatorBlock(
op=op,
base=base,
channels=out_features,
**(block_kwargs or {}),
)
def forward(self, x: Tensor) -> Tensor:
out: Tensor = self.block(self.linear(x))
return out
def extra_repr(self) -> str:
return (
f"in_features={self.in_features}, out_features={self.out_features}, "
f"op={self.block.op!r}, base={self.block.base_name!r}"
)Other public import paths
omnibias.torch.cmbLinearomnibias.torch.blocks.cmbLinearomnibias.torch.blocks.linear.cmbLinear