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

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

changed implementation of a couple of normalizer so that operator() takes two matrices of which one is an input marix and one is a result matrix, i.e., the result does only depend on the input matrix and the result is only used as a receiver - I think this behaviour is more intuitive, although it is not as general as the previous one. We should probably document somewhere how we expect a 2Dnormalizer to behave (refs #425).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
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
28namespace theplu {
29namespace yat {
30namespace 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       \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 ColumnNormalizer<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                                   "ColumnNormalizer: rows mismatch");
78    yat_assert<std::runtime_error>(matrix.columns()==result.columns(),
79                                   "ColumnNormalizer: columns mismatch");
80    for (size_t i=0; i<matrix.columns(); ++i)
81      normalizer_(matrix.begin_column(i), matrix.end_column(i),
82                  result.begin_column(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.