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