yat  0.16.4pre
Centralizer.h
1 #ifndef _theplu_yat_normalizer_centralizer_
2 #define _theplu_yat_normalizer_centralizer_
3 
4 // $Id: Centralizer.h 3550 2017-01-03 05:41:02Z peter $
5 
6 /*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2010, 2011, 2014, 2016 Peter Johansson
9 
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11 
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 3 of the
15  License, or (at your option) any later version.
16 
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with yat. If not, see <http://www.gnu.org/licenses/>.
24 */
25 
26 #include "utility.h"
27 
28 #include "yat/statistics/Average.h"
29 #include "yat/utility/concept_check.h"
30 #include "yat/utility/DataIterator.h"
31 #include "yat/utility/iterator_traits.h"
32 #include "yat/utility/WeightIterator.h"
33 
34 #include <boost/concept_check.hpp>
35 #include <boost/iterator/iterator_concepts.hpp>
36 
37 #include <algorithm>
38 #include <functional>
39 
40 namespace theplu {
41 namespace yat {
42 namespace normalizer {
43 
65  template<class UnaryFunction = statistics::Average>
67  {
68  public:
75  Centralizer(void){}
76 
80  Centralizer(const UnaryFunction& uf)
81  : func_(uf) {}
82 
106  template<class InputIterator, class OutputIterator>
107  void operator()(InputIterator first, InputIterator last,
108  OutputIterator result) const
109  {
110  BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<InputIterator>));
111  BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<OutputIterator>));
112  BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<OutputIterator>));
113 
114  // we need to traverse the input range once in call to func_ and
115  // one in call to std::transform, so single pass iterator will
116  // not suffice.
117  BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<InputIterator>));
118  // requirments for OutputIterator is different depending on
119  // whether it's weighted or not
121  check_requirements<OutputIterator>(tag);
122 
123  // copy weight if result is weighted
124  detail::copy_weight_if_weighted(first, last, result);
125  std::transform(utility::data_iterator(first),
126  utility::data_iterator(last),
127  utility::data_iterator(result),
128  std::bind2nd(std::minus<double>(),func_(first, last)));
129  }
130 
131  private:
132 
133  template<typename OutputIterator>
134  void check_requirements(utility::unweighted_iterator_tag) const
135  {
136  using boost_concepts::SinglePassIterator;
137  using boost_concepts::WritableIterator;
138  BOOST_CONCEPT_ASSERT((SinglePassIterator<OutputIterator>));
139  BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator, double>));
140 
141  }
142 
143  template<typename OutputIterator>
144  void check_requirements(utility::weighted_iterator_tag) const
145  {
146  using boost_concepts::ForwardTraversal;
147  using boost_concepts::WritableIterator;
148  BOOST_CONCEPT_ASSERT((ForwardTraversal<OutputIterator>));
149  BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator
150  , utility::DataWeight>));
151  }
152 
153  UnaryFunction func_;
154  };
155 
156 }}} // end of namespace normalizer, yat and thep
157 #endif
Centralize a range.
Definition: Centralizer.h:66
Centralizer(void)
default constructor
Definition: Centralizer.h:75
detail::weighted_iterator_traits_detail< value >::type type
Definition: iterator_traits.h:114
Concept check for Data Iterator.
Definition: concept_check.h:240
The Department of Theoretical Physics namespace as we define it.
Definition: iterator_traits.h:47
Centralizer(const UnaryFunction &uf)
Definition: Centralizer.h:80
Holds a pair of data and associated weight.
Definition: DataWeight.h:39
Definition: iterator_traits.h:55
void operator()(InputIterator first, InputIterator last, OutputIterator result) const
Definition: Centralizer.h:107

Generated on Thu Dec 12 2019 03:12:08 for yat by  doxygen 1.8.11