linalg::vector Class Reference

A wrapper class for GSL vectors. More...

#include <linalg.hpp>

Inheritance diagram for linalg::vector:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 vector ()
 Allocate zero vector of size one.
 vector (const size_t n, const double fillvalue=0)
 Allocate GSL vector of size n, filled with fillvalue.
 vector (gsl_vector *y)
 Associate a vector to a GSL vector pointer.
 vector (const gsl_vector *y)
 Associate a vector to a constant GSL vector pointer.
 vector (const vector &y)
 Copy contstructor.
vectoroperator= (const vector &y)
 Assignment.
 ~vector ()
 Clear memory assigned to vector by GSL.
size_t precision () const
 Number of decimal digits to output.
size_t size () const
 Number of elements.
double & operator() (const size_t i)
 Fortran-style parenthetical indexing (hence Octave-style too). Indices start at 1.
const double & operator() (const size_t i) const
 Constant version of previous function.
vector_view operator() (const slice &v)
 Indexing for vectorisation. The GSL provides limited vectorisation routines which can be useful for operating on blocks of vectors all at once.
const vector_view operator() (const slice &v) const
 Constant version of previous function.
vector operator* (const double a) const
 Scale the vector.
vector operator/ (const double a) const
 Scale the vector.
vector operator+ (const vector &w) const
 Vector addition.
vector operator- (const vector &w) const
 Vector subtration.
vector operator* (const vector &w) const
 Element-by-element multiplication.
vector operator/ (const vector &w) const
 Element-by-element division.
vector operator* (const matrix &M) const
 Computes vM where v is treated as a row vector.
bool operator== (const vector &w) const
 Compares vectors elementwise, using machine epsilon.
bool operator< (const vector &w) const
 Lexicographical order, used for putting into STL sets or maps.
double norm () const
 Euclidean norm.
double operator% (const vector &w) const
 Dot product.

Static Public Member Functions

static void set_precision (size_t p)
 Set the number of decimal digits to output.

Private Attributes

gsl_vector * x
 Pointer to associated GSL vector.

Static Private Attributes

static size_t precsn = 4
 Output precision.
static const double eps = std::numeric_limits<double>::epsilon()
 Machine epsilon.

Friends

class vector_view
class matrix


Detailed Description

A wrapper class for GSL vectors.

Constructor & Destructor Documentation

linalg::vector::vector (  ) 

Allocate zero vector of size one.

00426                 {
00427     x = gsl_vector_calloc(1); //Allocate zero vector of size one.
00428   }

linalg::vector::vector ( const size_t  n,
const double  fillvalue = 0 
)

Allocate GSL vector of size n, filled with fillvalue.

Parameters:
n - Size of new vector
fillvalue - Value for filling vector, default is 0.
00430                                                       {
00431     x = gsl_vector_alloc(n);
00432     gsl_vector_set_all(x,fillvalue);
00433   }

linalg::vector::vector ( gsl_vector *  y  ) 

Associate a vector to a GSL vector pointer.

00435                              {
00436     x = y;
00437   }

linalg::vector::vector ( const gsl_vector *  y  ) 

Associate a vector to a constant GSL vector pointer.

00439                                    {
00440     x = gsl_vector_alloc(y -> size);
00441     gsl_vector_memcpy(x,y);
00442   }

Here is the call graph for this function:

linalg::vector::vector ( const vector y  ) 

Copy contstructor.

00444                                {
00445     x = gsl_vector_alloc(y.x->size);
00446     gsl_vector_memcpy(x,y.x);
00447   }

linalg::vector::~vector (  ) 

Clear memory assigned to vector by GSL.

00458                  {
00459     if(x != 0) //Has subclass vector_view already deleted this vector?
00460       gsl_vector_free(x);
00461   }


Member Function Documentation

vector & linalg::vector::operator= ( const vector y  ) 

Assignment.

Reimplemented in linalg::vector_view.

00449                                           {
00450     if(this != &y){
00451       gsl_vector_free(x);
00452       x = gsl_vector_alloc(y.x -> size);
00453       gsl_vector_memcpy(x,y.x);
00454     }
00455     return *this;
00456   }

Here is the call graph for this function:

size_t linalg::vector::precision (  )  const

Number of decimal digits to output.

00466                                 {
00467     return precsn;
00468   }

void linalg::vector::set_precision ( size_t  p  )  [static]

Set the number of decimal digits to output.

00470                                     {
00471     precsn = p;
00472   }

size_t linalg::vector::size (  )  const

Number of elements.

00474                            {
00475     return x->size;
00476   }

double & linalg::vector::operator() ( const size_t  i  )  [inline]

Fortran-style parenthetical indexing (hence Octave-style too). Indices start at 1.

Parameters:
i - Index number.
Returns:
A reference to the vector element.
00473                                                   {
00474     try{
00475       return *gsl_vector_ptr(x,i-1);
00476     }
00477     catch(indexOutOfRange& exc){
00478       exc.i = i;
00479       exc.n = x -> size;
00480       throw exc;
00481     }
00482   }

Here is the call graph for this function:

const double & linalg::vector::operator() ( const size_t  i  )  const [inline]

Constant version of previous function.

00484                                                               {
00485     try{
00486       return *gsl_vector_const_ptr(x,i-1);
00487     }
00488     catch(indexOutOfRange& exc){
00489       exc.i = i;
00490       exc.n = x -> size;
00491       throw exc;
00492     }
00493   }

Here is the call graph for this function:

vector_view linalg::vector::operator() ( const slice v  ) 

Indexing for vectorisation. The GSL provides limited vectorisation routines which can be useful for operating on blocks of vectors all at once.

Parameters:
v - Slice range.
Returns:
A vector_view of the slice.
00478                                                {
00479     vector_view x_sub(x,s);
00480     return x_sub;
00481   }

const vector_view linalg::vector::operator() ( const slice v  )  const

Constant version of previous function.

00483                                                            {
00484     vector_view x_sub(x,s);
00485     return x_sub;
00486   }

vector linalg::vector::operator* ( const double  a  )  const

Scale the vector.

00490                                               {
00491     vector v = *this;
00492     gsl_vector_scale(v.x, a);
00493     return v;
00494   }

vector linalg::vector::operator/ ( const double  a  )  const

Scale the vector.

00496                                               {
00497     vector v = *this;
00498     gsl_vector_scale(v.x, 1.0/a);
00499     return v;
00500   }

vector linalg::vector::operator+ ( const vector w  )  const

Vector addition.

00502                                                {
00503     if(x -> size != w.x->size){
00504       inconformantSizes exc;
00505       exc.reason = "Cannot add vectors of different sizes.";
00506       exc.file = __FILE__;
00507       exc.line = __LINE__;
00508       exc.n_A = x->size;
00509       exc.n_B = w.x->size;
00510       throw exc;
00511     }
00512     vector u = *this;
00513     gsl_vector_add(u.x,w.x);
00514     return u;    
00515   }

Here is the call graph for this function:

vector linalg::vector::operator- ( const vector w  )  const

Vector subtration.

00517                                                {
00518     if(x -> size != w.x->size){
00519       inconformantSizes exc;
00520       exc.reason = "Cannot subtract vectors of different sizes.";
00521       exc.file = __FILE__;
00522       exc.line = __LINE__;
00523       exc.n_A = x->size;
00524       exc.n_B = w.x->size;
00525       throw exc;
00526     }
00527     vector u = *this;
00528     gsl_vector_sub(u.x,w.x);
00529     return u;    
00530   }

Here is the call graph for this function:

vector linalg::vector::operator* ( const vector w  )  const

Element-by-element multiplication.

00533   {
00534     vector u = *this;
00535     try{
00536       gsl_vector_mul(u.x, w.x);
00537     }
00538     catch(inconformantSizes& exc){
00539       exc.reason = "Can't multiply vectors of different sizes.";
00540       exc.file = __FILE__;
00541       exc.line = __LINE__;
00542       exc.n_A = x->size;
00543       exc.n_B = w.x -> size;
00544       throw exc;
00545     }
00546     return u;
00547   }

Here is the call graph for this function:

vector linalg::vector::operator/ ( const vector w  )  const

Element-by-element division.

00550   {
00551     vector u = *this;
00552     try{
00553       gsl_vector_div(u.x, w.x);
00554     }
00555     catch(inconformantSizes& exc){
00556       exc.reason = "Can't divide vectors of different sizes.";
00557       exc.file = __FILE__;
00558       exc.line = __LINE__;
00559       exc.n_A = x->size;
00560       exc.n_B = w.x -> size;
00561       throw exc;
00562     }
00563     return u;
00564   }

Here is the call graph for this function:

vector linalg::vector::operator* ( const matrix M  )  const

Computes vM where v is treated as a row vector.

00567   {
00568     return T(M)* (*this);
00569   }

Here is the call graph for this function:

bool linalg::vector::operator== ( const vector w  )  const

Compares vectors elementwise, using machine epsilon.

00594                                               {
00595     if(x -> size != w.x -> size){
00596       badArgument exc;
00597       exc.reason = "Cannot compare vectors of different sizes.";
00598       exc.file = __FILE__;
00599       exc.line = __LINE__;
00600       throw exc;
00601     }
00602 
00603     for(size_t i = 0; i < x -> size; i++)
00604       if(gsl_fcmp(gsl_vector_get(x,i), gsl_vector_get(w.x,i), eps) != 0)
00605         return false;
00606     
00607     return true;
00608   }

Here is the call graph for this function:

bool linalg::vector::operator< ( const vector w  )  const

Lexicographical order, used for putting into STL sets or maps.

Lexicographical ordering of vectors. Vectors of smaller dimension are smaller.

00610                                              {
00611     if(x -> size < w.x -> size) //Smaller vectors go first in this order.
00612        return true;
00613 
00614     for(size_t i = 0; i < x -> size; i++){
00615       double L = gsl_vector_get(x,i);
00616       double R = gsl_vector_get(w.x,i);
00617       if(L < R )
00618         return true;
00619       if(L > R )
00620         return false;
00621     }
00622    
00623     return false; //Then vectors are equal.
00624   }

Here is the call graph for this function:

double linalg::vector::norm (  )  const

Euclidean norm.

00572   {
00573     return gsl_blas_dnrm2(x);
00574   }

double linalg::vector::operator% ( const vector w  )  const

Dot product.

00577   {
00578     double a;
00579     try{
00580       gsl_blas_ddot(x, w.x, &a);
00581     }
00582     catch(inconformantSizes& exc){
00583       exc.reason = "Can't dot product vectors of different sizes.";
00584       exc.file = __FILE__;
00585       exc.line = __LINE__;
00586       exc.n_A = x->size;
00587       exc.n_B = w.x -> size;
00588       throw exc;
00589     }
00590     return a;
00591   }

Here is the call graph for this function:


Friends And Related Function Documentation

friend class vector_view [friend]

friend class matrix [friend]

Reimplemented in linalg::vector_view.


Member Data Documentation

gsl_vector* linalg::vector::x [private]

Pointer to associated GSL vector.

size_t linalg::vector::precsn = 4 [static, private]

Output precision.

const double linalg::vector::eps = std::numeric_limits<double>::epsilon() [static, private]

Machine epsilon.


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

Generated on Mon Sep 29 23:54:13 2008 for RBF-DDM by  doxygen 1.5.6