source: trunk/src/vector.h @ 12

Last change on this file since 12 was 12, checked in by daniel, 19 years ago

Matrix and vector APIs for GSL.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1#ifndef _thep_gsl_api_vector_
2#define _thep_gsl_api_vector_
3
4#include <iostream>
5#include <fstream>
6#include <iomanip>
7#include <cmath>
8#include <cstdlib>
9#include <cassert>
10
11#include <gsl/gsl_math.h>
12#include <gsl/gsl_vector.h>
13#include <gsl/gsl_linalg.h>
14#include <gsl/gsl_blas.h>
15
16
17namespace thep_gsl_api
18{
19
20  /**
21     This is a vector interface to GSL for c++.
22     Important: vector has two dimenstions depending on
23     whether it's a "row" vector or a "column" vector.
24     A column vector is created by default.
25     Note that the namespace is "thep_gsl_api".
26  */
27
28  class vector
29  {
30  public:
31    typedef double Type;
32 
33    /**
34       Default constructor
35       Does not allocate any memory
36    */
37    vector();
38
39    /**
40       Constructor taking three argumens:
41       N = Number of elements
42       init_to_zero, if true vector will be initialized with zeros.
43    */
44    vector( const size_t&, bool is_col_vector = true, 
45      bool init_to_zero = true );
46
47
48
49    /**
50  Copy constructor
51    */
52    vector( const vector& other );
53
54
55    /**
56       Constructor taking as only argument a matrix of gsl type.
57       Be causious here! Do not delete this matrix outside of
58       class: NO COPY IS MADE!!!
59    */
60    vector( gsl_vector*, bool is_col = true );
61
62    /**
63       Destructor will clear matrix's allocated memory
64    */
65    ~vector();
66
67
68    /**
69       The most important function when adding new classes to
70       c++_tools. This function will return a pointer to the
71       inner data of the class. Should be forbidden in a strictly
72       object-orientated environment.
73       Motivation: Effeciency! ( CAN IT BE MADE CONST? )
74       To be used when writting new classes using gsl-functions.
75    */
76    inline gsl_vector* get_gsl_vector() const; 
77
78
79    /**
80       Returns the number of rows in the vector.
81    */
82    size_t size() const { return v_->size; }
83
84
85    /**
86       Tells whether a vector is column or not
87     */
88    bool is_column() const { return is_col_; }
89
90
91    /**
92       get( i ) will return the vi element in vector v
93       where i = column (if row vector) or row (if column vector)
94    */
95    inline Type get( const size_t& i ) const;
96
97
98    /**
99       set( i, val ) will make vi = val in vector v
100       where i = column (if row vector) or row (if column vector)
101    */
102    inline void set( const size_t& i, const Type& val );
103
104    /**
105       set_all( val ) will make vi = val in matrix A
106       for all "i"
107    */
108    inline void set_all( const Type& val );
109
110
111    /**
112       Assignment-operator. No requirements on dimensions,
113       i.e. if a = b, then a will be a copy of b with b:s
114       dimensions.
115     */
116    vector& operator=( const vector& other );
117
118
119    /**
120       Access element-operator
121    */
122    inline double &operator[](size_t i)  { return *gsl_vector_ptr( v_, i ); }
123    const double &operator[](size_t i) const { return *gsl_vector_ptr( v_, i ); }
124
125   
126    /**
127       operators for comparison are: \n
128       == equal \n
129       != not equal
130    */
131    bool operator==( const vector &other ) const;
132    bool operator!=( const vector &other ) const; 
133
134    /**
135       operators for basic arithmetics are: \n
136       \f$+\f$ vector-vector addition \n
137       \f$-\f$ vector-vector subtraction \n
138       \f$/=\f$ divide all elements with a constant
139    */
140    vector operator+( const vector& other ) const;
141    vector operator-( const vector& other ) const;
142    int operator/=( const double& c );
143    int operator/=( const vector& other ) const;
144    //matrix operator*( const vector &other ) const;
145
146    /**
147  standard output operator is defined
148    */
149    friend std::ostream& operator<< ( std::ostream&, const vector& );
150
151
152
153
154  private:
155    gsl_vector* new_copy( const gsl_vector* );
156
157    gsl_vector* v_;
158    bool is_col_;
159  };
160#include "vector.icc"
161
162
163};
164
165
166
167
168#endif
Note: See TracBrowser for help on using the repository browser.