source: trunk/yat/normalizer/ColumnNormalizer.h

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

update copyright years

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1#ifndef _theplu_yat_normalizer_column_normalizer_
2#define _theplu_yat_normalizer_column_normalizer_
3
4// $Id: ColumnNormalizer.h 3330 2014-10-14 08:03:25Z 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 RowNormalizer
54   */
55  template<class T>
56  class ColumnNormalizer
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    ColumnNormalizer(void) {}
68
69    /**
70       \brief Constructor taking a functor \a norm
71     */
72    ColumnNormalizer(T norm)
73      : normalizer_(norm) {}
74
75    /**
76       Each column in \a matrix is normalized using class T, and
77       assigned to corresponding column 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, Container2D2& result) const
88    {
89      BOOST_CONCEPT_ASSERT((utility::Container2D<Container2D1>));
90      BOOST_CONCEPT_ASSERT((utility::Mutable_Container2D<Container2D2>));
91      YAT_ASSERT(matrix.rows()==result.rows());
92      YAT_ASSERT(matrix.columns()==result.columns());
93      for (size_t i=0; i<matrix.columns(); ++i)
94        normalizer_(matrix.begin_column(i), matrix.end_column(i),
95                    result.begin_column(i));
96    }
97
98  private:
99    T normalizer_;
100  };
101
102}}} // end of namespace normalizer, yat and thep
103#endif
Note: See TracBrowser for help on using the repository browser.