optim_sequence.h#
Lightweight description of an ONNX tensor sequence value used by onnx_optim shape-inference passes.
The onnx_optim stack already exposes :cpp:class:OptimTensor to describe tensor-typed values flowing through a graph. Operators such as SequenceConstruct, SequenceInsert, SplitToSequence or SequenceEmpty produce sequence values rather than tensors, so a matching descriptor is needed.
:cpp:class:OptimSequence is the analogue of :cpp:class:OptimTensor for sequence values. It records the common element dtype and one :cpp:class:OptimShape per element of the sequence (the ONNX SequenceConstruct operator only requires that elements share the same dtype, not the same shape). The sequence length is itself an :cpp:class:OptimDim so it can be either a concrete integer (e.g. for a SequenceConstruct node with N known inputs) or a symbolic expression (e.g. for the output of SplitToSequence whose length depends on a runtime split value). When the per-element shapes are known, the length is implicitly :cpp:func:ElemShapes().size().
Like :cpp:class:OptimTensor it is a small, value-typed, non-owning descriptor: it never allocates the underlying data.
-
namespace ONNX_LIGHT_NAMESPACE
-
namespace onnx_optim#
-
class OptimSequence#
- #include <optim_sequence.h>
Descriptor for an ONNX tensor-sequence value. A sequence carries a common element :cpp:type:
TensorTypeand one :cpp:class:OptimShapeper element. The sequence length is itself an :cpp:class:OptimDimso it can be either a concrete integer (e.g. for aSequenceConstructnode withNknown inputs) or a symbolic expression (e.g. for the output ofSplitToSequencewhose length depends on a runtimesplitvalue).When the element dtype is not known (e.g. for the output of
SequenceEmptywhose dtype is set by an attribute or defaults toFLOAT, or forSequenceConstructwith zero inputs), the descriptor stores :cpp:enumerator:TensorType::kUndefinedfor the dtype. When the per-element shapes are unknown (typically for sequences whose length is itself symbolic), the descriptor stores no shapes at all and :cpp:func:HasElemShapesreturnsfalse. Callers can use :cpp:func:HasElemDtypeand :cpp:func:HasElemShapesto distinguish “unknown” from “empty sequence” (length 0).Public Functions
-
OptimSequence() = default#
Default constructs an empty sequence descriptor with unknown element dtype, no per-element shapes recorded, and a zero length.
-
inline OptimSequence(TensorType elem_dtype, std::vector<OptimShape> elem_shapes)#
Constructs a sequence descriptor from a known element dtype and a vector of per-element shapes. The sequence length is set to the number of supplied shapes.
-
inline OptimSequence(TensorType elem_dtype, OptimDim length)#
Constructs a sequence descriptor from a known element dtype and a (possibly symbolic) length. No per-element shape is recorded.
-
inline TensorType ElemDtype() const noexcept#
Element dtype shared by every tensor in the sequence. Returns :cpp:enumerator:
TensorType::kUndefinedwhen the dtype is unknown (see :cpp:func:HasElemDtype).
-
inline const std::vector<OptimShape> &ElemShapes() const noexcept#
Per-element shapes of the sequence. The returned vector is empty when :cpp:func:
HasElemShapesisfalse; otherwise its size is the (concrete) sequence length andElemShapes()[i]is the shape of thei-th tensor in the sequence.
-
inline std::vector<OptimShape> &ElemShapes() noexcept#
-
inline const OptimDim &Length() const noexcept#
Sequence length, possibly symbolic. When :cpp:func:
HasElemShapesistrue, the length equalsElemShapes().size().
-
inline bool HasElemDtype() const noexcept#
truewhen an element dtype has been recorded for this sequence.
-
inline bool HasElemShapes() const noexcept#
truewhen per-element shapes have been recorded for this sequence. An empty vector still returnstrueand denotes a sequence of length 0.
-
inline void SetElemDtype(TensorType dtype) noexcept#
Replaces the recorded element dtype. Passing :cpp:enumerator:
TensorType::kUndefinedclears the dtype.
-
inline void SetElemShapes(std::vector<OptimShape> shapes)#
Replaces the recorded per-element shapes. Also synchronises the sequence length with the number of supplied shapes.
-
inline void ClearElemShapes() noexcept#
Clears the recorded per-element shapes. The sequence length is left untouched.
-
inline void SetLength(OptimDim length) noexcept#
Replaces the sequence length. Callers are responsible for keeping the length consistent with :cpp:func:
ElemShapeswhen both are recorded.
-
inline bool operator==(const OptimSequence &other) const noexcept#
Equality compares the element dtype, the per-element shapes, the sequence length, and the “known” flags.
-
inline bool operator!=(const OptimSequence &other) const noexcept#
Private Members
-
TensorType elem_dtype_ = TensorType::kUndefined#
-
std::vector<OptimShape> elem_shapes_ = {}#
-
bool has_elem_dtype_ = false#
-
bool has_elem_shapes_ = false#
-
OptimSequence() = default#
-
class OptimSequence#
-
namespace onnx_optim#