C++ API Reference#

This section documents the public C++ API of yet-another-onnxruntime-extensions, generated from the Doxygen XML output.

Custom ORT Kernel Structs#

Kernel structs declared in yaourt/ortops/sparse/cpu/ort_sparse_lite.h.

Defines

ORT_API_MANUAL_INIT#
namespace ortops#
struct DenseToSparseKernelLite#
#include <ort_sparse_lite.h>

Converts a 2-D dense float32 tensor into a compact flat sparse encoding. Only non-zero elements are stored. The 1-D output tensor encodes the original shape, the number of non-zero elements, their flat indices (stored as uint32), and their values (float32). The encoding is suitable as input to SparseToDense for a lossless round-trip.

Constraints: input must be exactly 2-D; only float32 is supported.

Param X:

[in] 2-D dense float32 input tensor of shape [n_rows, n_cols]. Zero elements are not stored in the sparse encoding.

Param Y:

[out] 1-D float32 tensor containing the sparse encoding of X. Layout: header | flat indices (uint32) | non-zero values (float32).

Public Functions

DenseToSparseKernelLite(const OrtApi *api, const OrtKernelInfo *info)#
Ort::Status Compute(const Ort::Custom::Tensor<float> &X, Ort::Custom::Tensor<float> &Y)#
struct SparseToDenseKernelLite#
#include <ort_sparse_lite.h>

Converts the compact sparse encoding produced by DenseToSparse back into a 2-D dense float32 tensor. Positions that were zero in the original tensor are filled with 0.0. The output shape is recovered from the sparse header embedded in the input.

Constraints: input must be 1-D with a valid sparse header; the encoded shape must be 2-D; only float32 is supported.

Param X:

[in] 1-D float32 sparse encoding produced by DenseToSparse.

Param Y:

[out] Reconstructed 2-D dense float32 tensor. The shape is recovered from the sparse header embedded in X.

Public Functions

SparseToDenseKernelLite(const OrtApi *api, const OrtKernelInfo *info)#
Ort::Status Compute(const Ort::Custom::Tensor<float> &X, Ort::Custom::Tensor<float> &Y)#

Sparse Tensor Encoding#

The sparse_struct type used to encode sparse tensors in-memory, declared in yaourt/cpp/include/common/sparse_tensor.h.

namespace onnx_sparse#
template<typename T>
struct CTypeToElementType#
#include <sparse_tensor.h>

Public Functions

uint32_t onnx_type() const#
template<>
struct CTypeToElementType<double>#
#include <sparse_tensor.h>

Public Functions

inline uint32_t onnx_type() const#
template<>
struct CTypeToElementType<float>#
#include <sparse_tensor.h>

Public Functions

inline uint32_t onnx_type() const#
template<>
struct CTypeToElementType<int32_t>#
#include <sparse_tensor.h>

Public Functions

inline uint32_t onnx_type() const#
struct sparse_struct#
#include <sparse_tensor.h>

This structure defines a 1D to 5D sparse tensor. It assumes the sparse tensor has less than 4Gb non null elements.

Public Functions

inline uint32_t *indices() const#
inline float *values() const#
inline std::size_t element_size() const#
inline std::size_t size_float() const#
inline void set(const std::vector<int64_t> &sh, uint32_t n, uint32_t dtype)#
inline void unmake(uint32_t &dims, uint32_t &n, const int64_t *&out_shape, uint32_t *&out_indices, float *&out_values) const#
template<typename T>
inline void to_maps(T &maps) const#
inline int64_t flatten_shape(int last = -1) const#
inline void csr(std::vector<uint32_t> &rows_index) const#
inline void csr(std::vector<uint32_t> &rows_index, std::vector<uint32_t> &element_indices) const#

Public Members

uint32_t fix_value#
uint32_t n_dims#
int64_t shape[4]#
uint32_t n_elements#
uint32_t onnx_type#
uint32_t begin#

Public Static Functions

static inline std::size_t element_size(uint32_t onnx_type)#
static inline std::size_t size_float(uint32_t n_elements, uint32_t onnx_type)#
static inline void copy(const std::vector<int64_t> &shape, const std::vector<uint32_t> &indices, const std::vector<float> &values, std::vector<float> &result)#

Helper Utilities#

String-building and enforcement helpers declared in yaourt/cpp/include/yaourt_helpers.h.

Defines

EXT_THROW(...)#
_THROW_DEFINED#
EXT_ENFORCE(cond, ...)#
_ENFORCE_DEFINED#
namespace yaourt_helpers#

Functions

std::string Version()#
std::vector<std::string> SplitString(const std::string &input, char delimiter)#
void MakeStringInternalElement(StringStream &ss, const char *t)#
void MakeStringInternalElement(StringStream &ss, const std::string &t)#
void MakeStringInternalElement(StringStream &ss, const char &t)#
void MakeStringInternalElement(StringStream &ss, const uint16_t &t)#
void MakeStringInternalElement(StringStream &ss, const uint32_t &t)#
void MakeStringInternalElement(StringStream &ss, const uint64_t &t)#
void MakeStringInternalElement(StringStream &ss, const int16_t &t)#
void MakeStringInternalElement(StringStream &ss, const int32_t &t)#
void MakeStringInternalElement(StringStream &ss, const int64_t &t)#
void MakeStringInternalElement(StringStream &ss, const uint64_t *&t)#
void MakeStringInternalElement(StringStream &ss, const uint64_t *t)#
void MakeStringInternalElement(StringStream &ss, const float &t)#
void MakeStringInternalElement(StringStream &ss, const double &t)#
void MakeStringInternalElement(StringStream &ss, const std::vector<uint16_t> &t)#
void MakeStringInternalElement(StringStream &ss, const std::vector<uint32_t> &t)#
void MakeStringInternalElement(StringStream &ss, const std::vector<uint64_t> &t)#
void MakeStringInternalElement(StringStream &ss, const std::vector<int16_t> &t)#
void MakeStringInternalElement(StringStream &ss, const std::vector<int32_t> &t)#
void MakeStringInternalElement(StringStream &ss, const std::vector<int64_t> &t)#
void MakeStringInternalElement(StringStream &ss, const std::vector<float> &t)#
void MakeStringInternalElement(StringStream &ss, const std::vector<double> &t)#
void MakeStringInternal(StringStream &ss)#
template<typename T, typename ...Args>
inline void MakeStringInternal(StringStream &ss, const T &t)#
template<typename T, typename ...Args>
inline void MakeStringInternal(StringStream &ss, const T &t, const Args&... args)#
template<typename ...Args>
inline std::string MakeString(const Args&... args)#
class StringStream#
#include <yaourt_helpers.h>

Public Functions

StringStream()#
virtual ~StringStream()#
virtual StringStream &append_uint16(const uint16_t &obj)#
virtual StringStream &append_uint32(const uint32_t &obj)#
virtual StringStream &append_uint64(const uint64_t &obj)#
virtual StringStream &append_int16(const int16_t &obj)#
virtual StringStream &append_int32(const int32_t &obj)#
virtual StringStream &append_int64(const int64_t &obj)#
virtual StringStream &append_float(const float &obj)#
virtual StringStream &append_double(const double &obj)#
virtual StringStream &append_char(const char &obj)#
virtual StringStream &append_string(const std::string &obj)#
virtual StringStream &append_charp(const char *obj)#
virtual std::string str()#

Public Static Functions

static StringStream *NewStream()#