last update 20 Sep 2009 |
#include <cvrVector.h>
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 | |
T | 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) |
T | computeSumOfElements () const |
T | computeProductOfElements () const |
Find extreme values | |
T | findMinimum () const |
int | findIndexOfMinimum () const |
T | findMaximum () const |
int | findIndexOfMaximum () const |
void | findExtremes (T &theMinimum, T &theMaximum) const |
void | findIndexOfExtremes (int &theIdxMinimum, int &theIdxMaximum) const |
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:
typedef genericVector<T>::const_iterator cvr::vector< T >::const_iterator |
typedef genericVector<T>::iterator cvr::vector< T >::iterator |
cvr::vector< T >::vector | ( | ) |
Default constructor creates an empty vector;.
cvr::vector< T >::vector | ( | const int | theSize | ) | [explicit] |
Create a vector of the given size.
The content of the vector is undefined.
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.theSize | number of elements of the vector. |
cvr::vector< T >::vector | ( | const int | theSize, | |
const T & | iniValue | |||
) | [explicit] |
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.
theSize | number of elements of the vector. | |
data | a pointer to the data that will be copied. |
cvr::vector< T >::vector | ( | const int | theSize, | |
T | 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!.
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: |
cvr::vector< T >::vector | ( | const genericVector< T > & | other | ) |
cvr::vector< T >::vector | ( | const genericVector< T > & | other, | |
const int | from, | |||
const int | to = genericVector< T >::MaxIndex | |||
) |
cvr::vector< T >::vector | ( | const genericVector< T > & | other, | |
const genericVector< int > & | idx | |||
) |
cvr::vector< T >::vector | ( | const std::vector< T > & | other | ) |
virtual cvr::vector< T >::~vector | ( | ) | [virtual] |
Destructor.
vector<T>& cvr::vector< T >::add | ( | const genericVector< T > & | other, | |
const T | cst | |||
) |
vector<T>& cvr::vector< T >::add | ( | const T | cst | ) |
vector<T>& cvr::vector< T >::add | ( | const genericVector< T > & | first, | |
const genericVector< T > & | second | |||
) |
vector<T>& cvr::vector< T >::add | ( | const genericVector< T > & | other | ) |
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:
If both vectors have different size, an assertion will be thrown
first | the first vector to be added after scaling | |
b | scaling factor for second | |
second | the second vector to be added after scaling |
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:
If both vectors have different size, an assertion will be thrown
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 |
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:
If both vectors have different size, an assertion will be thrown
b | scaling factor for other | |
other | the vector to be added after scaling |
virtual vector<T>* cvr::vector< T >::clone | ( | ) | const [virtual] |
Create a clone of this vector.
Reimplemented from cvr::genericVector< 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 '*='
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 '+='
vector<T>& cvr::vector< T >::divide | ( | const genericVector< T > & | other, | |
const T | cst | |||
) |
vector<T>& cvr::vector< T >::divide | ( | const T | cst | ) |
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.
other | the other vector to be multiplied with |
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).
other | the vector to be divide by the constant value | |
cst | the elements of the vector will be divided with this constant |
vector<T>& cvr::vector< T >::edivide | ( | const T | cst | ) | [inline] |
vector<T>& cvr::vector< T >::edivide | ( | const genericVector< T > & | first, | |
const genericVector< T > & | second | |||
) |
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
other | the other vector to be divided by |
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
first | the first vector | |
second | the second vector will be multiplied with the first vector |
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!
other | the other vector to be multiplied with |
void cvr::vector< T >::findExtremes | ( | T & | theMinimum, | |
T & | theMaximum | |||
) | const |
Find the extremes of the vector (smallest and biggest elements).
void cvr::vector< T >::findIndexOfExtremes | ( | int & | theIdxMinimum, | |
int & | theIdxMaximum | |||
) | const |
Find the indices of the extremes of the vector (smallest and biggest elements).
int cvr::vector< T >::findIndexOfMaximum | ( | ) | const |
Find the index of the biggest element of the vector.
int cvr::vector< T >::findIndexOfMinimum | ( | ) | const |
Find the index of the smallest element of the vector.
T cvr::vector< T >::findMaximum | ( | ) | const |
Find the biggest element of the vector.
T cvr::vector< T >::findMinimum | ( | ) | const |
Find the smallest element of the vector.
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
other | the other vector to be multiplied with the constant value | |
cst | constant scalar to be multiplied with the other vector. |
vector<T>& cvr::vector< T >::multiply | ( | const T | cst | ) |
const std::string& cvr::vector< T >::name | ( | ) | const [virtual] |
virtual vector<T>* cvr::vector< T >::newInstance | ( | ) | const [virtual] |
Create a new vector instance.
Reimplemented from cvr::genericVector< T >.
vector<T>& cvr::vector< T >::operator*= | ( | const T | cst | ) | [inline] |
vector<T>& cvr::vector< T >::operator+= | ( | const genericVector< T > & | other | ) | [inline] |
Alias for add(const vector<T>& other).
vector<T>& cvr::vector< T >::operator+= | ( | const T | cst | ) | [inline] |
Alias for add(const T cst).
vector<T>& cvr::vector< T >::operator-= | ( | const T | cst | ) | [inline] |
Alias for subtract(const T& cst).
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.
vector<T>& cvr::vector< T >::operator/= | ( | const T | cst | ) | [inline] |
Alias for divide(const T& cst).
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
other | the other vector to be compared with | |
tolerance | the tolerance to be used |
vector<T>& cvr::vector< T >::subtract | ( | const genericVector< T > & | first, | |
const genericVector< T > & | second | |||
) |
vector<T>& cvr::vector< T >::subtract | ( | const genericVector< T > & | other | ) |
vector<T>& cvr::vector< T >::subtract | ( | const genericVector< T > & | other, | |
const T | cst | |||
) |
vector<T>& cvr::vector< T >::subtract | ( | const T | cst | ) |