Imagine++
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
Imagine::Vector< T > Class Template Reference

Vector of variable size. More...

#include "Imagine/LinAlg.h"

Inheritance diagram for Imagine::Vector< T >:
Imagine::Array< T >

Public Types

typedef Base::const_iterator const_iterator
 Const iterator type.
 
typedef Base::iterator iterator
 Iterator type.
 
- Public Types inherited from Imagine::Array< T >
typedef const T * const_iterator
 Const iterator type.
 
typedef T * iterator
 Iterator type.
 

Public Member Functions

 Vector ()
 Empty constructor. More...
 
 Vector (size_t n)
 Constructor (known size). More...
 
 Vector (const Base &v)
 Copy constructor. More...
 
 Vector (T *ptr, size_t n, bool handleDelete=false)
 Constructor (pre-allocated). More...
 
 ~Vector ()
 Destructor. More...
 
Vector clone () const
 Cloning. More...
 
Vectorfill (T x)
 Filling. More...
 
Vector getSubVect (size_t offset, size_t size) const
 Sub vector. More...
 
Vector getSubVectRef (size_t offset, size_t size)
 Sub vector by reference. More...
 
Vectornormalize ()
 Euclidean in-place normalization. More...
 
Vector operator* (T x) const
 Scalar multiplication. More...
 
operator* (const Vector &v) const
 Scalar product. More...
 
Vectoroperator*= (T x)
 Scalar in place multiplication. More...
 
Vector operator+ (const Vector &v) const
 Addition. More...
 
Vector operator+ (T x) const
 Scalar Addition. More...
 
Vectoroperator+= (const Vector &v)
 In place Addition. More...
 
Vectoroperator+= (T x)
 Scalar in place Addition. More...
 
Vector operator- (const Vector &v) const
 Substraction. More...
 
Vector operator- (T x) const
 Scalar Substraction. More...
 
Vector operator- () const
 Opposite. More...
 
Vectoroperator-= (const Vector &v)
 In place Substraction. More...
 
Vectoroperator-= (T x)
 Scalar in place substractrion. More...
 
Vector operator/ (T x) const
 Scalar division. More...
 
Vectoroperator/= (T x)
 Scalar in place division. More...
 
Vectoroperator= (const Vector &v)
 Assignment. More...
 
- Public Member Functions inherited from Imagine::Array< T >
 Array ()
 Empty constructor. More...
 
 Array (size_t size)
 Constructor (known size). More...
 
 Array (T *ptr, size_t size, bool handleDelete=false)
 Constructor (pre-allocated). More...
 
 Array (const Array &A)
 Copy constructor. More...
 
template<typename T2 >
 Array (const Array< T2 > &A)
 Constructor (different type). More...
 
 Array (const std::list< T > &L)
 Constructor (from list). More...
 
virtual ~Array ()
 Destructor. More...
 
iterator begin ()
 Begin iterator. More...
 
const_iterator begin () const
 Begin const iterator. More...
 
Array clone () const
 Cloning. More...
 
T * data ()
 Data pointer (read/write). More...
 
const T * data () const
 Data pointer (read). More...
 
bool empty () const
 Is empty. More...
 
iterator end ()
 End iterator. More...
 
const_iterator end () const
 End const iterator. More...
 
Arrayfill (const T &x)
 Filling. More...
 
Array getSubArray (size_t offset, size_t size) const
 Sub array. More...
 
bool operator!= (const Array &A) const
 Inequality test. More...
 
Arrayoperator= (const Array &A)
 Assignment. More...
 
template<typename T2 >
Arrayoperator= (const Array< T2 > &A)
 Assignment (different type). More...
 
bool operator== (const Array &A) const
 Equality test. More...
 
const T & operator[] (size_t i) const
 Read access. More...
 
T & operator[] (size_t i)
 Write access. More...
 
void setSize (size_t size)
 Change size. More...
 
size_t size () const
 Size. More...
 

Static Public Member Functions

static Vector Zero (size_t n)
 Zero vector. More...
 

Friends

Vector convolution (const Vector &K, const Vector &v)
 Convolution. More...
 
correlation (const Vector &V1, const Vector &V2)
 Correlation. More...
 
double dist (const Vector &V1, const Vector &V2)
 Distance. More...
 
maxNorm (const Vector &v)
 Maximum norm. More...
 
mean (const Vector &v)
 Mean of values. More...
 
norm (const Vector &v)
 Euclidean norm. More...
 
norm2 (const Vector &v)
 Squared Euclidean norm. More...
 
Vector normalized (const Vector &v)
 Euclidean normalization. More...
 
normalizedCorrelation (const Vector &V1, const Vector &V2)
 Normalized Correlation. More...
 
Vector operator* (T x, const Vector &v)
 Scalar multiplication. More...
 
Vector operator+ (T x, const Vector &v)
 Scalar addition. More...
 
Vector operator- (T x, const Vector &v)
 Scalar substraction. More...
 
sum (const Vector &v)
 Sum of values. More...
 
Vector truncConvolution (const Vector &K, const Vector &v, size_t n=0)
 Truncated Convolution. More...
 

Detailed Description

template<typename T>
class Imagine::Vector< T >

Vector of variable size. Memory is reference counted, i.e.:

Parameters
Tvalue type
Examples:
LinAlg/test/test.cpp.

Constructor & Destructor Documentation

◆ Vector() [1/4]

template<typename T>
Imagine::Vector< T >::Vector ( )
inline

Constructs an unallocated vector of variables of type T

Vector<T> a; // non allocated

◆ Vector() [2/4]

template<typename T>
Imagine::Vector< T >::Vector ( size_t  n)
inlineexplicit

Constructs an allocated vector of size variables of type T

Parameters
nvector size
Vector<T> b(4); // allocated with specified size

◆ Vector() [3/4]

template<typename T>
Imagine::Vector< T >::Vector ( const Base v)
inline

Constructs a vector from another one (sharing memory!)

Parameters
vvector to copy
Vector<T> c(b); // copy constructor

◆ Vector() [4/4]

template<typename T>
Imagine::Vector< T >::Vector ( T *  ptr,
size_t  n,
bool  handleDelete = false 
)
inline

Constructs a vector of variables of type T stored at an already allocated memory. Does not allocate fresh memory. Does not free given memory at object destruction unless handleDelete=true. This memory must indeed stay available during object life.

Parameters
ptraddress of memory
nvector size
handleDeletedelete memory at destruction? (default=false)
T t[]={1,2,3}; // pre-allocated
Vector<T> e(t,3);
T *t2=new T[3];
Vector<T> e2(t2,3,true); // ...

◆ ~Vector()

template<typename T>
Imagine::Vector< T >::~Vector ( )
inline

Reference counted desctructor: frees memory if the object is the last one to use it.

Member Function Documentation

◆ clone()

template<typename T>
Vector Imagine::Vector< T >::clone ( ) const
inline

Clones: creates a new vector, with fresh memory, copying values to it

Returns
cloned vector
a=b.clone(); // cloning (fresh memory)

◆ fill()

template<typename T>
Vector& Imagine::Vector< T >::fill ( x)
inline

Fills with constant value

Parameters
xvalue to be copied to each element
Returns
self reference
b.fill(1.); // filling with constant value

◆ getSubVect()

template<typename T>
Vector Imagine::Vector< T >::getSubVect ( size_t  offset,
size_t  size 
) const
inline

Construct a sub vector, i.e. a new vector with fresh memory, initialized from a part of values of *this

Parameters
offsetposition of first element of sub vector
sizesize of sub vector
Returns
sub vector
c=b.getSubVect(1,2); // sub vector

◆ getSubVectRef()

template<typename T>
Vector Imagine::Vector< T >::getSubVectRef ( size_t  offset,
size_t  size 
)
inline

Construct a sub vector without allocating new memory but pointing to some part of *this. Beware: *this (or its memory) must not be destroyed as long as the returned subvectref is used!

Parameters
offsetposition of first element of sub vector
sizesize of sub vector
Returns
sub vector
c=b.getSubVectRef(1,2); // sub vector ref (beware of restrictions!)

◆ normalize()

template<typename T>
Vector& Imagine::Vector< T >::normalize ( )
inline

In-place normalization using Euclidean norm

Returns
self reference
c.normalize(); // Euclidean in-place normalization

◆ operator*() [1/2]

template<typename T>
Vector Imagine::Vector< T >::operator* ( x) const
inline

Multiplies each coordinate by a scalar

Parameters
xThe scalar
Returns
Result
c=a*2; // * scalar

◆ operator*() [2/2]

template<typename T>
T Imagine::Vector< T >::operator* ( const Vector< T > &  v) const
inline

Scalar product of Vectors

Parameters
vVector to be combined with myself
Returns
Scalar product
x=a*b; // scalar product

◆ operator*=()

template<typename T>
Vector& Imagine::Vector< T >::operator*= ( x)
inline

Multiplies each coordinate by a scalar

Parameters
xThe scalar
Returns
self reference
c*=2; // *= scalar

◆ operator+() [1/2]

template<typename T>
Vector Imagine::Vector< T >::operator+ ( const Vector< T > &  v) const
inline

Addition of two Vectors

Parameters
vVector to be added to myself
Returns
sum
c=a+b; // +

◆ operator+() [2/2]

template<typename T>
Vector Imagine::Vector< T >::operator+ ( x) const
inline

Adds a scalar to each coordinate

Parameters
xScalar to be added to myself
Returns
sum
c=a+1; // + scalar

◆ operator+=() [1/2]

template<typename T>
Vector& Imagine::Vector< T >::operator+= ( const Vector< T > &  v)
inline

In place Addition of Vectors

Parameters
vVector to be added to myself
Returns
self reference
c+=b; // +=

◆ operator+=() [2/2]

template<typename T>
Vector& Imagine::Vector< T >::operator+= ( x)
inline

Adds a scalar to each own coordinate

Parameters
xScalar to be added to myself
Returns
self reference
c+=1; // += scalar

◆ operator-() [1/3]

template<typename T>
Vector Imagine::Vector< T >::operator- ( const Vector< T > &  v) const
inline

Substraction of two Vectors

Parameters
vVector to be substracted from myself
Returns
difference
T t[]={1,2,3}; // pre-allocated

◆ operator-() [2/3]

template<typename T>
Vector Imagine::Vector< T >::operator- ( x) const
inline

Substracts a scalar to each coordinate

Parameters
xScalar to be substracted from myself
Returns
difference
c=a-1; // - scalar

◆ operator-() [3/3]

template<typename T>
Vector Imagine::Vector< T >::operator- ( ) const
inline

Opposite of a Vector

Returns
Opposite
c=-a; // unary -

◆ operator-=() [1/2]

template<typename T>
Vector& Imagine::Vector< T >::operator-= ( const Vector< T > &  v)
inline

In place Substraction of Vectors

Parameters
vVector to be substracted from myself
Returns
self reference
c-=b; // -=

◆ operator-=() [2/2]

template<typename T>
Vector& Imagine::Vector< T >::operator-= ( x)
inline

Subtracts a scalar to each own coordinate

Parameters
xScalar to be substracted from myself
Returns
self reference
c-=1; // -= scalar

◆ operator/()

template<typename T>
Vector Imagine::Vector< T >::operator/ ( x) const
inline

Divides each coordinate by a scalar

Parameters
xThe scalar
Returns
Result
c=a/2; // / scalar

◆ operator/=()

template<typename T>
Vector& Imagine::Vector< T >::operator/= ( x)
inline

Divides each coordinate by a scalar

Parameters
xThe scalar
Returns
self reference
c/=2; // /= scalar

◆ operator=()

template<typename T>
Vector& Imagine::Vector< T >::operator= ( const Vector< T > &  v)
inline

Assigns from another vector (sharing its memory)

Parameters
vvector to be assigned to
Returns
self reference
c=b; // assignment

◆ Zero()

template<typename T>
static Vector Imagine::Vector< T >::Zero ( size_t  n)
inlinestatic

Vector with constant 0 value

Parameters
nsize
Returns
vector
b=Vector<T>::Zero(4); // Vector with constant 0 value

Examples:
LinAlg/test/test.cpp.

Friends And Related Function Documentation

◆ convolution

template<typename T>
Vector convolution ( const Vector< T > &  K,
const Vector< T > &  v 
)
friend

Convolution. Returns a vector which size if sum of sizes minus 1

Parameters
Kkernel
vvector to convolution with K
Returns
Result

◆ correlation

template<typename T>
T correlation ( const Vector< T > &  V1,
const Vector< T > &  V2 
)
friend

Correlation between 2 vectors

Parameters
V1,V2vectors
Returns
correlation
x=correlation(a,b); // correlation

◆ dist

template<typename T>
double dist ( const Vector< T > &  V1,
const Vector< T > &  V2 
)
friend

Distance Correlation between 2 vectors

Parameters
V1,V2vectors
Returns
distance
/*double y=*/dist(a,b); // distance*/

◆ maxNorm

template<typename T>
T maxNorm ( const Vector< T > &  v)
friend

Maximum norm

Parameters
vargument
Returns
Maximum norm
x=maxNorm(a); // Maximum norm

◆ mean

template<typename T>
T mean ( const Vector< T > &  v)
friend

Mean of values

Parameters
vargument
Returns
Result
x=mean(a); // mean of values

◆ norm

template<typename T>
T norm ( const Vector< T > &  v)
friend

Euclidean norm

Parameters
vargument
Returns
squared Euclidean norm
x=norm2(a); // squared Euclidean norm

◆ norm2

template<typename T>
T norm2 ( const Vector< T > &  v)
friend

Squared Euclidean norm. NB: obtained from Euclidean norm, thus it's not faster to use norm2() instead of norm() ...

Parameters
vargument
Returns
squared Euclidean norm
x=norm2(a); // squared Euclidean norm

◆ normalized

template<typename T>
Vector normalized ( const Vector< T > &  v)
friend

Normalization using Euclidean norm

Parameters
vVector to normalize
Returns
normalized vector
c=normalized(a); // Euclidean normalization

◆ normalizedCorrelation

template<typename T>
T normalizedCorrelation ( const Vector< T > &  V1,
const Vector< T > &  V2 
)
friend

Normalized Correlation between 2 vectors

Parameters
V1,V2vectors
Returns
correlation
x=normalizedCorrelation(a,b); // normalized correlation

◆ operator*

template<typename T>
Vector operator* ( x,
const Vector< T > &  v 
)
friend

Multiplies each coordinate by a scalar

Parameters
xThe scalar
vThe Vector
Returns
The result
c=2*a; // scalar * Vector

◆ operator+

template<typename T>
Vector operator+ ( x,
const Vector< T > &  v 
)
friend

Adds a scalar to each coordinate

Parameters
xThe scalar
vThe Vector
Returns
The result
c=1+a; // scalar + Vector

◆ operator-

template<typename T>
Vector operator- ( x,
const Vector< T > &  v 
)
friend

Substract each coordinate to a scalar

Parameters
xThe scalar
vThe Vector
Returns
The result
c=1-a; // scalar - Vector

◆ sum

template<typename T>
T sum ( const Vector< T > &  v)
friend

Sum of values

Parameters
vargument
Returns
Result
x=sum(a); // sum of values

◆ truncConvolution

template<typename T>
Vector truncConvolution ( const Vector< T > &  K,
const Vector< T > &  v,
size_t  n = 0 
)
friend

Truncated convolution. Returns a vector of the same size than v.

Parameters
Kkernel
vvector to convolution with K
nshift
Returns
Result
c=truncConvolution(K,a,1); // Truncated convolution


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