ElementWiseShapeAttribute
Attributes · AiDotNet.Attributes
Declares that a layer changes VALUES but never SHAPE: whatever tensor goes in, a tensor of exactly the same dimensions comes out, at any rank.
Inheritance: Attribute → ElementWiseShapeAttribute
For Beginners
A “tensor” is just a box of numbers with a shape — for example
[32, 3, 64, 64] might be 32 images, 3 colour channels, 64 pixels tall, 64 wide. Most layers
change that shape: a pooling layer might turn 64x64 into 32x32, and a dense layer might
turn 128 features into 10.
How It Works
Some layers do not. Dropout randomly zeroes some numbers, layer normalization rescales them, a stop-gradient layer passes them straight through. Every one of those touches the NUMBERS and leaves the SHAPE alone. Put this attribute on a layer like that, and the shape system will know its output shape always equals its input shape — without you writing anything else.
Why this exists instead of using [TensorLayout].[TensorLayout] works by NAMING
each axis — Batch, Channels, Height, and so on — which is how the shape system reasons about
relationships like “the output height is the input height divided by two”. That naming is essential
for a pooling or convolution layer. But a dropout layer genuinely does not care what its axes mean:
it works the same on [128], on [32, 128], and on [8, 3, 64, 64]. Forcing it to
name axes would mean inventing meanings it does not have, and inventing one rank when it accepts
many. Both are worse than saying nothing, because a wrong declaration is trusted just as much as a
right one.
When NOT to use this. If the layer changes ANY dimension — pooling, striding, flattening,
projecting to a different feature count, concatenating, reducing over an axis — this attribute is
wrong. Use [TensorLayout] and name the axes, so the system can work out how each output axis
relates to the input. If you are unsure, run the discovery sweep
(LayerShapeDiscoverySweepTests): it probes the layer with several shapes and reports what the
output actually does, which is more reliable than reasoning about it.
Constructors
| Constructor | Summary |
|---|---|
ElementWiseShapeAttribute() |
Properties
| Property | Summary |
|---|---|
int MaxRank { get; set; } |
Highest rank the generated contract answers for. |
string Note { get; set; } |
Optional note explaining anything unusual, surfaced in diagnostics and documentation. |