Skip to main content

Variadic Ports

Standard neurons have a fixed number of input ports. Variadic ports let a neuron accept any number of inputs — two, three, ten — through a single declaration. This is essential for operations like concatenation, addition, and other N-ary reductions.

Declaration Syntax

A variadic input port uses * before the port name:

neuron Concat(dim):
in *inputs: [*shape]
out: [*shape_out]
impl: core,structural/Concat

The *inputs declaration means this neuron accepts a tuple of any length as input. Each element of the tuple is validated individually against the port's shape pattern ([*shape]).

Calling Variadic Neurons

Pass a tuple of connections to a variadic neuron:

Two-Input Concat

Two branches concatenated along the last dimension

NeuroScript
Loading editor...
PyTorch Output
Loading editor...

The tuple (pa, pb) feeds into Concat's variadic *inputs port. Each element is checked against the shape pattern independently.

Scaling to More Inputs

The same neuron works with any number of inputs — no overloads needed:

Three-Input Concat

Three branches concatenated — same Concat neuron, more inputs

NeuroScript
Loading editor...
PyTorch Output
Loading editor...

Composing Variadic Neurons

A composite neuron can itself declare a variadic port and pass it through:

Variadic Composite

ConcatNorm accepts any number of inputs, concatenates, then normalizes

NeuroScript
Loading editor...
PyTorch Output
Loading editor...

When a composite neuron has a variadic port, the incoming tuple is passed as-is to the first connection. Here, in carries the full tuple directly into Concat.

Inception-Style Pattern

Variadic ports enable multi-branch architectures where the number of branches is flexible:

Four-Way Concat

Four parallel paths merged via variadic Concat

NeuroScript
Loading editor...
PyTorch Output
Loading editor...

Rules and Constraints

  • Only input ports can be variadic — output ports cannot
  • A neuron with a variadic port must have exactly one in declaration
  • The variadic port must have an explicit name (e.g., *inputs, not just *)
  • Each tuple element is validated against the port's shape individually
  • In composite neurons, in carries the full tuple and passes it as-is to the first connection

Comparison with Fixed Ports

FeatureFixed portsVariadic port
Declarationin left: [*shape]in *inputs: [*shape]
Input countFixed at definitionAny tuple length
Shape checkPer-portPer-element against same pattern
Use caseKnown arity (Add, Fork)Variable arity (Concat, Sum)

Try It Yourself

Experiment with variadic ports:

  • Change the number of branches feeding into Concat
  • Create a composite neuron with a variadic port
  • Try passing different numbers of inputs to the same variadic neuron
  • Click "Show Analysis" to see how shapes flow through variadic connections