snnlab
API referencesnnlab.lang

snnlab.lang.ops

Complete declared API of the ops module, with signatures, data fields, validation and source.

Back to lang reference

Small serialisable operation vocabulary.

The signatures, defaults, fields, docstrings and implementation excerpts below are generated from the Python source. Annotations are shown as declared; unannotated means the source supplies no type annotation. These pages document callable surfaces, including legacy support utilities, without promising backend support for every declaration.

SymbolKind
linearfunction
reducefunction
dividefunction

linear

View source

def linear(source: Signal, *, size: int, name: str, trainable: bool=True) -> Signal

Author a linear operation with a zero-initialized matrix parameter. Its output preserves leading dimensions and replaces the final feature dimension with size.

ParameterAnnotationDefaultMeaning
sourceSignalrequiredDefined by the source contract and implementation below.
sizeintrequiredDefined by the source contract and implementation below.
namestrrequiredName used to identify the authored or rendered object.
trainableboolTrueDefined by the source contract and implementation below.

Return annotation: Signal.

Return expressions (branch-dependent; names refer to the linked implementation):

net.operation('linear', source, name=name, shape=(*source.shape[:-1], size), unit=source.unit, signal_type='continuous', parameters=(weight,), size=size, trainable=trainable)
Implementation
def linear(source: Signal, *, size: int, name: str, trainable: bool = True) -> Signal:
    net = source.network
    weight = net.parameter(
        f"{name}.weight",
        shape=(size, source.shape[-1]),
        initializer=Constant(0.0),
        constraint=None,
    )
    return net.operation(
        "linear",
        source,
        name=name,
        shape=(*source.shape[:-1], size),
        unit=source.unit,
        signal_type="continuous",
        parameters=(weight,),
        size=size,
        trainable=trainable,
    )

reduce

View source

def reduce(source: Signal, *, operation: str, over: str, name: str, window: str='full', mask: Signal | None=None) -> Signal

Author a reduction over the explicit time axis, removing that axis from the output shape. operation selects the reduction kind; mask and window are recorded for execution.

ParameterAnnotationDefaultMeaning
sourceSignalrequiredDefined by the source contract and implementation below.
operationstrrequiredDefined by the source contract and implementation below.
overstrrequiredDefined by the source contract and implementation below.
namestrrequiredName used to identify the authored or rendered object.
windowstr'full'Defined by the source contract and implementation below.
maskSignal | NoneNoneDefined by the source contract and implementation below.

Return annotation: Signal.

Return expressions (branch-dependent; names refer to the linked implementation):

source.network.operation(f'reduce_{operation}', sources, name=name, shape=tuple((dimension for index, dimension in enumerate(source.shape) if index != time_axis)), unit=source.unit, window=window, mask=mask.id if mask else None)

Explicit exceptions in this implementation; called helpers may raise additional errors:

Explicit exception expression
ValueError('v1 reductions support only an explicit time axis')
Implementation
def reduce(
    source: Signal,
    *,
    operation: str,
    over: str,
    name: str,
    window: str = "full",
    mask: Signal | None = None,
) -> Signal:
    if over != "time" or "time" not in source.shape:
        raise ValueError("v1 reductions support only an explicit time axis")
    time_axis = source.shape.index("time")
    sources = [source] + ([mask] if mask else [])
    return source.network.operation(
        f"reduce_{operation}",
        sources,
        name=name,
        shape=tuple(
            dimension
            for index, dimension in enumerate(source.shape)
            if index != time_axis
        ),
        unit=source.unit,
        window=window,
        mask=mask.id if mask else None,
    )

divide

View source

def divide(source: Signal, denominator: Signal, *, name: str, unit: str) -> Signal

Author elementwise division using source and denominator, retaining source shape and declaring the supplied output unit.

ParameterAnnotationDefaultMeaning
sourceSignalrequiredDefined by the source contract and implementation below.
denominatorSignalrequiredDefined by the source contract and implementation below.
namestrrequiredName used to identify the authored or rendered object.
unitstrrequiredDeclared physical unit; projection weights use uS.

Return annotation: Signal.

Return expressions (branch-dependent; names refer to the linked implementation):

source.network.operation('divide', [source, denominator], name=name, shape=source.shape, unit=unit)
Implementation
def divide(source: Signal, denominator: Signal, *, name: str, unit: str) -> Signal:
    return source.network.operation(
        "divide",
        [source, denominator],
        name=name,
        shape=source.shape,
        unit=unit,
    )

On this page