SCOREC core
Parallel unstructured mesh tools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
mth::Vector< T, N > Class Template Reference

compile-time (static) vector of size N More...

Inheritance diagram for mth::Vector< T, N >:
can::Array< T, N >

Public Member Functions

 Vector ()
 default constructor
 
 Vector (unsigned n)
 construct with n elems More...
 
 Vector (T const *v)
 construct from an array
 
T & operator() (unsigned i)
 mutable index operator More...
 
T const & operator() (unsigned i) const
 immutable index operator
 
Vector< T, N > & operator+= (Vector< T, N > const &b)
 add a vector to this vector
 
Vector< T, N > operator+ (Vector< T, N > const &b) const
 add two vectors
 
Vector< T, N > & operator-= (Vector< T, N > const &b)
 subtract a vector from this vector
 
Vector< T, N > operator- (Vector< T, N > const &b) const
 subtract two vectors
 
Vector< T, N > operator* (T const &s) const
 multiply a vector times a scalar More...
 
Vector< T, N > operator/ (T const &s) const
 divide a vector by a scalar More...
 
operator* (Vector< T, N > const &b) const
 vector dot product More...
 
getLength () const
 get the vector magnitude
 
Vector< T, N > normalize () const
 divide the vector by its magnitude
 
void zero ()
 zero the vector
 
- Public Member Functions inherited from can::Array< T, N >
 Array ()
 default constructor - necessary
 
 Array (Array< T, N > const &other)
 copy constructor
 
 ~Array ()
 elems is destroyed automatically
 
Array< T, N > & operator= (Array< T, N > const &other)
 assignment operator
 
T & operator[] (unsigned i)
 mutable index operator
 
T const & operator[] (unsigned i) const
 immutable index operator
 
unsigned size () const
 get the size of this array
 

Detailed Description

template<class T, unsigned N = 0>
class mth::Vector< T, N >

compile-time (static) vector of size N

This class endows Array<T,N> with the standard mathematical properties of a linear algebra vector. The vector is templated on scalar type so that math can be performed for a variety of (meaningful) scalar types.

Definition at line 29 of file mthVector.h.

Constructor & Destructor Documentation

template<class T, unsigned N = 0>
mth::Vector< T, N >::Vector ( unsigned  n)
inline

construct with n elems

A dummy constructor Vector(n) is provided so that dynamic and static vectors can be used interchangebly

Definition at line 37 of file mthVector.h.

37 {(void)n;}

Member Function Documentation

template<class T, unsigned N = 0>
T& mth::Vector< T, N >::operator() ( unsigned  i)
inline

mutable index operator

An index operator (i) is provided so that mth::Vector and mth::Matrix share a common index operator

Definition at line 47 of file mthVector.h.

47 {return (*this)[i];}
template<class T, unsigned N = 0>
Vector<T,N> mth::Vector< T, N >::operator* ( T const &  s) const
inline

multiply a vector times a scalar

currently there is no scalar times vector operator, so do be sure to put scalar on the right hand side

Definition at line 84 of file mthVector.h.

85  {
86  Vector<T,N> r;
87  for (unsigned i=0; i < N; ++i)
88  r[i] = (*this)[i] * s;
89  return r;
90  }
template<class T, unsigned N = 0>
T mth::Vector< T, N >::operator* ( Vector< T, N > const &  b) const
inline

vector dot product

we chose the default vector-vector multiplication operator to be the dot product. so far this seems to have been a good choice

Definition at line 104 of file mthVector.h.

105  {
106  T r = (T)0.0;
107  for (unsigned i=0; i < N; ++i)
108  r += (*this)[i] * b[i];
109  return r;
110  }
template<class T, unsigned N = 0>
Vector<T,N> mth::Vector< T, N >::operator/ ( T const &  s) const
inline

divide a vector by a scalar

equivalent to scaling by 1/s

Definition at line 93 of file mthVector.h.

94  {
95  Vector<T,N> r;
96  for (unsigned i=0; i < N; ++i)
97  r[i] = (*this)[i] / s;
98  return r;
99  }

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