FlexNN 1
Fully connected neural network built from scratch with flexible n-layer design and multiple activations.
Loading...
Searching...
No Matches
Layer.hpp File Reference

Type-erased wrapper for FlexNN::Layers — heterogeneous stack without inheritance. More...

#include <type_traits>
#include <variant>
#include "Dense.hpp"
#include "Conv1D.hpp"
#include "BatchNorm1D.hpp"
#include "Pool1D.hpp"
#include "activations/ActivationParameters.hpp"
Include dependency graph for Layer.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  FlexNN::Layers::Layer
 Type-erased layer — holds one concrete layer type. More...
 

Namespaces

namespace  FlexNN
 Namespace for the FlexNN neural network library.
 
namespace  FlexNN::Layers
 

Detailed Description

Type-erased wrapper for FlexNN::Layers — heterogeneous stack without inheritance.

Each concrete layer (Dense, Conv1D, BatchNorm1D, MaxPool1D, AvgPool1D) lives in its own header (include/layers/<Type>.hpp) and owns its weights. FlexNN::Layers::Layer is a thin wrapper over std::variant that lets FlexNN::NeuralNetwork hold a vector<Layer> of mixed types while keeping dispatch std::visit (no vtable, no heap, inline). New layer types are added by expanding the variant in later PRs — existing visit sites (forward/backward in NeuralNetwork, ModelIO) automatically handle them via the same pattern without touching old concrete headers.

Why variant, not inheritance (see LLD_FLEXNN §3):

  • Host training stays simple (Eigen, no vtable indirection)
  • For MCU we don't reuse these structs at all — export is flat arrays
  • Variant is inline (no indirection) and std::visit is optimized away