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

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

adding a RowNormalizer?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 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       \note \a result must have same dimensions as \a matrix.
64     */
65    void operator()(const utility::Matrix& matrix, 
66                    utility::Matrix& result) const;
67  private:
68    T normalizer_;
69  };
70
71  template<class T>
72  void RowNormalizer<T>::operator()(const utility::Matrix& matrix, 
73                                    utility::Matrix& result) const
74  {
75    using utility::yat_assert;
76    yat_assert<std::runtime_error>(matrix.rows()==result.rows(),
77                                   "RowNormalizer: rows mismatch");
78    yat_assert<std::runtime_error>(matrix.columns()==result.columns(),
79                                   "RowNormalizer: columns mismatch");
80    for (size_t i=0; i<matrix.rows(); ++i)
81      normalizer_(matrix.begin_row(i), matrix.end_row(i),
82                  result.begin_row(i));
83
84  }
85
86
87}}} // end of namespace normalizer, yat and thep
88#endif
Note: See TracBrowser for help on using the repository browser.