Jet  v1.3.3
Public Types | Public Member Functions | List of all members
jet::VectorN< T > Class Template Referencefinal

General purpose dynamically-sizedN-D vector class. More...

#include <jet/vector_n.h>

Inheritance diagram for jet::VectorN< T >:
jet::VectorExpression< T, VectorN< T > >

Public Types

typedef std::vector< T > ContainerType
 

Public Member Functions

 VectorN ()
 Constructs empty vector. More...
 
 VectorN (size_t n, const T &val=0)
 Constructs default vector (val, val, ... , val). More...
 
template<typename U >
 VectorN (const std::initializer_list< U > &lst)
 Constructs vector with given initializer list. More...
 
template<typename E >
 VectorN (const VectorExpression< T, E > &other)
 Constructs vector with expression template. More...
 
 VectorN (const VectorN &other)
 Copy constructor. More...
 
 VectorN (VectorN &&other)
 Move constructor. More...
 
void resize (size_t n, const T &val=0)
 Resizes to n dimensional vector with initial value val. More...
 
void clear ()
 Clears the vector and make it zero-dimensional. More...
 
void set (const T &s)
 Sets all elements to s. More...
 
template<typename U >
void set (const std::initializer_list< U > &lst)
 Sets all elements with given initializer list. More...
 
template<typename E >
void set (const VectorExpression< T, E > &other)
 Sets vector with expression template. More...
 
void append (const T &val)
 Adds an element. More...
 
void swap (VectorN &other)
 Swaps the content of the vector with other vector. More...
 
void setZero ()
 Sets all elements to zero. More...
 
void normalize ()
 Normalizes this vector. More...
 
size_t size () const
 Returns the size of the vector. More...
 
T * data ()
 Returns the raw pointer to the vector data. More...
 
const T *const data () const
 Returns the const raw pointer to the vector data. More...
 
ContainerType::iterator begin ()
 Returns the begin iterator of the vector. More...
 
ContainerType::const_iterator begin () const
 Returns the begin const iterator of the vector. More...
 
ContainerType::iterator end ()
 Returns the end iterator of the vector. More...
 
ContainerType::const_iterator end () const
 Returns the end const iterator of the vector. More...
 
ArrayAccessor1< T > accessor ()
 Returns the array accessor. More...
 
ConstArrayAccessor1< T > constAccessor () const
 Returns the const array accessor. More...
 
at (size_t i) const
 Returns const reference to the i -th element of the vector. More...
 
T & at (size_t i)
 Returns reference to the i -th element of the vector. More...
 
sum () const
 Returns the sum of all the elements. More...
 
avg () const
 Returns the average of all the elements. More...
 
min () const
 Returns the minimum element. More...
 
max () const
 Returns the maximum element. More...
 
absmin () const
 Returns the absolute minimum element. More...
 
absmax () const
 Returns the absolute maximum element. More...
 
size_t dominantAxis () const
 Returns the index of the dominant axis. More...
 
size_t subminantAxis () const
 Returns the index of the subminant axis. More...
 
VectorScalarDiv< T, VectorNnormalized () const
 Returns normalized vector. More...
 
length () const
 Returns the length of the vector. More...
 
lengthSquared () const
 Returns the squared length of the vector. More...
 
template<typename E >
distanceTo (const E &other) const
 Returns the distance to the other vector. More...
 
template<typename E >
distanceSquaredTo (const E &other) const
 Returns the squared distance to the other vector. More...
 
template<typename U >
VectorTypeCast< U, VectorN< T >, T > castTo () const
 Returns a vector with different value type. More...
 
template<typename E >
bool isEqual (const E &other) const
 Returns true if other is the same as this vector. More...
 
template<typename E >
bool isSimilar (const E &other, T epsilon=std::numeric_limits< T >::epsilon()) const
 Returns true if other is similar to this vector. More...
 
template<typename E >
VectorAdd< T, VectorN, E > add (const E &v) const
 Computes this + v. More...
 
VectorScalarAdd< T, VectorNadd (const T &s) const
 Computes this + (s, s, ... , s). More...
 
template<typename E >
VectorSub< T, VectorN, E > sub (const E &v) const
 Computes this - v. More...
 
VectorScalarSub< T, VectorNsub (const T &s) const
 Computes this - (s, s, ... , s). More...
 
template<typename E >
VectorMul< T, VectorN, E > mul (const E &v) const
 Computes this * v. More...
 
VectorScalarMul< T, VectorNmul (const T &s) const
 Computes this * (s, s, ... , s). More...
 
template<typename E >
VectorDiv< T, VectorN, E > div (const E &v) const
 Computes this / v. More...
 
VectorScalarDiv< T, VectorNdiv (const T &s) const
 Computes this / (s, s, ... , s). More...
 
template<typename E >
dot (const E &v) const
 Computes dot product. More...
 
VectorScalarRSub< T, VectorNrsub (const T &s) const
 Computes (s, s, ... , s) - this. More...
 
template<typename E >
VectorSub< T, VectorN, E > rsub (const E &v) const
 Computes v - this. More...
 
VectorScalarRDiv< T, VectorNrdiv (const T &s) const
 Computes (s, s, ... , s) / this. More...
 
template<typename E >
VectorDiv< T, VectorN, E > rdiv (const E &v) const
 Computes v / this. More...
 
void iadd (const T &s)
 Computes this += (s, s, ... , s). More...
 
template<typename E >
void iadd (const E &v)
 Computes this += v. More...
 
void isub (const T &s)
 Computes this -= (s, s, ... , s). More...
 
template<typename E >
void isub (const E &v)
 Computes this -= v. More...
 
void imul (const T &s)
 Computes this *= (s, s, ... , s). More...
 
template<typename E >
void imul (const E &v)
 Computes this *= v. More...
 
void idiv (const T &s)
 Computes this /= (s, s, ... , s). More...
 
template<typename E >
void idiv (const E &v)
 Computes this /= v. More...
 
template<typename Callback >
void forEach (Callback func) const
 Iterates the vector and invoke given func for each element. More...
 
template<typename Callback >
void forEachIndex (Callback func) const
 Iterates the vector and invoke given func for each index. More...
 
template<typename Callback >
void parallelForEach (Callback func)
 Iterates the vector and invoke given func for each element in parallel using multi-threading. More...
 
template<typename Callback >
void parallelForEachIndex (Callback func) const
 Iterates the vector and invoke given func for each index in parallel using multi-threading. More...
 
operator[] (size_t i) const
 Returns the i -th element. More...
 
T & operator[] (size_t i)
 Returns the reference to the i -th element. More...
 
template<typename U >
VectorNoperator= (const std::initializer_list< U > &lst)
 Sets vector with given initializer list. More...
 
template<typename E >
VectorNoperator= (const VectorExpression< T, E > &other)
 Sets vector with expression template. More...
 
VectorNoperator= (const VectorN &other)
 Copy assignment. More...
 
VectorNoperator= (VectorN &&other)
 Move assignment. More...
 
VectorNoperator+= (const T &s)
 Computes this += (s, s, ... , s) More...
 
template<typename E >
VectorNoperator+= (const E &v)
 Computes this += v. More...
 
VectorNoperator-= (const T &s)
 Computes this -= (s, s, ... , s) More...
 
template<typename E >
VectorNoperator-= (const E &v)
 Computes this -= v. More...
 
VectorNoperator*= (const T &s)
 Computes this *= (s, s, ... , s) More...
 
template<typename E >
VectorNoperator*= (const E &v)
 Computes this *= v. More...
 
VectorNoperator/= (const T &s)
 Computes this /= (s, s, ... , s) More...
 
template<typename E >
VectorNoperator/= (const E &v)
 Computes this /= v. More...
 
template<typename E >
bool operator== (const E &v) const
 Returns true if other is the same as this vector. More...
 
template<typename E >
bool operator!= (const E &v) const
 Returns true if other is the not same as this vector. More...
 
- Public Member Functions inherited from jet::VectorExpression< T, VectorN< T > >
size_t size () const
 Size of the vector. More...
 
const VectorN< T > & operator() () const
 Returns actual implementation (the subclass). More...
 

Detailed Description

template<typename T>
class jet::VectorN< T >

General purpose dynamically-sizedN-D vector class.

This class defines N-D vector data where its size can be defined dynamically.

Template Parameters
TType of the element.

Member Typedef Documentation

◆ ContainerType

template<typename T >
typedef std::vector<T> jet::VectorN< T >::ContainerType

Constructor & Destructor Documentation

◆ VectorN() [1/6]

template<typename T >
jet::VectorN< T >::VectorN ( )

Constructs empty vector.

◆ VectorN() [2/6]

template<typename T >
jet::VectorN< T >::VectorN ( size_t  n,
const T &  val = 0 
)

Constructs default vector (val, val, ... , val).

◆ VectorN() [3/6]

template<typename T >
template<typename U >
jet::VectorN< T >::VectorN ( const std::initializer_list< U > &  lst)

Constructs vector with given initializer list.

◆ VectorN() [4/6]

template<typename T >
template<typename E >
jet::VectorN< T >::VectorN ( const VectorExpression< T, E > &  other)

Constructs vector with expression template.

◆ VectorN() [5/6]

template<typename T >
jet::VectorN< T >::VectorN ( const VectorN< T > &  other)

Copy constructor.

◆ VectorN() [6/6]

template<typename T >
jet::VectorN< T >::VectorN ( VectorN< T > &&  other)

Move constructor.

Member Function Documentation

◆ absmax()

template<typename T >
T jet::VectorN< T >::absmax ( ) const

Returns the absolute maximum element.

◆ absmin()

template<typename T >
T jet::VectorN< T >::absmin ( ) const

Returns the absolute minimum element.

◆ accessor()

template<typename T >
ArrayAccessor1<T> jet::VectorN< T >::accessor ( )

Returns the array accessor.

◆ add() [1/2]

template<typename T >
template<typename E >
VectorAdd<T, VectorN, E> jet::VectorN< T >::add ( const E &  v) const

Computes this + v.

◆ add() [2/2]

template<typename T >
VectorScalarAdd<T, VectorN> jet::VectorN< T >::add ( const T &  s) const

Computes this + (s, s, ... , s).

◆ append()

template<typename T >
void jet::VectorN< T >::append ( const T &  val)

Adds an element.

◆ at() [1/2]

template<typename T >
T& jet::VectorN< T >::at ( size_t  i)

Returns reference to the i -th element of the vector.

◆ at() [2/2]

template<typename T >
T jet::VectorN< T >::at ( size_t  i) const

Returns const reference to the i -th element of the vector.

◆ avg()

template<typename T >
T jet::VectorN< T >::avg ( ) const

Returns the average of all the elements.

◆ begin() [1/2]

template<typename T >
ContainerType::iterator jet::VectorN< T >::begin ( )

Returns the begin iterator of the vector.

◆ begin() [2/2]

template<typename T >
ContainerType::const_iterator jet::VectorN< T >::begin ( ) const

Returns the begin const iterator of the vector.

◆ castTo()

template<typename T >
template<typename U >
VectorTypeCast<U, VectorN<T>, T> jet::VectorN< T >::castTo ( ) const

Returns a vector with different value type.

◆ clear()

template<typename T >
void jet::VectorN< T >::clear ( )

Clears the vector and make it zero-dimensional.

◆ constAccessor()

template<typename T >
ConstArrayAccessor1<T> jet::VectorN< T >::constAccessor ( ) const

Returns the const array accessor.

◆ data() [1/2]

template<typename T >
T* jet::VectorN< T >::data ( )

Returns the raw pointer to the vector data.

◆ data() [2/2]

template<typename T >
const T* const jet::VectorN< T >::data ( ) const

Returns the const raw pointer to the vector data.

◆ distanceSquaredTo()

template<typename T >
template<typename E >
T jet::VectorN< T >::distanceSquaredTo ( const E &  other) const

Returns the squared distance to the other vector.

◆ distanceTo()

template<typename T >
template<typename E >
T jet::VectorN< T >::distanceTo ( const E &  other) const

Returns the distance to the other vector.

◆ div() [1/2]

template<typename T >
template<typename E >
VectorDiv<T, VectorN, E> jet::VectorN< T >::div ( const E &  v) const

Computes this / v.

◆ div() [2/2]

template<typename T >
VectorScalarDiv<T, VectorN> jet::VectorN< T >::div ( const T &  s) const

Computes this / (s, s, ... , s).

◆ dominantAxis()

template<typename T >
size_t jet::VectorN< T >::dominantAxis ( ) const

Returns the index of the dominant axis.

◆ dot()

template<typename T >
template<typename E >
T jet::VectorN< T >::dot ( const E &  v) const

Computes dot product.

◆ end() [1/2]

template<typename T >
ContainerType::iterator jet::VectorN< T >::end ( )

Returns the end iterator of the vector.

◆ end() [2/2]

template<typename T >
ContainerType::const_iterator jet::VectorN< T >::end ( ) const

Returns the end const iterator of the vector.

◆ forEach()

template<typename T >
template<typename Callback >
void jet::VectorN< T >::forEach ( Callback  func) const

Iterates the vector and invoke given func for each element.

This function iterates the vector elements and invoke the callback function func. The callback function takes array's element as its input. The order of execution will be 0 to N-1 where N is the size of the vector. Below is the sample usage:

VectorN<float> vec(10, 4.f);
vec.forEach([](float elem) {
printf("%d\n", elem);
});

◆ forEachIndex()

template<typename T >
template<typename Callback >
void jet::VectorN< T >::forEachIndex ( Callback  func) const

Iterates the vector and invoke given func for each index.

This function iterates the vector elements and invoke the callback function func. The callback function takes one parameter which is the index of the vector. The order of execution will be 0 to N-1 where N is the size of the array. Below is the sample usage:

VectorN<float> vec(10, 4.f);
vec.forEachIndex([&](size_t i) {
vec[i] = 4.f * i + 1.5f;
});

◆ iadd() [1/2]

template<typename T >
template<typename E >
void jet::VectorN< T >::iadd ( const E &  v)

Computes this += v.

◆ iadd() [2/2]

template<typename T >
void jet::VectorN< T >::iadd ( const T &  s)

Computes this += (s, s, ... , s).

◆ idiv() [1/2]

template<typename T >
template<typename E >
void jet::VectorN< T >::idiv ( const E &  v)

Computes this /= v.

◆ idiv() [2/2]

template<typename T >
void jet::VectorN< T >::idiv ( const T &  s)

Computes this /= (s, s, ... , s).

◆ imul() [1/2]

template<typename T >
template<typename E >
void jet::VectorN< T >::imul ( const E &  v)

Computes this *= v.

◆ imul() [2/2]

template<typename T >
void jet::VectorN< T >::imul ( const T &  s)

Computes this *= (s, s, ... , s).

◆ isEqual()

template<typename T >
template<typename E >
bool jet::VectorN< T >::isEqual ( const E &  other) const

Returns true if other is the same as this vector.

◆ isSimilar()

template<typename T >
template<typename E >
bool jet::VectorN< T >::isSimilar ( const E &  other,
epsilon = std::numeric_limits< T >::epsilon() 
) const

Returns true if other is similar to this vector.

◆ isub() [1/2]

template<typename T >
template<typename E >
void jet::VectorN< T >::isub ( const E &  v)

Computes this -= v.

◆ isub() [2/2]

template<typename T >
void jet::VectorN< T >::isub ( const T &  s)

Computes this -= (s, s, ... , s).

◆ length()

template<typename T >
T jet::VectorN< T >::length ( ) const

Returns the length of the vector.

◆ lengthSquared()

template<typename T >
T jet::VectorN< T >::lengthSquared ( ) const

Returns the squared length of the vector.

◆ max()

template<typename T >
T jet::VectorN< T >::max ( ) const

Returns the maximum element.

◆ min()

template<typename T >
T jet::VectorN< T >::min ( ) const

Returns the minimum element.

◆ mul() [1/2]

template<typename T >
template<typename E >
VectorMul<T, VectorN, E> jet::VectorN< T >::mul ( const E &  v) const

Computes this * v.

◆ mul() [2/2]

template<typename T >
VectorScalarMul<T, VectorN> jet::VectorN< T >::mul ( const T &  s) const

Computes this * (s, s, ... , s).

◆ normalize()

template<typename T >
void jet::VectorN< T >::normalize ( )

Normalizes this vector.

◆ normalized()

template<typename T >
VectorScalarDiv<T, VectorN> jet::VectorN< T >::normalized ( ) const

Returns normalized vector.

◆ operator!=()

template<typename T >
template<typename E >
bool jet::VectorN< T >::operator!= ( const E &  v) const

Returns true if other is the not same as this vector.

◆ operator*=() [1/2]

template<typename T >
template<typename E >
VectorN& jet::VectorN< T >::operator*= ( const E &  v)

Computes this *= v.

◆ operator*=() [2/2]

template<typename T >
VectorN& jet::VectorN< T >::operator*= ( const T &  s)

Computes this *= (s, s, ... , s)

◆ operator+=() [1/2]

template<typename T >
template<typename E >
VectorN& jet::VectorN< T >::operator+= ( const E &  v)

Computes this += v.

◆ operator+=() [2/2]

template<typename T >
VectorN& jet::VectorN< T >::operator+= ( const T &  s)

Computes this += (s, s, ... , s)

◆ operator-=() [1/2]

template<typename T >
template<typename E >
VectorN& jet::VectorN< T >::operator-= ( const E &  v)

Computes this -= v.

◆ operator-=() [2/2]

template<typename T >
VectorN& jet::VectorN< T >::operator-= ( const T &  s)

Computes this -= (s, s, ... , s)

◆ operator/=() [1/2]

template<typename T >
template<typename E >
VectorN& jet::VectorN< T >::operator/= ( const E &  v)

Computes this /= v.

◆ operator/=() [2/2]

template<typename T >
VectorN& jet::VectorN< T >::operator/= ( const T &  s)

Computes this /= (s, s, ... , s)

◆ operator=() [1/4]

template<typename T >
template<typename U >
VectorN& jet::VectorN< T >::operator= ( const std::initializer_list< U > &  lst)

Sets vector with given initializer list.

◆ operator=() [2/4]

template<typename T >
template<typename E >
VectorN& jet::VectorN< T >::operator= ( const VectorExpression< T, E > &  other)

Sets vector with expression template.

◆ operator=() [3/4]

template<typename T >
VectorN& jet::VectorN< T >::operator= ( const VectorN< T > &  other)

Copy assignment.

◆ operator=() [4/4]

template<typename T >
VectorN& jet::VectorN< T >::operator= ( VectorN< T > &&  other)

Move assignment.

◆ operator==()

template<typename T >
template<typename E >
bool jet::VectorN< T >::operator== ( const E &  v) const

Returns true if other is the same as this vector.

◆ operator[]() [1/2]

template<typename T >
T& jet::VectorN< T >::operator[] ( size_t  i)

Returns the reference to the i -th element.

◆ operator[]() [2/2]

template<typename T >
T jet::VectorN< T >::operator[] ( size_t  i) const

Returns the i -th element.

◆ parallelForEach()

template<typename T >
template<typename Callback >
void jet::VectorN< T >::parallelForEach ( Callback  func)

Iterates the vector and invoke given func for each element in parallel using multi-threading.

This function iterates the vector elements and invoke the callback function func in parallel using multi-threading. The callback function takes vector's element as its input. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:

VectorN<float> vec(1000, 4.f);
vec.parallelForEach([](float& elem) {
elem *= 2;
});

The parameter type of the callback function doesn't have to be T&, but const T& or T can be used as well.

◆ parallelForEachIndex()

template<typename T >
template<typename Callback >
void jet::VectorN< T >::parallelForEachIndex ( Callback  func) const

Iterates the vector and invoke given func for each index in parallel using multi-threading.

This function iterates the vector elements and invoke the callback function func in parallel using multi-threading. The callback function takes one parameter which is the index of the vector. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:

VectorN<float> vec(1000, 4.f);
vec.parallelForEachIndex([](size_t i) {
array[i] *= 2;
});

◆ rdiv() [1/2]

template<typename T >
template<typename E >
VectorDiv<T, VectorN, E> jet::VectorN< T >::rdiv ( const E &  v) const

Computes v / this.

◆ rdiv() [2/2]

template<typename T >
VectorScalarRDiv<T, VectorN> jet::VectorN< T >::rdiv ( const T &  s) const

Computes (s, s, ... , s) / this.

◆ resize()

template<typename T >
void jet::VectorN< T >::resize ( size_t  n,
const T &  val = 0 
)

Resizes to n dimensional vector with initial value val.

◆ rsub() [1/2]

template<typename T >
template<typename E >
VectorSub<T, VectorN, E> jet::VectorN< T >::rsub ( const E &  v) const

Computes v - this.

◆ rsub() [2/2]

template<typename T >
VectorScalarRSub<T, VectorN> jet::VectorN< T >::rsub ( const T &  s) const

Computes (s, s, ... , s) - this.

◆ set() [1/3]

template<typename T >
template<typename U >
void jet::VectorN< T >::set ( const std::initializer_list< U > &  lst)

Sets all elements with given initializer list.

◆ set() [2/3]

template<typename T >
void jet::VectorN< T >::set ( const T &  s)

Sets all elements to s.

◆ set() [3/3]

template<typename T >
template<typename E >
void jet::VectorN< T >::set ( const VectorExpression< T, E > &  other)

Sets vector with expression template.

◆ setZero()

template<typename T >
void jet::VectorN< T >::setZero ( )

Sets all elements to zero.

◆ size()

template<typename T >
size_t jet::VectorN< T >::size ( ) const

Returns the size of the vector.

◆ sub() [1/2]

template<typename T >
template<typename E >
VectorSub<T, VectorN, E> jet::VectorN< T >::sub ( const E &  v) const

Computes this - v.

◆ sub() [2/2]

template<typename T >
VectorScalarSub<T, VectorN> jet::VectorN< T >::sub ( const T &  s) const

Computes this - (s, s, ... , s).

◆ subminantAxis()

template<typename T >
size_t jet::VectorN< T >::subminantAxis ( ) const

Returns the index of the subminant axis.

◆ sum()

template<typename T >
T jet::VectorN< T >::sum ( ) const

Returns the sum of all the elements.

◆ swap()

template<typename T >
void jet::VectorN< T >::swap ( VectorN< T > &  other)

Swaps the content of the vector with other vector.


The documentation for this class was generated from the following file: