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

Vector class, support some vector operations, like dot, cross, normalize, etc. 更多...

#include <VectorType.hpp>

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

Public 类型

using ApplyFunc = std::function<T(const T&, size_t)>
 apply function to vector
 
using SelfApplyFunc = std::function<void(T&, size_t)>
 apply function to each element of the vector
 

Public 成员函数

constexpr T & operator() (int idx)
 operator ()
 
constexpr const T & operator() (int idx) const
 operator () const
 
constexpr T & operator[] (int idx)
 operator []
 
constexpr const T & operator[] (int idx) const
 operator [] const
 
constexpr Vector< T, N > operator+ (const Vector< T, N > &other) const
 operator + for vector addition
 
constexpr Vector< T, N > operator- (const Vector< T, N > &other) const
 operator - for vector subtraction
 
constexpr Vector< T, N > operator+ () const
 operator +
 
constexpr Vector< T, N > operator- () const
 operator - for vector negation
 
constexpr Vector< T, N > operator* (const Vector< T, N > &other) const
 vector batch multiplication
 
constexpr Vector< T, N > operator/ (const Vector< T, N > &other) const
 vector batch division
 
constexpr Vector< T, N > operator+ (T val) const
 vector addition with value
 
constexpr Vector< T, N > operator- (T val) const
 vector subtraction with value
 
constexpr Vector< T, N > operator* (T val) const
 vector multiplication with value
 
constexpr Vector< T, N > operator/ (T val) const
 vector division with value
 
constexpr Vector< bool, N > operator== (const Vector< T, N > &other) const
 vector logical operations
 
constexpr Vector< bool, N > operator== (T other) const
 vector logical operations
 
constexpr Vector< bool, N > operator!= (const Vector< T, N > &other) const
 vector logical operations
 
constexpr Vector< bool, N > operator!= (T other) const
 vector logical operations
 
constexpr Vector< bool, N > operator> (const Vector< T, N > &other) const
 vector logical operations
 
constexpr Vector< bool, N > operator> (T other) const
 vector logical operations
 
constexpr Vector< bool, N > operator< (const Vector< T, N > &other) const
 vector logical operations
 
constexpr Vector< bool, N > operator< (T other) const
 vector logical operations
 
constexpr Vector< bool, N > operator>= (const Vector< T, N > &other) const
 vector logical operations
 
constexpr Vector< bool, N > operator>= (T other) const
 vector logical operations
 
constexpr Vector< bool, N > operator<= (const Vector< T, N > &other) const
 vector logical operations
 
constexpr Vector< bool, N > operator<= (T other) const
 vector logical operations
 
constexpr Vector< T, N > & operator+= (const Vector< T, N > &other)
 vector in-place addition
 
constexpr Vector< T, N > & operator-= (const Vector< T, N > &other)
 vector in-place subtraction
 
constexpr Vector< T, N > & operator*= (const Vector< T, N > &other)
 vector in-place batch multiplication
 
constexpr Vector< T, N > & operator/= (const Vector< T, N > &other)
 vector in-place batch division
 
constexpr Vector< T, N > & operator+= (T val)
 vector in-place addition with value
 
constexpr Vector< T, N > & operator-= (T val)
 vector in-place subtraction with value
 
constexpr Vector< T, N > & operator*= (T val)
 vector in-place multiplication with value
 
constexpr Vector< T, N > & operator/= (T val)
 vector in-place division with value
 
constexpr T dot (const Vector< T, N > &other) const
 vector dot product
 
length () const
 vector length in L2 norm
 
Vector< T, N > normalize () const
 vector normalize in L2 norm
 
constexpr T max () const
 Max element in vector
 
constexpr T min () const
 Min element in vector
 
constexpr T sum () const
 sum of all elements
 
constexpr T average () const
 average of all elements
 
void apply (SelfApplyFunc func)
 
template<size_t begin, size_t end, size_t step = 1>
Vector< T,(end - begin)/step > slice () const
 
constexpr Vector< T, N > remap (const Vector< int, N > &idx)
 remap the vector with given index
 

静态 Public 成员函数

static constexpr Vector< T, N > clamp (const Vector< T, N > &val, const Vector< T, N > &min, const Vector< T, N > &max)
 clamp val to min and max
 
static constexpr Vector< T, N > abs (const Vector< T, N > &val)
 abs val
 
static constexpr Vector< T, N > min (const Vector< T, N > &val1, const Vector< T, N > &val2)
 min val1 and val2
 
static constexpr Vector< T, N > max (const Vector< T, N > &val1, const Vector< T, N > &val2)
 max val1 and val2
 
static constexpr Vector< T, N > clamp (const Vector< T, N > &val, T min, T max)
 clamp val to min and max
 
static constexpr Vector< T, N > max (const Vector< T, N > &val, T max)
 max val to max
 
static constexpr Vector< T, N > min (const Vector< T, N > &val, T min)
 min val to min
 
static constexpr Vector< T, N > zeros ()
 create a vector with all elements set to 0
 
static constexpr Vector< T, N > ones ()
 create a vector with all elements set to 1
 
static Vector< T, N > apply (const Vector< T, N > &val, ApplyFunc func)
 apply function to vector element
 
static Vector< T, N > rand ()
 create a vector with random elements between 0 and 1
 
static constexpr Vector< T, N > where (const Vector< bool, N > &cond, const Vector< T, N > &val1, const Vector< T, N > &val2)
 Return a vector of elements selected from either val1 or val2, depending on condition.
 
static constexpr Vector< bool, N > eq (const Vector< T, N > &val1, const Vector< T, N > &val2)
 Computes element-wise equality
 
static constexpr Vector< bool, N > eq (const Vector< T, N > &val1, T val2)
 Computes element-wise equality
 
static constexpr Vector< bool, N > ne (const Vector< T, N > &val1, const Vector< T, N > &val2)
 Computes element-wise not equal to
 
static constexpr Vector< bool, N > ne (const Vector< T, N > &val1, T val2)
 Computes element-wise not equal to
 

友元

std::ostream & operator<< (std::ostream &os, const Vector< T, N > &vec)
 operator << for std::ostream
 

详细描述

template<typename T, size_t N>
class z::math::Vector< T, N >

Vector class, support some vector operations, like dot, cross, normalize, etc.

模板参数
Ttype of vector element
Nlength of vector

成员函数说明

◆ abs()

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::abs ( const Vector< T, N > & val)
inlinestaticconstexpr

abs val

参数
valvalue to abs
返回
Vector<T, N> abs result

◆ apply()

template<typename T, size_t N>
static Vector< T, N > z::math::Vector< T, N >::apply ( const Vector< T, N > & val,
ApplyFunc func )
inlinestatic

apply function to vector element

参数
valvector
funcapply function
返回
Vector<T, N> result vector

◆ average()

template<typename T, size_t N>
T z::math::Vector< T, N >::average ( ) const
inlineconstexpr

average of all elements

返回
T

◆ clamp() [1/2]

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::clamp ( const Vector< T, N > & val,
const Vector< T, N > & min,
const Vector< T, N > & max )
inlinestaticconstexpr

clamp val to min and max

参数
valvalue to clamp
minmin value
maxmax value
返回
Vector<T, N> clamp result

◆ clamp() [2/2]

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::clamp ( const Vector< T, N > & val,
T min,
T max )
inlinestaticconstexpr

clamp val to min and max

参数
valvalue to clamp
minmin value
maxmax value
返回
Vector<T, N> clamp result

◆ dot()

template<typename T, size_t N>
T z::math::Vector< T, N >::dot ( const Vector< T, N > & other) const
inlineconstexpr

vector dot product

参数
otherother vector
返回
T dot product result

◆ eq() [1/2]

template<typename T, size_t N>
static constexpr Vector< bool, N > z::math::Vector< T, N >::eq ( const Vector< T, N > & val1,
const Vector< T, N > & val2 )
inlinestaticconstexpr

Computes element-wise equality

参数
val1the vector to compare
val2the vector to compare with
返回
constexpr Vector<bool, N> the output vector

◆ eq() [2/2]

template<typename T, size_t N>
static constexpr Vector< bool, N > z::math::Vector< T, N >::eq ( const Vector< T, N > & val1,
T val2 )
inlinestaticconstexpr

Computes element-wise equality

参数
val1the vector to compare
val2the value to compare with
返回
constexpr Vector<bool, N> the output vector

◆ length()

template<typename T, size_t N>
T z::math::Vector< T, N >::length ( ) const
inline

vector length in L2 norm

返回
T length

◆ max() [1/3]

template<typename T, size_t N>
T z::math::Vector< T, N >::max ( ) const
inlineconstexpr

Max element in vector

返回
T

◆ max() [2/3]

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::max ( const Vector< T, N > & val,
T max )
inlinestaticconstexpr

max val to max

参数
valvalue to max
maxmax value
返回
Vector<T, N> max result

◆ max() [3/3]

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::max ( const Vector< T, N > & val1,
const Vector< T, N > & val2 )
inlinestaticconstexpr

max val1 and val2

参数
val1value 1
val2value 2
返回
Vector<T, N> max result

◆ min() [1/3]

template<typename T, size_t N>
T z::math::Vector< T, N >::min ( ) const
inlineconstexpr

Min element in vector

返回
T

◆ min() [2/3]

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::min ( const Vector< T, N > & val,
T min )
inlinestaticconstexpr

min val to min

参数
valvalue to min
minmin value
返回
Vector<T, N> min result

◆ min() [3/3]

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::min ( const Vector< T, N > & val1,
const Vector< T, N > & val2 )
inlinestaticconstexpr

min val1 and val2

参数
val1value 1
val2value 2
返回
Vector<T, N> min result

◆ ne() [1/2]

template<typename T, size_t N>
static constexpr Vector< bool, N > z::math::Vector< T, N >::ne ( const Vector< T, N > & val1,
const Vector< T, N > & val2 )
inlinestaticconstexpr

Computes element-wise not equal to

参数
val1the vector to compare
val2the vector to compare with
返回
constexpr Vector<bool, N> the output vector

◆ ne() [2/2]

template<typename T, size_t N>
static constexpr Vector< bool, N > z::math::Vector< T, N >::ne ( const Vector< T, N > & val1,
T val2 )
inlinestaticconstexpr

Computes element-wise not equal to

参数
val1the vector to compare
val2the value to compare with
返回
constexpr Vector<bool, N> the output vector

◆ normalize()

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::normalize ( ) const
inline

vector normalize in L2 norm

返回
Vector<T, N> normalized vector

◆ ones()

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::ones ( )
inlinestaticconstexpr

create a vector with all elements set to 1

返回
Vector<T, N>

◆ operator!=() [1/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator!= ( const Vector< T, N > & other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator!=() [2/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator!= ( T other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator()() [1/2]

template<typename T, size_t N>
T & z::math::Vector< T, N >::operator() ( int idx)
inlineconstexpr

operator ()

参数
idxindex
返回
T& reference of element

◆ operator()() [2/2]

template<typename T, size_t N>
const T & z::math::Vector< T, N >::operator() ( int idx) const
inlineconstexpr

operator () const

参数
idxindex
返回
const T& reference of element

◆ operator*() [1/2]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator* ( const Vector< T, N > & other) const
inlineconstexpr

vector batch multiplication

参数
otherother vector
返回
Vector<T, N>

◆ operator*() [2/2]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator* ( T val) const
inlineconstexpr

vector multiplication with value

参数
valvalue
返回
Vector<T, N>

◆ operator*=() [1/2]

template<typename T, size_t N>
Vector< T, N > & z::math::Vector< T, N >::operator*= ( const Vector< T, N > & other)
inlineconstexpr

vector in-place batch multiplication

参数
other
返回
Vector<T, N>&

◆ operator*=() [2/2]

template<typename T, size_t N>
Vector< T, N > & z::math::Vector< T, N >::operator*= ( T val)
inlineconstexpr

vector in-place multiplication with value

参数
val
返回
Vector<T, N>&

◆ operator+() [1/3]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator+ ( ) const
inlineconstexpr

operator +

返回
Vector<T, N>

◆ operator+() [2/3]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator+ ( const Vector< T, N > & other) const
inlineconstexpr

operator + for vector addition

参数
otherother vector
返回
Vector<T, N>

◆ operator+() [3/3]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator+ ( T val) const
inlineconstexpr

vector addition with value

参数
valvalue
返回
Vector<T, N>

◆ operator+=() [1/2]

template<typename T, size_t N>
Vector< T, N > & z::math::Vector< T, N >::operator+= ( const Vector< T, N > & other)
inlineconstexpr

vector in-place addition

参数
otherother vector
返回
Vector<T, N>&

◆ operator+=() [2/2]

template<typename T, size_t N>
Vector< T, N > & z::math::Vector< T, N >::operator+= ( T val)
inlineconstexpr

vector in-place addition with value

参数
val
返回
Vector<T, N>&

◆ operator-() [1/3]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator- ( ) const
inlineconstexpr

operator - for vector negation

返回
Vector<T, N>

◆ operator-() [2/3]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator- ( const Vector< T, N > & other) const
inlineconstexpr

operator - for vector subtraction

参数
otherother vector
返回
Vector<T, N>

◆ operator-() [3/3]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator- ( T val) const
inlineconstexpr

vector subtraction with value

参数
valvalue
返回
Vector<T, N>

◆ operator-=() [1/2]

template<typename T, size_t N>
Vector< T, N > & z::math::Vector< T, N >::operator-= ( const Vector< T, N > & other)
inlineconstexpr

vector in-place subtraction

参数
otherother vector
返回
Vector<T, N>&

◆ operator-=() [2/2]

template<typename T, size_t N>
Vector< T, N > & z::math::Vector< T, N >::operator-= ( T val)
inlineconstexpr

vector in-place subtraction with value

参数
val
返回
Vector<T, N>&

◆ operator/() [1/2]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator/ ( const Vector< T, N > & other) const
inlineconstexpr

vector batch division

参数
otherother vector
返回
Vector<T, N>

◆ operator/() [2/2]

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::operator/ ( T val) const
inlineconstexpr

vector division with value

参数
val
返回
Vector<T, N>

◆ operator/=() [1/2]

template<typename T, size_t N>
Vector< T, N > & z::math::Vector< T, N >::operator/= ( const Vector< T, N > & other)
inlineconstexpr

vector in-place batch division

参数
other
返回
Vector<T, N>&

◆ operator/=() [2/2]

template<typename T, size_t N>
Vector< T, N > & z::math::Vector< T, N >::operator/= ( T val)
inlineconstexpr

vector in-place division with value

参数
val
返回
Vector<T, N>&

◆ operator<() [1/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator< ( const Vector< T, N > & other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator<() [2/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator< ( T other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator<=() [1/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator<= ( const Vector< T, N > & other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator<=() [2/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator<= ( T other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator==() [1/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator== ( const Vector< T, N > & other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator==() [2/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator== ( T other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator>() [1/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator> ( const Vector< T, N > & other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator>() [2/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator> ( T other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator>=() [1/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator>= ( const Vector< T, N > & other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator>=() [2/2]

template<typename T, size_t N>
Vector< bool, N > z::math::Vector< T, N >::operator>= ( T other) const
inlineconstexpr

vector logical operations

参数
otherother vector
返回
constexpr Vector<bool, N>& result vector

◆ operator[]() [1/2]

template<typename T, size_t N>
T & z::math::Vector< T, N >::operator[] ( int idx)
inlineconstexpr

operator []

参数
idxindex
返回
constexpr T& reference of element

◆ operator[]() [2/2]

template<typename T, size_t N>
const T & z::math::Vector< T, N >::operator[] ( int idx) const
inlineconstexpr

operator [] const

参数
idxindex
返回
constexpr const T& reference of element

◆ rand()

template<typename T, size_t N>
static Vector< T, N > z::math::Vector< T, N >::rand ( )
inlinestatic

create a vector with random elements between 0 and 1

警告
this function does not set seed, therefore the result is not completely random user should set seed before call this function.
返回
Vector<T, N>

◆ remap()

template<typename T, size_t N>
Vector< T, N > z::math::Vector< T, N >::remap ( const Vector< int, N > & idx)
inlineconstexpr

remap the vector with given index

remap the vector with given index, for example, after remap with index {2,-1,1}, the origin vector {3,4,5} should be {5,5,4}

参数
idxnew index
返回
constexpr Vector<T, N>

◆ sum()

template<typename T, size_t N>
T z::math::Vector< T, N >::sum ( ) const
inlineconstexpr

sum of all elements

返回
T

◆ where()

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::where ( const Vector< bool, N > & cond,
const Vector< T, N > & val1,
const Vector< T, N > & val2 )
inlinestaticconstexpr

Return a vector of elements selected from either val1 or val2, depending on condition.

参数
condWhen True (nonzero), yield val1, otherwise yield val2
val1value vector 1
val2value vector 2
返回
constexpr Vector<T, N> result vector

◆ zeros()

template<typename T, size_t N>
static constexpr Vector< T, N > z::math::Vector< T, N >::zeros ( )
inlinestaticconstexpr

create a vector with all elements set to 0

返回
Vector<T, N>

友元及相关符号说明

◆ operator<<

template<typename T, size_t N>
std::ostream & operator<< ( std::ostream & os,
const Vector< T, N > & vec )
friend

operator << for std::ostream

参数
os
vec
返回
std::ostream&

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