Changeset 2283


Ignore:
Timestamp:
Jun 26, 2010, 4:14:39 AM (11 years ago)
Author:
Peter
Message:

fix Centralizer so it works with mixed iterators. Make it clear that result iterator must be a mutable forward iterator (output iterator does not work). refs #631

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/normalization_test.cc

    r2276 r2283  
    102102  // compile test should not be run
    103103  if (false) {
    104     boost::detail::dummy_constructor dummy_cons;
    105104    c(boost::input_iterator_archetype<double>(),
    106105      boost::input_iterator_archetype<double>(),
    107       boost::output_iterator_archetype<double>(dummy_cons));
    108 
    109     /* For ticket #631
     106      boost::mutable_forward_iterator_archetype<double>());
     107
    110108    c(boost::input_iterator_archetype<double>(),
    111109      boost::input_iterator_archetype<double>(),
    112       boost::output_iterator_archetype<utility::DataWeight>(dummy_cons));
    113 
    114     c(boost::input_iterator_archetype<utility::DataWeight>(),
    115       boost::input_iterator_archetype<utility::DataWeight>(),
    116       boost::output_iterator_archetype<double>(dummy_cons));
    117 
    118     c(boost::input_iterator_archetype<utility::DataWeight>(),
    119       boost::input_iterator_archetype<utility::DataWeight>(),
    120       boost::output_iterator_archetype<utility::DataWeight>(dummy_cons));
    121     */
     110      boost::mutable_forward_iterator_archetype<utility::DataWeight>());
     111
     112    c(boost::input_iterator_archetype_no_proxy<utility::DataWeight>(),
     113      boost::input_iterator_archetype_no_proxy<utility::DataWeight>(),
     114      boost::mutable_forward_iterator_archetype<double>());
     115
     116    c(boost::input_iterator_archetype_no_proxy<utility::DataWeight>(),
     117      boost::input_iterator_archetype_no_proxy<utility::DataWeight>(),
     118      boost::mutable_forward_iterator_archetype<utility::DataWeight>());
    122119  }
    123120}
  • trunk/yat/normalizer/Centralizer.h

    r2161 r2283  
    2424*/
    2525
     26#include "utility.h"
     27
    2628#include "yat/statistics/Average.h"
    2729#include "yat/utility/DataIterator.h"
     
    4547     mean, but this can be changed by providing a suitable
    4648     UnaryFunction.
     49
     50     Type Requirements:
     51     - InputIterator must be an \input_iterator
     52     - ForwardIterator must be a mutable \forward_iterator
    4753
    4854     \since New in yat 0.5
     
    7884       \see std::transform
    7985     */
    80     template<class InputIterator, class OutputIterator>
     86    template<class InputIterator, class ForwardIterator>
    8187    void operator()(InputIterator first, InputIterator last,
    82                     OutputIterator result) const
     88                    ForwardIterator result) const
    8389    {
    8490      BOOST_CONCEPT_ASSERT((boost::InputIterator<InputIterator>));
    85       typename utility::weighted_iterator_traits<InputIterator>::type tag;
    86       normalize(first, last, result, tag);
    87     }
    88 
    89   private:
    90     UnaryFunction func_;
    91 
    92     // unweighted version
    93     template<class InputIterator, class OutputIterator>
    94     void normalize(InputIterator first,InputIterator last,OutputIterator result,
    95                    utility::unweighted_iterator_tag tag) const
    96     {
    97       std::transform(first, last, result,
    98                      std::bind2nd(std::minus<double>(), func_(first, last)));
    99     }
    100 
    101 
    102     // weighted version
    103     template<class InputIterator, class OutputIterator>
    104     void normalize(InputIterator first,InputIterator last,OutputIterator result,
    105                    utility::weighted_iterator_tag tag) const
    106     {
    107       std::copy(utility::weight_iterator(first),
    108                 utility::weight_iterator(last),
    109                 utility::weight_iterator(result));
     91      BOOST_CONCEPT_ASSERT((boost::Mutable_ForwardIterator<ForwardIterator>));
     92      // copy weight if result is weighted
     93      detail::copy_weight_if_weighted(first, last, result);
    11094      std::transform(utility::data_iterator(first),
    11195                     utility::data_iterator(last),
     
    11498    }
    11599
     100  private:
     101    UnaryFunction func_;
    116102  };
    117103
Note: See TracChangeset for help on using the changeset viewer.