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

Tensor class, used to store tensor data 更多...

#include <TensorType.hpp>

类 z::math::Tensor< T, Dims > 继承关系图:
z::math::Tensor< T, Dims > 的协作图:

Public 类型

using Base = TensorBase<T, Dims...>
 
using Shape = typename Base::Shape
 
using ValueType = typename Base::ValueType
 
- Public 类型 继承自 z::math::TensorBase< T, Dims... >
using Shape
 
using ValueType
 

Public 成员函数

Vector< ValueType, Shape::total_size > toVector () const
 convert tensor to z vector
 
Tensor< ValueType, Dims... > operator+ (const Tensor< ValueType, Dims... > &other) const
 operator +, used to add two tensors or a tensor and a value
 
Tensor< ValueType, Dims... > operator+ (const ValueType &other) const
 operator +, used to add a tensor and a value
 
Tensor< ValueType, Dims... > & operator+= (const Tensor< ValueType, Dims... > &other)
 operator +=, used to add two tensors or a tensor and a value
 
Tensor< ValueType, Dims... > & operator+= (const ValueType &other)
 operator +=, used to add a tensor and a value
 
Tensor< ValueType, Dims... > operator- (const Tensor< ValueType, Dims... > &other) const
 operator -, used to subtract two tensors or a tensor and a value
 
Tensor< ValueType, Dims... > operator- (const ValueType &other) const
 operator -, used to subtract a tensor and a value
 
Tensor< ValueType, Dims... > & operator-= (const Tensor< ValueType, Dims... > &other)
 operator -=, used to subtract two tensors or a tensor and a value
 
Tensor< ValueType, Dims... > & operator-= (const ValueType &other)
 operator -=, used to subtract a tensor and a value
 
Tensor< ValueType, Dims... > operator* (const Tensor< ValueType, Dims... > &other) const
 operator *, used to multiply two tensors or a tensor and a value
 
Tensor< ValueType, Dims... > operator* (const ValueType &other) const
 operator *, used to multiply a tensor and a value
 
Tensor< ValueType, Dims... > & operator*= (const Tensor< ValueType, Dims... > &other)
 operator *=, used to multiply two tensors or a tensor and a value
 
Tensor< ValueType, Dims... > & operator*= (const ValueType &other)
 operator *=, used to multiply a tensor and a value
 
Tensor< ValueType, Dims... > operator/ (const Tensor< ValueType, Dims... > &other) const
 operator /, used to divide two tensors or a tensor and a value
 
Tensor< ValueType, Dims... > operator/ (const ValueType &other) const
 operator /, used to divide a tensor and a value
 
Tensor< ValueType, Dims... > & operator/= (const Tensor< ValueType, Dims... > &other)
 operator /=, used to divide two tensors or a tensor and a value
 
Tensor< ValueType, Dims... > & operator/= (const ValueType &other)
 operator /=, used to divide a tensor and a value
 
Tensor< ValueType, Dims... > operator+ () const
 operator +, used to return the tensor itself
 
Tensor< ValueType, Dims... > operator- () const
 operator -, used to return the negative of the tensor
 
Tensor< bool, Dims... > operator> (const Tensor< ValueType, Dims... > &other) const
 operator >, used to compare two tensors or a tensor and a value
 
Tensor< bool, Dims... > operator> (const ValueType &other) const
 operator >, used to compare a tensor and a value
 
Tensor< bool, Dims... > operator>= (const Tensor< ValueType, Dims... > &other) const
 operator >=, used to compare two tensors or a tensor and a value
 
Tensor< bool, Dims... > operator>= (const ValueType &other) const
 operator >=, used to compare a tensor and a value
 
Tensor< bool, Dims... > operator< (const Tensor< ValueType, Dims... > &other) const
 operator <, used to compare two tensors or a tensor and a value
 
Tensor< bool, Dims... > operator< (const ValueType &other) const
 operator <, used to compare a tensor and a value
 
Tensor< bool, Dims... > operator<= (const Tensor< ValueType, Dims... > &other) const
 operator <=, used to compare two tensors or a tensor and a value
 
Tensor< bool, Dims... > operator<= (const ValueType &other) const
 operator <=, used to compare a tensor and a value
 
Tensor< bool, Dims... > operator== (const Tensor< ValueType, Dims... > &other) const
 operator ==, used to compare two tensors or a tensor and a value
 
Tensor< bool, Dims... > operator== (const ValueType &other) const
 operator ==, used to compare a tensor and a value
 
Tensor< bool, Dims... > operator!= (const Tensor< ValueType, Dims... > &other) const
 operator !=, used to compare two tensors or a tensor and a value
 
Tensor< bool, Dims... > operator!= (const ValueType &other) const
 operator !=, used to compare a tensor and a value
 
TensorBase< T, Dims... > clone () const
 clone function, used to deepcopy a tensor
 
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)
 
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)
 
- Public 成员函数 继承自 z::math::TensorBase< T, Dims... >
 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.
 
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.
 
const T & operator() (Indices... indices) const
 this function is a overload of operator(), it will return the data according to the 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.
 
const T & at (Indices... indices) const
 this function is a overload of at, it will return the data according to the indices.
 
 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
 
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)
 
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)
 
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.
 
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.
 
const T & operator() (Indices... indices) const
 this function is a overload of operator(), it will return the data according to the 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.
 
const T & at (Indices... indices) const
 this function is a overload of at, it will return the data according to the indices.
 

额外继承的成员函数

- 静态 Public 成员函数 继承自 z::math::TensorBase< T, Dims... >
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
 
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 成员函数 继承自 z::math::TensorBase< T, Dims... >
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
 
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 属性 继承自 z::math::TensorBase< T, Dims... >
std::array< T, Shape::total_size > * data_ptr__
 data array, used to store tensor data
 
std::atomic< size_t > * ref_count__
 reference count
 
std::array< T, Shape::total_size > * data_ptr__
 data array, used to store tensor data
 
std::atomic< size_t > * ref_count__
 reference count
 

详细描述

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

Tensor class, used to store tensor data

模板参数
Ttype of tensor element
Dims

成员函数说明

◆ 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

◆ 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

◆ operator!=() [1/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator!= ( const Tensor< ValueType, Dims... > & other) const
inline

operator !=, used to compare two tensors or a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator!=() [2/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator!= ( const ValueType & other) const
inline

operator !=, used to compare a tensor and a value

参数
othervalue
返回
Tensor<bool, Dims...>

◆ operator*() [1/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator* ( const Tensor< ValueType, Dims... > & other) const
inline

operator *, used to multiply two tensors or a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>

◆ operator*() [2/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator* ( const ValueType & other) const
inline

operator *, used to multiply a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>

◆ operator*=() [1/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > & z::math::Tensor< T, Dims >::operator*= ( const Tensor< ValueType, Dims... > & other)
inline

operator *=, used to multiply two tensors or a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>&

◆ operator*=() [2/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > & z::math::Tensor< T, Dims >::operator*= ( const ValueType & other)
inline

operator *=, used to multiply a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>&

◆ operator+() [1/3]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator+ ( ) const
inline

operator +, used to return the tensor itself

返回
Tensor<ValueType, Dims...>

◆ operator+() [2/3]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator+ ( const Tensor< ValueType, Dims... > & other) const
inline

operator +, used to add two tensors or a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>

◆ operator+() [3/3]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator+ ( const ValueType & other) const
inline

operator +, used to add a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>

◆ operator+=() [1/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > & z::math::Tensor< T, Dims >::operator+= ( const Tensor< ValueType, Dims... > & other)
inline

operator +=, used to add two tensors or a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>&

◆ operator+=() [2/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > & z::math::Tensor< T, Dims >::operator+= ( const ValueType & other)
inline

operator +=, used to add a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>&

◆ operator-() [1/3]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator- ( ) const
inline

operator -, used to return the negative of the tensor

返回
Tensor<ValueType, Dims...>

◆ operator-() [2/3]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator- ( const Tensor< ValueType, Dims... > & other) const
inline

operator -, used to subtract two tensors or a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>

◆ operator-() [3/3]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator- ( const ValueType & other) const
inline

operator -, used to subtract a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>

◆ operator-=() [1/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > & z::math::Tensor< T, Dims >::operator-= ( const Tensor< ValueType, Dims... > & other)
inline

operator -=, used to subtract two tensors or a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>&

◆ operator-=() [2/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > & z::math::Tensor< T, Dims >::operator-= ( const ValueType & other)
inline

operator -=, used to subtract a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>&

◆ operator/() [1/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator/ ( const Tensor< ValueType, Dims... > & other) const
inline

operator /, used to divide two tensors or a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>

◆ operator/() [2/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > z::math::Tensor< T, Dims >::operator/ ( const ValueType & other) const
inline

operator /, used to divide a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>

◆ operator/=() [1/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > & z::math::Tensor< T, Dims >::operator/= ( const Tensor< ValueType, Dims... > & other)
inline

operator /=, used to divide two tensors or a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>&

◆ operator/=() [2/2]

template<typename T, int64_t... Dims>
Tensor< ValueType, Dims... > & z::math::Tensor< T, Dims >::operator/= ( const ValueType & other)
inline

operator /=, used to divide a tensor and a value

参数
other
返回
Tensor<ValueType, Dims...>&

◆ operator<() [1/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator< ( const Tensor< ValueType, Dims... > & other) const
inline

operator <, used to compare two tensors or a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator<() [2/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator< ( const ValueType & other) const
inline

operator <, used to compare a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator<=() [1/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator<= ( const Tensor< ValueType, Dims... > & other) const
inline

operator <=, used to compare two tensors or a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator<=() [2/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator<= ( const ValueType & other) const
inline

operator <=, used to compare a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator==() [1/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator== ( const Tensor< ValueType, Dims... > & other) const
inline

operator ==, used to compare two tensors or a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator==() [2/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator== ( const ValueType & other) const
inline

operator ==, used to compare a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator>() [1/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator> ( const Tensor< ValueType, Dims... > & other) const
inline

operator >, used to compare two tensors or a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator>() [2/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator> ( const ValueType & other) const
inline

operator >, used to compare a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator>=() [1/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator>= ( const Tensor< ValueType, Dims... > & other) const
inline

operator >=, used to compare two tensors or a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ operator>=() [2/2]

template<typename T, int64_t... Dims>
Tensor< bool, Dims... > z::math::Tensor< T, Dims >::operator>= ( const ValueType & other) const
inline

operator >=, used to compare a tensor and a value

参数
other
返回
Tensor<bool, Dims...>

◆ toVector()

template<typename T, int64_t... Dims>
Vector< ValueType, Shape::total_size > z::math::Tensor< T, Dims >::toVector ( ) const
inline

convert tensor to z vector

返回
Vector<ValueType, Shape::total_size> z vector

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