LayerStateBag

Structs · AiDotNet.Serialization

The saved constructor state of a single layer, as read back at deserialization time.

Inheritance: ValueType → LayerStateBag

How It Works

Generated factories built from LayerStateAttribute read their constructor arguments through this type. Every accessor throws a message naming the layer, the key and the keys that were present when a value is missing or unparseable, because the alternative — silently substituting a default — is how a restored layer ends up quietly the wrong size and only fails much later in a numeric comparison.

Lookup is case-insensitive so that generated readers keyed on a camelCase parameter name find the PascalCase keys existing hand-written GetMetadata overrides already write.

Constructors

Constructor Summary
LayerStateBag(Dictionary<string, object> values, string layerName) Creates a bag over the metadata restored for a layer.

Properties

Property Summary
string LayerName { get; } The layer type name this state belongs to.

Methods

Method Summary
TComponent Component(string key) Rebuilds a pluggable component (an RBF kernel, a distance metric, …) from the concrete type recorded at save time.
TConfiguration JsonObject(string key) Reads a JSON-backed, compile-time-fixed configuration object.
TEnum Enum(string key) Reads a required enum value.
TEnum Enum(string key, TEnum fallback) Reads an enum value, or fallback when it was not saved.
TEnum? NullableEnum(string key) Reads a nullable enum while preserving an explicitly saved null.
TEnum[] EnumArray(string key) Reads an array of enum values stored by name.
TObject CloneObject(string key) Reads and independently clones an object supplied through the in-memory construction channel.
TState PersistableState(string key) Reads a value that carries its own state via ILayerStatePersistable.
bool Boolean(string key) Reads a required boolean.
bool Boolean(string key, bool fallback) Reads a boolean, or fallback when it was not saved.
bool Has(string key) true when a value is present for key.
bool HasAll(string[] keys) true when every one of keys is present.
bool? NullableBoolean(string key) Reads a nullable boolean while preserving an explicitly saved null.
bool[] BooleanArray(string key) Reads a required boolean array, stored comma-separated.
bool[] BooleanArray(string key, bool[] fallback) Reads a boolean array, or fallback when it was not saved.
double Double(string key) Reads a required double.
double Double(string key, double fallback) Reads a double, or fallback when it was not saved.
double? NullableDouble(string key) Reads a nullable double while preserving an explicitly saved null.
double[] DoubleArray(string key) Reads a required double array, stored comma-separated.
double[] DoubleArray(string key, double[] fallback) Reads a double array, or fallback when it was not saved.
double[] NullableDoubleArray(string key) Reads a nullable double array while distinguishing null from an empty array.
float Single(string key) Reads a required single-precision float.
float? NullableSingle(string key) Reads a nullable single-precision value while preserving an explicitly saved null.
int Int32(string key) Reads a required 32-bit integer.
int Int32(string key, int fallback) Reads a 32-bit integer, or fallback when it was not saved.
int? NullableInt32(string key) Reads a nullable 32-bit integer while preserving an explicitly saved null.
int[] Int32Array(string key) Reads a required integer array, stored comma-separated.
int[] Int32Array(string key, int[] fallback) Reads an integer array, or fallback when it was not saved.
int[] NullableInt32Array(string key) Reads a nullable integer array while distinguishing null from an empty array.
int[][] Int32Jagged(string key) Reads a required jagged integer array: rows separated by ‘;’, values by ‘,’.
int[][] Int32Jagged(string key, int[][] fallback) Reads a jagged integer array, or fallback when it was not saved.
long Int64(string key) Reads a required 64-bit integer.
long? NullableInt64(string key) Reads a nullable 64-bit integer while preserving an explicitly saved null.
string Format(Enum value) Formats jagged integer state as semicolon-separated rows.
string Format(bool value) Formats jagged integer state as semicolon-separated rows.
string Format(bool[] value) Formats jagged integer state as semicolon-separated rows.
string Format(double value) Formats jagged integer state as semicolon-separated rows.
string Format(double[] value) Formats jagged integer state as semicolon-separated rows.
string Format(float value) Formats jagged integer state as semicolon-separated rows.
string Format(int value) Formats jagged integer state as semicolon-separated rows.
string Format(int[] value) Formats jagged integer state as semicolon-separated rows.
string Format(int[][] value) Formats jagged integer state as semicolon-separated rows.
string Format(long value) Formats jagged integer state as semicolon-separated rows.
string Format(string value) Formats jagged integer state as semicolon-separated rows.
string Format(string[] value) Formats jagged integer state as semicolon-separated rows.
string FormatCloneObject(object value) Formats an owned construction object for layer metadata.
string FormatDelegate(Delegate value, int[] inputShape) Formats a delegate-typed construction value for layer metadata through DelegateState: a Func<Tensor<T>, Tensor<T>> written in engine ops is traced into a portable tensor program at the layer’s input shape; anything else keeps the legacy…
string FormatEnumArray(TEnum[] value) Formats an enum array by member name.
string FormatJson(object value) Formats a fixed-type configuration object without polymorphic type metadata.
string FormatNullable(TEnum? value) Formats nullable integer-array state without conflating null with an empty array.
string FormatNullable(bool? value) Formats nullable integer-array state without conflating null with an empty array.
string FormatNullable(double? value) Formats nullable integer-array state without conflating null with an empty array.
string FormatNullable(float? value) Formats nullable integer-array state without conflating null with an empty array.
string FormatNullable(int? value) Formats nullable integer-array state without conflating null with an empty array.
string FormatNullable(int[] value) Formats nullable integer-array state without conflating null with an empty array.
string FormatNullable(long? value) Formats nullable integer-array state without conflating null with an empty array.
string FormatNullable(string value) Formats nullable integer-array state without conflating null with an empty array.
string FormatType(object value) Records a component’s concrete type so it can be rebuilt exactly.
string NullableString(string key) Reads nullable text while distinguishing null from the empty string.
string String(string key) Reads a required string.
string String(string key, string fallback) Reads a string, or fallback when it was not saved.
string[] StringArray(string key) Reads a required string array, stored newline-separated.
string[] StringArray(string key, string[] fallback) Reads a string array, or fallback when it was not saved.