ShapeInference
Helpers & Utilities · AiDotNet.NeuralNetworks
Computes output shapes from declared axis roles (TensorLayoutAttribute) plus declared
axis relations (IShapeContract), without running a forward pass.
How It Works
The join between the two halves of the shape system. The layout attribute names a tensor’s axes so a
raw int[] becomes {Batch: 1, Channels: 3, Height: 32, Width: 32}; the contract then says
how each OUTPUT axis is sized from those. Neither half is sufficient alone — roles without relations
cannot tell a stride-1 convolution from a stride-2 one, and relations without roles have no way to
say which input axis a relation refers to.
Everything here declines rather than guesses. A type that is unannotated, whose declared layout does
not accept the given rank, or whose contract contains an Unknown axis yields no shape at all.
A shape system that returns a plausible answer when it does not know is worse than one that returns
nothing, because callers cannot tell the two apart.
Methods
| Method | Summary |
|---|---|
IEnumerable<TensorLayoutAttribute> InputLayouts(Type type) |
Declared input layouts, read through the open generic definition. |
IEnumerable<TensorLayoutAttribute> OutputLayouts(Type type) |
Declared output layouts, read through the open generic definition. |
IReadOnlyDictionary<TensorAxis, int> NameAxes(Type type, IReadOnlyList<int> shape) |
Names the axes of a concrete shape using a type’s declared INPUT layout. |
ShapeRelationKind DeriveRelationKind(IReadOnlyList<OutputAxisContract> contract) |
Derives the coarse ShapeRelationKind implied by a symbolic contract. |
bool ContractMatchesLayout(object instance, int inputRank, string mismatch) |
Checks that a type’s IShapeContract agrees with its declared output layout. |
bool HasDeclaredOutputShapeContract(Type type) |
Reports whether a type’s effective OutputAxesFor implementation declares a probeable symbolic law rather than an explicit or conditional unavailable marker. |
int[] InferOutputShape(object instance, IReadOnlyList<IReadOnlyList<int>> inputShapes) |
Computes the output shape a MULTI-INPUT type produces for the given input shapes. |
int[] InferOutputShape(object instance, IReadOnlyList<int> inputShape) |
Computes the output shape a MULTI-INPUT type produces for the given input shapes. |
int[] InferOutputShape(object instance, IReadOnlyList<int> inputShape, bool isBatched) |
Computes the output shape a type produces, saying whether inputShape INCLUDES a batch axis. |