latest version v1.9 - last update 10 Apr 2010 |
Vector container class. More...
#include <ltiGenericVector.h>
Classes | |
class | const_iterator |
const iterator type (allows read-only operations). More... | |
class | constReferenceException |
constReferenceException class More... | |
class | iterator |
iterator type (allows read and write operations). More... | |
Public Types | |
typedef T | value_type |
typedef int | size_type |
Public Member Functions | |
genericVector () | |
genericVector (int theSize, const T &iniValue=T()) | |
genericVector (int theSize, const T data[]) | |
genericVector (int theSize, T data[], const bool constRef) | |
genericVector (const genericVector< T > &other) | |
genericVector (const genericVector< T > &other, int from, int to=MaxInt32) | |
genericVector (const genericVector< T > &other, const genericVector< int > &idx) | |
genericVector (const std::vector< T > &other) | |
genericVector (bool init, int theSize) | |
virtual | ~genericVector () |
const char * | getTypeName () const |
bool | ownsData () const |
void | restoreOwnership () |
void | useExternData (int theSize, T *data, bool constRef=false) |
void | attach (int theSize, T *data) |
void | detach (genericVector< T > &receiver) |
void | exchange (genericVector< T > &other) |
void | swap (genericVector< T > &other) |
const int & | size () const |
int | firstIdx () const |
const_iterator | begin () const |
iterator | begin () |
int | lastIdx () const |
const_iterator | end () const |
iterator | end () |
iterator | inverseBegin () |
const_iterator | inverseBegin () const |
iterator | inverseEnd () |
const_iterator | inverseEnd () const |
void | resize (int newSize, const T &iniValue=T(), bool copyData=true, bool initNew=true) |
void | clear () |
bool | empty () const |
void | fill (const T &iniValue, int from=0, int to=MaxInt32) |
void | fill (const T data[], int from=0, int to=MaxInt32) |
void | fill (const genericVector< T > &vct, int from=0, int to=MaxInt32, int startAt=0) |
T & | at (const int x) |
const T & | at (const int x) const |
T & | operator[] (const int x) |
const T & | operator[] (const int x) const |
genericVector< T > & | copy (const genericVector< T > &other) |
genericVector< T > & | copy (const genericVector< T > &other, int from, int to=MaxInt32) |
genericVector< T > & | copy (const genericVector< T > &other, const genericVector< int > &idx) |
genericVector< T > & | operator= (const genericVector< T > &other) |
virtual mathObject * | clone () const |
bool | equals (const genericVector< T > &other) const |
bool | operator== (const genericVector< T > &other) const |
bool | operator!= (const genericVector< T > &other) const |
template<class U > | |
genericVector< T > & | castFrom (const genericVector< U > &other) |
template<class U > | |
genericVector< T > & | castFrom (const std::vector< U > &other) |
Apply Methods | |
genericVector< T > & | apply (T(*function)(T)) |
genericVector< T > & | apply (const genericVector< T > &other, T(*function)(T)) |
genericVector< T > & | apply (T(*function)(const T &)) |
genericVector< T > & | apply (const genericVector< T > &other, T(*function)(const T &)) |
genericVector< T > & | apply (const genericVector< T > &other, T(*function)(const T &, const T &)) |
genericVector< T > & | apply (const genericVector< T > &other, T(*function)(T, T)) |
genericVector< T > & | apply (const genericVector< T > &a, const genericVector< T > &b, T(*function)(const T &, const T &)) |
genericVector< T > & | apply (const genericVector< T > &a, const genericVector< T > &b, T(*function)(T, T)) |
Input and Output | |
virtual bool | write (ioHandler &handler, const bool complete=true) const |
virtual bool | read (ioHandler &handler, const bool complete=true) |
Protected Attributes | |
int | vectorSize |
int | idxLastElement |
T * | theElements |
bool | ownData |
bool | constReference |
Vector container class.
The lti::genericVector 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. This means, you should not try to make lti::genericVector of other vectors or matrices, which administrate some memory. If you do so, the behaviour of copy or fill operations will be unpredictable.
The difference between lti::genericVector and its most used inherited class lti::vector is the support for arithmetical operations. The generic vector is more a container than a multi-dimensional point representation. It inherits its memory managment versatility to lti::vector. Again, it is usually employed as a container of any static type, which do not do by itself any memory managment.
The genericVector class is a generic container class implemented as template.
If you need to create a vector of floats with 256 elements all initialized with a value of 4.27 just create it:
lti::genericVector<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 }
typedef int lti::genericVector< T >::size_type |
Return type of the size() member.
typedef T lti::genericVector< T >::value_type |
Type of the genericVector elements.
lti::genericVector< T >::genericVector | ( | ) |
Default constructor creates an empty genericVector;.
lti::genericVector< T >::genericVector | ( | int | theSize, | |
const T & | iniValue = T() | |||
) | [explicit] |
Create a genericVector of the given size and initialize it with the given value.
theSize | number of elements of the genericVector. | |
iniValue | all elements will be initialized with this value. |
lti::genericVector< T >::genericVector | ( | int | theSize, | |
const T | data[] | |||
) |
Create a genericVector of the given size and initialize it with the given data.
The data will be copied.
theSize | number of elements of the genericVector. | |
data | a pointer to the data that will be copied. |
lti::genericVector< T >::genericVector | ( | int | theSize, | |
T | data[], | |||
const bool | constRef | |||
) |
Create a genericVector 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 genericVector. | |
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 genericVector. Despite this, the value of each element can be changed by the access operators. |
lti::genericVector< T >::genericVector | ( | const genericVector< T > & | other | ) |
Create this genericVector as a copy of another genericVector.
other | the genericVector to be copied. |
lti::genericVector< T >::genericVector | ( | const genericVector< T > & | other, | |
int | from, | |||
int | to = MaxInt32 | |||
) |
Create this genericVector as a copy of specified interval of elements of another genericVector.
Indices below zero are set to zero, indices greater than the size of the genericVector to the size-1.
other | the genericVector to be copied. | |
from | starting point included | |
to | end point included. |
lti::genericVector< T >::genericVector | ( | const genericVector< T > & | other, | |
const genericVector< int > & | idx | |||
) |
Create this genericVector as a copy of specified elements of another genericVector.
idx can contain the same index more than once.
other | the genericVector to be copied. | |
idx | indices of the elements to be copied |
lti::genericVector< T >::genericVector | ( | const std::vector< T > & | other | ) |
Create this genericVector as a copy of another std::genericVector.
other | the genericVector to be copied. |
lti::genericVector< T >::genericVector | ( | bool | init, | |
int | theSize | |||
) |
If init is true this constructor is equivalent to calling genericVector(int theSize), and thus initializing all elements with T().
However, in some cases the elements need not be initialized during construction, since complex initializion is required. Especially for large genericVectors, the unnecessary constructor initialization is very time consuming.
If init is false, memory is allocated but no initialization takes place. Thus the following is equivalent:
genericVector<int> a(false,10000); matrix<int> a; a.resize(10000,0,false,false);
init | initialize matrix or not | |
theSize | number of elements of the genericVector. |
virtual lti::genericVector< T >::~genericVector | ( | ) | [virtual] |
destructor
genericVector<T>& lti::genericVector< T >::apply | ( | const genericVector< T > & | a, | |
const genericVector< T > & | b, | |||
T(*)(T, T) | function | |||
) |
a two-parameter C-function receives the i-th elements of the given genericVectors and leaves the result here.
Note that both genericVectors MUST have the same size! If both genericVectors have different size, the function will throw an assertion without changing anything!
a | the first genericVector | |
b | the second genericVector | |
function | a pointer to a two parameters C-function |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
genericVector<T>& lti::genericVector< T >::apply | ( | const genericVector< T > & | a, | |
const genericVector< T > & | b, | |||
T(*)(const T &, const T &) | function | |||
) |
a two-parameter C-function receives the i-th elements of the given genericVectors and leaves the result here.
Note that both genericVectors MUST have the same size! If both genericVectors have different size, the function will throw an assertion without changing anything!
The following example uses lti::min as function. The genericVectors a and b contain the values [1,2,3,4] and [4,3,2,1], respectively. After applying the function, genericVector c contains the values [1,2,2,1].
igenericVector a,b,c; int i=0; for (i=0; i<4; ++i) { a.at(i)=i+1; b.at(i)=4-i; } c.apply(a,b,lti::min);
a | the first genericVector | |
b | the second genericVector | |
function | a pointer to a two parameters C-function |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
genericVector<T>& lti::genericVector< T >::apply | ( | const genericVector< T > & | other, | |
T(*)(T, T) | function | |||
) |
a two-parameter C-function receives the i-th elements of this and the given genericVector and the result will be left in this genericVector.
Note that both genericVectors MUST have the same size! If both genericVectors have different size, the function will throw an assertion without changing anything!
other | the second genericVector to be considered (the first genericVector will be this object!) | |
function | a pointer to a two parameters C-function |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
genericVector<T>& lti::genericVector< T >::apply | ( | const genericVector< T > & | other, | |
T(*)(const T &, const T &) | function | |||
) |
a two-parameter C-function receives the i-th elements of this and the given genericVector and the result will be left in this genericVector.
Note that both genericVectors MUST have the same size! If both genericVectors have different size, the function will throw an assertion without changing anything!
other | the second genericVector to be considered (the first genericVector will be this object!) | |
function | a pointer to a two parameters C-function |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
genericVector<T>& lti::genericVector< T >::apply | ( | const genericVector< T > & | other, | |
T(*)(const T &) | function | |||
) |
applies a C-function to each element the other genericVector and leaves the result here.
other | the genericVector with the source data | |
function | a pointer to a C-function |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
genericVector<T>& lti::genericVector< T >::apply | ( | T(*)(const T &) | function | ) |
applies a C-function to each element of the genericVector.
function | a pointer to a C-function |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
genericVector<T>& lti::genericVector< T >::apply | ( | const genericVector< T > & | other, | |
T(*)(T) | function | |||
) |
applies a C-function to each element of the other genericVector and leaves the result here.
other | the source genericVector | |
function | a pointer to a C-function |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
genericVector<T>& lti::genericVector< T >::apply | ( | T(*)(T) | function | ) |
applies a C-function to each element of the genericVector.
In the following example, genericVector vct is initialized with 4.0. After applying sqrt(), all elements of vct are 2.0.
function | a pointer to a C-function |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
const T& lti::genericVector< T >::at | ( | const int | x | ) | const [inline] |
access element x of the genericVector in a read-only modus
x | index of the genericVector element to be accessed. It should be between firstIdx() and lastIdx() |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
T& lti::genericVector< T >::at | ( | const int | x | ) | [inline] |
access element x of the genericVector
x | index of the genericVector element to be accessed. It should be between firstIdx() and lastIdx() |
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
Referenced by lti::decimation::apply(), lti::hPoint3D< T >::dot(), lti::hPoint2D< T >::dot(), lti::SOFM2DVisualizer::drawClasses(), lti::kNNClassifier::getColumnId(), lti::linePattern::isSet(), lti::medianFilter::realMedian(), lti::homography9DofEstimator::transform(), and lti::homography8DofEstimator::transform().
void lti::genericVector< T >::attach | ( | int | theSize, | |
T * | data | |||
) |
Attach extern data to the matrix.
This member allows the use of this object as an access-functor for the 'data'. An access to the element at (x) is equivalent to data[x]. If theSize is an invalid dimension, the behaviour will be unpredictible.
The memory will be administrated by this genericVector instance, and may be deleted if required (genericVector deleted or resized!). The user should not try to manipulate the memory allocation of the data after the attachment! See also useExternData().
theSize | number of elements of the genericVector | |
data | a pointer to the memory block to be used |
Example:
lti::genericVector<int> myVct; int block1[25]; int* block2; block2 = new int[25]; myVct.useExternData(25,block1); // ok myVct.attach(25,block1); // wrong!!! matrix will try to manipulate // stack memory: DO NOT DO THIS!!!!! myVct.attach(25,block2); // ok! but do not try to delete the memory // block2!!
iterator lti::genericVector< T >::begin | ( | ) | [inline] |
Returns iterator pointing to the first element.
The use of the iterators is similar to the iterators of the Standard Template Library (STL). If you need to iterate on all elements of the genericVector, you can use following code:
int tmp,accu; // a temporal variable lti::genericVector<int> myVct(10,1); // a genericVector with 10 elements lti::genericVector<int>::iterator it=myVct.begin(); // an iterator set to the beginning of myVct lti::genericVector<int>::iterator eit=myVct.begin(); // an iterator set to the end of myVct for (; it!=eit ; ++it) { tmp = *it; // tmp has value of element pointed // by the iterator. accu += tmp; (*it) = accu; // change the value in the genericVector. }
NOTE: It is significantly faster in debug builds to use a pre-increment with iterators (++it) than a post-increment (it++).
Please note that if you define it as a const_iterator, you can not do something like *it=accu.
const_iterator lti::genericVector< T >::begin | ( | ) | const [inline] |
Returns first element as a const_iterator.
Note that you can not change the values of the genericVector elements when you use a const_iterator. See also begin()
Referenced by lti::MLP::sigmoidFunctor::apply(), lti::MLP::signFunctor::apply(), lti::decimation::apply(), lti::tpointList< int >::castFrom(), lti::genericVector< point >::castFrom(), lti::cityBlockDistance(), lti::MLP::sigmoidFunctor::deriv(), lti::distanceSqr(), and lti::translationScaleEstimator::transform().
genericVector<T>& lti::genericVector< T >::castFrom | ( | const std::vector< U > & | other | ) | [inline] |
cast from a std::vector of the same type
genericVector<T>& lti::genericVector< T >::castFrom | ( | const genericVector< U > & | other | ) | [inline] |
copy the other genericVector by casting each of its elements.
other | The genericVector to be copied. |
For Example:
lti::genericVector<int> vctA(10,1); // a genericVector of integers lti::genericVector<double> vctB; // a genericVector of doubles vctB.castFrom(vctA); // this will copy vctA in vctB!!
Referenced by lti::mapperFunctor< Tin, Tout >::parameters::generateFrom().
void lti::genericVector< T >::clear | ( | ) |
clears the genericVector (dimension 0)
Referenced by lti::genericInterpolator< T >::parameters::parameters(), and lti::genericInterpolator< T >::parameters::~parameters().
virtual mathObject* lti::genericVector< T >::clone | ( | ) | const [virtual] |
create a clone of this genericVector
Implements lti::mathObject.
Reimplemented in lti::kernel1D< T >, lti::vector< T >, lti::kernel1D< double >, lti::kernel1D< float >, lti::vector< Tin >, lti::vector< int32 >, lti::vector< value_type >, lti::vector< double >, lti::vector< float >, lti::vector< int >, lti::vector< U >, lti::vector< trgbPixel< float > >, lti::vector< bufferElement >, lti::vector< Tout >, lti::vector< tpoint< float > >, lti::vector< ubyte >, lti::vector< rgbPixel >, and lti::vector< point >.
genericVector<T>& lti::genericVector< T >::copy | ( | const genericVector< T > & | other, | |
const genericVector< int > & | idx | |||
) |
assignment operator.
copy of specified elements of other in this object. idx can contain the same index more than once.
other | the genericVector to be copied. | |
idx | indices of the elements to be copied |
genericVector<T>& lti::genericVector< T >::copy | ( | const genericVector< T > & | other, | |
int | from, | |||
int | to = MaxInt32 | |||
) |
assignment operator.
copy of specified interval of elements of another genericVector.
other | the genericVector to be copied. | |
from | starting point included | |
to | end point included. |
genericVector<T>& lti::genericVector< T >::copy | ( | const genericVector< T > & | other | ) |
assigment operator.
copy the contents of other in this object.
other | the source genericVector to be copied. |
Reimplemented from lti::ioObject.
Reimplemented in lti::kernel1D< T >, lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
Referenced by lti::MLP::linearActFunctor::apply(), lti::mapperFunctor< Tin, Tout >::parameters::copy(), lti::genericInterpolator< T >::parameters::copy(), and lti::genericVector< point >::operator=().
void lti::genericVector< T >::detach | ( | genericVector< T > & | receiver | ) |
Free the data of this object and hand it over to the "receiver".
The value of ownsData is also transfered to the receiver. (see Note).
This function makes a "memory block transfusion" to another genericVector. It is a very efficient way to make a copy of this genericVector, if you don't need the source data anymore!
Note: Take care that if the attach() or useExternData() methods of this genericVector have been called before detachment, the same rules for memory management apply now for the receiver.
At the end of the detachment, this genericVector will be empty.
receiver | the genericVector which will receive the memory block. All data of that genericVector will be first deleted! |
Referenced by lti::decimation::apply().
bool lti::genericVector< T >::empty | ( | ) | const |
returns true if the genericVector is empty
iterator lti::genericVector< T >::end | ( | ) | [inline] |
const_iterator lti::genericVector< T >::end | ( | ) | const [inline] |
returns last index as a const iterator.
For an example see begin()
Referenced by lti::MLP::sigmoidFunctor::apply(), lti::MLP::signFunctor::apply(), lti::decimation::apply(), lti::tpointList< int >::castFrom(), lti::genericVector< point >::castFrom(), lti::cityBlockDistance(), lti::MLP::sigmoidFunctor::deriv(), and lti::distanceSqr().
bool lti::genericVector< T >::equals | ( | const genericVector< T > & | other | ) | const |
compare this genericVector with other
other | the other genericVector to be compared with |
void lti::genericVector< T >::exchange | ( | genericVector< T > & | other | ) |
void lti::genericVector< T >::fill | ( | const genericVector< T > & | vct, | |
int | from = 0 , |
|||
int | to = MaxInt32 , |
|||
int | startAt = 0 | |||
) |
fills the genericVector elements from from to to with the elements of vct starting at startAt.
vct | genericVector with the elements to be copied | |
from | first element index of the actual genericVector | |
to | last element index of the actual genericVector | |
startAt | start index of the source genericVector vct. |
Example: if a = [0 0 0 0 0] and b = [1 2 3], after a.fill(b,3,4,1) results a = [0 0 0 2 3]
void lti::genericVector< T >::fill | ( | const T | data[], | |
int | from = 0 , |
|||
int | to = MaxInt32 | |||
) |
fills the genericVector elements with data pointed by data between from and to.
data | the data to by copied into this genericVector | |
from | first element index | |
to | last element index |
If from or to are out of bounds, they will be (internaly) adjusted to to correct value.
Example:
double* data = {2,4,8,16}; lti::genericVector<double> myVct(10,0); // genericVector with 10 elements // with 0 myVct.fill(data,1,3); // myVct=[0,2,4,8,0,0,0,0,0,0]
void lti::genericVector< T >::fill | ( | const T & | iniValue, | |
int | from = 0 , |
|||
int | to = MaxInt32 | |||
) |
fills the genericVector elements with iniValue between from and to.
iniValue | the elements will be initialized with this value. | |
from | first element index | |
to | last element index |
If from or to are out of bounds, they will be (internaly) adjusted to to correct value.
Example:
lti::genericVector<double> myVct(10,0); // genericVector with 10 elements // with 0 myVct.fill(9,1,3); // myVct=[0,9,9,9,0,0,0,0,0,0]
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
Referenced by lti::MLP::signFunctor::deriv(), lti::MLP::linearActFunctor::deriv(), and lti::medianFilter::realMedian().
int lti::genericVector< T >::firstIdx | ( | ) | const [inline] |
Returns first index (normally 0).
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
const char* lti::genericVector< T >::getTypeName | ( | void | ) | const [inline, virtual] |
returns the name of this class: "genericVector"
Reimplemented from lti::mathObject.
Reimplemented in lti::kernel1D< T >, lti::array< T >, lti::vector< T >, lti::kernel1D< double >, lti::kernel1D< float >, lti::array< double >, lti::array< float >, lti::array< int >, lti::vector< Tin >, lti::vector< int32 >, lti::vector< value_type >, lti::vector< double >, lti::vector< float >, lti::vector< int >, lti::vector< U >, lti::vector< trgbPixel< float > >, lti::vector< bufferElement >, lti::vector< Tout >, lti::vector< tpoint< float > >, lti::vector< ubyte >, lti::vector< rgbPixel >, and lti::vector< point >.
const_iterator lti::genericVector< T >::inverseBegin | ( | ) | const [inline] |
This method returns an iterator that points to the last valid element of the genericVector.
See inverseBegin() for more details.
iterator lti::genericVector< T >::inverseBegin | ( | ) | [inline] |
This method returns an iterator that points to the last valid element of the genericVector.
It is used for inverse order iteration through the genericVector using normal iterators (as opposed to reverse_iterators used in the STL). This has the advantage that iterators going from front to end and in the inverse direction are the same and can thus be compared, copied etc. Further the implementation of reverse_iterators is not as fast as that of iterators and thus not desired in the LTI-Lib.
igenericVector v(false,10); int i,tmp; for (i=0; i<10; i++) { v.at(i)=i; } igenericVector::iterator forwardIt=v.begin(); igenericVector::iterator backIt=v.inverseBegin(); while (forwardIt<=backIt) { tmp = (*forwardIt); (*forwardIt)=(*backIt); (*backIt)=tmp; ++forwardIt; ++backIt; }
const_iterator lti::genericVector< T >::inverseEnd | ( | ) | const [inline] |
This method returns an iterator that points to the element before the first valid element of the genericVector.
iterator lti::genericVector< T >::inverseEnd | ( | ) | [inline] |
This method returns an iterator that points to the element before the first valid element of the genericVector.
It is used to mark the end for inverse order iteration through the genericVector using normal iterators (as opposed to reverse_iterators as used in the STL). This has the advantage that iterators going from front to end and in the inverse direction are the same and can thus be compared, copied etc.Further the implementation of reverse_iterators is not as fast as that of iterators and thus not desired in the LTI-Lib.
int lti::genericVector< T >::lastIdx | ( | ) | const [inline] |
returns last index (in a genericVector this is always size()-1)
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
bool lti::genericVector< T >::operator!= | ( | const genericVector< T > & | other | ) | const [inline] |
compare this genericVector with other
other | the other genericVector to be compared with |
genericVector<T>& lti::genericVector< T >::operator= | ( | const genericVector< T > & | other | ) | [inline] |
assigment operator (alias for copy(other)).
other | the genericVector to be copied |
Reimplemented from lti::ioObject.
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
bool lti::genericVector< T >::operator== | ( | const genericVector< T > & | other | ) | const [inline] |
compare this genericVector with other
other | the other genericVector to be compared with |
const T& lti::genericVector< T >::operator[] | ( | const int | x | ) | const [inline] |
const access operator (alias for at(const int x) const).
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
T& lti::genericVector< T >::operator[] | ( | const int | x | ) | [inline] |
access operator (alias for at(const int x)).
Reimplemented in lti::array< T >, lti::array< double >, lti::array< float >, and lti::array< int >.
bool lti::genericVector< T >::ownsData | ( | ) | const [inline] |
Check whether this object owns the data.
returns false if this genericVector contains a reference to extern data.
virtual bool lti::genericVector< T >::read | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | [virtual] |
read the object from the given ioHandler
Reimplemented from lti::mathObject.
Reimplemented in lti::kernel1D< T >, lti::array< T >, lti::kernel1D< double >, lti::kernel1D< float >, lti::array< double >, lti::array< float >, and lti::array< int >.
void lti::genericVector< T >::resize | ( | int | newSize, | |
const T & | iniValue = T() , |
|||
bool | copyData = true , |
|||
bool | initNew = true | |||
) |
change dimension of the genericVector.
newSize | the new size of the genericVector | |
iniValue | the initialization value. | |
copyData | if this parameter is true, the old data of the genericVector will be copied. If it is false, the old data will be lost. | |
initNew | if this parameter is true, then all new elements (if they exist) will be initialized with iniValue. if initNew is false, then the new elements are left uninitialized. |
For example:
lti::genericVector<int> myVct; // creates empty genericVector myVct.resize(5,0); // genericVector with 5 elements initialized // with 0 myVct.resize(10,2); // genericVector has now 10 elements: the // first five are still 0 and the // rest have a 2 myVct.resize(20,3,false,false); // now the genericVector has 20 // elements but their values // are unknown. myVct.resize(5,1,false,true); // the genericVector has now 5 // elements initialized with 1 // note that the last line could also be written: myVct.resize(5,1,false); // the genericVector has now 5 // elements initialized with 1
If the new size is not equal to the old size, the genericVector always owns the data afterwards (i.e. new memory is allocated) even if it didn't own the data before. Otherwise the ownership remains unchanged. You can use restoreOwnership() if you just want to own the data.
Referenced by lti::MLP::sigmoidFunctor::apply(), lti::MLP::signFunctor::apply(), lti::decimation::apply(), lti::genericVector< point >::castFrom(), and lti::mapperFunctor< Tin, Tout >::parameters::generateFrom().
void lti::genericVector< T >::restoreOwnership | ( | ) |
If this object does not own its data, this member will create a new memory buffer with the same data and will make this matrix as its owner.
You can also be sure, that the new memory block will be connected (see also getMode() ). If this genericVector already owns its data nothing happens.
const int& lti::genericVector< T >::size | ( | ) | const [inline] |
Returns the number of elements of the genericVector.
Referenced by lti::MLP::sigmoidFunctor::apply(), lti::MLP::signFunctor::apply(), lti::earthMoversDistance< W, C, D >::apply(), lti::genericVector< point >::castFrom(), lti::cityBlockDistance(), lti::sparseHistogram::dimensions(), lti::distanceSqr(), lti::hPoint3D< T >::dot(), lti::hPoint2D< T >::dot(), and lti::hmmOnlineClassifier::wordErrorRate().
void lti::genericVector< T >::swap | ( | genericVector< T > & | other | ) |
Exchange (in a fast way) the data between this and the other genericVector.
Similar to detach(), this method will exchange the complete memory blocks, avoiding an element-wise copy.
other | the genericVector with which the data will be exchanged. |
void lti::genericVector< T >::useExternData | ( | int | theSize, | |
T * | data, | |||
bool | constRef = false | |||
) |
Reference to extern data.
This member allows the use of this object as an wrapper-object to access some memory block as a genericVector. The user must take care for memory allocation and deallocation of the block. This object will never delete the external data!.
theSize | number of elements in the external block. Note that this is NOT the number of bytes of the external block. | |
data | pointer to the external memory block. | |
constRef | if this parameter is true, it will not be possible to change the pointer to the external memory block nor to resize the genericVector. Despite this, the value of each element can be changed by the access operators. For Example:
int i; double tmp; double a[10]; // memory block! for (i=0;i<10;i++) { a[i]=2*i; // initialize the memory block } lti::genericVector<double> myVct; // an empty genericVector myVct.resize(5,0); // resize the genericVector: now 5 elements // initialized with 0 myVct.useExternData(10,a,true); // use the genericVector as wrapper // for the memory block tmp = myVct.at(5); // tmp is now 10 myVct.at(9) = 3; // the last element of myVct // has now the value 3 myVct.resize(5); // INVALID!! this will throw an exception // constReferenceException() |
If theSize is greater than the allocated memory, the behaviour could be unpredictible.
virtual bool lti::genericVector< T >::write | ( | ioHandler & | handler, | |
const bool | complete = true | |||
) | const [virtual] |
write the object in the given ioHandler
Reimplemented from lti::mathObject.
Reimplemented in lti::kernel1D< T >, lti::array< T >, lti::kernel1D< double >, lti::kernel1D< float >, lti::array< double >, lti::array< float >, and lti::array< int >.
bool lti::genericVector< T >::constReference [protected] |
if constReference=true, is not possible to resize or change the reference of this genericVector.
Important for the matrix class!! (see useExternData())
int lti::genericVector< T >::idxLastElement [protected] |
index of the last element of the genericVector (always vectorSize-1)
bool lti::genericVector< T >::ownData [protected] |
reference to extern data.
if this value ist false, then the data pointed by theElements will never be deleted in this object! (see useExternData())
T* lti::genericVector< T >::theElements [protected] |
pointer to the first element of the genericVector.
Referenced by lti::array< int >::at(), and lti::array< int >::castFrom().
int lti::genericVector< T >::vectorSize [protected] |
dimension of the genericVector.