Skip to main content

omnibias.torch.blocks.linear

0.5.0rc1Release candidatePython >=3.10Apache-2.0

PyTorch activation derivatives, trainable operator layers, network jets, and direct differential-operator contractions.

import omnibias.torch.blocks.linear
Module 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.

CLASS

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

NameType & defaultContract
in_featurespositional-or-keywordintRequiredint
out_featurespositional-or-keywordintRequiredint
oppositional-or-keywordOpNameDefault: 'identity'OpName, default "identity" Operator role for the output activation.
basepositional-or-keywordstr | ActivationSpec[Tensor]Default: 'sigmoid'str or ActivationSpec, default "sigmoid"
biaspositional-or-keywordboolDefault: Truebool, default True Linear-layer bias (independent of the OMBU bias terms).
block_kwargspositional-or-keyworddict[str, Any] | NoneDefault: Nonedict, 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" -q
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.float64
python -m pytest packages/omnibias-torch/tests/test_audit_regressions.py -k test_cmblinear_uses_default_dtype -q

Fields & 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) -> None

See the class contract above and the exact method implementation below.

Parameters

NameType & defaultContract
in_featurespositional-or-keywordintRequiredSee the operation contract and implementation below.
out_featurespositional-or-keywordintRequiredSee the operation contract and implementation below.
oppositional-or-keywordOpNameDefault: 'identity'See the operation contract and implementation below.
basepositional-or-keywordstr | ActivationSpec[Tensor]Default: 'sigmoid'See the operation contract and implementation below.
biaspositional-or-keywordboolDefault: TrueSee the operation contract and implementation below.
block_kwargspositional-or-keyworddict[str, Any] | NoneDefault: NoneSee 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" -q
Method 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 {}),
        )
View source ↗
forwardmethod
forward(self, x: Tensor) -> Tensor

See the class contract above and the exact method implementation below.

Parameters

NameType & defaultContract
xpositional-or-keywordTensorRequiredSee 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" -q
Method implementation
    def forward(self, x: Tensor) -> Tensor:
        out: Tensor = self.block(self.linear(x))
        return out
View source ↗
extra_reprmethod
extra_repr(self) -> str

See 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}"
        )
View source ↗
in_featuresattribute
in_features: int = in_features

int

View source ↗
out_featuresattribute
out_features: int = out_features

int

View source ↗
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.float64
python -m pytest packages/omnibias-torch/tests/test_audit_regressions.py -k test_cmblinear_uses_default_dtype -q
View source ↗
blockattribute
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.float64
python -m pytest packages/omnibias-torch/tests/test_audit_regressions.py -k test_cmblinear_uses_default_dtype -q
View source ↗
Read 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.cmbLinear
  • omnibias.torch.blocks.cmbLinear
  • omnibias.torch.blocks.linear.cmbLinear