Contents

class

SushiAI::NN::LayerStack

Holds a runtime sequential list of polymorphic layers.

Declared in
include/SushiAI/nn/layer_stack.hpp

Public member functions

LayerStack()=default
LayerStack(LayerStack &&) noexcept=default
LayerStack & operator=(LayerStack &&) noexcept=default
LayerStack(const LayerStack &)=delete
LayerStack & operator=(const LayerStack &)=delete
void push(std::unique_ptr< ILayer > layer)

Appends layer to the end of the stack.

Parameters

layer

The layer; ownership is taken.

Exceptions

Error

If layer is null - a null entry would trace as a silent identity rather than failing.

Graph::ValueId forward(const Graph::GraphBuilder &builder, Graph::ValueId x)

Traces every layer in order.

Parameters

builder

Where the nodes go.

x

The input value.

Returns

The last layer's result.

Exceptions

Error

If the stack is empty, which would otherwise make the model the identity function.

void walk_parameters(std::string_view prefix, const ParameterVisitor &visitor)

Applies visitor to every declared parameter with index prefix.

Parameters

prefix

Parameter name prefix for hierarchy traversal.

visitor

Callback invoked once per declared parameter.

std::size_t size() const noexcept

How many layers the stack holds.

bool empty() const noexcept

Whether the stack holds no layers at all.

int64_t output_features() const

How many features a sample carries after the last layer.

Returns

The last layer's output width.

Exceptions

Error

If the stack is empty.

Shape output_shape() const

Returns the last layer's per-sample output shape, batch axis excluded.

Precondition

The stack holds at least one layer.

ILayer & layer(std::size_t index) const

The layer at index, for a test that wants to inspect it.

Parameters

index

Which layer, in [0, size()).

Returns

The layer; owned by the stack.

Exceptions

Error

If index is out of range.

Static public member functions

static constexpr auto fields()

No parameters of its own; the layers own them all.