Changeset 2148


Ignore:
Timestamp:
Jan 17, 2010, 4:16:27 AM (12 years ago)
Author:
Peter
Message:

fixes #582 and refs #583

Claify that normalizer::Spearman requires random_access_iterator as
input and Gauss inherits the requirement. Added compile test and
concept check for Gauss.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/normalization_test.cc

    r2147 r2148  
    335335  gauss(vec.begin(), vec.end(), vec.begin());
    336336  suite.add(suite.equal(vec.front(), -vec.back()));
    337 
     337  // compile test should not be run
     338  if (false) {
     339    gauss(boost::random_access_iterator_archetype<double>(),
     340          boost::random_access_iterator_archetype<double>(),
     341          boost::mutable_random_access_iterator_archetype<double>());
     342  }
    338343}
    339344
  • trunk/yat/normalizer/Gauss.h

    r2119 r2148  
    2727#include "yat/utility/iterator_traits.h"
    2828
     29#include <boost/concept_check.hpp>
     30
    2931#include <gsl/gsl_cdf.h>
     32
     33#include <iterator>
    3034
    3135namespace theplu {
     
    5357       same.
    5458
     59       Type requirements:
     60       - ForwardIterator must be a \forward_iterator and a \ref
     61       concept_data_iterator.
     62       - RandomAccessIterator must be a mutable \random_access_iterator
     63         and a \ref concept_data_iterator.
     64
    5565       \see gsl_cdf_ugaussian_Pinv
    5666     */
    57     template<typename ForwardIterator, typename RandomAccessIterator>
    58     void operator()(ForwardIterator first, ForwardIterator last,
    59                     RandomAccessIterator result) const
     67    template<typename RandomAccessIter1, typename RandomAccessIter2>
     68    void operator()(RandomAccessIter1 first, RandomAccessIter1 last,
     69                    RandomAccessIter2 result) const
    6070    {
     71      boost::function_requires<boost::RandomAccessIterator<RandomAccessIter1> >();
     72      boost::function_requires<boost::Mutable_RandomAccessIterator<RandomAccessIter2> >();
    6173      Spearman spearman;
    6274      spearman(first, last, result);
    63       RandomAccessIterator end = result + distance(first, last);
    64       utility::iterator_traits<RandomAccessIterator> trait;
     75      RandomAccessIter2 end = result + std::distance(first, last);
     76      utility::iterator_traits<RandomAccessIter2> trait;
    6577      while (result != end) {
    6678        trait.data(result) = gsl_cdf_ugaussian_Pinv(trait.data(result));
  • trunk/yat/normalizer/Spearman.h

    r2119 r2148  
    7070  private:
    7171    // unweighted version
    72     template<typename ForwardIterator, typename RandomAccessIterator>
    73     void normalize(ForwardIterator first, ForwardIterator last,
    74                    RandomAccessIterator result,
     72    template<typename RandomAccessIter1, typename RandomAccessIter2>
     73    void normalize(RandomAccessIter1 first, RandomAccessIter1 last,
     74                   RandomAccessIter2 result,
    7575                   utility::unweighted_iterator_tag) const
    7676    {
     
    9191
    9292    // weighted version
    93     template<typename ForwardIterator, typename RandomAccessIterator>
    94     void normalize(ForwardIterator first, ForwardIterator last,
    95                    RandomAccessIterator result,
     93    template<typename RandomAccessIter1, typename RandomAccessIter2>
     94    void normalize(RandomAccessIter1 first, RandomAccessIter1 last,
     95                   RandomAccessIter2 result,
    9696                   utility::weighted_iterator_tag) const
    9797    {
     
    100100                utility::weight_iterator(result));
    101101      // set values with w=0 to 0 to avoid problems with NaNs
    102       utility::iterator_traits<ForwardIterator> trait;
    103       for (ForwardIterator i=first; i!=last; ++i)
     102      utility::iterator_traits<RandomAccessIter1> trait;
     103      for (RandomAccessIter1 i=first; i!=last; ++i)
    104104        if (trait.weight(i)==0)
    105105          trait.data(i)=0.0;
     
    108108      utility::sort_index(utility::data_iterator(first),
    109109                          utility::data_iterator(last), perm);
    110       utility::iterator_traits<RandomAccessIterator> rtrait;
     110      utility::iterator_traits<RandomAccessIter2> rtrait;
    111111
    112112      double sum_w=0;
Note: See TracChangeset for help on using the changeset viewer.