shapes_context.h#
Name → :cpp:class:OptimTensor map shared by all onnx_optim shape-inference functions.
ShapesContext is the in/out parameter consumed and produced by the per-operator ComputeShape* functions (for example :cpp:func:ComputeShapeAbs). It holds the :cpp:class:OptimTensor descriptors of every named value (graph input, initializer or intermediate result) currently known to a shape-inference pass. ComputeShape* functions read the entries corresponding to a node’s inputs and insert new entries for the node’s outputs.
-
namespace ONNX_LIGHT_NAMESPACE
-
namespace onnx_optim
-
namespace shapes
Variables
-
constexpr int kUnknownOpsetVersion = -1#
Sentinel value returned by :cpp:func:
ShapesContext::OpsetVersionwhen no opset version has been recorded for the requested domain.
-
class ShapesContext#
- #include <shapes_context.h>
Lightweight container shared by the per-operator
ComputeShape*shape-inference functions.ShapesContextcarries two pieces of information:a
name → OptimTensormap describing every named value (graph input, initializer or intermediate result) currently known to the shape-inference pass;a
name → OptimSequencemap describing every named sequence-typed value (the output ofSequenceConstruct,SequenceEmpty,SplitToSequence, …);a
domain → opset_versionmap mirroring theopset_importentries of the surroundingModelProto, so thatComputeShape*functions can pick the correct schema revision when shape inference depends on the operator’s opset version.
The context is a thin wrapper and does not own any tensor data: the :cpp:class:
OptimTensorvalues stored here are themselves non-owning views.Public Functions
-
ShapesContext() = default#
-
inline void Set(const std::string &name, OptimTensor &&tensor)#
Inserts or replaces the descriptor for
name.tensoris consumed; callers must pass an rvalue (usestd::move).
-
inline void Set(const char *name, OptimTensor &&tensor)#
Overload:
namegiven as a null-terminated C string.
-
inline void Set(const utils::String &name, OptimTensor &&tensor)#
Overload:
namegiven as a :cpp:class:utils::String.
-
inline const OptimTensor &Get(const std::string &name) const#
Returns the descriptor for
name. Throwsstd::out_of_rangeif no such entry exists.
-
inline bool Empty() const noexcept#
truewhen no entries are stored.
-
inline void Clear() noexcept#
Removes every entry (both tensor descriptors and opset versions).
-
inline const std::unordered_map<std::string, OptimTensor> &Tensors() const noexcept#
Read-only access to the underlying map (useful for iteration).
-
inline void SetSequence(const std::string &name, OptimSequence &&sequence)#
Inserts or replaces the descriptor for a sequence-typed value named
name.sequenceis consumed; callers must pass an rvalue (usestd::move).
-
inline void SetSequence(const char *name, OptimSequence &&sequence)#
Overload:
namegiven as a null-terminated C string.
-
inline void SetSequence(const utils::String &name, OptimSequence &&sequence)#
Overload:
namegiven as a :cpp:class:utils::String.
-
inline bool HasSequence(const std::string &name) const#
Returns
truewhen a sequence-typed entry exists forname.
-
inline const OptimSequence &GetSequence(const std::string &name) const#
Returns the sequence descriptor for
name. Throwsstd::out_of_rangeif no such entry exists.
-
inline std::size_t SequencesSize() const noexcept#
Number of sequence-typed entries currently stored.
-
inline const std::unordered_map<std::string, OptimSequence> &Sequences() const noexcept#
Read-only access to the underlying sequence map (useful for iteration).
-
inline void SetOpsetVersion(const std::string &domain, int opset_version)#
Records the opset version of
domain. An emptydomainis normalised to :cpp:var:kOnnxDomain. Replaces any previous entry for the same domain.
-
inline bool HasOpsetVersion(const std::string &domain) const#
truewhen an opset version has been recorded fordomain(after normalising the empty domain to :cpp:var:kOnnxDomain).
Private Members
-
std::unordered_map<std::string, OptimTensor> tensors_#
-
std::unordered_map<std::string, OptimSequence> sequences_#
-
constexpr int kUnknownOpsetVersion = -1#
-
namespace shapes
-
namespace onnx_optim