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 (a TensorProto::DataType integer). Throws std::invalid_argument for unsupported types.

void FillValueInfo(const Tensor &tensor, ValueInfoProto &vi)#

Fills vi with the type/shape information described by tensor. vi.name is set to tensor.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#
inline Tensor(std::string n, int32_t dt, std::vector<int64_t> s, std::vector<uint8_t> d)#
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. Throws std::invalid_argument for unsupported types.

template<typename T>
const T *As() const#

Typed views over the underlying data buffer. They throw if the requested type does not match data_type.

The templated As<T>() accessor is the generic version. The non-template AsFloat/AsDouble/AsInt32/AsInt64 are thin wrappers kept for source compatibility.

template<typename T>
T *As()#
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()#
const std::vector<std::string> &AsStrings() const#

Typed view over the underlying string_data buffer. Throws std::invalid_argument if data_type is not TensorProto::DataType::STRING.

std::vector<std::string> &AsStrings()#

Public Members

std::string name#

Optional name of the tensor (input/output name in the test model).

int32_t data_type = 0#

Element data type stored as a TensorProto::DataType integer value.

std::vector<int64_t> shape#

Tensor shape; an empty shape denotes a scalar (element_count == 1).

std::vector<uint8_t> data#

Raw element bytes in row-major little-endian layout.

Unused (empty) when data_type is TensorProto::DataType::STRING; in that case the element values are stored in string_data instead since UTF-8 strings are variable length and do not have a fixed byte stride compatible with this raw buffer.

std::vector<std::string> string_data#

String element values in row-major layout. Populated only when data_type is TensorProto::DataType::STRING; empty for all other element types.

Public Static Functions

static inline Tensor MakeString(std::string n, std::vector<int64_t> s, std::vector<std::string> sd)#

Constructs a STRING tensor whose elements live in string_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 throw std::invalid_argument if any dimension in shape is negative or if values.size() does not match prod(shape).

The templated From<T> factory is the generic version. The non-template FromFloat/FromDouble/FromInt32/FromInt64 are 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 STRING tensor whose elements are the provided UTF-8 strings (stored in string_data). Throws std::invalid_argument if any dimension in shape is negative or if values.size() does not match prod(shape).