1520 |
21 Sep 08 |
peter |
1 |
#ifndef _theplu_yat_normalizer_row_normalizer_ |
3295 |
25 Jul 14 |
peter |
2 |
#define _theplu_yat_normalizer_row_normalizer_ |
1462 |
01 Sep 08 |
peter |
3 |
|
1575 |
14 Oct 08 |
jari |
// $Id$ |
1575 |
14 Oct 08 |
jari |
5 |
|
1462 |
01 Sep 08 |
peter |
6 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2009, 2010 Peter Johansson |
1462 |
01 Sep 08 |
peter |
9 |
|
1462 |
01 Sep 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
1462 |
01 Sep 08 |
peter |
11 |
|
1462 |
01 Sep 08 |
peter |
The yat library is free software; you can redistribute it and/or |
1462 |
01 Sep 08 |
peter |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
1462 |
01 Sep 08 |
peter |
License, or (at your option) any later version. |
1462 |
01 Sep 08 |
peter |
16 |
|
1462 |
01 Sep 08 |
peter |
The yat library is distributed in the hope that it will be useful, |
1462 |
01 Sep 08 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
1462 |
01 Sep 08 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1462 |
01 Sep 08 |
peter |
General Public License for more details. |
1462 |
01 Sep 08 |
peter |
21 |
|
1462 |
01 Sep 08 |
peter |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
1462 |
01 Sep 08 |
peter |
24 |
*/ |
1462 |
01 Sep 08 |
peter |
25 |
|
1518 |
21 Sep 08 |
peter |
26 |
#include "yat/utility/yat_assert.h" |
2371 |
12 Dec 10 |
peter |
27 |
#include "yat/utility/concept_check.h" |
1463 |
01 Sep 08 |
peter |
28 |
|
2371 |
12 Dec 10 |
peter |
29 |
#include <boost/concept_check.hpp> |
2371 |
12 Dec 10 |
peter |
30 |
|
1782 |
08 Feb 09 |
peter |
31 |
#include <cstddef> |
1518 |
21 Sep 08 |
peter |
32 |
#include <stdexcept> |
1518 |
21 Sep 08 |
peter |
33 |
|
1462 |
01 Sep 08 |
peter |
34 |
namespace theplu { |
1462 |
01 Sep 08 |
peter |
35 |
namespace yat { |
1497 |
12 Sep 08 |
peter |
36 |
namespace normalizer { |
1462 |
01 Sep 08 |
peter |
37 |
|
1462 |
01 Sep 08 |
peter |
38 |
/** |
1579 |
14 Oct 08 |
peter |
\brief Using a functor T to normalize each column. |
1462 |
01 Sep 08 |
peter |
40 |
|
1579 |
14 Oct 08 |
peter |
If the underlying normalizer_type allows normalization "in |
1579 |
14 Oct 08 |
peter |
place", i.e., it allows input range and result range to be the |
1579 |
14 Oct 08 |
peter |
same range, then it is safe to have same container for input as |
1579 |
14 Oct 08 |
peter |
output. |
4200 |
19 Aug 22 |
peter |
45 |
|
1579 |
14 Oct 08 |
peter |
In the case of views and lookups it is more complicated. The |
1579 |
14 Oct 08 |
peter |
assignment is done sequentially, so if the input container and |
1579 |
14 Oct 08 |
peter |
result container have the same underlying data, the normalization |
1579 |
14 Oct 08 |
peter |
is typically not safe. |
1462 |
01 Sep 08 |
peter |
50 |
|
1462 |
01 Sep 08 |
peter |
\since New in yat 0.5 |
1579 |
14 Oct 08 |
peter |
52 |
|
1579 |
14 Oct 08 |
peter |
\see ColumnNormalizer |
1462 |
01 Sep 08 |
peter |
54 |
*/ |
1462 |
01 Sep 08 |
peter |
55 |
template<class T> |
1520 |
21 Sep 08 |
peter |
56 |
class RowNormalizer |
1462 |
01 Sep 08 |
peter |
57 |
{ |
1462 |
01 Sep 08 |
peter |
58 |
public: |
1462 |
01 Sep 08 |
peter |
59 |
/** |
1462 |
01 Sep 08 |
peter |
functor used to normalize each column |
1462 |
01 Sep 08 |
peter |
61 |
*/ |
1463 |
01 Sep 08 |
peter |
62 |
typedef T normalizer_type; |
1462 |
01 Sep 08 |
peter |
63 |
|
1462 |
01 Sep 08 |
peter |
64 |
/** |
1462 |
01 Sep 08 |
peter |
\brief Default constructor |
1462 |
01 Sep 08 |
peter |
66 |
*/ |
1520 |
21 Sep 08 |
peter |
67 |
RowNormalizer(void) {} |
1462 |
01 Sep 08 |
peter |
68 |
|
1462 |
01 Sep 08 |
peter |
69 |
/** |
1462 |
01 Sep 08 |
peter |
\brief Constructor taking a functor \a norm |
1462 |
01 Sep 08 |
peter |
71 |
*/ |
4200 |
19 Aug 22 |
peter |
72 |
RowNormalizer(T norm) |
1462 |
01 Sep 08 |
peter |
73 |
: normalizer_(norm) {} |
1462 |
01 Sep 08 |
peter |
74 |
|
1462 |
01 Sep 08 |
peter |
75 |
/** |
1520 |
21 Sep 08 |
peter |
Each row in \a matrix is normalized using class T, and |
1782 |
08 Feb 09 |
peter |
assigned to corresponding row in \a result. |
1462 |
01 Sep 08 |
peter |
78 |
|
1544 |
01 Oct 08 |
peter |
Template argument Container2D1 should be a class modelling the |
1544 |
01 Oct 08 |
peter |
concept \ref concept_container_2d. The template argument |
1544 |
01 Oct 08 |
peter |
Container2D2 should be a class modelling the concept \ref |
1544 |
01 Oct 08 |
peter |
concept_mutable_container_2d. |
1544 |
01 Oct 08 |
peter |
83 |
|
1518 |
21 Sep 08 |
peter |
\note \a result must have same dimensions as \a matrix. |
1462 |
01 Sep 08 |
peter |
85 |
*/ |
1544 |
01 Oct 08 |
peter |
86 |
template<class Container2D1, class Container2D2> |
4200 |
19 Aug 22 |
peter |
87 |
void operator()(const Container2D1& matrix, |
1544 |
01 Oct 08 |
peter |
88 |
Container2D2& result) const |
1544 |
01 Oct 08 |
peter |
89 |
{ |
2371 |
12 Dec 10 |
peter |
90 |
BOOST_CONCEPT_ASSERT((utility::Container2D<Container2D1>)); |
2371 |
12 Dec 10 |
peter |
91 |
BOOST_CONCEPT_ASSERT((utility::Mutable_Container2D<Container2D2>)); |
1544 |
01 Oct 08 |
peter |
92 |
using utility::yat_assert; |
2210 |
05 Mar 10 |
peter |
93 |
YAT_ASSERT(matrix.rows()==result.rows()); |
2210 |
05 Mar 10 |
peter |
94 |
YAT_ASSERT(matrix.columns()==result.columns()); |
1544 |
01 Oct 08 |
peter |
95 |
for (size_t i=0; i<matrix.rows(); ++i) |
1544 |
01 Oct 08 |
peter |
96 |
normalizer_(matrix.begin_row(i), matrix.end_row(i), |
1544 |
01 Oct 08 |
peter |
97 |
result.begin_row(i)); |
1544 |
01 Oct 08 |
peter |
98 |
} |
1544 |
01 Oct 08 |
peter |
99 |
|
1462 |
01 Sep 08 |
peter |
100 |
private: |
1462 |
01 Sep 08 |
peter |
101 |
T normalizer_; |
1462 |
01 Sep 08 |
peter |
102 |
}; |
1462 |
01 Sep 08 |
peter |
103 |
|
1497 |
12 Sep 08 |
peter |
104 |
}}} // end of namespace normalizer, yat and thep |
1462 |
01 Sep 08 |
peter |
105 |
#endif |