proj home

Files   Classes   Functions   Hierarchy  

vec< A, T > Class Template Reference

Primitive vector. More...

#include <vec.h>

Inheritance diagram for vec< A, T >:
Collaboration diagram for vec< A, T >:

List of all members.

Public Member Functions

 vec (A ai_, uintc N_)
 Pass in the vector and it number of dimensions.
void operator= (T const x)
 Scalar assigned to each component.
template<typename Z >
void operator= (Z const &zi)
 Copy vector to ai.
void operator= (vec< A, T > const &vb)
 Copy vector to ai.
template<typename Z >
void operator*= (Z const &zi)
 Matching component multiplication.
template<typename Z >
void operator+= (Z const &zi)
 Matching component addition.
template<typename Z >
void operator-= (Z const &zi)
 Matching component subraction.
void operator+= (T const x)
 Scalar addition.
void operator*= (T const x)
 Scalar multiplication.
T const operator[] (uintc i) const
 Element access.
Toperator[] (uintc i)
 Element access.
void identity (uintc k, T const x=1)
 Set the value in the ith component, all others zero.
void difference ()
 Difference X=X-rightshift(X).
void sum ()
 X=X+rightshif(X).
void binomial (uintc N)
 Generate the binomial coefficients for N degree polynomial.
 operator string () const
 Write the vector out as a string separated with spaces.

Public Attributes

ai
 The vector.
uintc N
 The number of dimensions.


Detailed Description

template<typename A, typename T>
class vec< A, T >

Primitive vector.

Support arithmetic operations on a data type with the [] operator.

This class does not explicity manage memory. No array bounds error checking or anything, nothing to interfere with the cache. Let the emphasis be on the client data structures to provide such functionality if they choose to.

Example
  unsigned int const n=3;
  double a1[n] = { 2.0, 7.0, 0.0 };
  double a2[n] = { 1.0, -3.0, 2.0 };
  double a3[n] = { 0.0, 0.0, 0.0 };

  vec<double*,double> v1(&a1[0],n);
  vec<double*,double> v2(&a2[0],n);
  vec<double*,double> v3(&a3[0],n);

  // Calculate equation
  // a3 = 2(a1-a2)
  v3 = a1;
  v3 -= a2;
  v3 *= 2.0;

Definition at line 42 of file vec.h.


Constructor & Destructor Documentation

template<typename A, typename T>
vec< A, T >::vec ( ai_,
uintc  N_ 
) [inline]

Pass in the vector and it number of dimensions.

Definition at line 53 of file vec.h.

00054     : ai(ai_), N(N_) {}


Member Function Documentation

template<typename A , typename T >
void vec< A, T >::binomial ( uintc  N  )  [inline]

Generate the binomial coefficients for N degree polynomial.

Definition at line 133 of file vec.h.

References vec< A, T >::identity(), and vec< A, T >::sum().

Referenced by vectest::test02().

00134 {
00135   identity(0);
00136   for (uint i=0; i<N; ++i)
00137     sum();
00138 }

template<typename A , typename T >
void vec< A, T >::difference (  )  [inline]

Difference X=X-rightshift(X).

Definition at line 149 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

Referenced by patternsearchD2< EXP >::patternsearchD2(), and vectest::test02().

00150 {
00151   for (uint i=N-1; i>0; --i)
00152     ai[i] = ai[i] - ai[i-1];
00153 }

template<typename A , typename T>
void vec< A, T >::identity ( uintc  k,
T const   x = 1 
) [inline]

Set the value in the ith component, all others zero.

Definition at line 141 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

Referenced by vec< A, T >::binomial(), and patternsearchD2< EXP >::patternsearchD2().

00142 {
00143   for (uint i=0; i<N; ++i)
00144     ai[i] = 0;
00145   ai[k]=x;
00146 }

template<typename A , typename T >
vec< A, T >::operator string (  )  const [inline]

Write the vector out as a string separated with spaces.

Definition at line 115 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

00116 {
00117   if (N==0)
00118     return "";
00119 
00120   string s;
00121   { stringstream ss;  ss << ai[0]; s+=ss.str(); }
00122   
00123   for (uint i=1; i<N; ++i)
00124   {
00125     s += " ";
00126     { stringstream ss;  ss << ai[i]; s+=ss.str(); }
00127   }
00128   
00129   return s;
00130 }

template<typename A , typename T>
void vec< A, T >::operator*= ( T const  x  )  [inline]

Scalar multiplication.

Definition at line 202 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

00203 {
00204   for (uint i=0; i<N; ++i)
00205     ai[i] *= x; 
00206 }

template<typename A , typename T >
template<typename Z >
void vec< A, T >::operator*= ( Z const &  zi  )  [inline]

Matching component multiplication.

Definition at line 172 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

00173 {
00174   for (uint i=0; i<N; ++i)
00175     ai[i] *= zi[i];
00176 }

template<typename A , typename T>
void vec< A, T >::operator+= ( T const  x  )  [inline]

Scalar addition.

Definition at line 209 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

00210 {
00211   for (uint i=0; i<N; ++i)
00212     ai[i] += x; 
00213 }

template<typename A , typename T >
template<typename Z >
void vec< A, T >::operator+= ( Z const &  zi  )  [inline]

Matching component addition.

Definition at line 180 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

00181 {
00182   for (uint i=0; i<N; ++i)
00183     ai[i] += zi[i];
00184 }

template<typename A , typename T >
template<typename Z >
void vec< A, T >::operator-= ( Z const &  zi  )  [inline]

Matching component subraction.

Definition at line 188 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

00189 {
00190   for (uint i=0; i<N; ++i)
00191     ai[i] -= zi[i];
00192 }

template<typename A, typename T>
void vec< A, T >::operator= ( vec< A, T > const &  vb  )  [inline]

Copy vector to ai.

Definition at line 216 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

00217 {
00218   for (uint i=0; i<N; ++i)
00219     ai[i] = bi[i];
00220 }

template<typename A , typename T >
template<typename Z >
void vec< A, T >::operator= ( Z const &  zi  )  [inline]

Copy vector to ai.

Definition at line 164 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

00165 {
00166   for (uint i=0; i<N; ++i)
00167     ai[i] = zi[i];
00168 }

template<typename A , typename T>
void vec< A, T >::operator= ( T const  x  )  [inline]

Scalar assigned to each component.

Definition at line 195 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

00196 {
00197   for (uint i=0; i<N; ++i)
00198     ai[i] = x; 
00199 }

template<typename A, typename T>
T& vec< A, T >::operator[] ( uintc  i  )  [inline]

Element access.

Definition at line 89 of file vec.h.

00090     { return ai[i]; }

template<typename A, typename T>
T const vec< A, T >::operator[] ( uintc  i  )  const [inline]

Element access.

Definition at line 85 of file vec.h.

00086     { return ai[i]; }

template<typename A , typename T >
void vec< A, T >::sum (  )  [inline]

X=X+rightshif(X).

Definition at line 156 of file vec.h.

References vec< A, T >::ai, and vec< A, T >::N.

Referenced by vec< A, T >::binomial().

00157 {
00158   for (uint i=N-1; i>0; --i)
00159     ai[i] = ai[i] + ai[i-1];
00160 }


Member Data Documentation

template<typename A, typename T>
A vec< A, T >::ai

template<typename A, typename T>
uintc vec< A, T >::N


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

Generated on Fri Mar 4 00:50:23 2011 for Chelton Evans Source by  doxygen 1.5.8