#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 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 |
| 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. |
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 }

| 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 linalg::vector::operator/ | ( | const double | a | ) | 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 }

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 }

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 }

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 }

| 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 }

| 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 }

| double linalg::vector::norm | ( | ) | const |
| 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 }

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.
1.5.6