shape_generator.h#
Shape-inference functions for ONNX operators in the generator family.
-
namespace ONNX_LIGHT_NAMESPACE
-
namespace onnx_optim
-
namespace shapes
-
namespace generator#
Functions
-
void ComputeShapeConstant(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof aConstantnode and stores it inctx.Constantdeclares its output as the value of exactly one of the attributesvalue,sparse_value,value_int,value_ints,value_float,value_floats,value_stringorvalue_strings(which one is allowed depends on the schema revision, but for shape inference the union of every revision is accepted). The output dtype and shape are taken from the present attribute.When the resulting tensor carries at most :cpp:var:
kConstantValueAsShapeMaxElementsinteger elements and has rank at most one — i.e. it is small enough to plausibly be used later as a shape input of operators such asReshape,ExpandorConstantOfShape— its integer values are also recorded via :cpp:func:OptimTensor::SetValueAsShape. This mirrors the upstream ONNX shape-inference data-propagation behaviour for small integer constants.- Parameters:
ctx – In/out context. On return contains an entry for
node.output(0)describing the constant output.node – The
ConstantNodeProtowhose output should be described.node.op_type()must be"Constant"andnodemust declare at least one output.
- Throws:
std::invalid_argument – if
node.op_type()is not"Constant", ifnodehas no output, or if the attributes do not specify exactly one of the allowed value forms.
Variables
-
constexpr int64_t kConstantValueAsShapeMaxElements = 8#
Maximum element count of a
Constantvalue tensor for which :cpp:func:ComputeShapeConstantpopulates the output :cpp:func:OptimTensor::ValueAsShapeannotation. Constants beyond this threshold are not data-propagated (the output dtype and shape are still inferred normally).
-
void ComputeShapeConstant(ShapesContext &ctx, const NodeProto &node)#
-
namespace generator#
-
namespace shapes
-
namespace onnx_optim