yat  0.20.3pre
VectorBase.h
1 #ifndef _theplu_yat_utility_vector_base_
2 #define _theplu_yat_utility_vector_base_
3 
4 // $Id: VectorBase.h 3871 2020-03-01 22:46:57Z 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 Jari Häkkinen, Peter Johansson
13  Copyright (C) 2009, 2012, 2017, 2020 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 "BasicVector.h"
32 #include "BLAS_level1.h"// include these as they are expected when using Vector
33 #include "BLAS_level2.h"// include these as they are expected when using Vector
34 #include "StrideIterator.h"
35 #include "VectorExpression.h"
36 
37 #include <iosfwd>
38 #include <vector>
39 #include <cstddef> // size_t
40 
41 #include <gsl/gsl_vector.h>
42 
43 namespace theplu {
44 namespace yat {
45 namespace utility {
46 
47  class Vector;
48 
55  class VectorBase : public BasicVector<VectorBase>
56  {
57  public:
63  typedef double value_type;
64 
70  typedef const double& const_reference;
71 
74 
78  VectorBase(const gsl_vector* v=NULL);
79 
83  virtual ~VectorBase(void);
84 
88  const_iterator begin(void) const;
89 
93  const_iterator end(void) const;
94 
104  bool equal(const VectorBase&, const double precision=0) const;
105 
109  const gsl_vector* gsl_vector_p(void) const;
110 
117  virtual bool isview(void) const=0;
118 
122  size_t size(void) const;
123 
133  const double& operator()(size_t i) const;
134 
146  bool operator==(const VectorBase&) const;
147 
159  bool operator!=(const VectorBase&) const;
160 
164  double operator*(const VectorBase&) const;
165 
166  protected:
168  const gsl_vector* const_vec_;
169 
170  private:
171  // copy assignment not allowed
172  const VectorBase& operator=(const VectorBase&);
173  };
174 
183  bool isnull(const VectorBase&);
184 
192  double max(const VectorBase&);
193 
203  size_t max_index(const VectorBase&);
204 
212  double min(const VectorBase&);
213 
223  size_t min_index(const VectorBase&);
224 
240  bool nan(const VectorBase& templat, Vector& flag);
241 
249  double norm2_squared(const VectorBase& v);
250 
251 
264  void sort_index(std::vector<size_t>& sort_index, const VectorBase& invec);
265 
272  void sort_smallest_index(std::vector<size_t>& sort_index, size_t k,
273  const VectorBase& invec);
274 
281  void sort_largest_index(std::vector<size_t>& sort_index, size_t k,
282  const VectorBase& invec);
283 
291  double sum(const VectorBase&);
292 
306  std::ostream& operator<<(std::ostream& s, const VectorBase& v);
307 
309 
310  // Some convenience functions used in Vector and friends.
311  namespace detail {
312 
324  gsl_vector* create_gsl_vector(size_t n);
325 
329  gsl_vector* create_gsl_vector(size_t n, double init);
330 
342  gsl_vector* create_gsl_vector_copy(const gsl_vector*);
343 
344 
345  // return true if a and b overlap in memory
346  bool overlap(const gsl_vector* a, const gsl_vector* b);
347 
348  /*
349  Is a stricter condition that overlap(2). Basically it returns
350  false if it is safe to write code like:
351  for (size_t i=0; i<a->size; ++i)
352  a[i] = foo(b[i])
353 
354  in other words, it returns true if there exists i and j, i<j, such that
355  gsl_vector_const_ptr(a, j) == gsl_vector_const_ptr(b, i)
356 
357  For speed reasons function might return true in some cases when
358  condition above is not true, when both a and b have stride>1 and
359  elements sit between each other.
360 
361  Note, a and b must have same size.
362  */
363  bool serial_overlap(const gsl_vector* a, const gsl_vector* b);
364  }
365 
367 
368 }}} // of namespace utility, yat, and theplu
369 
370 #endif
bool operator==(const VectorBase &) const
Comparison operator. Takes linear time.
const_iterator begin(void) const
double value_type
Definition: VectorBase.h:63
The Department of Theoretical Physics namespace as we define it.
const gsl_vector * gsl_vector_p(void) const
StrideIterator< const double * > const_iterator
VectorBase::const_iterator.
Definition: VectorBase.h:73
const gsl_vector * const_vec_
pointer to underlying GSL vector
Definition: VectorBase.h:168
void sort_smallest_index(std::vector< size_t > &sort_index, size_t k, const VectorBase &invec)
bool equal(const VectorBase &, const double precision=0) const
Check whether VectorBases are equal within a user defined precision, set by precision.
T max(const T &a, const T &b, const T &c)
Definition: stl_utility.h:699
const_iterator end(void) const
This is the yat interface to GSL vector.
Definition: Vector.h:59
This is the yat interface to GSL vector.
Definition: VectorBase.h:55
virtual bool isview(void) const =0
void sort_index(InputIterator first, InputIterator last, std::vector< size_t > &sort_index)
Definition: sort_index.h:146
Definition: BasicVector.h:48
const double & const_reference
Definition: VectorBase.h:70
VectorBase(const gsl_vector *v=NULL)
Constructor.
const double & operator()(size_t i) const
Element access operator.
double operator*(const VectorBase &) const
void sort_largest_index(std::vector< size_t > &sort_index, size_t k, const VectorBase &invec)
Adaptor using a stride on underlying iterator.
Definition: StrideIterator.h:50
bool overlap(const yat::utility::Segment< T, Compare > &lhs, const yat::utility::Segment< T, Compare > &rhs)
Definition: Segment.h:322
bool operator!=(const VectorBase &) const
Comparison operator. Takes linear time.

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