Changeset 3541


Ignore:
Timestamp:
Dec 23, 2016, 5:04:10 AM (5 years ago)
Author:
Peter
Message:

refs #803; use boost iterator concepts in Centralizer and Zscore

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/normalization.cc

    r3342 r3541  
    3939#include "yat/utility/MatrixWeighted.h"
    4040#include "yat/utility/WeightIterator.h"
     41#include "yat/utility/WeightedIteratorArchetype.h"
    4142
    4243#include <boost/concept_archetype.hpp>
     
    106107  // compile test should not be run
    107108  if (false) {
    108 
    109     using boost::detail::dummy_constructor;
    110     c(boost::forward_iterator_archetype<double>(),
    111       boost::forward_iterator_archetype<double>(),
    112       boost::mutable_forward_iterator_archetype<double>());
    113 
    114     c(boost::forward_iterator_archetype<double>(),
    115       boost::forward_iterator_archetype<double>(),
    116       boost::mutable_forward_iterator_archetype<utility::DataWeight>());
    117 
    118     c(boost::forward_iterator_archetype<utility::DataWeight>(),
    119       boost::forward_iterator_archetype<utility::DataWeight>(),
    120       boost::mutable_forward_iterator_archetype<double>());
    121 
    122     c(boost::forward_iterator_archetype<utility::DataWeight>(),
    123       boost::forward_iterator_archetype<utility::DataWeight>(),
    124       boost::mutable_forward_iterator_archetype<utility::DataWeight>());
     109    test::UnweightedConstDataIterator<boost::forward_traversal_tag>
     110      unweighted_const_iterator;
     111    test::UnweightedDataIterator<boost::forward_traversal_tag>
     112      unweighted_mutable_iterator;
     113
     114    test::WeightedConstDataIterator<boost::forward_traversal_tag>
     115      weighted_const_iterator;
     116    test::WeightedDataIterator<boost::forward_traversal_tag>
     117      weighted_mutable_iterator;
     118
     119    c(unweighted_const_iterator, unweighted_const_iterator,
     120      unweighted_mutable_iterator);
     121    c(unweighted_const_iterator, unweighted_const_iterator,
     122      weighted_mutable_iterator);
     123    c(weighted_const_iterator, weighted_const_iterator,
     124      unweighted_mutable_iterator);
     125    c(weighted_const_iterator, weighted_const_iterator,
     126      weighted_mutable_iterator);
    125127  }
    126128}
     
    527529  // compile test should not be run
    528530  if (false) {
    529     boost::detail::dummy_constructor dummy_cons;
    530     zscore(boost::forward_iterator_archetype<double>(),
    531            boost::forward_iterator_archetype<double>(),
    532            boost::output_iterator_archetype<double>(dummy_cons));
    533     using utility::DataWeight;
    534     zscore(boost::forward_iterator_archetype<DataWeight>(),
    535            boost::forward_iterator_archetype<DataWeight>(),
    536            boost::mutable_forward_iterator_archetype<DataWeight>());
    537     zscore(boost::random_access_iterator_archetype<DataWeight>(),
    538            boost::random_access_iterator_archetype<DataWeight>(),
    539            boost::mutable_random_access_iterator_archetype<double>());
    540     zscore(boost::random_access_iterator_archetype<double>(),
    541            boost::random_access_iterator_archetype<double>(),
    542            boost::mutable_random_access_iterator_archetype<DataWeight>());
    543   }
    544 }
     531    test::UnweightedConstDataIterator<boost::forward_traversal_tag>
     532      unweighted_const_iterator;
     533    test::UnweightedDataIterator<boost::forward_traversal_tag>
     534      unweighted_mutable_iterator;
     535
     536    test::WeightedConstDataIterator<boost::forward_traversal_tag>
     537      weighted_const_iterator;
     538    test::WeightedDataIterator<boost::forward_traversal_tag>
     539      weighted_mutable_iterator;
     540
     541    zscore(unweighted_const_iterator, unweighted_const_iterator,
     542           unweighted_mutable_iterator);
     543    zscore(unweighted_const_iterator, unweighted_const_iterator,
     544           weighted_mutable_iterator);
     545    zscore(weighted_const_iterator, weighted_const_iterator,
     546           unweighted_mutable_iterator);
     547    zscore(weighted_const_iterator, weighted_const_iterator,
     548           weighted_mutable_iterator);
     549  }
     550}
  • trunk/yat/normalizer/Centralizer.h

    r3330 r3541  
    2727
    2828#include "yat/statistics/Average.h"
     29#include "yat/utility/concept_check.h"
    2930#include "yat/utility/DataIterator.h"
    3031#include "yat/utility/iterator_traits.h"
     
    107108                    OutputIterator result) const
    108109    {
    109       BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<InputIterator>));
     110      BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<InputIterator>));
     111      BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<OutputIterator>));
     112      BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<OutputIterator>));
     113
    110114      // we need to traverse the input range once in call to func_ and
    111115      // one in call to std::transform, so single pass iterator will
     
    131135    {
    132136      using boost_concepts::SinglePassIterator;
    133       using boost_concepts::ReadableIterator;
    134137      using boost_concepts::WritableIterator;
    135138      BOOST_CONCEPT_ASSERT((SinglePassIterator<OutputIterator>));
    136       BOOST_CONCEPT_ASSERT((ReadableIterator<OutputIterator>));
    137139      BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator, double>));
    138140
     
    143145    {
    144146      using boost_concepts::ForwardTraversal;
    145       using boost_concepts::ReadableIterator;
    146147      using boost_concepts::WritableIterator;
    147148      BOOST_CONCEPT_ASSERT((ForwardTraversal<OutputIterator>));
    148       BOOST_CONCEPT_ASSERT((ReadableIterator<OutputIterator>));
    149149      BOOST_CONCEPT_ASSERT((WritableIterator<OutputIterator
    150150                            , utility::DataWeight>));
  • trunk/yat/normalizer/Zscore.h

    r2992 r3541  
    2929#include "yat/statistics/AveragerWeighted.h"
    3030
     31#include "yat/utility/concept_check.h"
    3132#include "yat/utility/iterator_traits.h"
    3233
     
    4546     mean and unity variance.
    4647
     48       Type Requirements:
     49       - \c InputIterator is \ref concept_data_iterator
     50       - \c InputIterator is \forward_traversal_iterator
     51       - \c OutputIterator is \writable_iterator
     52       - \c OutputIterator is \forward_traversal_iterator
     53
    4754     \since New in yat 0.5
    4855   */
     
    6067       same. \see std::transform
    6168     */
    62     template<class ForwardIter1, class ForwardIter2>
    63     void operator()(ForwardIter1 first, ForwardIter1 last,
    64                     ForwardIter2 result) const
     69    template<class InputIterator, class OutputIterator>
     70    void operator()(InputIterator first, InputIterator last,
     71                    OutputIterator result) const
    6572    {
    66       typename utility::weighted_if_any2<ForwardIter1, ForwardIter2>::type tag;
     73      BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<InputIterator>));
     74      BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<OutputIterator>));
     75
     76      // needed for weighted_if_any2
     77      typename utility::weighted_if_any2<InputIterator, OutputIterator>::type tag;
    6778      normalize(first, last, result, tag);
    6879    }
     
    7485                   utility::unweighted_iterator_tag tag) const
    7586    {
    76       // we require 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>));
     87      // we need to traverse the input range once in calculating m
     88      // (and std) and a second time when assigning new values, so
     89      // single pass iterator will not suffice.
     90      BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<ForwardIterator>));
     91
     92      BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<OutputIterator>));
     93
    8094      statistics::Averager a;
    8195      add(a, first, last);
     
    89103    }
    90104
    91     template<class ForwardIter1, class ForwardIter2>
    92     void normalize(ForwardIter1 first, ForwardIter1 last, ForwardIter2 result,
     105    template<class ForwardIterator, class OutputIterator>
     106    void normalize(ForwardIterator first, ForwardIterator last,
     107                   OutputIterator result,
    93108                   utility::weighted_iterator_tag tag) const
    94109    {
    95       // we require 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>));
     110      // we need to traverse the input range once in calculating m
     111      // (and std) and a second time when assigning new values, so
     112      // single pass iterator will not suffice.
     113      BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<ForwardIterator>));
     114
     115      BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<OutputIterator>));
     116      // we traverse output range twice
     117      BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<OutputIterator>));
    99118      detail::copy_weight_if_weighted(first, last, result);
    100119      statistics::AveragerWeighted a;
     
    102121      double m = a.mean();
    103122      double std = a.std();
    104       utility::iterator_traits<ForwardIter1> in_trait;
    105       utility::iterator_traits<ForwardIter2> out_trait;
     123      utility::iterator_traits<ForwardIterator> in_trait;
     124      utility::iterator_traits<OutputIterator> out_trait;
    106125      while (first!=last) {
    107126        out_trait.data(result) = (in_trait.data(first) - m) / std;
  • trunk/yat/normalizer/utility.h

    r2155 r3541  
    11#ifndef _theplu_yat_normalizer_utility_
    2 #define _theplu_yat_normalizer_utility_ 
     2#define _theplu_yat_normalizer_utility_
    33
    44// $Id$
     
    2323*/
    2424
     25#include "yat/utility/concept_check.h"
    2526#include "yat/utility/iterator_traits.h"
    2627#include "yat/utility/WeightIterator.h"
     28
     29#include <boost/concept_check.hpp>
    2730
    2831#include <algorithm>
     
    6063                               OutputIterator result)
    6164  {
     65    BOOST_CONCEPT_ASSERT((utility::DataIteratorConcept<OutputIterator>));
    6266    typename utility::weighted_iterator_traits<OutputIterator>::type tag;
    6367    copy_weight_if_weighted(first, last, result, tag);
Note: See TracChangeset for help on using the changeset viewer.