tensor_util.h#
Tensor conversion helpers used by schema builders, including
onnx::ParseData() and onnx::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_NAMESPACE
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>