Changeset 3543


Ignore:
Timestamp:
Dec 23, 2016, 8:04:15 AM (7 years ago)
Author:
Peter
Message:

refs #803. use boost iterator categories in normalizer::Spearman

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Suite.h

    r3539 r3543  
    732732
    733733
    734   // For convenience four classes that are typical data iterators for
    735   // combinations of const/mutable and weighted/unweighted. Traversal
     734  // For convenience to create data iterator. This class typedefs four
     735  // classes that can be conveniently constructed in tests
     736  // (const/mutable and weighted/unweighted. Traversal
    736737  // is expected to be one of:
    737   // boost::incrementable_traversal_tag
    738   // boost::single_pass_traversal_tag
     738  //// boost::incrementable_traversal_tag (problematic with unweighted)
     739  // boost::single_pass_traversal_tag (problematic with unweighted)
    739740  // boost::forward_traversal_tag
    740741  // boost::bidirectional_traversal_tag
    741742  // boost::random_access_traversal_tag
    742   //
    743   // Note, is problematic to construct with
    744   // incrementable_traversal_tag or single_pass_traversal_tag
    745743  template<typename Traversal>
    746   class UnweightedConstDataIterator
    747     : public boost::iterator_archetype<
    748     double,
    749     boost::iterator_archetypes::readable_iterator_t,
    750     Traversal
    751     >
    752   {};
    753 
    754 
    755   template<typename Traversal>
    756   class UnweightedDataIterator
    757     : public boost::iterator_archetype<
    758     double,
    759     boost::iterator_archetypes::readable_writable_iterator_t,
    760     Traversal
    761     >
    762   {};
    763 
    764   template<typename Traversal>
    765   class WeightedConstDataIterator
    766     : public utility::WeightedIteratorArchetype<
    767     boost::iterator_archetypes::readable_iterator_t,
    768     Traversal>
    769   {};
    770 
    771   template<typename Traversal>
    772   class WeightedDataIterator
    773     : public utility::WeightedIteratorArchetype<
    774     boost::iterator_archetypes::readable_writable_iterator_t,
    775     Traversal>
    776   {};
    777 
    778 
     744  struct DataIterator
     745  {
     746    typedef boost::iterator_archetype<
     747      double,
     748      boost::iterator_archetypes::readable_iterator_t,
     749      Traversal
     750      > unweighted_const_iterator;
     751
     752    typedef boost::iterator_archetype<
     753      double,
     754      boost::iterator_archetypes::readable_writable_iterator_t,
     755      Traversal
     756      > unweighted_iterator;
     757
     758
     759    typedef utility::WeightedIteratorArchetype<
     760      boost::iterator_archetypes::readable_iterator_t, Traversal
     761      >
     762    weighted_const_iterator;
     763
     764    typedef utility::WeightedIteratorArchetype<
     765      boost::iterator_archetypes::readable_writable_iterator_t,
     766      Traversal
     767      >
     768    weighted_iterator;
     769  };
    779770}}}
    780771
  • trunk/test/normalization.cc

    r3541 r3543  
    107107  // compile test should not be run
    108108  if (false) {
    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;
     109    typedef test::DataIterator<boost::forward_traversal_tag> trait;
     110    trait::unweighted_const_iterator unweighted_const_iterator;
     111    trait::unweighted_iterator unweighted_mutable_iterator;
     112    trait::weighted_const_iterator weighted_const_iterator;
     113    trait::weighted_iterator weighted_mutable_iterator;
    118114
    119115    c(unweighted_const_iterator, unweighted_const_iterator,
     
    151147
    152148  if (false) { // do not run compile tests
    153     test::container2d_archetype<double> container2d; 
    154     test::mutable_container2d_archetype<double> mutable_container2d; 
     149    test::container2d_archetype<double> container2d;
     150    test::mutable_container2d_archetype<double> mutable_container2d;
    155151    qn(container2d, mutable_container2d);
    156152  }
     
    178174
    179175  // first column as target
    180   qQuantileNormalizer qqn(m.begin_column(0), m.end_column(0) ,9); 
     176  qQuantileNormalizer qqn(m.begin_column(0), m.end_column(0) ,9);
    181177  ColumnNormalizer<qQuantileNormalizer> cn(qqn);
    182178  utility::Matrix result(m.rows(),m.columns());
     
    187183  if (suite.add(result==m))
    188184    suite.err() << " ok.\n";
    189   else 
     185  else
    190186    suite.err() << " failed.\n";
    191187
     
    211207                             boost::forward_iterator_archetype<double>(),
    212208                             100);
    213     qqn3(boost::random_access_iterator_archetype<double>(), 
     209    qqn3(boost::random_access_iterator_archetype<double>(),
    214210         boost::random_access_iterator_archetype<double>(),
    215211         boost::mutable_random_access_iterator_archetype<double>());
     
    218214                             boost::forward_iterator_archetype<DataWeight>(),
    219215                             100);
    220     qqn4(boost::random_access_iterator_archetype<DataWeight>(), 
     216    qqn4(boost::random_access_iterator_archetype<DataWeight>(),
    221217         boost::random_access_iterator_archetype<DataWeight>(),
    222218         boost::mutable_random_access_iterator_archetype<DataWeight>());
    223     qqn4(boost::random_access_iterator_archetype<DataWeight>(), 
     219    qqn4(boost::random_access_iterator_archetype<DataWeight>(),
    224220         boost::random_access_iterator_archetype<DataWeight>(),
    225221         boost::mutable_random_access_iterator_archetype<double>());
     
    244240    source.push_back(source.size()*10);
    245241  std::vector<double> result(source.size());
    246  
     242
    247243  qQN(source.begin(), source.end(), result.begin());
    248  
     244
    249245  using utility::DataWeight;
    250246  suite.err() << "Testing with unweighted target and weighted source\n";
     
    269265  MWi+=5;
    270266  result_w2.erase(MWi);
    271   suite.add(suite.equal_range(utility::data_iterator(result_w.begin()), 
     267  suite.add(suite.equal_range(utility::data_iterator(result_w.begin()),
    272268                              utility::data_iterator(result_w.end()),
    273269                              utility::data_iterator(result_w2.begin())));
     
    285281  MWi+=5;
    286282  result_w3.erase(MWi);
    287   suite.add(suite.equal_range(utility::data_iterator(result_w3.begin()), 
     283  suite.add(suite.equal_range(utility::data_iterator(result_w3.begin()),
    288284                              utility::data_iterator(result_w3.end()),
    289285                              utility::data_iterator(result_w2.begin())));
    290  
     286
    291287}
    292288
     
    320316  using namespace normalizer;
    321317  suite.err() << "Testing RowNormalizer\n";
    322  
     318
    323319  utility::Matrix m(2,3);
    324320  m(0,0) = 0;
     
    335331  suite.equal_range(m.begin(), m.end(), m2.begin());
    336332  if (false) { // do not run compile tests
    337     test::container2d_archetype<double> container2d; 
    338     test::mutable_container2d_archetype<double> mutable_container2d; 
     333    test::container2d_archetype<double> container2d;
     334    test::mutable_container2d_archetype<double> mutable_container2d;
    339335    rn(container2d, mutable_container2d);
    340336  }
     
    363359  suite.add(suite.equal_range(vec.begin(), vec.end(), correct.begin()));
    364360  test_spearman_weighted(suite);
     361
    365362}
    366363
     
    445442    m(0,i).weight() *= 2;
    446443    correct_w[i] *= 2;
    447   }   
     444  }
    448445  spearman(m.begin_row(0), m.end_row(0), res.begin_row(0));
    449446  suite.add(suite.equal_range(data_iterator(res.begin_row(0)),
     
    454451                               correct_w.begin()));
    455452
    456  
     453
    457454  suite.err() << "Testing case with a zero weight\n";
    458455  m(0,1).data() = std::numeric_limits<double>::quiet_NaN();
    459456  m(0,1).weight() = 0.0;
    460457  spearman(m.begin_row(0), m.end_row(0), res.begin_row(0));
    461   suite.add(suite.equal(res(0,0).data(), 0.5/3)); 
    462   suite.add(suite.equal(res(0,2).data(), 2.5/3)); 
    463   suite.add(suite.equal(res(0,3).data(), 1.5/3)); 
     458  suite.add(suite.equal(res(0,0).data(), 0.5/3));
     459  suite.add(suite.equal(res(0,2).data(), 2.5/3));
     460  suite.add(suite.equal(res(0,3).data(), 1.5/3));
    464461
    465462  suite.err() << "Testing case with ties\n";
    466463  m(0,0).data() = m(0,2).data();
    467464  spearman(m.begin_row(0), m.end_row(0), res.begin_row(0));
    468   suite.add(suite.equal(res(0,0).data(), 2.0/3)); 
    469   suite.add(suite.equal(res(0,2).data(), 2.0/3)); 
    470   suite.add(suite.equal(res(0,3).data(), 0.5/3)); 
    471   // compile test should not be run
     465  suite.add(suite.equal(res(0,0).data(), 2.0/3));
     466  suite.add(suite.equal(res(0,2).data(), 2.0/3));
     467  suite.add(suite.equal(res(0,3).data(), 0.5/3));
     468  // do not run compile test
    472469  if (false) {
    473     using boost::iterator_archetype;
    474     iterator_archetype<double,
    475                        boost::iterator_archetypes::readable_iterator_t,
    476                        boost::random_access_traversal_tag>
    477       readable_iterator;
    478 
    479     iterator_archetype<double,
    480                        boost::iterator_archetypes::readable_writable_iterator_t,
    481                        boost::random_access_traversal_tag>
    482       writable_iterator;
    483 
    484     // We have to use lvalue here because otherwise proxy classes
    485     // provided by boost kick in and they do not provide the needed
    486     // data() and weight() functions that e.g. DataWeightProxy does.
    487     iterator_archetype<utility::DataWeight,
    488                        boost::iterator_archetypes::readable_lvalue_iterator_t,
    489                        boost::random_access_traversal_tag>
    490       weighted_readable_iterator;
    491 
    492     iterator_archetype<utility::DataWeight,
    493                        boost::iterator_archetypes::writable_lvalue_iterator_t,
    494                        boost::random_access_traversal_tag>
    495       weighted_writable_iterator;
    496 
    497     spearman(readable_iterator, readable_iterator, writable_iterator);
    498     spearman(readable_iterator, readable_iterator, weighted_writable_iterator);
    499     spearman(weighted_readable_iterator, weighted_readable_iterator,
    500              writable_iterator);
    501     spearman(weighted_readable_iterator, weighted_readable_iterator,
    502              weighted_writable_iterator);
    503   }
    504 
    505 }
     470    typedef test::DataIterator<boost::random_access_traversal_tag> trait;
     471    trait::unweighted_const_iterator unweighted_const_iterator;
     472    trait::unweighted_iterator unweighted_mutable_iterator;
     473    trait::weighted_const_iterator weighted_const_iterator;
     474    trait::weighted_iterator weighted_mutable_iterator;
     475
     476    spearman(unweighted_const_iterator, unweighted_const_iterator,
     477             unweighted_mutable_iterator);
     478    spearman(unweighted_const_iterator, unweighted_const_iterator,
     479             weighted_mutable_iterator);
     480    spearman(weighted_const_iterator, weighted_const_iterator,
     481             unweighted_mutable_iterator);
     482    spearman(weighted_const_iterator, weighted_const_iterator,
     483             weighted_mutable_iterator);
     484  }
     485}
     486
    506487
    507488void test_z_score(test::Suite& suite)
     
    529510  // compile test should not be run
    530511  if (false) {
    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;
     512    typedef test::DataIterator<boost::forward_traversal_tag> trait;
     513    trait::unweighted_const_iterator unweighted_const_iterator;
     514    trait::unweighted_iterator unweighted_mutable_iterator;
     515    trait::weighted_const_iterator weighted_const_iterator;
     516    trait::weighted_iterator weighted_mutable_iterator;
    540517
    541518    zscore(unweighted_const_iterator, unweighted_const_iterator,
  • trunk/test/weighted_iterator_archetype.cc

    r3534 r3543  
    137137
    138138  test_interoperability(i, ci, traversal);
     139
     140}
     141
     142
     143// test test::DataIterator
     144template<typename TraversalCategory>
     145void test2(void)
     146{
     147  TraversalCategory traversal;
     148  typedef test::DataIterator<TraversalCategory> trait;
     149  typename trait::unweighted_const_iterator const_iterator;
     150  test_const_access(const_iterator);
     151  test_traversal(const_iterator, traversal);
     152  typename trait::unweighted_iterator iterator;
     153  test_access(iterator);
     154  test_traversal(iterator, traversal);
     155
     156  typename trait::weighted_const_iterator weighted_const_iterator;
     157  test_const_access(weighted_const_iterator);
     158  test_traversal(weighted_const_iterator, traversal);
     159  typename trait::weighted_iterator weighted_iterator;
     160  test_access(weighted_iterator);
     161  test_traversal(weighted_iterator, traversal);
    139162}
    140163
     
    149172    test1<boost::bidirectional_traversal_tag>();
    150173    test1<boost::random_access_traversal_tag>();
     174
     175    test2<boost::forward_traversal_tag>();
     176    test2<boost::bidirectional_traversal_tag>();
     177    test2<boost::random_access_traversal_tag>();
    151178  }
    152179
  • trunk/yat/normalizer/Spearman.h

    r3330 r3543  
    3535
    3636#include <boost/concept_check.hpp>
     37#include <boost/iterator/iterator_concepts.hpp>
    3738
    3839#include <algorithm>
     
    6869
    6970       Type Requirements:
    70        - \c RandomAccessIter1 is \readable_iterator
    7171       - \c RandomAccessIter1 is \random_access_traversal_iterator
    7272       - \c RandomAccessIter1 is \ref concept_data_iterator
    73        - \c RandomAccessIter2 is \readable_iterator
    7473       - \c RandomAccessIter2 is \writable_iterator
    7574       - \c RandomAccessIter2 is \random_access_traversal_iterator
     
    8079                    RandomAccessIter2 result) const
    8180    {
    82       using boost_concepts::ReadableIterator;
    83       BOOST_CONCEPT_ASSERT((ReadableIterator<RandomAccessIter1>));
    8481      using boost_concepts::RandomAccessTraversal;
    8582      BOOST_CONCEPT_ASSERT((RandomAccessTraversal<RandomAccessIter1>));
     
    8784      BOOST_CONCEPT_ASSERT((DataIteratorConcept<RandomAccessIter1>));
    8885
    89       BOOST_CONCEPT_ASSERT((ReadableIterator<RandomAccessIter2>));
    9086      using boost_concepts::WritableIterator;
    9187      BOOST_CONCEPT_ASSERT((WritableIterator<RandomAccessIter2>));
Note: See TracChangeset for help on using the changeset viewer.