snnlab.lang.ops
Complete declared API of the ops module, with signatures, data fields, validation and source.
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.
linear
def linear(source: Signal, *, size: int, name: str, trainable: bool=True) -> SignalAuthor a linear operation with a zero-initialized matrix parameter. Its output preserves leading dimensions and replaces the final feature dimension with size.
| Parameter | Annotation | Default | Meaning |
|---|---|---|---|
source | Signal | required | Defined by the source contract and implementation below. |
size | int | required | Defined by the source contract and implementation below. |
name | str | required | Name used to identify the authored or rendered object. |
trainable | bool | True | Defined 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
def reduce(source: Signal, *, operation: str, over: str, name: str, window: str='full', mask: Signal | None=None) -> SignalAuthor 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.
| Parameter | Annotation | Default | Meaning |
|---|---|---|---|
source | Signal | required | Defined by the source contract and implementation below. |
operation | str | required | Defined by the source contract and implementation below. |
over | str | required | Defined by the source contract and implementation below. |
name | str | required | Name used to identify the authored or rendered object. |
window | str | 'full' | Defined by the source contract and implementation below. |
mask | Signal | None | None | Defined 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
def divide(source: Signal, denominator: Signal, *, name: str, unit: str) -> SignalAuthor elementwise division using source and denominator, retaining source shape and declaring the supplied output unit.
| Parameter | Annotation | Default | Meaning |
|---|---|---|---|
source | Signal | required | Defined by the source contract and implementation below. |
denominator | Signal | required | Defined by the source contract and implementation below. |
name | str | required | Name used to identify the authored or rendered object. |
unit | str | required | Declared 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,
)