sym_map.h#

Lightweight description of an ONNX map(K,V) value used by onnx_shapes shape-inference passes.

The onnx_shapes stack already exposes :cpp:class:SymTensor and :cpp:class:SymSequence to describe tensor- and sequence-typed values flowing through a graph. Operators such as ZipMap, CastMap or DictVectorizer (from the ai.onnx.ml domain) consume or produce map values, so a matching descriptor is needed.

:cpp:class:SymMap is the analogue of :cpp:class:SymTensor and :cpp:class:SymSequence for map values. An ONNX map(K,V) value associates scalar keys of a fixed key type (INT64 or STRING per the ONNX spec) with values of a fixed value type V. This descriptor records the key :cpp:type:TensorType, the value :cpp:type:TensorType, and the value’s :cpp:class:SymShape (for value types that are themselves tensors, e.g. map(int64, tensor) is not part of the ONNX spec today but the shape is kept for forward-compatibility with per-value tensor shapes).

Like :cpp:class:SymTensor and :cpp:class:SymSequence it is a small, value-typed, non-owning descriptor: it never allocates the underlying data.

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_NAMESPACE so both names resolve to the same namespace.

Symbol-visibility attribute for the public onnx-light C++ API.

Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when lib_onnx_proto uses hidden visibility by default.

Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal onnx namespace — rather than the ONNX_NAMESPACE macro — resolves to the onnx-light namespace. The standard onnx package lives in namespace onnx; onnx-light uses onnx_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 from onnx.

namespace core
namespace symbolic#
class SymMap#
#include <sym_map.h>

Descriptor for an ONNX map(K,V) value. A map carries a key :cpp:type:TensorType (conceptually INT64 or STRING per the ONNX spec, though this descriptor does not enforce that constraint) and a value :cpp:type:TensorType together with an optional :cpp:class:SymShape describing the shape of each value.

When the key or value dtype is not known (e.g. for the output of an operator whose map type depends on an attribute that has not been resolved yet), the descriptor stores :cpp:enumerator:TensorType::kUndefined for the corresponding field. Callers can use :cpp:func:HasKeyType and :cpp:func:HasValueDtype to distinguish “unknown” from “explicitly undefined”.

Public Functions

SymMap() = default#

Default constructs a map descriptor with unknown key type, unknown value dtype, and no recorded value shape.

inline SymMap(TensorType key_type, TensorType value_dtype, SymShape value_shape = SymShape())#

Constructs a map descriptor from a known key type, a known value dtype, and an optional value shape (defaults to a scalar, rank-0 shape).

inline TensorType KeyType() const noexcept#

Key type of the map. Returns :cpp:enumerator:TensorType::kUndefined when the key type is unknown (see :cpp:func:HasKeyType).

inline TensorType ValueDtype() const noexcept#

Value dtype of the map. Returns :cpp:enumerator:TensorType::kUndefined when the value dtype is unknown (see :cpp:func:HasValueDtype).

inline const SymShape &ValueShape() const noexcept#

Shape of each value stored in the map. Defaults to a scalar (rank-0) shape for the common case where values are single numbers or strings.

inline SymShape &ValueShape() noexcept#
inline bool HasKeyType() const noexcept#

true when a key type has been recorded for this map.

inline bool HasValueDtype() const noexcept#

true when a value dtype has been recorded for this map.

inline void SetKeyType(TensorType key_type) noexcept#

Replaces the recorded key type. Passing :cpp:enumerator:TensorType::kUndefined clears the key type.

inline void SetValueDtype(TensorType value_dtype) noexcept#

Replaces the recorded value dtype. Passing :cpp:enumerator:TensorType::kUndefined clears the value dtype.

inline void SetValueShape(SymShape value_shape)#

Replaces the recorded value shape.

inline bool operator==(const SymMap &other) const noexcept#

Equality compares the key type, the value dtype, the value shape, and the “known” flags.

inline bool operator!=(const SymMap &other) const noexcept#

Private Members

TensorType key_type_ = TensorType::kUndefined#
TensorType value_dtype_ = TensorType::kUndefined#
SymShape value_shape_ = {}#
bool has_key_type_ = false#
bool has_value_dtype_ = false#