shape_tensor.h#
Shape-inference functions for ONNX operators in the tensor family.
-
namespace onnx_light
Alias that makes onnx-light headers compatible with code that references
ONNX_LIGHT_NAMESPACE(the macro used in the standard onnx package).Set to
ONNX_LIGHT_NAMESPACEso both names resolve to the same namespace.Symbol-visibility attribute for the public onnx-light C++ API.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_light(via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs fromonnx.-
namespace onnx_optim
-
namespace shapes
-
namespace tensor#
Functions
-
void ComputeShapeConcat(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aConcatnode and stores it inctx.Concatconcatenates a variadic list of input tensors along the axis specified by theaxisattribute. All inputs must share the same rank and the same dimension sizes on every axis other than the concatenation axis. The output dtype always matches the dtype of the first input (type constraintT); the output shape is:on the concatenation axis: the sum of all input dimensions when every input dimension on that axis is a concrete integer; otherwise a fresh symbolic dimension;
on every other axis: the merged dimension between all inputs (concrete dimensions must match across inputs, otherwise an exception is thrown; a concrete value overrides a symbolic one).
The
axisattribute can be negative, in which case it is interpreted asaxis + rank. When the attribute is missing the default of1(the opset 1 default) is used.- Parameters:
ctx – In/out context. Must already contain an entry for every name in
node.input. On return it also contains an entry fornode.output(0).node – The
ConcatNodeProtowhose output should be described.node.op_type()must be"Concat",nodemust declare at least one input and at least one output.
- Throws:
-
void ComputeShapeCast(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aCastnode and stores it inctx.Castproduces an output whose shape is identical to the shape of its single input and whose element type is given by the required integer attributeto(aTensorProto::DataTypevalue). The other optional attributes (saturate,round_mode) do not affect the output shape or dtype and are therefore not inspected by this function.- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0). On return it also contains an entry fornode.output(0).node – The
CastNodeProtowhose output should be described.node.op_type()must be"Cast",nodemust declare at least one input and at least one output and must carry the requiredtoattribute.
- Throws:
-
void ComputeShapeBitCast(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aBitCastnode (opset 26) and stores it inctx.BitCastreinterprets the bit pattern of its input as the data type specified by the requiredtoattribute. The output shape always matches the input shape; the output dtype is taken fromto. The target dtype must have the same per-element bit-width as the input dtype (the upstream ONNX schema enforces this rule); if the widths differ this function throwsstd::invalid_argument.- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0); on return it also contains an entry fornode.output(0).node – The
BitCastNodeProtowhose output should be described.node.op_type()must be"BitCast"andnodemust declare at least one output.
- Throws:
std::invalid_argument – if
node.op_type()is not"BitCast", ifnodehas no output, if thetoattribute is missing, if its value does not map to a supported (non-string) :cpp:enum:TensorType, or if the input and output element bit-widths differ.std::out_of_range – if the input name is missing from
ctx.
-
void ComputeShapeCastLike(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aCastLikenode and stores it inctx.CastLikeproduces an output whose shape is identical to the shape of its first input (input) and whose element type is taken from the second input (target_type); the values oftarget_typeare ignored. The optional attributes (saturate,round_mode) do not affect the output shape or dtype and are therefore not inspected by this function.- Parameters:
ctx – In/out context. Must already contain entries for
node.input(0)andnode.input(1). On return it also contains an entry fornode.output(0).node – The
CastLikeNodeProtowhose output should be described.node.op_type()must be"CastLike",nodemust declare two inputs and at least one output.
- Throws:
-
void ComputeShapeReshape(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aReshapenode and stores it inctx.Reshapetakes adatatensor and a 1-D int64shapetensor whose values describe the desired output shape. The output dtype is the dtype ofdata(type constraintT). The output shape is derived element-by-element from the target shape:a positive value is used verbatim;
0means “copy from the input ``data`` shape at the same
index”, unless the
allowzeroattribute is set to1(in which case0is honoured literally);exactly one
-1is allowed; the corresponding dimension is inferred so that the total number of elements is preserved (whendatais fully known and the other dims are concrete);symbolic target dims are forwarded as symbolic output dims.
Shape values are read from the
shapeinput’s :cpp:func:OptimTensor::ValueAsShapeannotation (populated for small constants, e.g. by :cpp:func:ComputeShapeConstant). When that annotation is missing the output rank is taken from the static shape of theshapeinput (its single dimension, when concrete) and every output dim is left symbolic. When the rank itself is unknown the output is left as a fully-symbolic rank-1 tensor.- Parameters:
ctx – In/out context. Must contain entries for
node.input(0)(data) andnode.input(1)(shape). On return it also contains an entry fornode.output(0).node – The
ReshapeNodeProtowhose output should be described.node.op_type()must be"Reshape",nodemust declare two inputs and at least one output.
- Throws:
std::invalid_argument – if
node.op_type()is not"Reshape", ifnodehas fewer than two inputs or no output, if the target shape contains more than one-1, contains a value strictly less than-1, if a0entry (withallowzero == 0) refers to a position outside the input rank, or if a-1cannot be reconciled with the input’s element count.std::out_of_range – if any input name is missing from
ctx.
-
void ComputeShapeSlice(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aSlicenode and stores it inctx.Slicepreserves input rank and dtype. Whenstarts/ends(and optionalaxes/steps) values are known through :cpp:func:OptimTensor::ValueAsShape, concrete output lengths are inferred per sliced axis; otherwise sliced axes are left symbolic.
-
void ComputeShapeExpand(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof anExpandnode and stores it inctx.Expandbroadcasts its first input (input) to the shape described by its second input (shape), following the ONNX numpy-style broadcasting rules. The output dtype matches the dtype ofinput(type constraintT).Shape values are read from the
shapeinput’s :cpp:func:OptimTensor::ValueAsShapeannotation (populated for small constants). When that annotation is present the output shape is computed asBroadcastShapes(input.shape, target). When it is absent the output rank is taken from the static shape of theshapeinput (its single dimension, when concrete) and every output dim is left symbolic.- Parameters:
ctx – In/out context. Must already contain entries for
node.input(0)(input) andnode.input(1)(shape). On return it also contains an entry fornode.output(0).node – The
ExpandNodeProtowhose output should be described.node.op_type()must be"Expand",nodemust declare two inputs and at least one output.
- Throws:
-
void ComputeShapeSqueeze(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aSqueezenode and stores it inctx.Squeezeremoves dimensions of size 1 from the input shape. When the optionalaxesinput is provided and its values are known, only those axes are removed (and each selected axis must be 1 when concrete). Whenaxesis omitted, every concrete unit dimension is removed.
-
void ComputeShapeUnsqueeze(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof anUnsqueezenode and stores it inctx.Unsqueezeinserts dimensions of size 1 at the indices given by the requiredaxesinput.
-
void ComputeShapeTile(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aTransposenode and stores it inctx.Transposepermutes the axes of its input tensor according to the optionalpermattribute. Whenpermis absent, axes are reversed. The output dtype matches the input dtype.Tileconstructs a tensor by repeating its first input (input) a number of times along each axis given by the 1-D INT64repeatstensor. The output has the same rank and dtype asinput(type constraintT); its dimensioniisinput.shape[i] * repeats[i].Repeats values are read from the
repeatsinput’s :cpp:func:OptimTensor::ValueAsShapeannotation (populated for small constants). When that annotation is present each output dim is computed asinput.shape[i] * repeats[i](the multiplication is performed symbolically wheninput.shape[i]is not a concrete integer; whenrepeats[i]is symbolic the output dim is left symbolic). When the annotation is absent the output rank is taken from the static rank ofinputand every output dim is left symbolic.- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0). On return it also contains an entry fornode.output(0).node – The
TransposeNodeProtowhose output should be described.node.op_type()must be"Transpose",nodemust declare one input and at least one output.ctx – In/out context. Must already contain entries for
node.input(0)(input) andnode.input(1)(repeats). On return it also contains an entry fornode.output(0).node – The
TileNodeProtowhose output should be described.node.op_type()must be"Tile",nodemust declare two inputs and at least one output.
- Throws:
std::invalid_argument – if
node.op_type()is not"Transpose", ifnodehas no input or output, ifpermlength differs from input rank, ifpermcontains an out-of-range value, or if it contains duplicates.std::out_of_range – if the input name is missing from
ctx. Computes the output :cpp:class:OptimTensorof aTilenode and stores it inctx.std::invalid_argument – if
node.op_type()is not"Tile", ifnodehas fewer than two inputs or no output, or if a knownrepeatsinput has a length different from the rank ofinput.std::out_of_range – if any input name is missing from
ctx.
-
void ComputeShapePad(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aPadnode and stores it inctx. Supports the full Pad history (opsets 1, 2, 11, 13, 18, 19, 21, 23, 24, 25):opsets 1 and 2 read the padding values from the
paddings/padsINTS attribute and apply them on every input axis.opsets >= 11 read the padding values from the 1-D INT64
padsinput (when statically known via data-propagation).opsets >= 18 additionally accept an optional
axesinput that restricts the padding to a subset of the input axes (negative values count from the back).
The output dtype always matches the dtype of
data. The output shape is rank-preserving; on every axis the output dim becomesinput_dim + pad_begin + pad_endwhen both the input dim and the relevant pad values are statically known, otherwise a fresh symbolic dimension is produced.- Parameters:
ctx – In/out context. Must already contain an entry for every name in
node.input. On return it also contains an entry fornode.output(0).node – The
PadNodeProtowhose output should be described.node.op_type()must be"Pad".
- Throws:
-
void ComputeShapeUpsample(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof anUpsamplenode and stores it inctx. Supports Upsample opsets 1, 7, 9 and 10:v1: the per-spatial-axis
width_scaleandheight_scaleFLOAT attributes give the scales of the two trailing axes of a 4-D NCHW input. Output dimkisfloor(input_dim[k] * scale[k]).v7: the
scalesFLOATS attribute carries one scale per input axis.v9/v10: the
scalesinput tensor (1-D FLOAT) carries one scale per input axis. Because the data-propagation lattice only tracks integer shape values, the float scales cannot be recovered here in general; the output rank is preserved and every output dim is left symbolic.
The output dtype always matches the input dtype (type constraint
T) and the output rank equals the input rank.
-
void ComputeShapeResize(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aResizenode and stores it inctx.Resize(since opset 10 in theai.onnxdomain) accepts a runtimescalesorsizesinput that selects the output shape. Three schema layouts are supported:v10: inputs
(X, scales)—scalesis a 1-D FLOAT tensor (one entry per input axis).v11 / v13: inputs
(X, roi, scales, sizes)—roiand eitherscalesorsizescan be omitted via empty-string input names.v18 / v19: same as v11/v13 but with optional
axes/keep_aspect_ratio_policyattributes.
The output dtype always matches the input dtype (type constraint
T1) and the output rank equals the input rank. Per-axis output dims are computed concretely when both the corresponding input dim and thesizesconstant are statically known (data-propagation lattice only carries integer shape values, soscales— a FLOAT input — always leaves dims symbolic).
-
void ComputeShapeTranspose(ShapesContext &ctx, const NodeProto &node)#
-
void ComputeShapeDepthToSpace(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aDepthToSpacenode and stores it inctx.DepthToSpacerequires a rank-4 input of shape(N, C, H, W)and a required positive integer attributeblocksize. The output dtype matches the input dtype (type constraintT) and the output shape is(N, C/(blocksize*blocksize), H*blocksize, W*blocksize)(each axis is computed symbolically when the corresponding input dim is symbolic).- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0). On return it also contains an entry fornode.output(0).node – The
DepthToSpaceNodeProtowhose output should be described.
- Throws:
std::invalid_argument – if
node.op_type()is not"DepthToSpace", ifnodehas no input or output, if the input rank is known and is not 4, ifblocksizeis missing or non-positive, or if the input channel dim is concrete and not divisible byblocksize * blocksize.std::out_of_range – if the input name is missing from
ctx.
-
void ComputeShapeSpaceToDepth(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aSpaceToDepthnode and stores it inctx.SpaceToDepthrequires a rank-4 input of shape(N, C, H, W)and a required positive integer attributeblocksize. The output dtype matches the input dtype (type constraintT) and the output shape is(N, C*blocksize*blocksize, H/blocksize, W/blocksize)(each axis is computed symbolically when the corresponding input dim is symbolic).- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0). On return it also contains an entry fornode.output(0).node – The
SpaceToDepthNodeProtowhose output should be described.
- Throws:
std::invalid_argument – if
node.op_type()is not"SpaceToDepth", ifnodehas no input or output, if the input rank is known and is not 4, ifblocksizeis missing or non-positive, or if the input H or W dim is concrete and not divisible byblocksize.std::out_of_range – if the input name is missing from
ctx.
-
void ComputeShapeAffineGrid(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof anAffineGridnode and stores it inctx.AffineGridproduces a flow field of sampling coordinates from a batch of affine matricesthetaand a targetsize. The output dtype matchestheta’s dtype (type constraintT1).The output shape is derived as follows:
If
sizeexposes a value via :cpp:func:OptimTensor::ValueAsShape(typically because it is a Constant), the spatial output dims(H, W)for 2-D /(D, H, W)for 3-D are taken verbatim fromsizeand the rank of the output is fully known.sizemust have 4 (2-D) or 5 (3-D) entries.Otherwise the rank of
thetadetermines whether the output is 2-D (thetashape(N, 2, 3)) or 3-D (thetashape(N, 3, 4)), and the spatial dims are left symbolic.
The leading batch dim
Nis taken fromtheta[0]; the final inner dim is the constant2(2-D) or3(3-D).- Parameters:
ctx – In/out context. Must already contain entries for
thetaandsize. On return it also contains an entry fornode.output(0).node – The
AffineGridNodeProtowhose output should be described.node.op_type()must be"AffineGrid",nodemust declare two inputs and at least one output.
- Throws:
-
void ComputeShapeGridSample(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aGridSamplenode and stores it inctx.GridSamplesamples an input tensorXof rankr+2and shape(N, C, D1, D2, ..., Dr)at the normalised locations given by a flow fieldgridof rankr+2and shape(N, D1_out, D2_out, ..., Dr_out, r), producing an output of rankr+2and shape(N, C, D1_out, D2_out, ..., Dr_out). The output dtype matchesX’s dtype (type constraintT1).The output shape is derived as follows (each dim independently):
output[0]: merged dim betweenX[0]andgrid[0].output[1]:X[1](the channel dim).output[2 .. r+1]: the spatial dims taken fromgrid[1 .. r].
- Parameters:
ctx – In/out context. Must already contain entries for
Xandgrid. On return it also contains an entry fornode.output(0).node – The
GridSampleNodeProtowhose output should be described.node.op_type()must be"GridSample",nodemust declare two inputs and at least one output.
- Throws:
-
void ComputeShapeNonZero(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aNonZeronode and stores it inctx.NonZeroreturns the indices of the non-zero elements of its single input tensor (in row-major order). The output is always an :cpp:enum:TensorType::kInt642-D tensor of shape(rank, nnz)whererankis the rank of the input andnnzis the number of non-zero elements. For scalar input (rank == 0) the upstream spec dictates an output shape of(0, nnz), which differs from NumPy’s behaviour.Because the number of non-zero elements is a runtime value, the second output dimension is left symbolic. The first output dimension is concrete when the input rank is known and otherwise symbolic.
- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0). On return it also contains an entry fornode.output(0).node – The
NonZeroNodeProtowhose output should be described.node.op_type()must be"NonZero",nodemust declare one input and at least one output.
- Throws:
-
void ComputeShapeOneHot(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aOneHotnode and stores it inctx.OneHot(since opset 9 in theai.onnxdomain) produces a tensor of rankrank(indices) + 1, inserting a new dimension at positionaxis(default-1). The dtype of the output matchesvalues(the third input). When the value of thedepthinput is known via data-propagation the inserted dimension is concrete; otherwise it is a symbolic dimension.- Parameters:
ctx – In/out context. Must already contain entries for
node.input(0)(indices),node.input(1)(depth) andnode.input(2)(values). On return it also contains an entry fornode.output(0).node – The
OneHotNodeProtowhose output should be described.node.op_type()must be"OneHot"andnodemust declare three inputs and at least one output.
- Throws:
-
void ComputeShapeUnique(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorentries of aUniquenode and stores them inctx.Unique(opset 11) returns up to four outputs (Y,indices,inverse_indices,counts). All optional outputs are 1-D :cpp:enum:TensorType::kInt64tensors of an unknown length.Ymatches the dtype of the input:when the
axisattribute is not provided the input is flattened andYis 1-D with an unknown length;when
axisis providedYhas the same rank and shape as the input except alongaxis, whose dimension is symbolic.
Optional outputs declared as the empty string in
node.outputare skipped.- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0). On return it also contains entries for every non-empty entry innode.output.node – The
UniqueNodeProtowhose outputs should be described.node.op_type()must be"Unique",nodemust declare one input and at least one output.
- Throws:
-
void ComputeShapeShape(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aShapenode and stores it inctx.Shapereturns a 1-D :cpp:enum:TensorType::kInt64tensor whose entries are the dimensions of its input. Optionalstartandendattributes (since opset 15) bound the sliceinput.shape[start:end]: negative values count from the back and out-of-range values are clamped to[0, r]whereris the input rank. Whenstart > end(after normalisation) the output is empty.The output dimension is concrete when the input rank is known (which is always the case when an :cpp:class:
OptimTensoris available inctx). The data buffer of the input is never inspected.- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0). On return it also contains an entry fornode.output(0).node – The
ShapeNodeProtowhose output should be described.node.op_type()must be"Shape";nodemust declare one input and at least one output.
- Throws:
-
void ComputeShapeSize(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aSizenode and stores it inctx.Sizereturns a 0-D (scalar) INT64 tensor whose single value is the total number of elements of the input tensor (the product of its dimensions). The output shape is therefore always known (the empty shape); the scalar value is also recorded as a single-elementValueAsShapewhen every input dimension is a concrete (non-symbolic) value, so that downstream operators can propagate it.- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0). On return it also contains an entry fornode.output(0).node – The
SizeNodeProtowhose output should be described.node.op_type()must be"Size";nodemust declare one input and at least one output.
- Throws:
-
void ComputeShapeIdentity(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof anIdentitynode and stores it inctx.Identitycopies its single input verbatim, so the output has the same dtype and shape as the input.
-
void ComputeShapeGather(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aGathernode and stores it inctx.Gatherindexes thedatatensor alongaxisusing the integerindicestensor. The output has rankq + (r - 1)wherer = rank(data)andq = rank(indices); concretely the output shape isdata.shape[:axis] + indices.shape + data.shape[axis+1:]. The output dtype matches the dtype ofdata(type constraintT).
-
void ComputeShapeGatherElements(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aGatherElementsnode and stores it inctx.The output has the same shape as
indicesand the same dtype asdata.
-
void ComputeShapeGatherND(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aGatherNDnode and stores it inctx.The output has rank
q + r - indices_shape[-1] - 1 - bwherebis thebatch_dimsattribute (defaulting to0); concretely the output shape isindices.shape[:-1] + data.shape[b + indices.shape[-1]:].
-
void ComputeShapeScatterElements(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aScatterElementsnode and stores it inctx.The output has the same shape and dtype as
data.
-
void ComputeShapeScatter(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof a deprecatedScatternode and stores it inctx.The output has the same shape and dtype as
data.
-
void ComputeShapeScatterND(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aScatterNDnode and stores it inctx.The output has the same shape and dtype as
data.
-
void ComputeShapeTensorScatter(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aTensorScatternode and stores it inctx.TensorScatterwrites slices ofupdateinto a copy ofpast_cachealong the sequenceaxisand produces an output with the same dtype and the same shape aspast_cache. The dimensions ofupdatemust matchpast_cacheon every axis other thanaxisand be<=the correspondingpast_cachedimension onaxis; the optionalwrite_indicesinput must be a rank-1 tensor of lengthbatch_size.- Parameters:
ctx – In/out context. Must already contain entries for
node.input(0)(past_cache) andnode.input(1)(update);node.input(2)(write_indices) is optional. On return it also contains an entry fornode.output(0).node – The
TensorScatterNodeProtowhose output should be described.node.op_type()must be"TensorScatter",nodemust declare at least two inputs and at least one output, and the inputs must have the same rank>= 2.
- Throws:
-
void ComputeShapeTrilu(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aTrilunode and stores it inctx.Trilureturns the upper (upperattribute = 1, the default) or lower (upper= 0) triangular part of the input tensor; the optionalkinput shifts the diagonal. The output has the same dtype and the same shape asnode.input(0); the optionalkinput is not consulted for shape inference (its value only affects element values, not the result shape).- Parameters:
ctx – In/out context. Must already contain an entry for
node.input(0). On return it also contains an entry fornode.output(0).node – The
TriluNodeProtowhose output should be described.node.op_type()must be"Trilu",nodemust declare at least one input and at least one output, and the rank of the input must be>= 2.
- Throws:
-
void ComputeShapeCenterCropPad(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aCenterCropPadnode (since opset 18) and stores it inctx.The output has the same dtype as
node.input(0)and the same rank as the input. The output dimensions are taken from theshapeinput (input(1)) for axes listed in the optionalaxesattribute (or all axes whenaxesis absent); other axes keep the input dimension. Whenshapeis not available as a known value, the affected output dimensions become symbolic.- Parameters:
ctx – In/out context. Must already contain entries for
node.input(0)(input_data) andnode.input(1)(shape). On return it also contains an entry fornode.output(0).node – The
CenterCropPadNodeProtowhose output should be described.node.op_type()must be"CenterCropPad",nodemust declare two inputs and at least one output.
- Throws:
-
void ComputeShapeReverseSequence(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aReverseSequencenode and stores it inctx.ReverseSequencereverses the firstsequence_lens[i]elements of each slice along the time axis. The output has the same dtype and the same shape asnode.input(0); thesequence_lensinput only affects element values, not the result shape.- Parameters:
ctx – In/out context. Must already contain entries for
node.input(0)(input) andnode.input(1)(sequence_lens). On return it also contains an entry fornode.output(0).node – The
ReverseSequenceNodeProtowhose output should be described.node.op_type()must be"ReverseSequence",nodemust declare two inputs and at least one output, and the rank of the first input must be>= 2while the rank ofsequence_lensmust be exactly 1.
- Throws:
-
void ComputeShapeCompress(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aCompressnode and stores it inctx.When the
axisattribute is present the output has the same rank and dtype asnode.input(0)but with the axis dimension replaced by a symbolic dimension (the number oftrueentries inconditionis a runtime value). Whenaxisis absent the input is conceptually flattened and the output is a 1-D tensor of symbolic length.- Parameters:
ctx – In/out context. Must already contain entries for
node.input(0)(input) andnode.input(1)(condition). On return it also contains an entry fornode.output(0).node – The
CompressNodeProtowhose output should be described.node.op_type()must be"Compress"andnodemust declare at least two inputs and one output.
- Throws:
-
void ComputeShapeSplit(ShapesContext &ctx, const NodeProto &node)#
Computes the per-output :cpp:class:
OptimTensorof aSplitnode and stores them inctx.Splitdividesinputalongaxisintonode.output_size()tensors. The split sizes are taken from (in order of priority):the
splitinput (opset 13 and above) when present and known as an initializer value;the
splitattribute (opset 1, 2 and 11) when present;the
num_outputsattribute (opset 18+) when present;otherwise the input dimension is divided evenly into
node.output_size()chunks (with the last chunk taking the remainder).
Each output has the same rank, dtype, and dimensions as
input, except alongaxiswhere the dimension equals the resolved split size when known. When the split sizes are unknown (for example because thesplitinput is dynamic) the per-outputaxisdimension is set to a fresh symbolic dimension.- Parameters:
ctx – In/out context. Must already contain entries for every name in
node.input. On return it also contains entries for every named output.node – The
SplitNodeProtowhose outputs should be described.node.op_type()must be"Split"andnodemust declare at least one input and one output.
- Throws:
-
void ComputeShapeConcat(ShapesContext &ctx, const NodeProto &node)#
-
namespace tensor#
-
namespace shapes
-
namespace onnx_optim