Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

CoinDenseVector< T > Class Template Reference

#include <CoinDenseVector.hpp>

List of all members.

Public Member Functions

Get methods.
int getNumElements () const
 Get the size.

int size () const
const T * getElements () const
 Get element values.

T * getElements ()
 Get element values.

Set methods
void clear ()
 Reset the vector (i.e. set all elemenets to zero).

CoinDenseVectoroperator= (const CoinDenseVector &)
T & operator[] (int index) const
void setVector (int size, const T *elems)
void setConstant (int size, T elems)
void setElement (int index, T element)
void resize (int newSize, T fill=T())
void append (const CoinDenseVector &)
norms, sum and scale
oneNorm () const
 1-norm of vector

double twoNorm () const
 2-norm of vector

infNorm () const
 infinity-norm of vector

sum () const
 sum of vector elements

void scale (T factor)
 scale vector elements

Arithmetic operators.
void operator+= (T value)
 add value to every entry

void operator-= (T value)
 subtract value from every entry

void operator *= (T value)
 multiply every entry by value

void operator/= (T value)
 divide every entry by value

Constructors and destructors
 CoinDenseVector ()
 CoinDenseVector (int size, const T *elems)
 CoinDenseVector (int size, T element=T())
 CoinDenseVector (const CoinDenseVector &)
 ~CoinDenseVector ()

Private Member Functions

Private methods
void gutsOfSetVector (int size, const T *elems)
 Copy internal data.

void gutsOfSetConstant (int size, T value)
 Set all elements to a given value.


Private Attributes

Private member data
int nElements_
 Size of element vector.

T * elements_
 Vector elements.


Detailed Description

template<typename T>
class CoinDenseVector< T >

Dense Vector

Stores a dense (or expanded) vector of floating point values. Type of vector elements is controlled by templating. (Some working quantities such as accumulated sums are explicitly declared of type double). This allows the components of the vector integer, single or double precision.

Here is a sample usage:

    const int ne = 4;
    double el[ne] = { 10., 40., 1., 50. };

    // Create vector and set its value
    CoinDenseVector<double> r(ne,el);

    // access each element
    assert( r.getElements()[0]==10. );
    assert( r.getElements()[1]==40. );
    assert( r.getElements()[2]== 1. );
    assert( r.getElements()[3]==50. );

    // Test for equality
    CoinDenseVector<double> r1;
    r1=r;

    // Add dense vectors.
    // Similarly for subtraction, multiplication,
    // and division.
    CoinDenseVector<double> add = r + r1;
    assert( add[0] == 10.+10. );
    assert( add[1] == 40.+40. );
    assert( add[2] ==  1.+ 1. );
    assert( add[3] == 50.+50. );

    assert( r.sum() == 10.+40.+1.+50. );

Definition at line 63 of file CoinDenseVector.hpp.


Constructor & Destructor Documentation

template<typename T>
CoinDenseVector< T >::CoinDenseVector  ) 
 

Default constructor

Definition at line 129 of file CoinDenseVector.cpp.

00129                                                          :
00130    nElements_(0),
00131    elements_(NULL)
00132 {}
  

template<typename T>
CoinDenseVector< T >::CoinDenseVector int  size,
const T *  elems
 

Alternate Constructors - set elements to vector of Ts

Definition at line 137 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::gutsOfSetVector().

00137                                                             :
00138    nElements_(0),
00139    elements_(NULL)
00140 {
00141   gutsOfSetVector(size, elems);
00142 }

template<typename T>
CoinDenseVector< T >::CoinDenseVector int  size,
element = T()
 

Alternate Constructors - set elements to same scalar value

Definition at line 146 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::gutsOfSetConstant().

00146                                                                           :
00147    nElements_(0),
00148    elements_(NULL)
00149 {
00150   gutsOfSetConstant(size, value);
00151 }

template<typename T>
CoinDenseVector< T >::CoinDenseVector const CoinDenseVector< T > &   ) 
 

Copy constructors

Definition at line 156 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::setVector().

00156                                                                  :
00157    nElements_(0),
00158    elements_(NULL)
00159 {
00160      setVector(rhs.getNumElements(), rhs.getElements());
00161 }

template<typename T>
CoinDenseVector< T >::~CoinDenseVector  ) 
 

Destructor

Definition at line 165 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::elements_.

00166 {
00167    delete [] elements_;
00168 }


Member Function Documentation

template<typename T>
void CoinDenseVector< T >::append const CoinDenseVector< T > &   ) 
 

Append a dense vector to this dense vector

Definition at line 81 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::elements_, CoinDenseVector< T >::getElements(), CoinDenseVector< T >::getNumElements(), CoinDenseVector< T >::nElements_, and CoinDenseVector< T >::resize().

00082 {
00083    const int s = nElements_;
00084    const int cs = caboose.getNumElements();
00085    int newsize = s + cs;
00086    resize(newsize);
00087    const T * celem = caboose.getElements();
00088    CoinDisjointCopyN(celem, cs, elements_ + s);
00089 }

template<typename T>
CoinDenseVector< T > & CoinDenseVector< T >::operator= const CoinDenseVector< T > &   ) 
 

Assignment operator

Definition at line 24 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::getElements(), CoinDenseVector< T >::getNumElements(), and CoinDenseVector< T >::setVector().

00025 {
00026    if (this != &rhs) {
00027      setVector(rhs.getNumElements(), rhs.getElements());
00028    }
00029    return *this;
00030 }

template<typename T>
T & CoinDenseVector< T >::operator[] int  index  )  const
 

Member of array operator

Definition at line 197 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::nElements_.

00198 {
00199   assert(index >= 0 && index < nElements_);
00200   T *where = elements_ + index;
00201   return *where;
00202 }

template<typename T>
void CoinDenseVector< T >::resize int  newSize,
fill = T()
 

Resize the dense vector to be the first newSize elements. If length is decreased, vector is truncated. If increased new entries, set to new default element

Definition at line 54 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::nElements_.

Referenced by CoinDenseVector< T >::append(), CoinDenseVector< T >::gutsOfSetConstant(), CoinDenseVector< T >::gutsOfSetVector(), CoinDenseVector< T >::setConstant(), and CoinDenseVector< T >::setVector().

00055 {
00056   if (newsize != nElements_){   
00057     assert(newsize > 0);
00058     T *newarray = new T[newsize];
00059     int cpysize = min(newsize, nElements_);
00060     memcpy(newarray, elements_, cpysize*sizeof(T));
00061     delete[] elements_;
00062     elements_ = newarray;
00063     nElements_ = newsize;
00064     for(int i=cpysize; i<newsize; i++)
00065       elements_[i] = value;
00066   }
00067 }

template<typename T>
void CoinDenseVector< T >::setConstant int  size,
elems
 

Elements set to have the same scalar value

Definition at line 44 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::resize().

00045 {
00046    resize(size);
00047    for(int i=0; i<size; i++)
00048      elements_[i] = value;
00049 }

template<typename T>
void CoinDenseVector< T >::setElement int  index,
element
 

Set an existing element in the dense vector The first argument is the "index" into the elements() array

Definition at line 72 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::nElements_.

00073 {
00074   assert(index >= 0 && index < nElements_);
00075    elements_[index] = element;
00076 }

template<typename T>
void CoinDenseVector< T >::setVector int  size,
const T *  elems
 

Set vector size, and elements. Size is the length of the elements vector. The element vector is copied into this class instance's member data.

Definition at line 35 of file CoinDenseVector.cpp.

References CoinDenseVector< T >::elements_, and CoinDenseVector< T >::resize().

Referenced by CoinDenseVector< T >::CoinDenseVector(), and CoinDenseVector< T >::operator=().

00036 {
00037    resize(size);
00038    memcpy(elements_, elems, size*sizeof(T));
00039 }


The documentation for this class was generated from the following files:
Generated on Wed Dec 3 14:34:25 2003 for Coin by doxygen 1.3.5