1 | #ifndef _theplu_yat_normalizer_column_normalizer_ |
---|
2 | #define _theplu_yat_normalizer_column_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 | |
---|
28 | namespace theplu { |
---|
29 | namespace yat { |
---|
30 | namespace normalizer { |
---|
31 | |
---|
32 | /** |
---|
33 | \brief Normalize each column |
---|
34 | |
---|
35 | Using a functor T to normalize each column. |
---|
36 | |
---|
37 | \since New in yat 0.5 |
---|
38 | */ |
---|
39 | template<class T> |
---|
40 | class ColumnNormalizer |
---|
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 | ColumnNormalizer(void) {} |
---|
52 | |
---|
53 | /** |
---|
54 | \brief Constructor taking a functor \a norm |
---|
55 | */ |
---|
56 | ColumnNormalizer(T norm) |
---|
57 | : normalizer_(norm) {} |
---|
58 | |
---|
59 | /** |
---|
60 | Each column 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, Container2D2& result) const |
---|
72 | { |
---|
73 | using utility::yat_assert; |
---|
74 | yat_assert<std::runtime_error>(matrix.rows()==result.rows(), |
---|
75 | "ColumnNormalizer: rows mismatch"); |
---|
76 | yat_assert<std::runtime_error>(matrix.columns()==result.columns(), |
---|
77 | "ColumnNormalizer: columns mismatch"); |
---|
78 | for (size_t i=0; i<matrix.columns(); ++i) |
---|
79 | normalizer_(matrix.begin_column(i), matrix.end_column(i), |
---|
80 | result.begin_column(i)); |
---|
81 | |
---|
82 | } |
---|
83 | |
---|
84 | private: |
---|
85 | T normalizer_; |
---|
86 | }; |
---|
87 | |
---|
88 | }}} // end of namespace normalizer, yat and thep |
---|
89 | #endif |
---|