yat  0.21pre
RangeNormalizer.h
1 #ifndef _theplu_yat_normalizer_range_normalizer_
2 #define _theplu_yat_normalizer_range_normalizer_
3 
4 // $Id: RangeNormalizer.h 3954 2020-07-22 13:03:31Z peter $
5 
6 /*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2010, 2011, 2014, 2016, 2020 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/utility/concept_check.h"
29 #include "yat/utility/DataIterator.h"
30 #include "yat/utility/iterator_traits.h"
31 #include "yat/utility/WeightIterator.h"
32 
33 #include <boost/concept_check.hpp>
34 #include <boost/iterator/iterator_concepts.hpp>
35 
36 #include <algorithm>
37 #include <functional>
38 
39 namespace theplu {
40 namespace yat {
41 namespace normalizer {
42 
63  template<class UnaryFunction, class Operator>
65  {
66  public:
74 
78  // This is superfluous but required to keep the Centralizer API
79  // with version 0.17
80  RangeNormalizer(const UnaryFunction& uf)
81  : func_(uf) {}
82 
88  RangeNormalizer(const UnaryFunction& uf, const Operator& op)
89  : func_(uf), op_(op) {}
90 
114  template<class InputIterator, class OutputIterator>
115  void operator()(InputIterator first, InputIterator last,
116  OutputIterator result) const
117  {
118  BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<InputIterator>));
119  BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<OutputIterator>));
120  BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<OutputIterator>));
121 
122  // we need to traverse the input range once in call to func_ and
123  // one in call to std::transform, so single pass iterator will
124  // not suffice.
125  BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<InputIterator>));
126  // requirments for OutputIterator is different depending on
127  // whether it's weighted or not
129  check_requirements<OutputIterator>(tag);
130 
131  // copy weight if result is weighted
132  detail::copy_weight_if_weighted(first, last, result);
133  double val = func_(first, last);
134  std::transform(utility::data_iterator(first),
135  utility::data_iterator(last),
136  utility::data_iterator(result),
137  [this, val](double x) {return op_(x, val);});
138  }
139 
140  private:
141 
142  template<typename OutputIterator>
143  void check_requirements(utility::unweighted_iterator_tag) const
144  {
145  using boost_concepts::SinglePassIterator;
146  using boost_concepts::WritableIterator;
147  BOOST_CONCEPT_ASSERT((SinglePassIterator<OutputIterator>));
148  BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator, double>));
149 
150  }
151 
152  template<typename OutputIterator>
153  void check_requirements(utility::weighted_iterator_tag) const
154  {
155  using boost_concepts::ForwardTraversal;
156  using boost_concepts::WritableIterator;
157  BOOST_CONCEPT_ASSERT((ForwardTraversal<OutputIterator>));
158  BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator
159  , utility::DataWeight>));
160  }
161 
162  UnaryFunction func_;
163  Operator op_;
164  };
165 
166 }}} // end of namespace normalizer, yat and thep
167 #endif
detail::weighted_iterator_traits_detail< value >::type type
Definition: iterator_traits.h:114
Concept check for Data Iterator.
Definition: concept_check.h:240
RangeNormalizer(void)
default constructor
Definition: RangeNormalizer.h:73
The Department of Theoretical Physics namespace as we define it.
Definition: iterator_traits.h:47
RangeNormalizer(const UnaryFunction &uf, const Operator &op)
Definition: RangeNormalizer.h:88
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: RangeNormalizer.h:115
RangeNormalizer(const UnaryFunction &uf)
Definition: RangeNormalizer.h:80
Definition: RangeNormalizer.h:64

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14