yat  0.15.2pre
VectorBase.h
1 #ifndef _theplu_yat_utility_vector_base_
2 #define _theplu_yat_utility_vector_base_
3 
4 // $Id: VectorBase.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 Jari Häkkinen, Peter Johansson
13  Copyright (C) 2009, 2012, 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 "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 
254  void sort_index(std::vector<size_t>& sort_index, const VectorBase& invec);
255 
262  void sort_smallest_index(std::vector<size_t>& sort_index, size_t k,
263  const VectorBase& invec);
264 
271  void sort_largest_index(std::vector<size_t>& sort_index, size_t k,
272  const VectorBase& invec);
273 
281  double sum(const VectorBase&);
282 
296  std::ostream& operator<<(std::ostream& s, const VectorBase& v);
297 
299 
300  // Some convenience functions used in Vector and friends.
301  namespace detail {
302 
314  gsl_vector* create_gsl_vector(size_t n);
315 
319  gsl_vector* create_gsl_vector(size_t n, double init);
320 
332  gsl_vector* create_gsl_vector_copy(const gsl_vector*);
333 
334 
335  // return true if a and b overlap in memory
336  bool overlap(const gsl_vector* a, const gsl_vector* b);
337 
338  /*
339  Is a stricter condition that overlap(2). Basically it returns
340  false if it is safe to write code like:
341  for (size_t i=0; i<a->size; ++i)
342  a[i] = foo(b[i])
343 
344  in other words, it returns true if there exists i and j, i<j, such that
345  gsl_vector_const_ptr(a, j) == gsl_vector_const_ptr(b, i)
346 
347  For speed reasons function might return true in some cases when
348  condition above is not true, when both a and b have stride>1 and
349  elements sit between each other.
350 
351  Note, a and b must have same size.
352  */
353  bool serial_overlap(const gsl_vector* a, const gsl_vector* b);
354  }
355 
357 
358 }}} // of namespace utility, yat, and theplu
359 
360 #endif
const gsl_vector * gsl_vector_p(void) const
const double & operator()(size_t i) const
Element access operator.
std::ostream & operator<<(std::ostream &s, const VectorBase &v)
The output operator for the VectorBase class.
double value_type
Definition: VectorBase.h:63
void sort_largest_index(std::vector< size_t > &sort_index, size_t k, const VectorBase &invec)
size_t min_index(const VectorBase &)
Locate the minimum value in the VectorBase.
The Department of Theoretical Physics namespace as we define it.
bool operator!=(const VectorBase &) const
Comparison operator. Takes linear time.
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
double max(const VectorBase &)
Get the maximum value of the VectorBase.
bool nan(const VectorBase &templat, Vector &flag)
Create a VectorBase flag indicating NaN&#39;s in another VectorBase templat.
const_iterator begin(void) const
bool operator==(const VectorBase &) const
Comparison operator. Takes linear time.
double sum(const VectorBase &)
Calculate the sum of all VectorBase elements.
void sort_smallest_index(std::vector< size_t > &sort_index, size_t k, const VectorBase &invec)
This is the yat interface to GSL vector.
Definition: Vector.h:59
This is the yat interface to GSL vector.
Definition: VectorBase.h:55
void sort_index(std::vector< size_t > &sort_index, const VectorBase &invec)
double operator*(const VectorBase &) const
bool equal(const VectorBase &, const double precision=0) const
Check whether VectorBases are equal within a user defined precision, set by precision.
double min(const VectorBase &)
Get the minimum value of the VectorBase.
const_iterator end(void) const
Definition: BasicVector.h:48
const double & const_reference
Definition: VectorBase.h:70
VectorBase(const gsl_vector *v=NULL)
Constructor.
bool isnull(const VectorBase &)
Check if all elements of the VectorBase are zero.
virtual bool isview(void) const =0
size_t max_index(const VectorBase &)
Locate the maximum value in the VectorBase.
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:310

Generated on Fri Jul 13 2018 02:33:27 for yat by  doxygen 1.8.11