shape_reduction.h#
Shape-inference functions for ONNX operators in the reduction 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 reduction#
Functions
-
void ComputeShapeReduceSum(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceSumnode and stores it inctx.ReduceSumreduces the input tensor along a set of axes. The output dtype always matches the input dtype (type constraintT); the output shape is the input shape with the reduced axes either dropped (keepdims=0) or replaced by1(keepdims=1, the default).The way axes are specified depends on the opset:
opset < 13:
axesis a repeated INTS attribute. If absent every dimension is reduced.opset >= 13:
axesis an optional second input. When the input is missing or empty the behaviour is controlled by thenoop_with_empty_axesattribute (default0):0means reduce all axes,1means identity (no axes reduced).When the
axesinput is provided this function looks at the :cpp:func:OptimTensor::ValueAsShapeannotation ofaxesto identify the reduced axes. If the annotation is missing the output rank can still be inferred whenkeepdims=1(same rank as the input, with each previously-known dimension kept as is and reduced positions left symbolic) or when the number of axes is known via the shape ofaxes(keepdims=0: output rank = input rank − number of axes, with every dimension marked symbolic).
- Parameters:
ctx – In/out context. Must already contain an entry for
dataand, when provided and non-empty,axes. On return it also contains an entry fornode.output(0).node – The
ReduceSumNodeProtowhose output should be described.node.op_type()must be"ReduceSum"andnodemust declare at least one output.data – Name of the data input value to read from
ctx. Must be present inctx.axes – Name of the axes input value to read from
ctxfor opset >= 13, ornullptr/ empty string when the axes input is omitted (use the attribute / default “reduce all” behaviour). For opset < 13 the value is ignored and theaxesattribute is consulted.
- Throws:
-
void ComputeShapeReduceMax(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceMaxnode. Shape/attribute semantics are the same as :cpp:func:ComputeShapeReduceSumand the output dtype matches the input dtype.
-
void ComputeShapeReduceMin(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceMinnode. Shape/attribute semantics are the same as :cpp:func:ComputeShapeReduceSumand the output dtype matches the input dtype.
-
void ComputeShapeReduceL1(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceL1node. Shape/attribute semantics are the same as :cpp:func:ComputeShapeReduceSumand the output dtype matches the input dtype.
-
void ComputeShapeReduceL2(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceL2node. Shape/attribute semantics are the same as :cpp:func:ComputeShapeReduceSumand the output dtype matches the input dtype.
-
void ComputeShapeReduceSumSquare(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceSumSquarenode. Shape/attribute semantics are the same as :cpp:func:ComputeShapeReduceSumand the output dtype matches the input dtype.
-
void ComputeShapeReduceLogSum(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceLogSumnode. Shape/attribute semantics are the same as :cpp:func:ComputeShapeReduceSumand the output dtype matches the input dtype.
-
void ComputeShapeReduceLogSumExp(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceLogSumExpnode. Shape/attribute semantics are the same as :cpp:func:ComputeShapeReduceSumand the output dtype matches the input dtype.
-
void ComputeShapeReduceProd(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceProdnode. Shape/attribute semantics are the same as :cpp:func:ComputeShapeReduceSumand the output dtype matches the input dtype.
-
void ComputeShapeReduceMean(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
Computes the output :cpp:class:
OptimTensorof aReduceMeannode. Shape/attribute semantics are the same as :cpp:func:ComputeShapeReduceSumand the output dtype matches the input dtype.
-
void ComputeShapeArgReduce(ShapesContext &ctx, const NodeProto &node, const char *data)#
Computes the output :cpp:class:
OptimTensorof anArgMaxorArgMinnode and stores it inctx.ArgMax/ArgMinreduce the input tensor along a singleaxis(attribute, default0; accepts negative values from opset 11). The output dtype is alwaystensor(int64)(independent of the input dtype); the output shape is the input shape with the reduced axis either dropped (keepdims=0) or replaced by1(keepdims=1, the default).The
select_last_indexattribute introduced in opset 12 does not affect the output shape and is therefore ignored here.- Parameters:
ctx – In/out context. Must already contain an entry for
data. On return it also contains an entry fornode.output(0).node – The
ArgMaxorArgMinNodeProtowhose output should be described.node.op_type()must be either"ArgMax"or"ArgMin"andnodemust declare at least one output.data – Name of the data input value to read from
ctx. Must be present inctx.
- Throws:
-
void ComputeShapeReduceSum(ShapesContext &ctx, const NodeProto &node, const char *data, const char *axes)#
-
namespace reduction#
-
namespace shapes
-
namespace onnx_optim