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::OpsetVersion when no opset version has been recorded for the requested domain.

constexpr const char *kOnnxDomain = "ai.onnx"#

Canonical domain string used for the standard ONNX operator set (ai.onnx). An empty domain on a NodeProto is treated as equivalent to this value.

class ShapesContext#
#include <shapes_context.h>

Lightweight container shared by the per-operator ComputeShape* shape-inference functions. ShapesContext carries two pieces of information:

  • a name OptimTensor map describing every named value (graph input, initializer or intermediate result) currently known to the shape-inference pass;

  • a name OptimSequence map describing every named sequence-typed value (the output of SequenceConstruct, SequenceEmpty, SplitToSequence, …);

  • a domain opset_version map mirroring the opset_import entries of the surrounding ModelProto, so that ComputeShape* 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:OptimTensor values 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. tensor is consumed; callers must pass an rvalue (use std::move).

inline void Set(const char *name, OptimTensor &&tensor)#

Overload: name given as a null-terminated C string.

inline void Set(const utils::String &name, OptimTensor &&tensor)#

Overload: name given as a :cpp:class:utils::String.

inline bool Has(const std::string &name) const#

Returns true when an entry exists for name.

inline const OptimTensor &Get(const std::string &name) const#

Returns the descriptor for name. Throws std::out_of_range if no such entry exists.

inline std::size_t Size() const noexcept#

Number of named entries currently stored.

inline bool Empty() const noexcept#

true when 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. sequence is consumed; callers must pass an rvalue (use std::move).

inline void SetSequence(const char *name, OptimSequence &&sequence)#

Overload: name given as a null-terminated C string.

inline void SetSequence(const utils::String &name, OptimSequence &&sequence)#

Overload: name given as a :cpp:class:utils::String.

inline bool HasSequence(const std::string &name) const#

Returns true when a sequence-typed entry exists for name.

inline const OptimSequence &GetSequence(const std::string &name) const#

Returns the sequence descriptor for name. Throws std::out_of_range if 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 empty domain is normalised to :cpp:var:kOnnxDomain. Replaces any previous entry for the same domain.

inline bool HasOpsetVersion(const std::string &domain) const#

true when an opset version has been recorded for domain (after normalising the empty domain to :cpp:var:kOnnxDomain).

inline int OpsetVersion(const std::string &domain) const#

Returns the recorded opset version of domain, or :cpp:var:kUnknownOpsetVersion if none was recorded. An empty domain is normalised to :cpp:var:kOnnxDomain.

inline const std::unordered_map<std::string, int> &Opsets() const noexcept#

Read-only access to the underlying domain opset_version map.

Private Members

std::unordered_map<std::string, OptimTensor> tensors_#
std::unordered_map<std::string, OptimSequence> sequences_#
std::unordered_map<std::string, int> opsets_#

Private Static Functions

static inline std::string NormaliseDomain(const std::string &domain)#