LayerFactoryRegistry<T>

Helpers & Utilities · AiDotNet.Serialization

Rebuilds a layer that the generated factory table does not know about.

How It Works

GeneratedLayerFactories is compiled from AiDotNet’s own source, so it can only ever name layers AiDotNet ships. A layer defined in a consumer’s assembly has no entry in it and never will: the generator does not run in their compilation, and even if it did, their generated class would live in their assembly where this one cannot name it. Cloning a user-defined layer failed for that reason, with an error telling the author to add [LayerState] – advice that cannot work from outside this assembly.

So there are two ways in besides the generated table. Register takes a factory from any assembly, which is what generated code in a consumer’s project will call. Failing that, a layer is rebuilt by reading its constructor’s parameters out of the saved state by name – slower and unverified at compile time, but it means a hand-written layer works without its author registering anything, which is the promise the options half of this already keeps.

Methods

Method Summary
bool IsRegistered(Type genericDefinition) Whether a factory has been registered for the given open generic type.
bool TryCreate(Type closedType, Type genericDefinition, LayerStateBag state, object scalarActivation, object vectorActivation, object layer) Rebuilds a layer from a registered factory, or by reading its constructor.
void Register(Type genericDefinition, Func<LayerStateBag, object, object, object> factory) Registers a factory for a layer this assembly cannot name.