golib  0.5
goMath::Vector< T > Class Template Reference

General vector class. More...

#include <govector.h>

Public Types

typedef T value_type
 

Public Member Functions

 Vector (goSize_t s, goSize_t reserve=0, goSize_t resize_overhead=0)
 
 Vector (T *ptr, goSize_t size, goIndex_t stride=1)
 
 Vector (const goFixedArray< T > &o)
 
Vector< T > & operator= (const goFixedArray< T > &other)
 
void print (const char *formatstring="%f\n") const
 
Vector< T > operator* (const goMath::Matrix< T > &M) const
 Quite inefficient vector-matrix multiplication. More...
 
Vector< T > cross (const Vector< T > &other) const
 
bool cross (const Vector< T > &other, Vector< T > &ret) const
 
operator* (const Vector< T > &other) const
 Inner product. More...
 
Vector< T > & operator*= (T scalar)
 
Vector< T > & operator/= (T scalar)
 
Vector< T > & operator-= (T s)
 
Vector< T > & operator+= (T s)
 
Vector< T > & operator+= (const Vector< T > &other)
 
Vector< T > & operator-= (const Vector< T > &other)
 
Vector< T > operator- (const Vector< T > &other) const
 
Vector< T > operator+ (const Vector< T > &other) const
 
Vector< T > operator* (T scalar) const
 
Vector< T > operator/ (T scalar) const
 
template<class To >
Vector< T > & operator*= (const Vector< To > &other)
 
template<class To >
Vector< T > & operator/= (const Vector< To > &other)
 
Vector< T > & operator*= (const goMath::Matrix< T > &m)
 this = m * this More...
 
void outerProduct (const Vector< T > &other, goMath::Matrix< T > &ret) const
 Outer product. More...
 
template<class To >
bool copy (Vector< To > &target, goIndex_t startIndex=0, goIndex_t skip=0, goIndex_t lastIndex=-1) const
 
template<class To >
bool copy (To *target, goIndex_t startIndex=0, goIndex_t skip=0, goIndex_t lastIndex=-1) const
 
template<class To , class To2 >
bool cat (const Vector< To > &other, Vector< To2 > &target) const
 
square () const
 
conjInnerProduct (const Vector< T > &) const
 
abs () const
 Deprecated. Calls norm2() for scalar real types, special implementation for goComplex types. More...
 
norm2 () const
 2-Norm of this vector. More...
 
norm1 () const
 1-Norm of this vector: The sum of absolute values. More...
 
sum (goIndex_t start=0, goIndex_t end=-1) const
 
min () const
 
max () const
 
void fillRange (const T &start, const T &step, const T &end)
 
bool readASCII (const char *filename)
 
bool readASCII (FILE *file)
 
bool writeASCII (const char *filename) const
 
bool writeASCII (FILE *file) const
 
template<>
goComplexf conjInnerProduct (const Vector< goComplexf > &v) const
 
template<>
goMath::Vector< goFloat > & operator= (const goFixedArray< goFloat > &other)
 
template<>
goMath::Vector< goDouble > & operator= (const goFixedArray< goDouble > &other)
 
template<>
void print (const char *formatstring) const
 
template<>
void print (const char *formatstring) const
 
template<>
goFloat operator* (const goMath::Vector< goFloat > &other) const
 
template<>
goDouble operator* (const goMath::Vector< goDouble > &other) const
 
template<>
goMath::Vector< goComplexf > & operator*= (const goMath::Matrix< goComplexf > &)
 
template<>
goComplexf square () const
 Calculates conj(this) * this. More...
 
template<>
goComplexf abs () const
 
template<>
goComplexd abs () const
 
template<>
goFloat norm2 () const
 
template<>
goDouble norm2 () const
 
template<>
goFloat norm1 () const
 
template<>
goDouble norm1 () const
 
template<>
goComplexf norm2 () const
 
template<>
goComplexd norm2 () const
 
template<>
goComplexf norm1 () const
 
template<>
goComplexd norm1 () const
 
template<>
bool writeASCII (FILE *) const
 
template<>
bool readASCII (FILE *)
 
template<>
goComplexf min () const
 
template<>
goComplexf max () const
 
template<>
goMath::Vector< goFloat > & operator*= (goFloat n)
 
template<>
goMath::Vector< goDouble > & operator*= (goDouble n)
 
template<>
goMath::Vector< goFloat > & operator-= (const goMath::Vector< goFloat > &other)
 
template<>
goMath::Vector< goDouble > & operator-= (const goMath::Vector< goDouble > &other)
 
template<>
goMath::Vector< goFloat > & operator+= (const goMath::Vector< goFloat > &other)
 
template<>
goMath::Vector< goDouble > & operator+= (const goMath::Vector< goDouble > &other)
 
template<>
goMath::Vector< goFloat > operator- (const goMath::Vector< goFloat > &other) const
 
template<>
goMath::Vector< goDouble > operator- (const goMath::Vector< goDouble > &other) const
 
template<>
goMath::Vector< goFloat > operator+ (const goMath::Vector< goFloat > &other) const
 
template<>
goMath::Vector< goDouble > operator+ (const goMath::Vector< goDouble > &other) const
 
- Public Member Functions inherited from goFixedArray< T >
 goFixedArray (goSize_t size=1, goSize_t reserve=0, goSize_t resize_overhead=0)
 Constructor. More...
 
 goFixedArray (const goFixedArray< T > &other)
 
 goFixedArray (T *ptr, goSize_t size, goIndex_t stride)
 
goFixedArray< T > & operator= (const goFixedArray< T > &other)
 
void setData (T *ptr, goSize_t size, goIndex_t stride)
 
void setPtr (T *ptr)
 
void ref (goFixedArray< T > &target, goSize_t startIndex=0, goSize_t size=0)
 
T & operator() (goIndex_t i)
 
T & operator[] (goIndex_t i)
 
const T & operator() (goIndex_t i) const
 
const T & operator[] (goIndex_t i) const
 
goSize_t getSize () const
 Get the size of the array in number of elements. More...
 
goSize_t size () const
 Same as getSize().
 
goSize_t getReserved () const
 Get the number of actually allocated elements. More...
 
goSize_t getResizeOverhead () const
 Get the number of resize overhead elements. More...
 
goIndex_t getStride () const
 
void setResizeOverhead (goSize_t ro)
 Set the resize overhead in number of elements. More...
 
void setSize (goSize_t newSize, goSize_t reserve=0, goSize_t resize_overhead=0)
 Set the size of the array, deleting old content. More...
 
bool resize (goSize_t newSize)
 Proper resize with copying. More...
 
bool operator== (const goFixedArray< T > &other) const
 
bool operator!= (const goFixedArray< T > &other) const
 
T * getPtr ()
 Get the pointer to the data. More...
 
const T * getPtr () const
 Get the pointer to the data. More...
 
void fill (const T &value)
 Fill the array with value. More...
 
void flip ()
 Flip the direction of the data. More...
 

Detailed Description

template<class T>
class goMath::Vector< T >

General vector class.

Use this instead of goNVector, which should be deprecated soon. This may not be optimal yet, but it will be improved when I have more need for the class.

Todo:
Document members.
Author
Christian Gosch
Examples
karchermean/km.cpp, and so3/so3.cpp.

Member Function Documentation

◆ abs()

template<class T >
T goMath::Vector< T >::abs ( ) const

Deprecated. Calls norm2() for scalar real types, special implementation for goComplex types.

Use norm2() instead.

◆ norm1()

template<class T >
T goMath::Vector< T >::norm1 ( ) const

1-Norm of this vector: The sum of absolute values.

Uses cblas_<>asum(). Not implemented for goComplex types.

Todo:
Use cblas for complex as well. Use cblas internal cblas storage then.
Returns
2-norm of this vector.

◆ norm2()

template<class T >
T goMath::Vector< T >::norm2 ( ) const

2-Norm of this vector.

Uses cblas_<>nrm2(). Calls special abs() implementation for complex.

Todo:
Use cblas for complex as well. Use cblas internal cblas storage then.
Returns
2-norm of this vector.

◆ operator*() [1/2]

template<class T>
Vector<T> goMath::Vector< T >::operator* ( const goMath::Matrix< T > &  M) const
inline

Quite inefficient vector-matrix multiplication.

If possible, avoid this or use only matrices in your programs if you can.

@TODO This is inefficient, but may be frequently needed. Solve this issue!

Returns
this * M

◆ operator*() [2/2]

template<class T>
T goMath::Vector< T >::operator* ( const Vector< T > &  other) const

Inner product.

Note
Uses CBLAS.
Returns
The inner product this * other.

◆ operator*=()

template<class T>
goMath::Vector< T > & goMath::Vector< T >::operator*= ( const goMath::Matrix< T > &  m)

this = m * this

Parameters
mMatrix
Returns
this = m * this

◆ outerProduct()

template<class T>
void goMath::Vector< T >::outerProduct ( const Vector< T > &  other,
goMath::Matrix< T > &  ret 
) const

Outer product.

Note
Untested.
Returns

◆ square()

template<>
goComplexf goMath::Vector< goComplexf >::square ( ) const

Calculates conj(this) * this.

Returns
The return value is of the form r+i*0, meaning the imaginary part is 0.

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