CVR-Lib last update 20 Sep 2009

cvr::vector< T > Class Template Reference
[Aggregate Data TypesLinear Algebra]

Mathematical vector container class. More...

#include <cvrVector.h>

Inheritance diagram for cvr::vector< T >:

Inheritance graph
[legend]
Collaboration diagram for cvr::vector< T >:

Collaboration graph
[legend]

List of all members.

Public Types

typedef genericVector< T >
::iterator 
iterator
typedef genericVector< T >
::const_iterator 
const_iterator

Public Member Functions

 vector ()
 vector (const int theSize)
 vector (const int theSize, const T &iniValue)
 vector (const int theSize, const T data[])
 vector (const int theSize, T data[], const eConstantReference constRef)
 vector (const genericVector< T > &other)
 vector (const genericVector< T > &other, const int from, const int to=genericVector< T >::MaxIndex)
 vector (const genericVector< T > &other, const genericVector< int > &idx)
 vector (const std::vector< T > &other)
virtual ~vector ()
const std::string & name () const
virtual vector< T > * clone () const
virtual vector< T > * newInstance () const
bool prettyCloseTo (const genericVector< T > &other, const T &tolerance) const
Arithmetical Operations
dot (const genericVector< T > &other) const
vector< T > & emultiply (const genericVector< T > &other)
vector< T > & emultiply (const genericVector< T > &first, const genericVector< T > &second)
vector< T > & edivide (const genericVector< T > &other)
vector< T > & edivide (const genericVector< T > &first, const genericVector< T > &second)
vector< T > & edivide (const T cst)
vector< T > & edivide (const genericVector< T > &other, const T cst)
vector< T > & add (const genericVector< T > &other)
vector< T > & add (const genericVector< T > &first, const genericVector< T > &second)
vector< T > & add (const T cst)
vector< T > & add (const genericVector< T > &other, const T cst)
vector< T > & operator+= (const T cst)
vector< T > & operator+= (const genericVector< T > &other)
vector< T > & addScaled (const T b, const genericVector< T > &other)
vector< T > & addScaled (const T a, const genericVector< T > &first, const T b, const genericVector< T > &second)
vector< T > & addScaled (const genericVector< T > &first, const T b, const genericVector< T > &second)
vector< T > & subtract (const T cst)
vector< T > & subtract (const genericVector< T > &other, const T cst)
vector< T > & subtract (const genericVector< T > &other)
vector< T > & subtract (const genericVector< T > &first, const genericVector< T > &second)
vector< T > & operator-= (const genericVector< T > &other)
vector< T > & operator-= (const T cst)
vector< T > & multiply (const T cst)
vector< T > & multiply (const genericVector< T > &other, const T cst)
vector< T > & operator*= (const T cst)
vector< T > & divide (const T cst)
vector< T > & divide (const genericVector< T > &other, const T cst)
vector< T > & operator/= (const T cst)
computeSumOfElements () const
computeProductOfElements () const
Find extreme values
findMinimum () const
int findIndexOfMinimum () const
findMaximum () const
int findIndexOfMaximum () const
void findExtremes (T &theMinimum, T &theMaximum) const
void findIndexOfExtremes (int &theIdxMinimum, int &theIdxMaximum) const


Detailed Description

template<typename T>
class cvr::vector< T >

Mathematical vector container class.

The cvr::vector class allows the representation of n-dimensional vectors. The elements of the vector will be indexed between 0 an n-1.

Note that this class is NOT intended to be a subtitute for std::vector. If you need a vector of elements which use some sort of dynamic memory allocation then you should use the std::vector class of the Standard Template Library.

Only following types are supported by cvr::vector:

This restriction is done to avoid the typical template code explosion due to frequently used types in the library. If you need the vector as container of any other type, consider using the std::vector or the cvr::genericVector.

The vector class is a container class implemented as template, where the template type T denotes the type of the elements. It is by no means a generic container, since the types it supports must fulfill many requirements, specially support for all arithmetical operators, and the types supported are explicitely instantiated in the library.

If you need to create a vector of floats with 256 elements, all initialized with a value of 4.27 just create it:

 cvr::vector<float> myVct(256,4.27f) // creates vector with 256 elements
                                     // all initialized with 4.27f

To access the vector elements use the access operators at() (or the overloaded operator[]()). For example:

 float accu = 0; // initialize accumulator

 for (int i = 0; i < myVct.size(); i++) {
   tmp += myVct.at(i); // access each element of the vector
 }

The vector has following methods:


Member Typedef Documentation

template<typename T>
typedef genericVector<T>::const_iterator cvr::vector< T >::const_iterator

Exception thrown when a constant reference is violated.

Reimplemented from cvr::genericVector< T >.

template<typename T>
typedef genericVector<T>::iterator cvr::vector< T >::iterator

Exception thrown when a constant reference is violated.

Reimplemented from cvr::genericVector< T >.


Constructor & Destructor Documentation

template<typename T>
cvr::vector< T >::vector (  ) 

Default constructor creates an empty vector;.

template<typename T>
cvr::vector< T >::vector ( const int  theSize  )  [explicit]

Create a vector of the given size.

The content of the vector is undefined.

Warning:
This is an interface change with the previous library. It has been done to be consistent with the more basic features of the C++ language. If you write for example "int c;", the content of c is not defined, and in the same way, if you want a vector with initialized data, you have to specify explicitely the value with which the elements have to be initialized.
Parameters:
theSize number of elements of the vector.

template<typename T>
cvr::vector< T >::vector ( const int  theSize,
const T &  iniValue 
) [explicit]

Create a vector of the given size and initialize it with the given value.

Parameters:
theSize number of elements of the vector.
iniValue all elements will be initialized with this value.

template<typename T>
cvr::vector< T >::vector ( const int  theSize,
const T  data[] 
)

Create a vector of the given size and initialize it with the given data.

The data will be copied.

See also:
useExternData()
Parameters:
theSize number of elements of the vector.
data a pointer to the data that will be copied.

template<typename T>
cvr::vector< T >::vector ( const int  theSize,
data[],
const eConstantReference  constRef 
)

Create a vector of the given size and initialize it with the given data, the same way "useExternData" does.

The data will not be copied!.

See also:
useExternData()
Parameters:
theSize number of elements of the vector.
data a pointer to the data that will be used.
constRef if this parameter is true, it will not be possible to change the pointer to the external memory block nor to resize the vector. Despite this, the value of each element can be changed by the access operators. For Example:

template<typename T>
cvr::vector< T >::vector ( const genericVector< T > &  other  ) 

Create this vector as a copy of another genericVector.

Parameters:
other the vector to be copied.

template<typename T>
cvr::vector< T >::vector ( const genericVector< T > &  other,
const int  from,
const int  to = genericVector< T >::MaxIndex 
)

Create this vector as a copy of specified interval of elements of another vector.

Indices below zero are set to zero, indices greater than the size of the vector to the size-1.

Parameters:
other the vector to be copied.
from starting point included
to end point included.

template<typename T>
cvr::vector< T >::vector ( const genericVector< T > &  other,
const genericVector< int > &  idx 
)

Create this vector as a copy of specified elements of another vector.

idx can contain the same index more than once.

Parameters:
other the vector to be copied.
idx indices of the elements to be copied

template<typename T>
cvr::vector< T >::vector ( const std::vector< T > &  other  ) 

Create this vector as a copy of another std::vector.

Parameters:
other the vector to be copied.

template<typename T>
virtual cvr::vector< T >::~vector (  )  [virtual]

Destructor.


Member Function Documentation

template<typename T>
vector<T>& cvr::vector< T >::add ( const genericVector< T > &  other,
const T  cst 
)

Add constant to the other vector and leave the result here.

Returns a reference to this vector.

Parameters:
other the other vector
cst constant scalar to be added with each element of the other vector
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::add ( const T  cst  ) 

Add constant to this vector.

This vector is changed. Returns this vector.

Parameters:
cst constant scalar to be added with each element
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::add ( const genericVector< T > &  first,
const genericVector< T > &  second 
)

Add two vector and leave the result in this object.

If both vectors have different size, an assertion will be thrown

Parameters:
first the first vector
second the second vector will be added with the first vector
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::add ( const genericVector< T > &  other  ) 

Add another vector of the same type and same dimension and leave the result in this object.

If both vectors have different size, an assertion will be thrown

Parameters:
other the other vector to be added with
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::addScaled ( const genericVector< T > &  first,
const T  b,
const genericVector< T > &  second 
)

Leave the addition of the first vector and the second vector scaled with the given factor in this vector.

The vectors must be of the same types and dimensions. Let A be the first vector and B the second vector with corresponding scaling factor b, further C this vector, then this method performs:

$C=A+b\cdot B$ If both vectors have different size, an assertion will be thrown

Parameters:
first the first vector to be added after scaling
b scaling factor for second
second the second vector to be added after scaling
Returns:
a reference to this vector

template<typename T>
vector<T>& cvr::vector< T >::addScaled ( const T  a,
const genericVector< T > &  first,
const T  b,
const genericVector< T > &  second 
)

Leave the scaled sum of two vectors in this vector.

The vectors must be of the same types and dimensions. Let A be the first vector and B the second vector with corresponding scaling factors a and b, further C this vector, then this method performs:

$C=a\cdot A+b\cdot B$ If both vectors have different size, an assertion will be thrown

Parameters:
a scaling factor for first
first the first vector to be added after scaling
b scaling factor for second
second the second vector to be added after scaling
Returns:
a reference to this vector

template<typename T>
vector<T>& cvr::vector< T >::addScaled ( const T  b,
const genericVector< T > &  other 
)

Add another vector scaled by b to this vector.

The vectors must be of the same types and dimensions. Let A be this vector and B the other vector, then this method performs:

$A=A+b\cdot B$ If both vectors have different size, an assertion will be thrown

Parameters:
b scaling factor for other
other the vector to be added after scaling
Returns:
a reference to this vector

template<typename T>
virtual vector<T>* cvr::vector< T >::clone (  )  const [virtual]

Create a clone of this vector.

Returns:
a pointer to a copy of this vector

Reimplemented from cvr::genericVector< T >.

template<typename T>
T cvr::vector< T >::computeProductOfElements (  )  const

Calculate the product of all elements of the vector.

This member can be used with classes which define the operator '*='

template<typename T>
T cvr::vector< T >::computeSumOfElements (  )  const

Calculate the sum of all elements of the vector.

This member can be used with classes which define the operator '+='

template<typename T>
vector<T>& cvr::vector< T >::divide ( const genericVector< T > &  other,
const T  cst 
)

Divide the other vector by a constant and leave the result here.

Returns a reference to this vector.

Parameters:
other the vector to be divide by the constant value
cst the elements of the vector will be divided with this constant
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::divide ( const T  cst  ) 

Divide this vector by a constant.

This vector will changed! Returns this vector.

Parameters:
cst the elements of the vector will be divided with this constant
Returns:
a reference to the actual vector

template<typename T>
T cvr::vector< T >::dot ( const genericVector< T > &  other  )  const

Dot product with another vector of the same type.

For complex types, this vector is complex conjugated.

If the dimensions of both vector are not the same, an assertion will be thrown.

Parameters:
other the other vector to be multiplied with
Returns:
a scalar value with the type of the vector elements

template<typename T>
vector<T>& cvr::vector< T >::edivide ( const genericVector< T > &  other,
const T  cst 
) [inline]

Divide the other vector with a constant and leave the result here.

Returns a reference to this vector.

synonym for divide(const vector<T>& other,const T cst).

Parameters:
other the vector to be divide by the constant value
cst the elements of the vector will be divided with this constant
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::edivide ( const T  cst  )  [inline]

Divide this vector with a constant.

This vector will changed! Returns this vector. synonym for divide(const T cst).

Parameters:
cst the elements of the vector will be divided with this constant
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::edivide ( const genericVector< T > &  first,
const genericVector< T > &  second 
)

Elementwise division.

This vector will contain the elementwise division of the elements in first by second. If both vectors have different size, an assertion will be thrown

Parameters:
first the first vector
second the second vector, is the divisor
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::edivide ( const genericVector< T > &  other  ) 

Elementwise division.

Each element of this vector will be divided by the elements of the other vector and the result will be left in this object! The returned vector is this object! If both vectors have different size, an assertion will be thrown

Parameters:
other the other vector to be divided by
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::emultiply ( const genericVector< T > &  first,
const genericVector< T > &  second 
)

Elementwise multiplication.

This vector will contain the elementwise multiplication of the elements in first and second. If both vectors have different size, an assertion will be thrown

Parameters:
first the first vector
second the second vector will be multiplied with the first vector
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::emultiply ( const genericVector< T > &  other  ) 

Elementwise multiplication.

Each element of this vector will be multiplied with the elements of the other vector and the result will be left in this object! If both vectors have different size, an assertion will be thrown The return vector is this object!

Parameters:
other the other vector to be multiplied with
Returns:
a reference to the actual vector

template<typename T>
void cvr::vector< T >::findExtremes ( T &  theMinimum,
T &  theMaximum 
) const

Find the extremes of the vector (smallest and biggest elements).

template<typename T>
void cvr::vector< T >::findIndexOfExtremes ( int &  theIdxMinimum,
int &  theIdxMaximum 
) const

Find the indices of the extremes of the vector (smallest and biggest elements).

template<typename T>
int cvr::vector< T >::findIndexOfMaximum (  )  const

Find the index of the biggest element of the vector.

template<typename T>
int cvr::vector< T >::findIndexOfMinimum (  )  const

Find the index of the smallest element of the vector.

template<typename T>
T cvr::vector< T >::findMaximum (  )  const

Find the biggest element of the vector.

template<typename T>
T cvr::vector< T >::findMinimum (  )  const

Find the smallest element of the vector.

template<typename T>
vector<T>& cvr::vector< T >::multiply ( const genericVector< T > &  other,
const T  cst 
)

Multiply the other vector with a constant and leave the result here.

Returns a reference to this vector. If both vectors have different size, an assertion will be thrown

Parameters:
other the other vector to be multiplied with the constant value
cst constant scalar to be multiplied with the other vector.
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::multiply ( const T  cst  ) 

Multiply this vector with a constant.

This vector will changed! Returns this vector. If both vectors have different size, an assertion will be thrown

Parameters:
cst constant scalar to be multiplied with
Returns:
a reference to the actual vector

template<typename T>
const std::string& cvr::vector< T >::name (  )  const [virtual]

Returns the name of this class.

Reimplemented from cvr::genericVector< T >.

template<typename T>
virtual vector<T>* cvr::vector< T >::newInstance (  )  const [virtual]

Create a new vector instance.

Returns:
a pointer to a new instance of vector

Reimplemented from cvr::genericVector< T >.

template<typename T>
vector<T>& cvr::vector< T >::operator*= ( const T  cst  )  [inline]

Multiply with a constant.

This vector is changed.

Parameters:
cst constant scalar to be multiplied with
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::operator+= ( const genericVector< T > &  other  )  [inline]

Alias for add(const vector<T>& other).

template<typename T>
vector<T>& cvr::vector< T >::operator+= ( const T  cst  )  [inline]

Alias for add(const T cst).

template<typename T>
vector<T>& cvr::vector< T >::operator-= ( const T  cst  )  [inline]

Alias for subtract(const T& cst).

template<typename T>
vector<T>& cvr::vector< T >::operator-= ( const genericVector< T > &  other  )  [inline]

Alias for substract(const vector<T>& other) If both vectors have different size, an assertion will be thrown.

template<typename T>
vector<T>& cvr::vector< T >::operator/= ( const T  cst  )  [inline]

Alias for divide(const T& cst).

template<typename T>
bool cvr::vector< T >::prettyCloseTo ( const genericVector< T > &  other,
const T &  tolerance 
) const

Compare this vector with other, and use the given tolerance to determine if the value of each element of the other vector approximately equals the values of the actual vector elements.

An element x is approximately equal to another element y with a tolerance t, if following equation holds: x-t < y < x+t

Parameters:
other the other vector to be compared with
tolerance the tolerance to be used
Returns:
true if both vectors are approximatly equal

template<typename T>
vector<T>& cvr::vector< T >::subtract ( const genericVector< T > &  first,
const genericVector< T > &  second 
)

Subtracts two vectors and leaves the result in this object.

If both vectors have different size, an assertion will be thrown

Parameters:
first the first vector
second the second vector will be substracted from the first vector
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::subtract ( const genericVector< T > &  other  ) 

Subtracts another vector of the same type and same dimension and leaves the result in this object If both vectors have different size, an assertion will be thrown.

Parameters:
other will be substracted from this vector
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::subtract ( const genericVector< T > &  other,
const T  cst 
)

Subtract constant from the other vector and leave the result here.

Returns a reference to this vector.

Parameters:
other the other vector
cst constant scalar to be subtracted from each element of the other vector
Returns:
a reference to the actual vector

template<typename T>
vector<T>& cvr::vector< T >::subtract ( const T  cst  ) 

Subtract constant from this vector.

This vector is changed. Returns this vector.

Parameters:
cst constant scalar to be subtracted from each element
Returns:
a reference to the actual vector


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

Generated on Sun Sep 20 22:09:06 2009 for CVR-Lib by Doxygen 1.5.8