MathTL
algebra/vector.h
00001 // -*- c++ -*-
00002 
00003 // +--------------------------------------------------------------------+
00004 // | This file is part of MathTL - the Mathematical Template Library    |
00005 // |                                                                    |
00006 // | Copyright (c) 2002-2009                                            |
00007 // | Thorsten Raasch, Manuel Werner                                     |
00008 // +--------------------------------------------------------------------+
00009 
00010 #ifndef _MATHTL_VECTOR_H
00011 #define _MATHTL_VECTOR_H
00012 
00013 #include <iostream>
00014 
00015 // external functionality, for convenience:
00016 #include <algebra/vector_norms.h>
00017 #include <algebra/vector_arithmetics.h>
00018 
00019 namespace MathTL
00020 {
00032   template <class C>
00033   class Vector
00034   {
00035   public:
00039     typedef C value_type;
00040     
00044     typedef value_type* pointer;
00045 
00049     typedef const value_type* const_pointer;
00050 
00054     typedef value_type* iterator;
00055 
00059     typedef const value_type* const_iterator;
00060 
00064     typedef value_type& reference;
00065     
00069     typedef const value_type& const_reference;
00070 
00074     typedef size_t size_type;
00075 
00079     Vector();
00080 
00088     explicit Vector(const size_type s, const bool initialize = true);
00089 
00096     Vector(const size_type s, const char* str);
00097 
00101     Vector(const Vector<C>& v);
00102 
00106     virtual ~Vector();
00107 
00111     size_type size() const;
00112 
00116     size_type memory_consumption() const;
00117 
00121     bool empty() const;
00122 
00126     void resize(const size_type s, const bool initialize = true);
00127 
00131     const C operator [] (const size_type i) const;
00132 
00136     const C operator () (const size_type i) const;
00137 
00141     C& operator [] (const size_type i);
00142 
00146     C& operator () (const size_type i);
00147 
00151     const_iterator begin() const;
00152 
00156     iterator begin();
00157 
00162     const_iterator end() const;
00163 
00168     iterator end();
00169 
00173     Vector<C>& operator = (const C c);
00174 
00178     Vector<C>& operator = (const Vector<C>& v);
00179 
00183     void swap (Vector<C>& v);
00184 
00188     template <class C2>
00189     bool operator == (const Vector<C2>& v) const;
00190 
00194     template <class C2>
00195     bool operator != (const Vector<C2>& v) const;
00196 
00200     template <class C2>
00201     bool operator < (const Vector<C2>& v) const;
00202 
00206     template <class C2>
00207     void add(const Vector<C2>& v);
00208     
00212     template <class C2>
00213     void add(const C2 s, const Vector<C2>& v);
00214     
00219     template <class C2>
00220     void sadd(const C s, const Vector<C2>& v);
00221 
00225     void scale(const C s);
00226 
00230     template <class C2>
00231     Vector<C>& operator += (const Vector<C2>& v);
00232 
00236     template <class C2>
00237     void subtract(const Vector<C2>& v);
00238 
00242     template <class C2>
00243     Vector<C>& operator -= (const Vector<C2>& v);
00244 
00248     template <class C2>
00249     const C inner_product (const Vector<C2>& v) const;
00250 
00254     Vector<C>& operator *= (const C c);
00255     
00259     Vector<C>& operator /= (const C c);
00260 
00264     template <class C2>
00265     const C operator * (const Vector<C2>& v) const;
00266 
00271     void compress(const double eta = 1e-15);
00272 
00280     double wrmsqr_norm(const double atol, const double rtol,
00281                        const Vector<C>& v, const Vector<C>& w) const;
00282     
00283   protected:
00287     C* values_;
00288 
00292     size_type size_;
00293   };
00294 
00298   template <class C>
00299   void swap(Vector<C>& v1, Vector<C>& v2);
00300 
00306   template <class C, class C2>
00307   Vector<C> operator + (const Vector<C>& v1, const Vector<C2>& v2);
00308 
00314   template <class C, class C2>
00315   Vector<C> operator - (const Vector<C>& v1, const Vector<C2>& v2);
00316 
00321   template <class C>
00322   std::ostream& operator << (std::ostream& os, const Vector<C>& v);
00323 }
00324 
00325 // include implementation of inline functions
00326 #include <algebra/vector.cpp>
00327 
00328 #endif
 All Classes Functions Variables Typedefs Enumerations