#include <linalg.hpp>
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. | |
vector & | operator= (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 vector &w) const |
Vector addition. | |
vector | operator- (const vector &w) const |
Vector subtration. | |
double | operator* (const vector &w) const |
xDot product. | |
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. | |
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 |
linalg::vector::vector | ( | ) |
linalg::vector::vector | ( | const size_t | n, | |
const double | fillvalue = 0 | |||
) |
linalg::vector::vector | ( | gsl_vector * | y | ) |
linalg::vector::vector | ( | const gsl_vector * | y | ) |
linalg::vector::vector | ( | const vector & | y | ) |
linalg::vector::~vector | ( | ) |
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 }
size_t linalg::vector::precision | ( | ) | const |
void linalg::vector::set_precision | ( | size_t | p | ) | [static] |
size_t linalg::vector::size | ( | ) | const |
double & linalg::vector::operator() | ( | const size_t | i | ) | [inline] |
Fortran-style parenthetical indexing (hence Octave-style too). Indices start at 1.
i | - Index number. |
00447 { 00448 try{ 00449 return *gsl_vector_ptr(x,i-1); 00450 } 00451 catch(indexOutOfRange& exc){ 00452 exc.i = i; 00453 exc.n = x -> size; 00454 throw exc; 00455 } 00456 }
const double & linalg::vector::operator() | ( | const size_t | i | ) | const [inline] |
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.
v | - Slice range. |
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 |
Vector addition.
00496 { 00497 if(x -> size != w.x->size){ 00498 inconformantSizes exc; 00499 exc.reason = "Cannot add vectors of different sizes."; 00500 exc.file = __FILE__; 00501 exc.line = __LINE__; 00502 exc.n_A = x->size; 00503 exc.n_B = w.x->size; 00504 throw exc; 00505 } 00506 vector u = *this; 00507 gsl_vector_add(u.x,w.x); 00508 return u; 00509 }
Vector subtration.
00511 { 00512 if(x -> size != w.x->size){ 00513 inconformantSizes exc; 00514 exc.reason = "Cannot subtract vectors of different sizes."; 00515 exc.file = __FILE__; 00516 exc.line = __LINE__; 00517 exc.n_A = x->size; 00518 exc.n_B = w.x->size; 00519 throw exc; 00520 } 00521 vector u = *this; 00522 gsl_vector_sub(u.x,w.x); 00523 return u; 00524 }
double linalg::vector::operator* | ( | const vector & | w | ) | const |
xDot product.
00526 { 00527 double a; 00528 try{ 00529 gsl_blas_ddot(x, w.x, &a); 00530 } 00531 catch(inconformantSizes& exc){ 00532 exc.reason = "Can't dot product vectors of different sizes."; 00533 exc.file = __FILE__; 00534 exc.line = __LINE__; 00535 exc.n_A = x->size; 00536 exc.n_B = w.x -> size; 00537 throw exc; 00538 } 00539 return a; 00540 }
bool linalg::vector::operator== | ( | const vector & | w | ) | const |
Compares vectors elementwise, using machine epsilon.
00551 { 00552 if(x -> size != w.x -> size){ 00553 badArgument exc; 00554 exc.reason = "Cannot compare vectors of different sizes."; 00555 exc.file = __FILE__; 00556 exc.line = __LINE__; 00557 throw exc; 00558 } 00559 00560 for(size_t i = 0; i < x -> size; i++) 00561 //if(gsl_fcmp(gsl_vector_get(x,i), gsl_vector_get(w.x,i), eps) != 0) 00562 if (gsl_vector_get(x,i) != gsl_vector_get(w.x,i)) 00563 return false; 00564 00565 return true; 00566 }
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.
00568 { 00569 if(x -> size < w.x -> size) //Smaller vectors go first in this order. 00570 return true; 00571 00572 for(size_t i = 0; i < x -> size; i++){ 00573 double L = gsl_vector_get(x,i); 00574 double R = gsl_vector_get(w.x,i); 00575 if(L < R ) 00576 return true; 00577 if(L > R ) 00578 return false; 00579 } 00580 00581 return false; //Then vectors are equal. 00582 }
double linalg::vector::norm | ( | ) | const |
friend class vector_view [friend] |
friend class matrix [friend] |
Reimplemented in linalg::vector_view.
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.