ExpressionState

Helpers & Utilities · AiDotNet.Serialization

Saves and restores an expression tree a layer was constructed with.

How It Works

The middle of DelegateState’s three descriptions. A traced graph records what an expression computed on one probe input; a method reference names a function that already exists. An expression tree sits between them: the function as data, complete with its captured constants, for a layer that was handed one before it was compiled.

It has to be captured at construction. Compiling an Expression to a delegate is one-way – the tree is not recoverable from the result – so a layer that wants this takes the expression itself and keeps it.

Unlike a traced graph, an expression can name any method, so the allowlist here is not free the way TensorOperations lookup is. Loading resolves methods only on types the host has approved, and rejects the tree otherwise – before Compile is ever called. Nothing is executed to decide this.

Methods

Method Summary
Expression<TDelegate> Load(string saved, string layerName, string key) Rebuilds the expression a saved tree records.
bool IsAllowed(Type type) Types whose methods a restored expression may call.
string Save(LambdaExpression expression) Describes an expression tree, or returns empty when it uses something unsupported.