yat  0.20.3pre
VectorMutable.h
1 #ifndef _theplu_yat_utility_vector_mutable_
2 #define _theplu_yat_utility_vector_mutable_
3 
4 // $Id: VectorMutable.h 3661 2017-07-14 01:10:35Z peter $
5 
6 /*
7  Copyright (C) 2003 Daniel Dalevi, Peter Johansson
8  Copyright (C) 2004 Jari Häkkinen, Peter Johansson
9  Copyright (C) 2005 Jari Häkkinen, Peter Johansson, Markus Ringnér
10  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér
11  Copyright (C) 2007 Jari Häkkinen, Peter Johansson, Markus Ringnér
12  Copyright (C) 2008, 2009 Jari Häkkinen, Peter Johansson
13  Copyright (C) 2012, 2016, 2017 Peter Johansson
14 
15  This file is part of the yat library, http://dev.thep.lu.se/trac/yat
16 
17  The yat library is free software; you can redistribute it and/or
18  modify it under the terms of the GNU General Public License as
19  published by the Free Software Foundation; either version 3 of the
20  License, or (at your option) any later version.
21 
22  The yat library is distributed in the hope that it will be useful,
23  but WITHOUT ANY WARRANTY; without even the implied warranty of
24  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25  General Public License for more details.
26 
27  You should have received a copy of the GNU General Public License
28  along with yat. If not, see <http://www.gnu.org/licenses/>.
29 */
30 
31 #include "VectorBase.h"
32 #include "VectorExpression.h"
33 #include "StrideIterator.h"
34 
35 #include <gsl/gsl_vector.h>
36 
37 #include <cstddef> // size_t
38 
39 namespace theplu {
40 namespace yat {
41 namespace utility {
42 
43  class matrix;
44  class Vector;
45 
56  class VectorMutable : public VectorBase
57  {
58  public:
64  typedef double& reference;
65 
70 
74  VectorMutable(void);
75 
79  VectorMutable(gsl_vector*);
80 
84  VectorMutable(const gsl_vector*);
85 
89  virtual ~VectorMutable(void);
90 
94  void all(double value);
95 
99  iterator begin(void);
100 
101  // to allow overload from base class
102  using VectorBase::begin;
103 
110  void div(const VectorBase& other);
111 
115  iterator end(void);
116 
117  // to allow overload from base class
118  using VectorBase::end;
119 
123  gsl_vector* gsl_vector_p(void);
124 
126 
134  virtual bool isview(void) const=0;
135 
142  void mul(const VectorBase& other);
143 
147  void reverse(void);
148 
152  void swap(size_t i, size_t j);
153 
163  double& operator()(size_t i);
164 
165  // to allow overload from base class
166  using VectorBase::operator();
167 
176  const VectorMutable& operator+=(const VectorBase&);
177 
183  template<class T>
185  {
186  *this = *this + rhs;
187  return *this;
188  }
189 
196  const VectorMutable& operator+=(double d);
197 
206  const VectorMutable& operator-=(const VectorBase&);
207 
213  template<class T>
215  {
216  *this = *this - rhs;
217  return *this;
218  }
219 
226  const VectorMutable& operator-=(double d);
227 
234  const VectorMutable& operator*=(double d);
235 
241  const VectorMutable& operator=(const VectorMutable&);
242 
248  const VectorMutable& operator=(const VectorBase&);
249 
255  template<class T>
257  {
258  assign(rhs.gsl_vector_p());
259  return *this;
260  }
261 
262  protected:
269  gsl_vector* vec_;
270 
271  private:
272  virtual const VectorMutable& assign(const VectorBase& rhs)=0;
273  virtual const VectorMutable& assign(const gsl_vector* rhs)=0;
274  };
275 
279  void shuffle(VectorMutable& invec);
280 
286  void sort(VectorMutable& vec);
287 
288 }}} // of namespace utility, yat, and theplu
289 
290 #endif
void shuffle(VectorMutable &invec)
StrideIterator< double * > iterator
mutable iterator
Definition: VectorMutable.h:69
const_iterator begin(void) const
void swap(size_t i, size_t j)
Exchange elements i and j.
The Department of Theoretical Physics namespace as we define it.
VectorMutable & operator+=(const VectorExpression< T > &rhs)
Addition and assign operator.
Definition: VectorMutable.h:184
const gsl_vector * gsl_vector_p(void) const
VectorMutable(void)
default constructor
VectorMutable & operator=(const VectorExpression< T > &rhs)
assignment from vector expression
Definition: VectorMutable.h:256
VectorMutable & operator-=(const VectorExpression< T > &rhs)
Subtraction and assign operator.
Definition: VectorMutable.h:214
const VectorMutable & operator+=(const VectorBase &)
Addition and assign operator. VectorBase addition, .
const_iterator end(void) const
const VectorMutable & operator-=(const VectorBase &)
Subtract and assign operator. VectorBase subtraction, .
virtual bool isview(void) const =0
This is the yat interface to GSL vector.
Definition: VectorBase.h:55
gsl_vector * vec_
Definition: VectorMutable.h:269
const VectorMutable & operator*=(double d)
Multiply with scalar and assign operator, .
An expression that can be converted to a Vector.
Definition: VectorExpression.h:67
This is the mutable interface to GSL vector.
Definition: VectorMutable.h:56
void div(const VectorBase &other)
This function performs element-wise division, .
void sort(VectorMutable &vec)
double & operator()(size_t i)
Element access operator.
const gsl_vector * gsl_vector_p(void) const
return a GSL vector pointer
Definition: VectorExpression.h:110
void mul(const VectorBase &other)
This function performs element-wise multiplication, .
double & reference
Definition: VectorMutable.h:64
const VectorMutable & operator=(const VectorMutable &)
assignment
Adaptor using a stride on underlying iterator.
Definition: StrideIterator.h:50
void reverse(void)
Reverse the order of elements in the VectorMutable.

Generated on Sat Feb 18 2023 03:31:44 for yat by  doxygen 1.8.14