Public Member Functions | Private Attributes | Friends | List of all members
PLMD::VectorGeneric< n > Class Template Reference

Class implementing fixed size vectors of doubles. More...

#include <Vector.h>

Public Member Functions

 VectorGeneric (double, double)
 Create it with preassigned components. More...
 
 VectorGeneric (double, double, double)
 
 VectorGeneric (double, double, double, double)
 
 VectorGeneric ()
 create it null More...
 
void zero ()
 set it to zero More...
 
double & operator[] (unsigned i)
 array-like access [i] More...
 
const double & operator[] (unsigned i) const
 array-like access [i] More...
 
double & operator() (unsigned i)
 parenthesis access (i) More...
 
const double & operator() (unsigned i) const
 parenthesis access (i) More...
 
VectorGenericoperator+= (const VectorGeneric &b)
 increment More...
 
VectorGenericoperator-= (const VectorGeneric &b)
 decrement More...
 
VectorGenericoperator*= (double s)
 multiply More...
 
VectorGenericoperator/= (double s)
 divide More...
 
VectorGeneric operator+ () const
 sign + More...
 
VectorGeneric operator- () const
 sign - More...
 
double modulo2 () const
 compute the squared modulo More...
 
double modulo () const
 Compute the modulo. More...
 
template<>
 VectorGeneric (double x0, double x1)
 
template<>
 VectorGeneric (double x0, double x1, double x2)
 
template<>
 VectorGeneric (double x0, double x1, double x2, double x3)
 

Private Attributes

double d [n]
 

Friends

template<unsigned m>
VectorGeneric< m > operator+ (const VectorGeneric< m > &, const VectorGeneric< m > &)
 return v1+v2 More...
 
template<unsigned m>
VectorGeneric< m > operator- (const VectorGeneric< m > &, const VectorGeneric< m > &)
 return v1-v2 More...
 
template<unsigned m>
VectorGeneric< m > operator* (double, const VectorGeneric< m > &)
 return s*v More...
 
template<unsigned m>
VectorGeneric< m > operator* (const VectorGeneric< m > &, double)
 return v*s More...
 
template<unsigned m>
VectorGeneric< m > operator/ (const VectorGeneric< m > &, double)
 return v/s More...
 
template<unsigned m>
VectorGeneric< m > delta (const VectorGeneric< m > &v1, const VectorGeneric< m > &v2)
 return v2-v1 More...
 
template<unsigned m>
double dotProduct (const VectorGeneric< m > &, const VectorGeneric< m > &)
 return v1 .scalar. v2 More...
 
VectorGeneric< 3 > crossProduct (const VectorGeneric< 3 > &, const VectorGeneric< 3 > &)
 return v1 .vector. More...
 
template<unsigned m>
double modulo2 (const VectorGeneric< m > &)
 friend version of modulo2 (to simplify some syntax) More...
 
template<unsigned m>
double modulo (const VectorGeneric< m > &)
 friend version of modulo (to simplify some syntax) More...
 
template<unsigned m>
std::ostream & operator<< (std::ostream &os, const VectorGeneric< m > &)
 << operator. More...
 

Detailed Description

template<unsigned n>
class PLMD::VectorGeneric< n >

Class implementing fixed size vectors of doubles.

Template Parameters
nThe number of elements of the vector.

This class implements a vector of doubles with size fixed at compile time. It is useful for small fixed size objects (e.g. 3d vectors) as it does not waste space to store the vector size. Moreover, as the compiler knows the size, it can be completely opimized inline. All the methods are inlined for better optimization and all the loops are explicitly unrolled using PLMD::LoopUnroller class. Vector elements are initialized to zero by default. Notice that this means that constructor is a bit slow. This point might change in future if we find performance issues. Accepts both [] and () syntax for access. Several functions are declared as friends even if not necessary so as to properly appear in Doxygen documentation.

Aliases are defined to simplify common declarations (Vector, Vector2d, Vector3d, Vector4d). Also notice that some operations are only available for 3 dimensional vectors.

Example of usage

#include "Vector.h"

using namespace PLMD;

int main(){
  VectorGeneric<3> v1;
  v1[0]=3.0;
// use equivalently () and [] syntax:
  v1(1)=5.0;
// initialize with components
  VectorGeneric<3> v2=VectorGeneric<3>(1.0,2.0,3.0);
  VectorGeneric<3> v3=crossProduct(v1,v2);
  double d=dotProduct(v1,v2);
  v3+=v1;
  v2=v1+2.0*v3;
}

Constructor & Destructor Documentation

template<unsigned n>
PLMD::VectorGeneric< n >::VectorGeneric ( double  ,
double   
)

Create it with preassigned components.

Only available for sizes 2, 3 and 4

template<unsigned n>
PLMD::VectorGeneric< n >::VectorGeneric ( double  ,
double  ,
double   
)
template<unsigned n>
PLMD::VectorGeneric< n >::VectorGeneric ( double  ,
double  ,
double  ,
double   
)
template<unsigned n>
PLMD::VectorGeneric< n >::VectorGeneric ( )

create it null

template<>
PLMD::VectorGeneric< 2 >::VectorGeneric ( double  x0,
double  x1 
)
inline
template<>
PLMD::VectorGeneric< 3 >::VectorGeneric ( double  x0,
double  x1,
double  x2 
)
inline
template<>
PLMD::VectorGeneric< 4 >::VectorGeneric ( double  x0,
double  x1,
double  x2,
double  x3 
)
inline

Member Function Documentation

template<unsigned n>
double PLMD::VectorGeneric< n >::modulo ( ) const

Compute the modulo.

Shortcut for sqrt(v.modulo2())

template<unsigned n>
double PLMD::VectorGeneric< n >::modulo2 ( ) const

compute the squared modulo

template<unsigned n>
double & PLMD::VectorGeneric< n >::operator() ( unsigned  i)

parenthesis access (i)

template<unsigned n>
const double & PLMD::VectorGeneric< n >::operator() ( unsigned  i) const

parenthesis access (i)

template<unsigned n>
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator*= ( double  s)

multiply

template<unsigned n>
VectorGeneric< n > PLMD::VectorGeneric< n >::operator+ ( ) const

sign +

template<unsigned n>
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator+= ( const VectorGeneric< n > &  b)

increment

template<unsigned n>
VectorGeneric< n > PLMD::VectorGeneric< n >::operator- ( ) const

sign -

template<unsigned n>
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator-= ( const VectorGeneric< n > &  b)

decrement

template<unsigned n>
VectorGeneric< n > & PLMD::VectorGeneric< n >::operator/= ( double  s)

divide

template<unsigned n>
double & PLMD::VectorGeneric< n >::operator[] ( unsigned  i)

array-like access [i]

template<unsigned n>
const double & PLMD::VectorGeneric< n >::operator[] ( unsigned  i) const

array-like access [i]

template<unsigned n>
void PLMD::VectorGeneric< n >::zero ( )

set it to zero

Friends And Related Function Documentation

template<unsigned n>
VectorGeneric<3> crossProduct ( const VectorGeneric< 3 > &  v1,
const VectorGeneric< 3 > &  v2 
)
friend

return v1 .vector.

v2 Only available for size 3

template<unsigned n>
template<unsigned m>
VectorGeneric<m> delta ( const VectorGeneric< m > &  v1,
const VectorGeneric< m > &  v2 
)
friend

return v2-v1

template<unsigned n>
template<unsigned m>
double dotProduct ( const VectorGeneric< m > &  ,
const VectorGeneric< m > &   
)
friend

return v1 .scalar. v2

template<unsigned n>
template<unsigned m>
double modulo ( const VectorGeneric< m > &  )
friend

friend version of modulo (to simplify some syntax)

template<unsigned n>
template<unsigned m>
double modulo2 ( const VectorGeneric< m > &  )
friend

friend version of modulo2 (to simplify some syntax)

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator* ( double  ,
const VectorGeneric< m > &   
)
friend

return s*v

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator* ( const VectorGeneric< m > &  ,
double   
)
friend

return v*s

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator+ ( const VectorGeneric< m > &  ,
const VectorGeneric< m > &   
)
friend

return v1+v2

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator- ( const VectorGeneric< m > &  ,
const VectorGeneric< m > &   
)
friend

return v1-v2

template<unsigned n>
template<unsigned m>
VectorGeneric<m> operator/ ( const VectorGeneric< m > &  ,
double   
)
friend

return v/s

template<unsigned n>
template<unsigned m>
std::ostream& operator<< ( std::ostream &  os,
const VectorGeneric< m > &   
)
friend

<< operator.

Allows printing vector v with std::cout<<v;

Member Data Documentation

template<unsigned n>
double PLMD::VectorGeneric< n >::d[n]
private

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