yat/normalizer/RowNormalizer.h

Code
Comments
Other
Rev Date Author Line
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 4 // $Id$
1575 14 Oct 08 jari 5
1462 01 Sep 08 peter 6 /*
2119 12 Dec 09 peter 7   Copyright (C) 2008 Jari Häkkinen, Peter Johansson
4359 23 Aug 23 peter 8   Copyright (C) 2009, 2010 Peter Johansson
1462 01 Sep 08 peter 9
1462 01 Sep 08 peter 10   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 12   The yat library is free software; you can redistribute it and/or
1462 01 Sep 08 peter 13   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 14   published by the Free Software Foundation; either version 3 of the
1462 01 Sep 08 peter 15   License, or (at your option) any later version.
1462 01 Sep 08 peter 16
1462 01 Sep 08 peter 17   The yat library is distributed in the hope that it will be useful,
1462 01 Sep 08 peter 18   but WITHOUT ANY WARRANTY; without even the implied warranty of
1462 01 Sep 08 peter 19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1462 01 Sep 08 peter 20   General Public License for more details.
1462 01 Sep 08 peter 21
1462 01 Sep 08 peter 22   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 23   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 39      \brief Using a functor T to normalize each column.
1462 01 Sep 08 peter 40
1579 14 Oct 08 peter 41      If the underlying normalizer_type allows normalization "in
1579 14 Oct 08 peter 42      place", i.e., it allows input range and result range to be the
1579 14 Oct 08 peter 43      same range, then it is safe to have same container for input as
1579 14 Oct 08 peter 44      output.
4200 19 Aug 22 peter 45
1579 14 Oct 08 peter 46      In the case of views and lookups it is more complicated. The
1579 14 Oct 08 peter 47      assignment is done sequentially, so if the input container and
1579 14 Oct 08 peter 48      result container have the same underlying data, the normalization
1579 14 Oct 08 peter 49      is typically not safe.
1462 01 Sep 08 peter 50
1462 01 Sep 08 peter 51      \since New in yat 0.5
1579 14 Oct 08 peter 52
1579 14 Oct 08 peter 53      \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 60        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 65        \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 70        \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 76        Each row in \a matrix is normalized using class T, and
1782 08 Feb 09 peter 77        assigned to corresponding row in \a result.
1462 01 Sep 08 peter 78
1544 01 Oct 08 peter 79        Template argument Container2D1 should be a class modelling the
1544 01 Oct 08 peter 80        concept \ref concept_container_2d. The template argument
1544 01 Oct 08 peter 81        Container2D2 should be a class modelling the concept \ref
1544 01 Oct 08 peter 82        concept_mutable_container_2d.
1544 01 Oct 08 peter 83
1518 21 Sep 08 peter 84        \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