Ctrl-Z
一个多线程机器人运动控制强化学习部署框架
载入中...
搜索中...
未找到
z::math::TensorBase< T, Dims > 模板类 参考

TensorBase class, base class for tensor 更多...

#include <TensorType.hpp>

Public 类型

using Shape = TensorShape<Dims...>
 
using ValueType = T
 

Public 成员函数

 TensorBase ()
 Construct a new Tensor Base object with all elements set to default value
 
 TensorBase (const T &val)
 Construct a new Tensor Base object with all elements set to given value
 
 TensorBase (const std::array< ValueType, Shape::total_size > &data)
 Construct a new Tensor Base object, copy from std::array
 
 TensorBase (std::array< ValueType, Shape::total_size > &&data)
 Construct a new Tensor Base object, move from std::array
 
 TensorBase (const TensorBase &other) noexcept
 Construct a new Tensor Base object, copy from another tensor
 
 TensorBase (TensorBase &&other) noexcept
 Construct a new Tensor Base object, move from another tensor
 
TensorBase< T, Dims... > & operator= (const TensorBase &other) noexcept
 assignment operator, copy from another tensor
 
TensorBase< T, Dims... > & operator= (TensorBase &&other) noexcept
 assignment operator, move from another tensor
 
TensorBase< T, Dims... > clone () const
 clone function, used to deepcopy a tensor
 
TensorBase< T, Dims... > DeepCopy () const
 DeepCopy function, used to deepcopy a tensor
 
void DeepCopy (TensorBase< T, Dims... > &other)
 deep copy from other tensor without change data_ptr address, this is useful when the original tensor's data ptr is already registerd in somewhere else. (e.g. warped in onnx runtime)
 
void clone (TensorBase< T, Dims... > &other)
 deep copy from other tensor without change data_ptr address, this is useful when the original tensor's data ptr is already registerd in somewhere else. (e.g. warped in onnx runtime)
 
bool same (const TensorBase &other) const
 compare two tensors, used to check if the given two tensors are the same tensor.
 
bool equal (const TensorBase &other) const
 compare two tensors, used to check if the given two tensors are the same tensor.
 
std::array< ValueType, Shape::total_size > & Array ()
 convert to std::array
 
const std::array< ValueType, Shape::total_size > & Array () const
 
ValueType * data ()
 get data pointer
 
T & operator[] (size_t index)
 get data according to index, this function will ignore the shape of tensor, the index is the offset in the memory.
 
const T & operator[] (size_t index) const
 this function is a overload of operator[], it will return the data according to the index.
 
template<typename... Indices>
T & operator() (Indices... indices)
 get data according to indices, this function will calculate the offset according to the shape of tensor. for example, a tensor with shape {2, 3, 4}, the index (1, 2, 3) will be calculated as 1*3*4 + 2*4 + 3 = 35.
 
template<typename... Indices>
const T & operator() (Indices... indices) const
 this function is a overload of operator(), it will return the data according to the indices.
 
template<typename... Indices>
T & at (Indices... indices)
 get data according to indices, this function will calculate the offset according to the shape of tensor. for example, a tensor with shape {2, 3, 4}, the index (1, 2, 3) will be calculated as 1*3*4 + 2*4 + 3 = 35.
 
template<typename... Indices>
const T & at (Indices... indices) const
 this function is a overload of at, it will return the data according to the indices.
 

静态 Public 成员函数

static constexpr size_t size ()
 get total size of tensor
 
static constexpr std::array< int64_t, Shape::num_dimsshape ()
 get shape of tensor
 
static constexpr const int64_t * shape_ptr ()
 
static constexpr size_t num_dims ()
 get the number of dimensions
 

静态 Protected 成员函数

template<typename... Indices>
static constexpr size_t calculate_index (Indices... indices)
 calculate the index according to the indices
 
static void PrintTensorElements (std::ostream &os, const TensorBase &tensor, size_t index, size_t level)
 print tensor elements recursively
 

Protected 属性

std::array< T, Shape::total_size > * data_ptr__ = nullptr
 data array, used to store tensor data
 
std::atomic< size_t > * ref_count__ = nullptr
 reference count
 

友元

std::ostream & operator<< (std::ostream &os, const TensorBase &tensor)
 operator << for std::ostream, used to output tensor data
 

详细描述

template<typename T, int64_t... Dims>
class z::math::TensorBase< T, Dims >

TensorBase class, base class for tensor

模板参数
Ttype of tensor element
Dimstensor shape

构造及析构函数说明

◆ TensorBase() [1/4]

template<typename T, int64_t... Dims>
z::math::TensorBase< T, Dims >::TensorBase ( const std::array< ValueType, Shape::total_size > & data)
inline

Construct a new Tensor Base object, copy from std::array

参数
dataan array of data

◆ TensorBase() [2/4]

template<typename T, int64_t... Dims>
z::math::TensorBase< T, Dims >::TensorBase ( std::array< ValueType, Shape::total_size > && data)
inline

Construct a new Tensor Base object, move from std::array

参数
dataan array of data

◆ TensorBase() [3/4]

template<typename T, int64_t... Dims>
z::math::TensorBase< T, Dims >::TensorBase ( const TensorBase< T, Dims > & other)
inlinenoexcept

Construct a new Tensor Base object, copy from another tensor

参数
otheranother tensor

◆ TensorBase() [4/4]

template<typename T, int64_t... Dims>
z::math::TensorBase< T, Dims >::TensorBase ( TensorBase< T, Dims > && other)
inlinenoexcept

Construct a new Tensor Base object, move from another tensor

参数
otheranother tensor

成员函数说明

◆ Array()

template<typename T, int64_t... Dims>
std::array< ValueType, Shape::total_size > & z::math::TensorBase< T, Dims >::Array ( )
inline

convert to std::array

返回
std::array<T, Shape::total_size>& reference of data array

◆ at() [1/2]

template<typename T, int64_t... Dims>
template<typename... Indices>
T & z::math::TensorBase< T, Dims >::at ( Indices... indices)
inline

get data according to indices, this function will calculate the offset according to the shape of tensor. for example, a tensor with shape {2, 3, 4}, the index (1, 2, 3) will be calculated as 1*3*4 + 2*4 + 3 = 35.

模板参数
Indicesindices
参数
indicesindices
返回
T& reference of data

◆ at() [2/2]

template<typename T, int64_t... Dims>
template<typename... Indices>
const T & z::math::TensorBase< T, Dims >::at ( Indices... indices) const
inline

this function is a overload of at, it will return the data according to the indices.

模板参数
Indicesindices
参数
indicesindices
返回
const T& reference of data

◆ calculate_index()

template<typename T, int64_t... Dims>
template<typename... Indices>
static constexpr size_t z::math::TensorBase< T, Dims >::calculate_index ( Indices... indices)
inlinestaticconstexprprotected

calculate the index according to the indices

模板参数
Indices
参数
indices
返回
constexpr size_t

◆ clone() [1/2]

template<typename T, int64_t... Dims>
TensorBase< T, Dims... > z::math::TensorBase< T, Dims >::clone ( ) const
inline

clone function, used to deepcopy a tensor

返回
TensorBase<T, Dims...>

◆ clone() [2/2]

template<typename T, int64_t... Dims>
void z::math::TensorBase< T, Dims >::clone ( TensorBase< T, Dims... > & other)
inline

deep copy from other tensor without change data_ptr address, this is useful when the original tensor's data ptr is already registerd in somewhere else. (e.g. warped in onnx runtime)

参数
other

◆ data()

template<typename T, int64_t... Dims>
ValueType * z::math::TensorBase< T, Dims >::data ( )
inline

get data pointer

返回
ValueType* the pointer of data

◆ DeepCopy() [1/2]

template<typename T, int64_t... Dims>
TensorBase< T, Dims... > z::math::TensorBase< T, Dims >::DeepCopy ( ) const
inline

DeepCopy function, used to deepcopy a tensor

返回
TensorBase<T, Dims...>

◆ DeepCopy() [2/2]

template<typename T, int64_t... Dims>
void z::math::TensorBase< T, Dims >::DeepCopy ( TensorBase< T, Dims... > & other)
inline

deep copy from other tensor without change data_ptr address, this is useful when the original tensor's data ptr is already registerd in somewhere else. (e.g. warped in onnx runtime)

参数
other

◆ equal()

template<typename T, int64_t... Dims>
bool z::math::TensorBase< T, Dims >::equal ( const TensorBase< T, Dims > & other) const
inline

compare two tensors, used to check if the given two tensors are the same tensor.

参数
otheranother tensor
返回
true same
false not the same

◆ num_dims()

template<typename T, int64_t... Dims>
static constexpr size_t z::math::TensorBase< T, Dims >::num_dims ( )
inlinestaticconstexpr

get the number of dimensions

返回
constexpr size_t number of dimensions

◆ operator()() [1/2]

template<typename T, int64_t... Dims>
template<typename... Indices>
T & z::math::TensorBase< T, Dims >::operator() ( Indices... indices)
inline

get data according to indices, this function will calculate the offset according to the shape of tensor. for example, a tensor with shape {2, 3, 4}, the index (1, 2, 3) will be calculated as 1*3*4 + 2*4 + 3 = 35.

模板参数
Indicesindices
参数
indicesindices
返回
T& reference of data

◆ operator()() [2/2]

template<typename T, int64_t... Dims>
template<typename... Indices>
const T & z::math::TensorBase< T, Dims >::operator() ( Indices... indices) const
inline

this function is a overload of operator(), it will return the data according to the indices.

模板参数
Indicesindices
参数
indicesindices
返回
const T& reference of data

◆ operator=() [1/2]

template<typename T, int64_t... Dims>
TensorBase< T, Dims... > & z::math::TensorBase< T, Dims >::operator= ( const TensorBase< T, Dims > & other)
inlinenoexcept

assignment operator, copy from another tensor

参数
otheranother tensor
返回
TensorBase& reference of this tensor

◆ operator=() [2/2]

template<typename T, int64_t... Dims>
TensorBase< T, Dims... > & z::math::TensorBase< T, Dims >::operator= ( TensorBase< T, Dims > && other)
inlinenoexcept

assignment operator, move from another tensor

参数
otheranother tensor
返回
TensorBase& reference of this tensor

◆ operator[]() [1/2]

template<typename T, int64_t... Dims>
T & z::math::TensorBase< T, Dims >::operator[] ( size_t index)
inline

get data according to index, this function will ignore the shape of tensor, the index is the offset in the memory.

参数
indexdata index
返回
T& reference of data

◆ operator[]() [2/2]

template<typename T, int64_t... Dims>
const T & z::math::TensorBase< T, Dims >::operator[] ( size_t index) const
inline

this function is a overload of operator[], it will return the data according to the index.

参数
indexdata index
返回
const T& reference of data

◆ PrintTensorElements()

template<typename T, int64_t... Dims>
static void z::math::TensorBase< T, Dims >::PrintTensorElements ( std::ostream & os,
const TensorBase< T, Dims > & tensor,
size_t index,
size_t level )
inlinestaticprotected

print tensor elements recursively

参数
osoutput stream
tensortensor to print
indexindex of elements
levellevel of elements

◆ same()

template<typename T, int64_t... Dims>
bool z::math::TensorBase< T, Dims >::same ( const TensorBase< T, Dims > & other) const
inline

compare two tensors, used to check if the given two tensors are the same tensor.

参数
otheranother tensor
返回
true same
false not the same

◆ shape()

template<typename T, int64_t... Dims>
static constexpr std::array< int64_t, Shape::num_dims > z::math::TensorBase< T, Dims >::shape ( )
inlinestaticconstexpr

get shape of tensor

返回
constexpr std::array<size_t, Shape::num_dims>

◆ size()

template<typename T, int64_t... Dims>
static constexpr size_t z::math::TensorBase< T, Dims >::size ( )
inlinestaticconstexpr

get total size of tensor

返回
constexpr size_t

友元及相关符号说明

◆ operator<<

template<typename T, int64_t... Dims>
std::ostream & operator<< ( std::ostream & os,
const TensorBase< T, Dims > & tensor )
friend

operator << for std::ostream, used to output tensor data

参数
osstd::ostream
tensorTensorBase
返回
std::ostream&

该类的文档由以下文件生成: