source: trunk/yat/normalizer/RowNormalizer.h

Last change on this file was 3295, checked in by Peter, 7 years ago

merge release 0.12 into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svndigest:ignore set to 1518
File size: 2.9 KB
Line 
1#ifndef _theplu_yat_normalizer_row_normalizer_
2#define _theplu_yat_normalizer_row_normalizer_
3
4// $Id: RowNormalizer.h 3295 2014-07-25 04:24:39Z peter $
5
6/*
7  Copyright (C) 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2010, 2014 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 "yat/utility/yat_assert.h"
27#include "yat/utility/concept_check.h"
28
29#include <boost/concept_check.hpp>
30
31#include <cstddef>
32#include <stdexcept>
33
34namespace theplu {
35namespace yat {
36namespace normalizer {
37
38  /**
39     \brief Using a functor T to normalize each column.
40
41     If the underlying normalizer_type allows normalization "in
42     place", i.e., it allows input range and result range to be the
43     same range, then it is safe to have same container for input as
44     output.
45     
46     In the case of views and lookups it is more complicated. The
47     assignment is done sequentially, so if the input container and
48     result container have the same underlying data, the normalization
49     is typically not safe.
50
51     \since New in yat 0.5
52
53     \see ColumnNormalizer
54   */
55  template<class T>
56  class RowNormalizer
57  {
58  public:
59    /**
60       functor used to normalize each column
61    */
62    typedef T normalizer_type;
63
64    /**
65       \brief Default constructor
66     */
67    RowNormalizer(void) {}
68
69    /**
70       \brief Constructor taking a functor \a norm
71     */
72    RowNormalizer(T norm) 
73      : normalizer_(norm) {}
74
75    /**
76       Each row in \a matrix is normalized using class T, and
77       assigned to corresponding row in \a result.
78
79       Template argument Container2D1 should be a class modelling the
80       concept \ref concept_container_2d. The template argument
81       Container2D2 should be a class modelling the concept \ref
82       concept_mutable_container_2d.
83
84       \note \a result must have same dimensions as \a matrix.
85     */
86    template<class Container2D1, class Container2D2>
87    void operator()(const Container2D1& matrix, 
88                    Container2D2& result) const
89    {
90      BOOST_CONCEPT_ASSERT((utility::Container2D<Container2D1>));
91      BOOST_CONCEPT_ASSERT((utility::Mutable_Container2D<Container2D2>));
92      using utility::yat_assert;
93      YAT_ASSERT(matrix.rows()==result.rows());
94      YAT_ASSERT(matrix.columns()==result.columns());
95      for (size_t i=0; i<matrix.rows(); ++i)
96        normalizer_(matrix.begin_row(i), matrix.end_row(i),
97                  result.begin_row(i));
98    }
99
100  private:
101    T normalizer_;
102  };
103
104}}} // end of namespace normalizer, yat and thep
105#endif
Note: See TracBrowser for help on using the repository browser.