shape_math.h#
Shape-inference functions for ONNX operators in the math 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 math#
Functions
-
void ComputeShapeAbs(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anAbsnode and stores it inctx.Absis element-wise and unary in every revision of its schema (v1, v6, v13 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
AbsNodeProtowhose output should be described.node.op_type()must be"Abs"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeNeg(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aNegnode and stores it inctx.Negis element-wise and unary in every revision of its schema (v1, v6, v13 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
NegNodeProtowhose output should be described.node.op_type()must be"Neg"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeAdd(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof anAddnode and stores it inctx.Addis element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 7; earlier revisions had an explicitbroadcastattribute but the shape propagation rules are identical when broadcasting is enabled, which onnx-light assumes). The output dtype matches the input dtype (both operands share the same type via theTtype constraint) and the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
AddNodeProtowhose output should be described.node.op_type()must be"Add"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeSub(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aSubnode and stores it inctx.Subis element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 7). The output dtype matches the input dtype (both operands share the same type via theTtype constraint) and the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
SubNodeProtowhose output should be described.node.op_type()must be"Sub"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeMul(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aMulnode and stores it inctx.Mulis element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 7). The output dtype matches the input dtype (both operands share the same type via theTtype constraint) and the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
MulNodeProtowhose output should be described.node.op_type()must be"Mul"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapePow(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aPownode and stores it inctx.Powis element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 7). The output dtype matches the first input dtype and the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
PowNodeProtowhose output should be described.node.op_type()must be"Pow"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapePRelu(ShapesContext &ctx, const NodeProto &node, const char *x, const char *slope)#
Computes the output :cpp:class:
OptimTensorof aPRelunode and stores it inctx.PReluis element-wise binary, with theslopeoperand unidirectionally broadcastable to theXoperand (since opset 7). The output dtype matches the input dtype (both operands share the same type via theTtype constraint) and the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
xandslope; on return it also contains an entry fornode.output(0).node – The
PReluNodeProtowhose output should be described.node.op_type()must be"PRelu"andnodemust declare at least one output.x – Name of the
Xinput to read fromctx.slope – Name of the
slopeinput to read fromctx.
- Throws:
-
void ComputeShapeDiv(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aDivnode and stores it inctx.Divis element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 7). The output dtype matches the input dtype (both operands share the same type via theTtype constraint) and the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
DivNodeProtowhose output should be described.node.op_type()must be"Div"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeMod(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aModnode and stores it inctx.Modis element-wise and binary, with numpy-style multidirectional broadcasting between its two operands (since opset 13). The output dtype matches the input dtype (both operands share the same type via theTtype constraint) and the output shape is the broadcast of the two input shapes.- Parameters:
ctx – In/out context. Must already contain entries for both
aandb; on return it also contains an entry fornode.output(0).node – The
ModNodeProtowhose output should be described.node.op_type()must be"Mod"andnodemust declare at least one output.a – Name of the first input value to read from
ctx.b – Name of the second input value to read from
ctx.
- Throws:
-
void ComputeShapeMish(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aMishnode and stores it inctx.Mishis element-wise and unary: the output dtype and shape match the input.
-
void ComputeShapeAcos(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anAcosnode and stores it inctx.Acosis element-wise and unary in every revision of its schema (v7, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
AcosNodeProtowhose output should be described.node.op_type()must be"Acos"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeAcosh(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anAcoshnode and stores it inctx.Acoshis element-wise and unary in every revision of its schema (v9, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
AcoshNodeProtowhose output should be described.node.op_type()must be"Acosh"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeAsin(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anAsinnode and stores it inctx.Asinis element-wise and unary in every revision of its schema (v7, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
AsinNodeProtowhose output should be described.node.op_type()must be"Asin"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeAsinh(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anAsinhnode and stores it inctx.Asinhis element-wise and unary in every revision of its schema (v9, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
AsinhNodeProtowhose output should be described.node.op_type()must be"Asinh"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeAtan(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anAtannode and stores it inctx.Atanis element-wise and unary in every revision of its schema (v7, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
AtanNodeProtowhose output should be described.node.op_type()must be"Atan"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeAtanh(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof anAtanhnode and stores it inctx.Atanhis element-wise and unary in every revision of its schema (v9, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
AtanhNodeProtowhose output should be described.node.op_type()must be"Atanh"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeCos(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aCosnode and stores it inctx.Cosis element-wise and unary in every revision of its schema (v7, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
CosNodeProtowhose output should be described.node.op_type()must be"Cos"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeCosh(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aCoshnode and stores it inctx.Coshis element-wise and unary in every revision of its schema (v9, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.- Parameters:
ctx – In/out context. Must already contain an entry for
x; on return it also contains an entry fornode.output(0).node – The
CoshNodeProtowhose output should be described.node.op_type()must be"Cosh"andnodemust declare at least one output.x – Name of the input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeExp(ShapesContext &ctx, const NodeProto &node, const char *x)#
Exp is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeErf(ShapesContext &ctx, const NodeProto &node, const char *x)#
Erf is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeSign(ShapesContext &ctx, const NodeProto &node, const char *x)#
Sign is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeGemm(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aGemmnode and stores it inctx.GemmcomputesY = alpha * A' * B' + beta * Cwhere the transposition flagstransA/transBare read from the node attributes (both default to0). A must be 2-D and B must be 2-D; withtransA=0A has shape(M, K)and withtransA=1it has shape(K, M). SimilarlytransB=0gives B shape(K, N)andtransB=1gives(N, K). The output Y has shape(M, N)and the same dtype as A.- Parameters:
ctx – In/out context. Must already contain entries for
aandb; on return it also contains an entry fornode.output(0).node – The
GemmNodeProtowhose output should be described.node.op_type()must be"Gemm"andnodemust declare at least one output.a – Name of the A input value to read from
ctx.b – Name of the B input value to read from
ctx.
- Throws:
-
void ComputeShapeMatMul(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aMatMulnode and stores it inctx.MatMulfollows NumPy matmul rules:rank-1 x rank-1 -> scalar
rank-2 x rank-2 -> matrix
higher-rank prefixes are broadcast, then matrix multiply is applied on the trailing two dimensions.
-
void ComputeShapeMatMulInteger(ShapesContext &ctx, const NodeProto &node, const char *a, const char *b)#
Computes the output :cpp:class:
OptimTensorof aMatMulIntegernode and stores it inctx.The shape rule matches :cpp:func:
ComputeShapeMatMulapplied to the inputsA(input 0) andB(input 1). The output dtype is always :cpp:enumerator:TensorType::kInt32.
-
void ComputeShapeLog(ShapesContext &ctx, const NodeProto &node, const char *x)#
Log is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeDet(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aDetnode and stores it inctx.Dettakes one input of shape[*, M, M](rank >= 2) and produces an output of shape[*]containing the determinants of all input submatrices. The output dtype matches the input dtype.
-
void ComputeShapeSigmoid(ShapesContext &ctx, const NodeProto &node, const char *x)#
Sigmoid is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeSwish(ShapesContext &ctx, const NodeProto &node, const char *x)#
Swish is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeSoftmax(ShapesContext &ctx, const NodeProto &node, const char *x)#
Softmax preserves dtype/shape and validates the axis attribute.
-
void ComputeShapeLogSoftmax(ShapesContext &ctx, const NodeProto &node, const char *x)#
LogSoftmax preserves dtype/shape and validates the axis attribute.
-
void ComputeShapeHardmax(ShapesContext &ctx, const NodeProto &node, const char *x)#
Hardmax preserves dtype/shape and validates the axis attribute.
-
void ComputeShapeHardSigmoid(ShapesContext &ctx, const NodeProto &node, const char *x)#
HardSigmoid is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeHardSwish(ShapesContext &ctx, const NodeProto &node, const char *x)#
HardSwish is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeSoftplus(ShapesContext &ctx, const NodeProto &node, const char *x)#
Softplus is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeSoftsign(ShapesContext &ctx, const NodeProto &node, const char *x)#
Softsign is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeSoftmaxCrossEntropyLoss(ShapesContext &ctx, const NodeProto &node, const char *scores, const char *labels, const char *weights)#
Computes the output
OptimTensor(s) of aSoftmaxCrossEntropyLossnode and stores them inctx.Inputs are
scores(shape(N, C)or(N, C, D1, ..., Dk)),labels(shape(N)or(N, D1, ..., Dk)), and optionallyweights(shape(C)). The first outputoutputhas the loss shape:(N, D1, ..., Dk)whenreduction = "none"and a scalar otherwise. The optional second outputlog_probhas the same shape and dtype asscores.
-
void ComputeShapeNegativeLogLikelihoodLoss(ShapesContext &ctx, const NodeProto &node, const char *input, const char *target, const char *weight)#
Computes the output
OptimTensorof aNegativeLogLikelihoodLossnode and stores it inctx.Inputs are
input(shape(N, C)or(N, C, D1, ..., Dk)),target(shape(N)or(N, D1, ..., Dk)), and optionallyweight(shape(C)). The single outputlosshas shape(N, D1, ..., Dk)whenreduction = "none"and is a scalar otherwise. The output dtype matches the dtype ofinput.
-
void ComputeShapeSin(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aSinnode and stores it inctx.Sinis element-wise and unary in every revision of its schema (v7, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.
-
void ComputeShapeReciprocal(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aReciprocalnode and stores it inctx.Reciprocalis element-wise and unary in every revision of its schema (v1, v6, v13 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.
-
void ComputeShapeSinh(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aSinhnode and stores it inctx.Sinhis element-wise and unary in every revision of its schema (v9, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.
-
void ComputeShapeSqrt(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aSqrtnode and stores it inctx.Sqrtis element-wise and unary in every revision of its schema (v1, v6, v13 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.
-
void ComputeShapeTan(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aTannode and stores it inctx.Tanis element-wise and unary in every revision of its schema (v7, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.
-
void ComputeShapeTanh(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aTanhnode and stores it inctx.Tanhis element-wise and unary in every revision of its schema (v1, v6, v13 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.
-
void ComputeShapeThresholdedRelu(ShapesContext &ctx, const NodeProto &node, const char *x)#
ThresholdedRelu is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeRelu(ShapesContext &ctx, const NodeProto &node, const char *x)#
Relu is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeLeakyRelu(ShapesContext &ctx, const NodeProto &node, const char *x)#
LeakyRelu is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeElu(ShapesContext &ctx, const NodeProto &node, const char *x)#
Elu is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeCelu(ShapesContext &ctx, const NodeProto &node, const char *x)#
Celu is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeGelu(ShapesContext &ctx, const NodeProto &node, const char *x)#
Gelu is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeSelu(ShapesContext &ctx, const NodeProto &node, const char *x)#
Selu is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeShrink(ShapesContext &ctx, const NodeProto &node, const char *x)#
Shrink is element-wise unary: output dtype and shape match the input.
-
void ComputeShapeFloor(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aFloornode and stores it inctx.Flooris element-wise and unary in every revision of its schema (v1, v6, v13 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.
-
void ComputeShapeCeil(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aCeilnode and stores it inctx.Ceilis element-wise and unary in every revision of its schema (v1, v6, v13 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.
-
void ComputeShapeClip(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aClipnode and stores it inctx.Clipis element-wise; the optionalminandmaxinputs are scalars (or in v1/v6 schema attributes) that do not influence the output shape or dtype, which always match the inputx.
-
void ComputeShapeRound(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aRoundnode and stores it inctx.Roundis element-wise and unary in every revision of its schema (v11, v22 — later revisions only widen the accepted dtype set), so the output dtype and shape always match those of the input.
-
void ComputeShapeEinsum(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof anEinsumnode (opset 12) and stores it inctx.Einsumevaluates the Einstein summation expressed by theequationattribute over the variadic input tensors. The equation may contain an ellipsis (...) to broadcast leading dimensions, and may be given either in explicit form (->followed by the output term) or implicit form. The output dtype is the dtype of the first input.- Parameters:
ctx – In/out context. Must already contain entries for every value listed in
node.input; on return it also contains an entry fornode.output(0).node – The
EinsumNodeProtowhose output should be described.node.op_type()must be"Einsum",nodemust declare at least one input and one output, and must carry anequationSTRING attribute.
- Throws:
-
void ComputeShapeSum(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aSumnode and stores it inctx.Sumis a variadic element-wise operator: every input must share the same float dtype (type constraintT); since opset 8 the inputs may have different shapes that follow NumPy-style multidirectional broadcasting rules (earlier opsets required identical shapes, which is a strict subset). The output dtype matches the inputs’ shared dtype and the output shape is the broadcast of all input shapes. Reads the descriptors of every input fromctxand stores the result undernode.output(0).- Parameters:
ctx – In/out context. Must already contain entries for every value listed in
node.input; on return it also contains an entry fornode.output(0).node – The
SumNodeProtowhose output should be described.node.op_type()must be"Sum"andnodemust declare at least one input and at least one output.
- Throws:
-
void ComputeShapeMax(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aMaxnode and stores it inctx.Max(opsets 1-13) is a variadic element-wise maximum operator. Since opset 8 it supports NumPy-style multidirectional broadcasting; in earlier opsets all inputs are required to share the same shape. The output dtype always matches that of the first input, and the output shape is the multidirectional broadcast of every input shape.- Parameters:
ctx – In/out context. Must already contain entries for every input of
node. On return it also contains an entry fornode.output(0).node – The
MaxNodeProtowhose output should be described.node.op_type()must be"Max"andnodemust declare at least one input and at least one output.
- Throws:
-
void ComputeShapeMin(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aMinnode and stores it inctx.Min(opsets 1-13) is a variadic element-wise minimum operator. Since opset 8 it supports NumPy-style multidirectional broadcasting; in earlier opsets all inputs are required to share the same shape. The output dtype always matches that of the first input, and the output shape is the multidirectional broadcast of every input shape.- Parameters:
ctx – In/out context. Must already contain entries for every input of
node. On return it also contains an entry fornode.output(0).node – The
MinNodeProtowhose output should be described.node.op_type()must be"Min"andnodemust declare at least one input and at least one output.
- Throws:
-
void ComputeShapeMean(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aMeannode and stores it inctx.Mean(opsets 1, 6, 8 and 13) is a variadic element-wise mean operator. Since opset 8 it supports NumPy-style multidirectional broadcasting; in earlier opsets all inputs are required to share the same shape. The output dtype always matches that of the first input (the type constraintTforces every input to share the same float dtype), and the output shape is the multidirectional broadcast of every input shape.- Parameters:
ctx – In/out context. Must already contain entries for every input of
node. On return it also contains an entry fornode.output(0).node – The
MeanNodeProtowhose output should be described.node.op_type()must be"Mean"andnodemust declare at least one input and at least one output.
- Throws:
-
void ComputeShapeCumSum(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aCumSumnode and stores it inctx.CumSum(opsets 11 and 14) is a unary running-sum operator along an axis selected by a second 0-Daxisinput tensor. The output dtype and shape always match those of the first inputx; theaxis,exclusiveandreverseparameters affect values only.- Parameters:
ctx – In/out context. Must already contain an entry for
x(the data input). On return it also contains an entry fornode.output(0).node – The
CumSumNodeProtowhose output should be described.node.op_type()must be"CumSum"andnodemust declare at least one output.x – Name of the data input value to read from
ctx.
- Throws:
-
void ComputeShapeCumProd(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorof aCumProdnode and stores it inctx.CumProd(opset 26) is a unary running-product operator along an axis selected by a second 0-Daxisinput tensor. The output dtype and shape always match those of the first inputx.- Parameters:
ctx – In/out context. Must already contain an entry for
x(the data input). On return it also contains an entry fornode.output(0).node – The
CumProdNodeProtowhose output should be described.node.op_type()must be"CumProd"andnodemust declare at least one output.x – Name of the data input value to read from
ctx.
- Throws:
-
void ComputeShapeTopK(ShapesContext &ctx, const NodeProto &node, const char *x)#
Computes the output :cpp:class:
OptimTensorentries of aTopKnode and stores them inctx.TopKreturns two outputs that share the same shape:Valueshas the same dtype as the inputxand shapex.shapewith theaxisdimension replaced byk.Indiceshas dtypeINT64and the same shape asValues.
In opset 1 the number
kis read from the required integer attributek. In opsets 10 and 11kis supplied as a 1-D tensor input; because :class:OptimTensordoes not always carry concrete data, the axis dimension is emitted as a symbolic dimension (TopK_<output>_k) whenkcannot be resolved from a constant.- Parameters:
ctx – In/out context. Must already contain an entry for the data input
x. On return it also contains entries fornode.output(0)and (when present)node.output(1).node – The
TopKNodeProtowhose outputs should be described.node.op_type()must be"TopK"andnodemust declare at least one output.x – Name of the data input value to read from
ctx.
- Throws:
-
void ComputeShapeDFT(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aDFTnode and stores it inctx.DFT(since opset 17;axismoved from attribute to input at opset 20) returns a tensor of the same rank asnode.input(0). Its trailing dimension is1whenonesidedandinverseare both set (IRFFT) and2otherwise. The signal axis dimension is replaced bydft_length(orfloor(dft_length/2)+1for RFFT) when thedft_lengthinput is a known scalar constant; it is left symbolic otherwise. The non-signal/non-trailing dimensions are copied from the input.- 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
DFTNodeProtowhose output should be described.node.op_type()must be"DFT"andnodemust declare at least one input and one output.
- Throws:
-
void ComputeShapeSTFT(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof anSTFTnode and stores it inctx.STFT(opset 17) returns a rank-4 tensor with shape[batch_size, n_frames, dft_unique_bins, 2]wheren_frames = (signal_length - frame_length) / frame_step + 1anddft_unique_binsisfloor(frame_length / 2) + 1whenonesidedis enabled (its default) orframe_lengthotherwise. Thesignal_length,frame_stepandframe_length(or window length) may be unknown at shape-inference time; in that case the corresponding dimension 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
STFTNodeProtowhose output should be described.node.op_type()must be"STFT"andnodemust declare at least two inputs (signal, frame_step) and one output.
- Throws:
-
void ComputeShapeAbs(ShapesContext &ctx, const NodeProto &node, const char *x)#
-
namespace math#
-
namespace shapes
-
namespace onnx_optim