tensor.h#

Defines

define_data(type, field)#
namespace ONNX_LIGHT_NAMESPACE

Functions

template<>
inline std::string *data<std::string>()#
template<>
inline const std::string *data<std::string>() const#
struct Tensor#
#include <tensor.h>

Stores an in-memory tensor payload and metadata.

Represents the ONNX tensor fields used by the lightweight parser, including dimensions, element type, typed repeated values, raw bytes, optional segment information, and external-data metadata.

Public Functions

inline const std::vector<int64_t> &sizes() const#

Returns the tensor dimensions.

inline std::vector<int64_t> &sizes()#

Returns mutable access to the tensor dimensions.

inline int64_t elem_num() const#

Returns the total number of elements.

inline int64_t size_from_dim(int dim) const#

Returns the number of elements from a given dimension to the end.

Parameters:

dimDimension index, supports negative indexing from the back.

inline int32_t elem_type() const#

Returns the ONNX element type.

inline int32_t &elem_type()#

Returns mutable access to the ONNX element type.

inline std::vector<std::string> &strings()#

Returns mutable access to string tensor values.

inline const std::vector<std::string> &strings() const#

Returns string tensor values.

inline std::vector<float> &floats()#

Returns mutable access to float tensor values.

inline const std::vector<float> &floats() const#

Returns float tensor values.

inline std::vector<double> &doubles()#

Returns mutable access to double tensor values.

inline const std::vector<double> &doubles() const#

Returns double tensor values.

inline std::vector<int32_t> &int32s()#

Returns mutable access to int32 tensor values.

inline const std::vector<int32_t> &int32s() const#

Returns int32 tensor values.

inline std::vector<int64_t> &int64s()#

Returns mutable access to int64 tensor values.

inline const std::vector<int64_t> &int64s() const#

Returns int64 tensor values.

inline std::vector<uint64_t> &uint64s()#

Returns mutable access to uint64 tensor values.

inline const std::vector<uint64_t> &uint64s() const#

Returns uint64 tensor values.

inline const std::string &raw() const#

Returns raw tensor bytes.

inline void set_raw_data(std::string raw_data)#

Sets raw tensor bytes and marks the tensor as raw-backed.

Parameters:

raw_data – Raw tensor payload.

template<typename T>
T *data()#

Returns a mutable pointer to typed tensor data.

Template Parameters:

T – Element type to access.

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

Returns a const pointer to typed tensor data.

Template Parameters:

T – Element type to access.

inline bool is_segment() const#

Returns whether a segment is defined.

inline int64_t segment_begin() const#

Returns the inclusive segment begin index.

inline int64_t segment_end() const#

Returns the exclusive segment end index.

inline void set_segment_begin_and_end(int64_t begin, int64_t end)#

Sets segment bounds and marks the segment as present.

Parameters:
  • begin – Inclusive begin index.

  • end – Exclusive end index.

inline bool hasName() const#

Returns whether the tensor name is set.

inline const std::string &name() const#

Returns the tensor name.

inline void setName(std::string name)#

Sets the tensor name.

Parameters:

nameTensor name.

inline bool is_raw_data() const#

Returns whether tensor values are stored as raw bytes.

inline const std::vector<std::pair<std::string, std::string>> &external_data() const#

Returns external-data entries.

inline std::vector<std::pair<std::string, std::string>> &external_data()#

Returns mutable external-data entries.

inline bool has_data_location() const#

Returns whether the data location differs from the default.

inline const ONNX_LIGHT_NAMESPACE::TensorProto::DataLocation &data_location() const#

Returns the tensor data location.

inline ONNX_LIGHT_NAMESPACE::TensorProto::DataLocation &data_location()#

Returns mutable access to the tensor data location.

template<>
inline float *data()#

doc

template<>
inline const float *data() const#
template<>
inline double *data()#

doc

template<>
inline const double *data() const#
template<>
inline int32_t *data()#

doc

template<>
inline const int32_t *data() const#
template<>
inline int64_t *data()#

doc

template<>
inline const int64_t *data() const#
template<>
inline uint64_t *data()#

doc

template<>
inline const uint64_t *data() const#

Private Members

bool is_segment_ = {false}#
int64_t segment_begin_ = {0}#
int64_t segment_end_ = {0}#
bool has_name_ = {false}#
std::string name_#
int32_t elem_type_ = {static_cast<int32_t>(ONNX_LIGHT_NAMESPACE::TensorProto::DataType::UNDEFINED)}#
std::vector<int64_t> sizes_#
std::vector<float> float_data_#
std::vector<double> double_data_#
std::vector<int32_t> int32_data_#
std::vector<int64_t> int64_data_#
std::vector<uint64_t> uint64_data_#
std::vector<std::string> string_data_#
bool is_raw_data_ = {false}#
std::string raw_data_#
std::vector<std::pair<std::string, std::string>> external_data_#
ONNX_LIGHT_NAMESPACE::TensorProto::DataLocation data_location_{ONNX_LIGHT_NAMESPACE::TensorProto::DEFAULT}#