simple_tensor.h#
Defines
-
ONNX_LIGHT_DECLARE_TENSOR_ELEMENT_TYPE(CPP_TYPE, ENUM_VALUE)#
-
namespace ONNX_LIGHT_NAMESPACE
-
namespace onnx_backend_test
Functions
-
ONNX_LIGHT_DECLARE_TENSOR_ELEMENT_TYPE(float, TensorProto::DataType::FLOAT)#
-
ONNX_LIGHT_DECLARE_TENSOR_ELEMENT_TYPE(double, TensorProto::DataType::DOUBLE)#
-
ONNX_LIGHT_DECLARE_TENSOR_ELEMENT_TYPE(int32_t, TensorProto::DataType::INT32)#
-
ONNX_LIGHT_DECLARE_TENSOR_ELEMENT_TYPE(int64_t, TensorProto::DataType::INT64)#
-
size_t ElementSize(int32_t dtype)#
Returns the size in bytes of one element of
dtype(aTensorProto::DataTypeinteger). Throwsstd::invalid_argumentfor unsupported types.
-
void FillValueInfo(const Tensor &tensor, ValueInfoProto &vi)#
Fills
viwith the type/shape information described bytensor.vi.nameis set totensor.name.
-
struct Tensor#
- #include <simple_tensor.h>
Tensor — minimal runtime tensor used by backend test cases.
This struct is intentionally distinct from
TensorProto: it carries no protobuf wire dependency, owns its bytes in row-major little-endian layout, and is meant to be consumed directly by a runtime exercising a single backend test node case.Public Functions
-
Tensor() = default#
-
int64_t element_count() const#
Returns the product of all shape dimensions; 1 for an empty shape.
-
size_t element_size() const#
Returns the size in bytes of one element of
data_type. Throwsstd::invalid_argumentfor unsupported types.
-
template<typename T>
const T *As() const# Typed views over the underlying
databuffer. They throw if the requested type does not matchdata_type.The templated
As<T>()accessor is the generic version. The non-templateAsFloat/AsDouble/AsInt32/AsInt64are thin wrappers kept for source compatibility.
-
const float *AsFloat() const#
-
float *AsFloat()#
-
const double *AsDouble() const#
-
double *AsDouble()#
-
const int32_t *AsInt32() const#
-
int32_t *AsInt32()#
-
const int64_t *AsInt64() const#
-
int64_t *AsInt64()#
Public Members
-
int32_t data_type = 0#
Element data type stored as a
TensorProto::DataTypeinteger value.
-
std::vector<uint8_t> data#
Raw element bytes in row-major little-endian layout.
Unused (empty) when
data_typeisTensorProto::DataType::STRING; in that case the element values are stored instring_datainstead since UTF-8 strings are variable length and do not have a fixed byte stride compatible with this raw buffer.
Public Static Functions
-
static inline Tensor MakeString(std::string n, std::vector<int64_t> s, std::vector<std::string> sd)#
Constructs a
STRINGtensor whose elements live instring_data. Distinct from the bytes-based constructor so brace-enclosed{ ... }initializer lists at call sites are unambiguous.
-
template<typename T>
static Tensor From(const std::string &name, const std::vector<int64_t> &shape, const std::vector<T> &values)# Typed factories that construct a tensor of the given shape and copy the provided values into
data. They throwstd::invalid_argumentif any dimension inshapeis negative or ifvalues.size()does not matchprod(shape).The templated
From<T>factory is the generic version. The non-templateFromFloat/FromDouble/FromInt32/FromInt64are thin wrappers kept for source compatibility.
-
static Tensor FromFloat(const std::string &name, const std::vector<int64_t> &shape, const std::vector<float> &values)#
-
static Tensor FromDouble(const std::string &name, const std::vector<int64_t> &shape, const std::vector<double> &values)#
-
static Tensor FromInt32(const std::string &name, const std::vector<int64_t> &shape, const std::vector<int32_t> &values)#
-
static Tensor FromInt64(const std::string &name, const std::vector<int64_t> &shape, const std::vector<int64_t> &values)#
-
static Tensor FromStrings(const std::string &name, const std::vector<int64_t> &shape, const std::vector<std::string> &values)#
Constructs a
STRINGtensor whose elements are the provided UTF-8 strings (stored instring_data). Throwsstd::invalid_argumentif any dimension inshapeis negative or ifvalues.size()does not matchprod(shape).
-
Tensor() = default#
-
ONNX_LIGHT_DECLARE_TENSOR_ELEMENT_TYPE(float, TensorProto::DataType::FLOAT)#
-
namespace onnx_backend_test