Changeset 2157


Ignore:
Timestamp:
Jan 18, 2010, 1:19:52 AM (12 years ago)
Author:
Peter
Message:

refs #498. Zscore now works with mixed iterators and also refined requirements on iterator types

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/normalization_test.cc

    r2156 r2157  
    467467  suite.add(suite.equal(vec3[1].data(), 1.0));
    468468  suite.add(suite.equal(vec3[2].data(), 1.0));
    469 }
    470 
    471 
     469  // compile test should not be run
     470  if (false) {
     471    boost::detail::dummy_constructor dummy_cons;
     472    zscore(boost::forward_iterator_archetype<double>(),
     473           boost::forward_iterator_archetype<double>(),
     474           boost::output_iterator_archetype<double>(dummy_cons));
     475    using utility::DataWeight;
     476    zscore(boost::forward_iterator_archetype<DataWeight>(),
     477           boost::forward_iterator_archetype<DataWeight>(),
     478           boost::mutable_forward_iterator_archetype<DataWeight>());
     479    zscore(boost::random_access_iterator_archetype<DataWeight>(),
     480           boost::random_access_iterator_archetype<DataWeight>(),
     481           boost::mutable_random_access_iterator_archetype<double>());
     482    zscore(boost::random_access_iterator_archetype<double>(),
     483           boost::random_access_iterator_archetype<double>(),
     484           boost::mutable_random_access_iterator_archetype<DataWeight>());
     485  }
     486}
     487
     488
  • trunk/yat/normalizer/Zscore.h

    r2119 r2157  
    2424*/
    2525
     26#include "utility.h"
     27
    2628#include "yat/statistics/Averager.h"
    2729#include "yat/statistics/AveragerWeighted.h"
    2830
    2931#include "yat/utility/iterator_traits.h"
     32
     33#include <boost/concept_check.hpp>
    3034
    3135namespace theplu {
     
    5660       same. \see std::transform
    5761     */
    58     template<class InputIterator, class OutputIterator>
    59     void operator()(InputIterator first, InputIterator last,
    60                     OutputIterator result) const
     62    template<class ForwardIter1, class ForwardIter2>
     63    void operator()(ForwardIter1 first, ForwardIter1 last,
     64                    ForwardIter2 result) const
    6165    {
    62       typename utility::weighted_iterator_traits<InputIterator>::type tag;
     66      typename utility::weighted_if_any2<ForwardIter1, ForwardIter2>::type tag;
    6367      normalize(first, last, result, tag);
    6468    }
    6569
    6670  private:
    67     template<class InputIterator, class OutputIterator>
    68     void normalize(InputIterator first,InputIterator last,OutputIterator result,
     71    template<class ForwardIterator, class OutputIterator>
     72    void normalize(ForwardIterator first, ForwardIterator last,
     73                   OutputIterator result,
    6974                   utility::unweighted_iterator_tag tag) const
    7075    {
     76      // we requre forward iterator since we iterate through the range
     77      // multiple times.
     78      BOOST_CONCEPT_ASSERT((boost::ForwardIterator<ForwardIterator>));
     79      BOOST_CONCEPT_ASSERT((boost::OutputIterator<OutputIterator, double>));
    7180      statistics::Averager a;
    7281      add(a, first, last);
     
    8089    }
    8190
    82     template<class InputIterator, class OutputIterator>
    83     void normalize(InputIterator first,InputIterator last,OutputIterator result,
     91    template<class ForwardIter1, class ForwardIter2>
     92    void normalize(ForwardIter1 first, ForwardIter1 last, ForwardIter2 result,
    8493                   utility::weighted_iterator_tag tag) const
    8594    {
    86       std::copy(utility::weight_iterator(first),
    87                 utility::weight_iterator(last),
    88                 utility::weight_iterator(result));
     95      // we requre forward iterator since we iterate through the range
     96      // multiple times.
     97      BOOST_CONCEPT_ASSERT((boost::ForwardIterator<ForwardIter1>));
     98      BOOST_CONCEPT_ASSERT((boost::Mutable_ForwardIterator<ForwardIter2>));
     99      detail::copy_weight_if_weighted(first, last, result);
    89100      statistics::AveragerWeighted a;
    90101      add(a, first, last);
    91102      double m = a.mean();
    92103      double std = a.std();
    93       utility::iterator_traits<InputIterator> trait;
     104      utility::iterator_traits<ForwardIter1> in_trait;
     105      utility::iterator_traits<ForwardIter2> out_trait;
    94106      while (first!=last) {
    95         trait.data(result) = (trait.data(first) - m) / std;
     107        out_trait.data(result) = (in_trait.data(first) - m) / std;
    96108        ++first;
    97109        ++result;
Note: See TracChangeset for help on using the changeset viewer.