shape_optional.h#
Shape-inference functions for ONNX operators in the optional 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 optional#
Functions
-
void ComputeShapeOptional(ShapesContext &ctx, const NodeProto &node)#
Computes the output :cpp:class:
OptimTensorof anOptionalnode and stores it inctx.Optional(since opset 15) wraps a value into an optional-type output. The wrapped element type is determined either by the input value (when an input is provided) or by thetypeTypeProtoattribute (when no input is provided). Since :cpp:class:OptimTensordoes not model optional or sequence types, this implementation only supports the tensor-element path: the output descriptor mirrors the dtype and shape of the wrapped tensor.Supported cases:
nodehas one input: the output dtype and shape are copied from the input descriptor stored inctx.nodehas no input and thetypeattribute wraps a tensor type (either directly or as theelem_typeof anoptional_type): the output dtype and shape are taken from the attribute.
- Parameters:
ctx – In/out context. When the node has an input,
ctxmust already contain an entry for it; on returnctxcontains an entry fornode.output(0).node – The
OptionalNodeProtowhose output should be described.node.op_type()must be"Optional"andnodemust declare exactly one output.
- Throws:
-
void ComputeShapeOptionalGetElement(ShapesContext &ctx, const NodeProto &node)#
Computes the output descriptor of an
OptionalGetElementnode and stores it inctx.OptionalGetElement(since opset 15 in theai.onnxdomain) extracts the element from an optional-type input. Since opset 18 the operator also accepts non-optional tensor or sequence inputs as a no-op. Because :cpp:class:OptimTensordoes not model optional values, this implementation forwards the input descriptor verbatim:if the input name is bound to an :cpp:class:
OptimSequenceinctx, the output is registered as the same sequence;otherwise the input must be bound to an :cpp:class:
OptimTensorand the output is registered as a tensor with the same dtype and 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
OptionalGetElementNodeProto.
- Throws:
-
void ComputeShapeOptionalHasElement(ShapesContext &ctx, const NodeProto &node)#
Computes the output descriptor of an
OptionalHasElementnode and stores it inctx.OptionalHasElement(since opset 15 in theai.onnxdomain) produces a scalar boolean tensor indicating whether the input optional contains an element. Since opset 18 the input may also be a non-optional tensor or sequence, and the input may be omitted entirely (in which case the output isfalse). The output is always a scalar :cpp:class:OptimTensorof dtype :cpp:enumerator:TensorType::kBool.- Parameters:
ctx – In/out context. On return it contains an :cpp:class:
OptimTensorentry fornode.output(0).node – The
OptionalHasElementNodeProto.
- Throws:
std::invalid_argument – if
node.op_type()is not"OptionalHasElement", ifnodedeclares more than one input or does not declare exactly one output.
-
void ComputeShapeOptional(ShapesContext &ctx, const NodeProto &node)#
-
namespace optional#
-
namespace shapes
-
namespace onnx_optim