source: trunk/yat/normalizer/RowNormalizer.h @ 1544

Last change on this file since 1544 was 1544, checked in by Peter, 13 years ago

making RowNormalizer? and ColumnNormalizer? more general

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1#ifndef _theplu_yat_normalizer_row_normalizer_
2#define _theplu_yat_normalizer_rows_normalizer_
3
4/*
5  Copyright (C) 2008 Peter Johansson
6
7  This file is part of the yat library, http://dev.thep.lu.se/yat
8
9  The yat library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 3 of the
12  License, or (at your option) any later version.
13
14  The yat library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with yat. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include "yat/utility/Matrix.h"
24#include "yat/utility/yat_assert.h"
25
26#include <stdexcept>
27
28namespace theplu {
29namespace yat {
30namespace normalizer {
31
32  /**
33     \brief Normalize each row
34
35     Using a functor T to normalize each row.
36
37     \since New in yat 0.5
38   */
39  template<class T>
40  class RowNormalizer
41  {
42  public:
43    /**
44       functor used to normalize each column
45    */
46    typedef T normalizer_type;
47
48    /**
49       \brief Default constructor
50     */
51    RowNormalizer(void) {}
52
53    /**
54       \brief Constructor taking a functor \a norm
55     */
56    RowNormalizer(T norm) 
57      : normalizer_(norm) {}
58
59    /**
60       Each row in \a matrix is normalized using class T, and
61       assigned to Matrix \a result.
62
63       Template argument Container2D1 should be a class modelling the
64       concept \ref concept_container_2d. The template argument
65       Container2D2 should be a class modelling the concept \ref
66       concept_mutable_container_2d.
67
68       \note \a result must have same dimensions as \a matrix.
69     */
70    template<class Container2D1, class Container2D2>
71    void operator()(const Container2D1& matrix, 
72                    Container2D2& result) const
73    {
74      using utility::yat_assert;
75      yat_assert<std::runtime_error>(matrix.rows()==result.rows(),
76                                     "RowNormalizer: rows mismatch");
77      yat_assert<std::runtime_error>(matrix.columns()==result.columns(),
78                                     "RowNormalizer: columns mismatch");
79      for (size_t i=0; i<matrix.rows(); ++i)
80        normalizer_(matrix.begin_row(i), matrix.end_row(i),
81                  result.begin_row(i));
82    }
83
84  private:
85    T normalizer_;
86  };
87
88}}} // end of namespace normalizer, yat and thep
89#endif
Note: See TracBrowser for help on using the repository browser.