gsl_vector_double.h

Go to the documentation of this file.
00001 
00002 
00003 //
00013 
00014 //  This vector double class has been adapted from the gslwrap project.
00015 //  It is a C++ wrapper for the GNU Scientific Library
00016 //  Copyright (C) 2001 Ramin Nakisa
00017 
00018 //  This program is free software; you can redistribute it and/or modify
00019 //  it under the terms of the GNU General Public License as published by
00020 //  the Free Software Foundation; either version 2 of the License, or
00021 //  (at your option) any later version.
00022 
00023 //  This program is distributed in the hope that it will be useful,
00024 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00025 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00026 //  GNU General Public License for more details.
00027 
00028 //  You should have received a copy of the GNU General Public License
00029 //  along with this program; if not, write to the Free Software
00030 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00031 
00032 
00033 #ifndef _GSL_VECTOR_DOUBLE_H
00034 #define _GSL_VECTOR_DOUBLE_H
00035 
00036 #include <iostream>
00037 #include <assert.h>
00038 #include <gsl/gsl_math.h>
00039 #include <gsl/gsl_vector.h>
00040 
00041 #define type_is
00042 #ifdef  type_is
00043 #define type_is_double
00044 #endif
00045 
00046 
00047 class vector_view;
00048 
00050 //
00051 
00052 class vector
00053 {
00054 
00055 protected:
00056 
00058 //
00059 
00060 gsl_vector *v;
00061 
00062 public:
00063 
00065 //
00067 //
00068 
00069 vector();
00070 
00072 //
00079 //
00080 
00081 vector(size_t n, bool clear=true);
00082 
00084 //
00086 //
00087 
00088 ~vector();
00089 
00091 // 
00097 //
00098 
00099 int fprintf (FILE * stream, const char * format) const;
00100 
00102 //
00106 //
00107 
00108 int fscanf (FILE * stream);
00109 
00111 // 
00115 //
00116 
00117 void resize(size_t n);
00118 
00120 // 
00124 //
00125 
00126 void copy(const vector& other);
00127 
00129 //
00130 
00131 size_t size() const;
00132 
00134 //
00139 //
00140 
00141 void  set(size_t i,double x);
00142 
00144 //
00148 //
00149 
00150 double get(size_t i) const;
00151 
00153 //
00157 //
00158 
00159 void set_all(double x);
00160 
00162 //
00164 //
00165 
00166 void set_zero();
00167 
00169 //
00170 
00171 double max() const;
00172 
00174 //
00175 
00176 double min() const;
00177 
00179 //
00180 
00181 size_t max_index();
00182 
00184 //
00185 
00186 size_t min_index();
00187 
00189 //
00191 //
00192 
00193 double &operator[](size_t i);
00194 
00196 //
00198 //
00199 
00200 const double &operator[](size_t i) const;
00201 
00203 //
00205 //      
00206 
00207 bool operator==(const vector& other) const;
00208 
00210 //
00212 //
00213 
00214 bool operator!=(const vector& other) const { return (!((*this)==other));}
00215 
00217 //
00219 //
00220 
00221 vector& operator=(const vector& other){copy(other);return (*this);}
00222 
00224 //
00228 
00229 vector operator+( const vector &other ) const;
00230 
00232 //
00236 
00237 vector operator-( const vector &other ) const;
00238 
00240 //
00244 
00245 int operator+=(const vector &other) {return gsl_vector_add (v, other.v);}
00246 
00248 //
00252 
00253 int operator-=(const vector &other) {return gsl_vector_sub (v, other.v);}
00254 
00256 //
00260 
00261 int operator*=(const vector &other) {return gsl_vector_mul (v, other.v);}
00262 
00264 //
00268 
00269 int operator/=(const vector &other) {return gsl_vector_div (v, other.v);}
00270 
00272 //
00275 //
00276 
00277 int operator*=(double x) {return gsl_vector_scale (v, x);}
00278 
00280 //
00283 //
00284 
00285 int operator+=(double x) {return gsl_vector_add_constant (v,x);}
00286 
00288 //
00291 //
00292 
00293 int operator/=(double x) {return gsl_vector_scale (v, 1/x);}
00294 
00295 
00297 //
00301 //  
00302 
00303 void alloc(size_t n);
00304 
00306 //
00310 
00311 void calloc(size_t n);
00312 
00313 // Function that removes the vector from memeory.
00314 //
00315 
00316 void free();
00317 
00319 //
00320 
00321 bool is_set() const;
00322 
00324 //
00325 
00326 double sum() const;
00327 
00329 //
00330 
00331 double norm2() const;
00332 
00334 //
00335 
00336 gsl_vector       *gslobj()       {assert(v);return v;}
00337 
00339 //
00340 
00341 const gsl_vector *gslobj() const {assert(v);return v;}
00342 
00344 //
00356 //
00357 
00358 static vector_view create_vector_view( const gsl_vector_view &other );
00359 
00361 //
00368 // 
00369 
00370 vector_view subvector (size_t offset, size_t n);
00371 
00373 //
00378 //
00379 
00380 const vector_view subvector (size_t offset, size_t n) const;
00381 
00383 //
00388 //
00389 
00390 };
00391 
00393 //
00394 
00395 class vector_view : public vector
00396 {
00397  public:
00398         vector_view(const vector&     other) :vector(){init(other);}
00399         vector_view(const vector_view& other):vector(){init(other);}
00400         vector_view(const gsl_vector& gsl_other) : vector() {init_with_gsl_vector(gsl_other);}
00401 
00402         void init(const vector& other);
00403         void init_with_gsl_vector(const gsl_vector& gsl_other);
00404         void change_view(const vector& other){init(other);}
00405  private:
00406 };
00407 
00408 #define tmp_type_is
00409 /*#ifdef tmp_type_is
00410 typedef vector vector_double;
00411 template<class T> 
00412 struct vector_type  {typedef vector_double   type;};
00413 
00414 template<class T> 
00415 struct value_type  {typedef double   type;};
00416 
00417 #else
00418 template<> struct vector_type<double> {typedef vector type;};
00419 #endif*/
00420 #undef tmp_type_is
00421 
00422 #endif // GSL_VECTOR_DOUBLE_H
00423 
All Classes Files Functions Variables Typedefs Friends Defines