Library of Assembled Shared Sources
lass::num::Vector< T, S > Class Template Reference

a dynamic sized n-dimensional vector with vector expression templates More...

#include <spline_cubic.h>

Inheritance diagram for lass::num::Vector< T, S >:

Public Member Functions

 Vector ()
 constructs an empty vector
 
 Vector (TSize iDimension, TParam iInitialValue=TNumTraits::zero)
 Construct a vector of dimension iDimension.
 
 Vector (const TStorage &iStorage)
 construct vector from storage type
 
template<typename VectorType>
 Vector (const VectorType &iVector)
 contruct by any particular type supporting [] and size().
 
template<typename T2, typename S2>
 Vector (const Vector< T2, S2 > &iOther)
 construct storage/expression vector to this (this should be a storage vector).
 
template<typename T2, typename S2>
Vector< T, S > & operator= (const Vector< T2, S2 > &iOther)
 assign storage/expression vector to this (this should be a storage vector).
 
TSize size () const
 return dimension of vector.
 
const TValue operator[] (TSize iIndex) const
 return the iIndex'th component value.
 
TReference operator[] (TSize iIndex)
 access the iIndex'th component value.
 
const TValue at (TSize iIndex) const
 return the iIndex'th component value and wrap index if necessary.
 
TReference at (TSize iIndex)
 access the iIndex'th component value and wrap index if necessary.
 
const Vector< T, S > & operator+ () const
 A weird way to get back the same object.
 
const Vector< T, impl::VNeg< T, S > > operator- () const
 return a vector with all components negated (-v)[i] == -(v[i]).
 
template<typename T2, typename S2>
Vector< T, S > & operator+= (const Vector< T2, S2 > &iB)
 add storage/expression vector to this (this should be a storage vector).
 
template<typename T2, typename S2>
Vector< T, S > & operator-= (const Vector< T2, S2 > &iB)
 subtract storage/expression vector from this (this should be a storage vector).
 
template<typename T2, typename S2>
Vector< T, S > & operator*= (const Vector< T2, S2 > &iB)
 multiply storage/expression vector with this (this should be a storage vector).
 
template<typename T2, typename S2>
Vector< T, S > & operator/= (const Vector< T2, S2 > &iB)
 divide this by storage/expression vector (this should be a storage vector).
 
template<typename T2>
Vector< T, S > & operator+= (const T2 &iB)
 add iB to all components
 
template<typename T2>
Vector< T, S > & operator-= (const T2 &iB)
 subtract iB from all components
 
template<typename T2>
Vector< T, S > & operator*= (const T2 &iB)
 multiply all components with iB.
 
template<typename T2>
Vector< T, S > & operator/= (const T2 &iB)
 divide all components by iB.
 
bool isEmpty () const
 return true if vector contains no dataa at all
 
bool isZero () const
 Return true if all the components are (exactly!) zero.
 
const TValue sum () const
 Return sum of all components of vector.
 
const TValue min () const
 Return minimum of all components of vector.
 
const TValue max () const
 Return maximum of all components of vector.
 
const TValue squaredNorm () const
 Return squared norm of vector.
 
const TValue norm () const
 Return norm of vector.
 
const Vector< T, impl::VMul< T, S, impl::VScalar< T > > > normal () const
 return a unit vector with same direction/sense as this vector.
 
const Vector< T, impl::VRec< T, S > > reciprocal () const
 return a vector with each component being the reciprocal value of this vector.
 
template<typename S2>
const Vector< T, impl::VMul< T, S, impl::VScalar< T > > > project (const Vector< T, S2 > &iB) const
 Project vector on this one.
 
template<typename S2>
const Vector< T, impl::VSub< T, S2, impl::VMul< T, S, impl::VScalar< T > > > > reject (const Vector< T, S2 > &iB) const
 Project vector on this one.
 
void normalize ()
 Normalize vector.
 
void swap (Vector< T, S > &iOther)
 swap storage of two vectors
 

Related Symbols

(Note that these are not member symbols.)

template<typename T, typename S1, typename S2>
Vector< T, impl::MVRightProd< T, S1, S2 > > operator* (const Matrix< T, S1 > &iA, const Vector< T, S2 > &iB)
 multiply matrix with column vector
 
template<typename T, typename S>
Matrix< T, impl::MVDiag< T, S > > diagonal (const Vector< T, S > &iB)
 Create diagonal matrix from vector.
 
template<typename T, typename S>
void solve (const Matrix< T, S > &iA, Vector< T > &iB)
 Solves set of equation A * X == B.
 
template<typename T, typename S1, typename S2>
const T dot (const Vector< T, S1 > &iA, const Vector< T, S2 > &iB)
 dot product.
 
template<typename T, typename S1, typename S2>
const Vector< T, impl::VAdd< T, S1, S2 > > operator+ (const Vector< T, S1 > &iA, const Vector< T, S2 > &iB)
 componentwise addition
 
template<typename T, typename S1, typename S2>
const Vector< T, impl::VSub< T, S1, S2 > > operator- (const Vector< T, S1 > &iA, const Vector< T, S2 > &iB)
 componentwise subtraction
 
template<typename T, typename S1, typename S2>
const Vector< T, impl::VMul< T, S1, S2 > > operator* (const Vector< T, S1 > &iA, const Vector< T, S2 > &iB)
 componentwise multiplication
 
template<typename T, typename S1, typename S2>
const Vector< T, impl::VDiv< T, S1, S2 > > operator/ (const Vector< T, S1 > &iA, const Vector< T, S2 > &iB)
 componentwise division
 
template<typename T, typename S>
const Vector< T, impl::VAdd< T, impl::VScalar< T >, S > > operator+ (const T &iA, const Vector< T, S > &iB)
 add iA to all components of iB
 
template<typename T, typename S>
const Vector< T, impl::VSub< T, impl::VScalar< T >, S > > operator- (const T &iA, const Vector< T, S > &iB)
 add iA to all negated components of iB
 
template<typename T, typename S>
const Vector< T, impl::VMul< T, impl::VScalar< T >, S > > operator* (const T &iA, const Vector< T, S > &iB)
 multiply iA with all components of iB
 
template<typename T, typename S>
const Vector< T, impl::VDiv< T, impl::VScalar< T >, S > > operator/ (const T &iA, const Vector< T, S > &iB)
 multiply iA with all reciprocal components of iB
 
template<typename T, typename S>
const Vector< T, impl::VAdd< T, S, impl::VScalar< T > > > operator+ (const Vector< T, S > &iA, const T &iB)
 add iB to all components of iA
 
template<typename T, typename S>
const Vector< T, impl::VSub< T, S, impl::VScalar< T > > > operator- (const Vector< T, S > &iA, const T &iB)
 subtract iB from all components of iA
 
template<typename T, typename S>
const Vector< T, impl::VMul< T, S, impl::VScalar< T > > > operator* (const Vector< T, S > &iA, const T &iB)
 multiply all components of iA with iB.
 
template<typename T, typename S>
const Vector< T, impl::VDiv< T, S, impl::VScalar< T > > > operator/ (const Vector< T, S > &iA, const T &iB)
 multiply all components of iA with iB.
 

Detailed Description

template<typename T, typename S = impl::VStorage<T>>
class lass::num::Vector< T, S >

a dynamic sized n-dimensional vector with vector expression templates

Author
Bram de Greve [BdG]

Definition at line 70 of file vector.h.

Constructor & Destructor Documentation

◆ Vector() [1/5]

template<typename T, typename S>
lass::num::Vector< T, S >::Vector ( )

constructs an empty vector

Exception safety:
strong guarentee.

Definition at line 73 of file vector.inl.

References size().

◆ Vector() [2/5]

template<typename T, typename S>
lass::num::Vector< T, S >::Vector ( TSize iDimension,
TParam iInitialValue = TNumTraits::zero )
explicit

Construct a vector of dimension iDimension.

Parameters
iDimensionthe dimension of the vector to be created. You can pass zero, but you shouldn't pass negative dimensions though.
iInitialValuethe initial value of all vector components, zero by default.
Complexity:
O(iDimension)
Exception safety:
strong guarentee.

Definition at line 93 of file vector.inl.

◆ Vector() [3/5]

template<typename T, typename S>
lass::num::Vector< T, S >::Vector ( const TStorage & iStorage)
explicit

construct vector from storage type

Complexity:
O(iStorage.size())
Exception safety:
strong guarentee.

Definition at line 109 of file vector.inl.

◆ Vector() [4/5]

template<typename T, typename S>
template<typename VectorType>
lass::num::Vector< T, S >::Vector ( const VectorType & iVector)
explicit

contruct by any particular type supporting [] and size().

Should only be used with writable storage type (like std::vector which is the default).

Complexity:
O(iVector.size())
Exception safety:
strong guarentee.

Definition at line 127 of file vector.inl.

◆ Vector() [5/5]

template<typename T, typename S>
template<typename T2, typename S2>
lass::num::Vector< T, S >::Vector ( const Vector< T2, S2 > & iOther)

construct storage/expression vector to this (this should be a storage vector).

Precondition
this must be an l-value.
Complexity:
O(iOther.size())
Exception safety:
strong guarentee.

Definition at line 146 of file vector.inl.

Member Function Documentation

◆ operator=()

template<typename T, typename S>
template<typename T2, typename S2>
Vector< T, S > & lass::num::Vector< T, S >::operator= ( const Vector< T2, S2 > & iOther)

assign storage/expression vector to this (this should be a storage vector).

Precondition
this must be an l-value.
Complexity:
O(iOther.size())
Exception safety:
basic guarentee.

Definition at line 170 of file vector.inl.

◆ size()

template<typename T, typename S>
Vector< T, S >::TSize lass::num::Vector< T, S >::size ( ) const
inline

return dimension of vector.

this should never be a negative value.

Exception safety:
nofail.

Definition at line 191 of file vector.inl.

Referenced by dot(), operator*(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/(), operator/=(), operator[](), operator[](), and Vector().

◆ operator[]() [1/2]

template<typename T, typename S>
const Vector< T, S >::TValue lass::num::Vector< T, S >::operator[] ( TSize iIndex) const
inline

return the iIndex'th component value.

Precondition
iIndex must be in [0, this->size()), unless you're asking for trouble.
Exception safety:
strong guarentee.

Definition at line 207 of file vector.inl.

References size().

◆ operator[]() [2/2]

template<typename T, typename S>
Vector< T, S >::TReference lass::num::Vector< T, S >::operator[] ( TSize iIndex)
inline

access the iIndex'th component value.

Precondition
  • iIndex must be in [0, this->size()), unless you're asking for trouble.
  • this must be an l-value.
Exception safety:
strong guarentee.

Definition at line 226 of file vector.inl.

References size().

◆ at() [1/2]

template<typename T, typename S>
const Vector< T, S >::TValue lass::num::Vector< T, S >::at ( TSize iIndex) const
inline

return the iIndex'th component value and wrap index if necessary.

if iIndex is out of the range [0, this->size()), it will be wrapped to map in this range. This is simply a modulus operation: mod(iIndex, this->size()).

Exception safety:
strong guarentee.

Definition at line 242 of file vector.inl.

◆ at() [2/2]

template<typename T, typename S>
Vector< T, S >::TReference lass::num::Vector< T, S >::at ( TSize iIndex)
inline

access the iIndex'th component value and wrap index if necessary.

if iIndex is out of the range [0, this->size()), it will be wrapped to map in this range. This is simply a modulus operation: mod(iIndex, this->size()).

Precondition
this must be an l-value.
Exception safety:
strong guarentee.

Definition at line 260 of file vector.inl.

◆ operator+()

template<typename T, typename S>
const Vector< T, S > & lass::num::Vector< T, S >::operator+ ( ) const
inline

A weird way to get back the same object.

Complexity:
O(1)
Exception safety:
nofail guarentee.

Definition at line 277 of file vector.inl.

◆ operator-()

template<typename T, typename S>
const Vector< T, impl::VNeg< T, S > > lass::num::Vector< T, S >::operator- ( ) const

return a vector with all components negated (-v)[i] == -(v[i]).

Complexity:
O(1)
Exception safety:
nofail.

Definition at line 295 of file vector.inl.

◆ operator+=() [1/2]

template<typename T, typename S>
template<typename T2, typename S2>
Vector< T, S > & lass::num::Vector< T, S >::operator+= ( const Vector< T2, S2 > & iB)

add storage/expression vector to this (this should be a storage vector).

Precondition
  • this->size() == iB.size()
  • this must be an l-value.
Complexity:
O(this->size())
Exception safety:
basic guarentee.

Definition at line 317 of file vector.inl.

◆ operator-=() [1/2]

template<typename T, typename S>
template<typename T2, typename S2>
Vector< T, S > & lass::num::Vector< T, S >::operator-= ( const Vector< T2, S2 > & iB)

subtract storage/expression vector from this (this should be a storage vector).

Precondition
  • this->size() == iB.size()
  • this must be an l-value.
Complexity:
O(this->size())
Exception safety:
basic guarentee.

Definition at line 344 of file vector.inl.

◆ operator*=() [1/2]

template<typename T, typename S>
template<typename T2, typename S2>
Vector< T, S > & lass::num::Vector< T, S >::operator*= ( const Vector< T2, S2 > & iB)

multiply storage/expression vector with this (this should be a storage vector).

Precondition
  • this->size() == iB.size()
  • this must be an l-value.
Complexity:
O(this->size())
Exception safety:
basic guarentee.

Definition at line 371 of file vector.inl.

◆ operator/=() [1/2]

template<typename T, typename S>
template<typename T2, typename S2>
Vector< T, S > & lass::num::Vector< T, S >::operator/= ( const Vector< T2, S2 > & iB)

divide this by storage/expression vector (this should be a storage vector).

Precondition
  • this->size() == iB.size()
  • this must be an l-value.
Complexity:
O(this->size())
Exception safety:
basic guarentee.

Definition at line 398 of file vector.inl.

◆ operator+=() [2/2]

template<typename T, typename S>
template<typename T2>
Vector< T, S > & lass::num::Vector< T, S >::operator+= ( const T2 & iB)

add iB to all components

Precondition
this must be an l-value.
Complexity:
O(this->size())

Definition at line 420 of file vector.inl.

References size().

◆ operator-=() [2/2]

template<typename T, typename S>
template<typename T2>
Vector< T, S > & lass::num::Vector< T, S >::operator-= ( const T2 & iB)

subtract iB from all components

Precondition
this must be an l-value.
Complexity:
O(this->size())

Definition at line 441 of file vector.inl.

References size().

◆ operator*=() [2/2]

template<typename T, typename S>
template<typename T2>
Vector< T, S > & lass::num::Vector< T, S >::operator*= ( const T2 & iB)

multiply all components with iB.

Precondition
this must be an l-value.
Complexity:
O(this->size())

Definition at line 462 of file vector.inl.

References size().

◆ operator/=() [2/2]

template<typename T, typename S>
template<typename T2>
Vector< T, S > & lass::num::Vector< T, S >::operator/= ( const T2 & iB)

divide all components by iB.

Precondition
this must be an l-value.
Complexity:
O(this->size())

Definition at line 483 of file vector.inl.

References size().

◆ isEmpty()

template<typename T, typename S>
bool lass::num::Vector< T, S >::isEmpty ( ) const
inline

return true if vector contains no dataa at all

Complexity:
O(1)
Exception safety:
nofail.

Definition at line 503 of file vector.inl.

◆ isZero()

template<typename T, typename S>
bool lass::num::Vector< T, S >::isZero ( ) const

Return true if all the components are (exactly!) zero.

Complexity:
O(this->size())

Definition at line 516 of file vector.inl.

◆ sum()

template<typename T, typename S>
const Vector< T, S >::TValue lass::num::Vector< T, S >::sum ( ) const

Return sum of all components of vector.

Complexity:
O(this->size())

Definition at line 540 of file vector.inl.

◆ min()

template<typename T, typename S>
const Vector< T, S >::TValue lass::num::Vector< T, S >::min ( ) const

Return minimum of all components of vector.

Complexity:
O(this->size())

Definition at line 560 of file vector.inl.

◆ max()

template<typename T, typename S>
const Vector< T, S >::TValue lass::num::Vector< T, S >::max ( ) const

Return maximum of all components of vector.

Complexity:
O(this->size())

Definition at line 584 of file vector.inl.

◆ squaredNorm()

template<typename T, typename S>
const Vector< T, S >::TValue lass::num::Vector< T, S >::squaredNorm ( ) const

Return squared norm of vector.

Returns
dot(*this, *this)
Complexity:
O(this->size())

Definition at line 609 of file vector.inl.

References lass::num::sqr().

Referenced by norm(), and project().

◆ norm()

template<typename T, typename S>
const Vector< T, S >::TValue lass::num::Vector< T, S >::norm ( ) const

Return norm of vector.

Returns
sqrt(this->squaredNorm())
Complexity:
O(this->size())

Definition at line 630 of file vector.inl.

References squaredNorm().

◆ normal()

template<typename T, typename S>
const Vector< T, impl::VMul< T, S, impl::VScalar< T > > > lass::num::Vector< T, S >::normal ( ) const

return a unit vector with same direction/sense as this vector.

The normalized vector of X is a vector in the same direction but with norm (length) 1. It is denoted X^ and given by X^ = X / |X|, http://mathworld.wolfram.com/dimension_ormalizedVector.html.

Returns
*this / this->norm()
Complexity:
O(this->size())

Definition at line 650 of file vector.inl.

References lass::num::norm().

◆ reciprocal()

template<typename T, typename S>
const Vector< T, impl::VRec< T, S > > lass::num::Vector< T, S >::reciprocal ( ) const

return a vector with each component being the reciprocal value of this vector.

Complexity:
O(1)

Definition at line 666 of file vector.inl.

◆ project()

template<typename T, typename S>
template<typename S2>
const Vector< T, impl::VMul< T, S, impl::VScalar< T > > > lass::num::Vector< T, S >::project ( const Vector< T, S2 > & iB) const

Project vector on this one.

Precondition
this->size() == iB.size()
Complexity:
O(this->size())

Definition at line 684 of file vector.inl.

References dot(), and squaredNorm().

Referenced by reject().

◆ reject()

template<typename T, typename S>
template<typename S2>
const Vector< T, impl::VSub< T, S2, impl::VMul< T, S, impl::VScalar< T > > > > lass::num::Vector< T, S >::reject ( const Vector< T, S2 > & iB) const

Project vector on this one.

Precondition
this->size() == iB.size()
Complexity:
O(this->size())

Definition at line 704 of file vector.inl.

References project().

◆ normalize()

template<typename T, typename S>
void lass::num::Vector< T, S >::normalize ( )

Normalize vector.

Precondition
this must be an l-value.
Complexity:
O(this->size())

Definition at line 719 of file vector.inl.

References lass::num::norm().

◆ swap()

template<typename T, typename S>
void lass::num::Vector< T, S >::swap ( Vector< T, S > & iOther)

swap storage of two vectors

Precondition
this and @ a iOther must be l-values
Complexity:
O(1)
Exception safety:
no-fail

Definition at line 755 of file vector.inl.

Friends And Related Symbol Documentation

◆ diagonal()

template<typename T, typename S>
Matrix< T, impl::MVDiag< T, S > > diagonal ( const Vector< T, S > & iB)
related

Create diagonal matrix from vector.

See also
lass::num::Matrix::isDiagonal

Definition at line 89 of file matrix_vector.inl.

◆ solve()

template<typename T, typename S>
void solve ( const Matrix< T, S > & iA,
Vector< T > & iB )
related

Solves set of equation A * X == B.

See also
lass::num::Matrix::solve

Definition at line 103 of file matrix_vector.inl.

◆ dot()

template<typename T, typename S1, typename S2>
const T dot ( const Vector< T, S1 > & iA,
const Vector< T, S2 > & iB )
related

dot product.

Precondition
iA.size() == iB.size()
Complexity:
O(iA.size())

Definition at line 842 of file vector.inl.

Referenced by project().

◆ operator+() [1/3]

template<typename T, typename S1, typename S2>
const Vector< T, impl::VAdd< T, S1, S2 > > operator+ ( const Vector< T, S1 > & iA,
const Vector< T, S2 > & iB )
related

componentwise addition

Precondition
iA.size() == iB.size()
Complexity:
O(1)

Definition at line 868 of file vector.inl.

◆ operator-() [1/3]

template<typename T, typename S1, typename S2>
const Vector< T, impl::VSub< T, S1, S2 > > operator- ( const Vector< T, S1 > & iA,
const Vector< T, S2 > & iB )
related

componentwise subtraction

Precondition
iA.size() == iB.size()
Complexity:
O(1)

Definition at line 887 of file vector.inl.

◆ operator*() [1/3]

template<typename T, typename S1, typename S2>
const Vector< T, impl::VMul< T, S1, S2 > > operator* ( const Vector< T, S1 > & iA,
const Vector< T, S2 > & iB )
related

componentwise multiplication

Precondition
iA.size() == iB.size()
Complexity:
O(1)

Definition at line 906 of file vector.inl.

◆ operator/() [1/3]

template<typename T, typename S1, typename S2>
const Vector< T, impl::VDiv< T, S1, S2 > > operator/ ( const Vector< T, S1 > & iA,
const Vector< T, S2 > & iB )
related

componentwise division

Precondition
iA.size() == iB.size()
Complexity:
O(1)

Definition at line 925 of file vector.inl.

◆ operator+() [2/3]

template<typename T, typename S>
const Vector< T, impl::VAdd< T, impl::VScalar< T >, S > > operator+ ( const T & iA,
const Vector< T, S > & iB )
related

add iA to all components of iB

Complexity:
O(1)

Definition at line 942 of file vector.inl.

◆ operator-() [2/3]

template<typename T, typename S>
const Vector< T, impl::VSub< T, impl::VScalar< T >, S > > operator- ( const T & iA,
const Vector< T, S > & iB )
related

add iA to all negated components of iB

Complexity:
O(1)

Definition at line 958 of file vector.inl.

◆ operator*() [2/3]

template<typename T, typename S>
const Vector< T, impl::VMul< T, impl::VScalar< T >, S > > operator* ( const T & iA,
const Vector< T, S > & iB )
related

multiply iA with all components of iB

Complexity:
O(1)

Definition at line 974 of file vector.inl.

◆ operator/() [2/3]

template<typename T, typename S>
const Vector< T, impl::VDiv< T, impl::VScalar< T >, S > > operator/ ( const T & iA,
const Vector< T, S > & iB )
related

multiply iA with all reciprocal components of iB

Complexity:
O(1)

Definition at line 990 of file vector.inl.

◆ operator+() [3/3]

template<typename T, typename S>
const Vector< T, impl::VAdd< T, S, impl::VScalar< T > > > operator+ ( const Vector< T, S > & iA,
const T & iB )
related

add iB to all components of iA

Complexity:
O(1)

Definition at line 1006 of file vector.inl.

◆ operator-() [3/3]

template<typename T, typename S>
const Vector< T, impl::VSub< T, S, impl::VScalar< T > > > operator- ( const Vector< T, S > & iA,
const T & iB )
related

subtract iB from all components of iA

Complexity:
O(1)

Definition at line 1022 of file vector.inl.

◆ operator*() [3/3]

template<typename T, typename S>
const Vector< T, impl::VMul< T, S, impl::VScalar< T > > > operator* ( const Vector< T, S > & iA,
const T & iB )
related

multiply all components of iA with iB.

Complexity:
O(1)

Definition at line 1038 of file vector.inl.

◆ operator/() [3/3]

template<typename T, typename S>
const Vector< T, impl::VDiv< T, S, impl::VScalar< T > > > operator/ ( const Vector< T, S > & iA,
const T & iB )
related

multiply all components of iA with iB.

Complexity:
O(1)

Definition at line 1054 of file vector.inl.


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