tensor_util.h#
Tensor conversion helpers used by schema builders, including
onnx_light::ParseData() and onnx_light::ToTensor().
Declares tensor conversion helpers used by ONNX schema definitions.
This header provides utility templates to decode typed values from a Tensor wrapper and to construct TensorProto constants from scalar and vector C++ values.
-
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.
Maps the upstream compatibility macro to onnx-light’s explicit proto ABI annotation. This keeps declarations from vendored ONNX headers visible when
lib_onnx_protouses hidden visibility by default.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.Functions
-
template<typename T>
std::vector<T> ParseData(const TensorProto *tensor)# Extracts typed element data from a Tensor wrapper.
- Template Parameters:
T – Element type to decode.
- Parameters:
tensor – Source tensor wrapper.
- Returns:
A vector containing tensor data converted to T.
-
int64_t RawDataElementCount(const TensorProto &tensor, size_t element_size, bool exact_fit)#
Returns the element count implied by tensor dimensions after validating raw data size.
- Parameters:
tensor – Source tensor.
element_size – Size of one decoded element.
exact_fit – Whether raw data must contain exactly the implied number of elements.
- Returns:
The number of elements implied by the tensor dimensions.
-
template<typename T>
std::vector<T> ParseRawData(const TensorProto &tensor, bool exact_fit = false)# Decodes little-endian raw tensor data as values of type T.
- Template Parameters:
T – Arithmetic element type to decode.
- Parameters:
tensor – Source tensor.
exact_fit – Whether raw data must contain exactly the implied number of elements.
- Returns:
A vector containing the decoded elements.
-
template<typename T>
std::vector<T> ParseData(const Tensor *tensor)# Extracts typed element data from a Tensor wrapper.
- Template Parameters:
T – Element type to decode.
- Parameters:
tensor – Source tensor wrapper.
- Returns:
A vector containing tensor data converted to T.
-
template<typename T>
TensorProto ToTensor(const T &value)# Creates a scalar TensorProto from a C++ value.
- Template Parameters:
T – Scalar value type.
- Parameters:
value – Scalar value to encode.
- Returns:
A TensorProto containing one element.
-
template<typename T>
TensorProto ToTensor(const std::vector<T> &values)# Creates a 1D TensorProto from a vector of values.
- Template Parameters:
T – Element value type.
- Parameters:
values – Values to encode.
- Returns:
A TensorProto containing values in order.
-
inline TensorProto ToTensor(const TensorProto &tensor)#
Returns a TensorProto input unchanged.
- Parameters:
tensor – TensorProto to pass through.
- Returns:
tensor.
-
template<typename T>