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.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.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.
-
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>