Changeset 3224


Ignore:
Timestamp:
May 12, 2014, 6:30:09 AM (7 years ago)
Author:
Peter
Message:

improve documentation; remove trailing WS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/merge.h

    r2372 r3224  
    11#ifndef _theplu_yat_utility_merge_
    2 #define _theplu_yat_utility_merge_ 
     2#define _theplu_yat_utility_merge_
    33
    44// $Id$
    55
    66/*
    7   Copyright (C) 2009, 2010 Peter Johansson
     7  Copyright (C) 2009, 2010, 2014 Peter Johansson
    88
    99  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    6464  */
    6565  template<class Container2D>
    66   void merge(const Container2D& x, std::vector<std::string>& labels, Matrix& y); 
     66  void merge(const Container2D& x, std::vector<std::string>& labels, Matrix& y);
    6767
    6868
     
    7070     \brief merge rows in a \ref concept_container_2d using a Functor
    7171
    72      Same as utility::merge(const Container2D&, std::vector<std::string>&,
     72     Same as merge(const Container2D&, std::vector<std::string>&,
    7373     Matrix&) but instead of calculating the merged element as the
    7474     (weighted) arithmetic mean, the merged element is calculated as
    7575     defined by \a func.
    7676
     77     \param x input container to be merged.
     78     \param labels telling which rows to merge.
     79     \param y resulting merged container.
     80     \param func defines how data values are calculated
     81
     82     \c Functor \a func has an \c operator()(Iterator first, Iterator
     83     last) \c const that calculates the merged value from range
     84     [first, last).
     85
     86     Type Requirements:
     87     - \c Container2D is a \ref concept_container_2d
     88     - \c Functor is a <a href=http://www.sgi.com/tech/stl/BinaryFunction.html>
     89     Binary Function</a>.
     90     - \c Container2D::const_column_iterator is convertible to
     91       argument types of \c Functor.
     92     - \c Return type of \c Functor is convertible to \c double
     93
    7794     If Functor works on both unweighted and weighted iterators, merge
    7895     works on both unweighted and weighted Container2D.
     96
     97     \note If \a x and \a y overlap in their underlying data
     98     structures, the result is undefined.
    7999
    80100     \since New in yat 0.6
     
    82102  template<class Container2D, class Functor>
    83103  void merge(const Container2D& x, std::vector<std::string>& labels, Matrix& y,
    84              Functor func); 
     104             Functor func);
    85105
    86106  /**
     
    106126     \param weight_func defines how weight values are calculated
    107127
     128     \c Functor1 and \c Functor2 have an \c operator()(Iterator first,
     129     Iterator last) \c const that calculates the merged value and
     130     weight, respectively, from range [first, last).
     131
     132     Type Requirements:
     133     - \c Container2D is a \ref concept_container_2d
     134     - \c Functor1 is a <a href=http://www.sgi.com/tech/stl/BinaryFunction.html>
     135     Binary Function</a>.
     136     - \c Functor2 is a <a href=http://www.sgi.com/tech/stl/BinaryFunction.html>
     137     Binary Function</a>.
     138     - \c Container2D::const_column_iterator is convertible to
     139       argument types of \c Functor1 and \c Functor2.
     140     - \c Return type of \c Functor1 is convertible to \c double
     141     - \c Return type of \c Functor2 is convertible to \c double
     142
     143     If \c Functor1 and \c Functor2 work on both unweighted and
     144     weighted iterators, merge works on both unweighted and weighted
     145     Container2D.
     146
    108147     \note If \a x and \a y overlap in their underlying data
    109148     structures, the result is undefined.
     
    112151  */
    113152  template<class Container2D, class Functor1, class Functor2>
    114   void merge(const Container2D& x, std::vector<std::string>& labels, 
    115              MatrixWeighted& y, Functor1 data_func, Functor2 weight_func); 
     153  void merge(const Container2D& x, std::vector<std::string>& labels,
     154             MatrixWeighted& y, Functor1 data_func, Functor2 weight_func);
    116155
    117156  namespace detail {
    118    
     157
    119158    /**
    120159       assign x using func1 on range [first, last).
     
    136175                Functor2 func2);
    137176
    138     void merge_labels(std::vector<std::string>&, 
     177    void merge_labels(std::vector<std::string>&,
    139178                      std::map<std::string, std::vector<size_t> >&);
    140179
    141180
    142     template<class Container2D, class MutableContainer2D, 
     181    template<class Container2D, class MutableContainer2D,
    143182             class Functor1, class Functor2>
    144     void merge(const Container2D& x, 
    145                std::map<std::string, std::vector<size_t> >& label2index, 
     183    void merge(const Container2D& x,
     184               std::map<std::string, std::vector<size_t> >& label2index,
    146185               MutableContainer2D& result, Functor1 func1, Functor2 func2);
    147186
     
    159198
    160199  template<class Container2D, class Functor>
    161   void merge(const Container2D& x, std::vector<std::string>& labels, 
     200  void merge(const Container2D& x, std::vector<std::string>& labels,
    162201             Matrix& result, Functor func)
    163202  {
     
    170209
    171210  template<class Container2D, class Functor1, class Functor2>
    172   void merge(const Container2D& x, std::vector<std::string>& labels, 
     211  void merge(const Container2D& x, std::vector<std::string>& labels,
    173212             MatrixWeighted& result, Functor1 func1, Functor2 func2)
    174213  {
     
    177216    detail::merge_labels(labels, label2index);
    178217    detail::merge(x, label2index, result, func1, func2);
    179   } 
     218  }
    180219
    181220  // implemantions of private functions
     
    199238
    200239
    201     void merge_labels(std::vector<std::string>& labels, 
     240    void merge_labels(std::vector<std::string>& labels,
    202241                      std::map<std::string, std::vector<size_t> >& label2index)
    203242    {
     
    210249
    211250
    212     template<class Container2D, class MutableContainer2D, 
     251    template<class Container2D, class MutableContainer2D,
    213252             class Functor1, class Functor2>
    214     void merge(const Container2D& x, 
    215                std::map<std::string, std::vector<size_t> >& label2index, 
     253    void merge(const Container2D& x,
     254               std::map<std::string, std::vector<size_t> >& label2index,
    216255               MutableContainer2D& result, Functor1 func1, Functor2 func2)
    217256    {
     
    220259      result.resize(label2index.size(), x.columns());
    221260      typedef std::map<std::string, std::vector<size_t> > Map;
    222       Map::const_iterator iter=label2index.begin(); 
     261      Map::const_iterator iter=label2index.begin();
    223262
    224263      for (size_t row=0; row<result.rows(); ++row) {
    225264        const std::vector<size_t>& index = iter->second;
    226265        for (size_t col=0; col<result.columns(); ++col) {
    227           assign(result(row,col), 
    228                  boost::make_permutation_iterator(x.begin_column(col), 
     266          assign(result(row,col),
     267                 boost::make_permutation_iterator(x.begin_column(col),
    229268                                                  index.begin()),
    230                  boost::make_permutation_iterator(x.end_column(col), 
     269                 boost::make_permutation_iterator(x.end_column(col),
    231270                                                  index.end()),
    232271                 func1, func2);
     
    234273        ++iter;
    235274      }
    236     } 
     275    }
    237276
    238277  } // end of namespace detail
Note: See TracChangeset for help on using the changeset viewer.