Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r68070 - in trunk: boost/random boost/random/detail libs/random/test
From: steven_at_[hidden]
Date: 2011-01-12 14:53:43


Author: steven_watanabe
Date: 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
New Revision: 68070
URL: http://svn.boost.org/trac/boost/changeset/68070

Log:
Concept test for distributions.
Text files modified:
   trunk/boost/random/detail/vector_io.hpp | 12 +++---
   trunk/boost/random/discrete_distribution.hpp | 3 +
   trunk/boost/random/extreme_value_distribution.hpp | 10 ++++-
   trunk/boost/random/fisher_f_distribution.hpp | 11 ++++-
   trunk/boost/random/normal_distribution.hpp | 4 +-
   trunk/boost/random/piecewise_constant_distribution.hpp | 3 +
   trunk/boost/random/student_t_distribution.hpp | 4 +-
   trunk/boost/random/weibull_distribution.hpp | 10 ++++-
   trunk/libs/random/test/concepts.hpp | 73 ++++++++++++++++++++++++++++++++++-----
   trunk/libs/random/test/test_discrete_distribution.cpp | 5 ++
   trunk/libs/random/test/test_distribution.ipp | 4 ++
   trunk/libs/random/test/test_piecewise_constant_distribution.cpp | 5 ++
   trunk/libs/random/test/test_piecewise_linear_distribution.cpp | 5 ++
   13 files changed, 122 insertions(+), 27 deletions(-)

Modified: trunk/boost/random/detail/vector_io.hpp
==============================================================================
--- trunk/boost/random/detail/vector_io.hpp (original)
+++ trunk/boost/random/detail/vector_io.hpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -28,26 +28,26 @@
     typename std::vector<T>::const_iterator
         iter = vec.begin(),
         end = vec.end();
- os << '[';
+ os << os.widen('[');
     if(iter != end) {
         os << *iter;
         ++iter;
         for(; iter != end; ++iter)
         {
- os << ' ' << *iter;
+ os << os.widen(' ') << *iter;
         }
     }
- os << ']';
+ os << os.widen(']');
 }
 
 template<class CharT, class Traits, class T>
 void read_vector(std::basic_istream<CharT, Traits>& is, std::vector<T>& vec)
 {
- char ch;
+ CharT ch;
     if(!(is >> ch)) {
         return;
     }
- if(ch != '[') {
+ if(ch != is.widen('[')) {
         is.putback(ch);
         is.setstate(std::ios_base::failbit);
         return;
@@ -61,7 +61,7 @@
         if(!(is >> ch)) {
             return;
         }
- if(ch != ']') {
+ if(ch != is.widen(']')) {
             is.putback(ch);
             is.setstate(std::ios_base::failbit);
         }

Modified: trunk/boost/random/discrete_distribution.hpp
==============================================================================
--- trunk/boost/random/discrete_distribution.hpp (original)
+++ trunk/boost/random/discrete_distribution.hpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -49,6 +49,9 @@
 
     class param_type {
     public:
+
+ typedef discrete_distribution distribution_type;
+
         /**
          * Constructs a @c param_type object, representing a distribution
          * with \f$p(0) = 1\f$ and \f$p(k|k>0) = 0\f$.

Modified: trunk/boost/random/extreme_value_distribution.hpp
==============================================================================
--- trunk/boost/random/extreme_value_distribution.hpp (original)
+++ trunk/boost/random/extreme_value_distribution.hpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -115,10 +115,10 @@
     RealType b() const { return _b; }
 
     /** Returns the smallest value that the distribution can produce. */
- RealType min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const
     { return -std::numeric_limits<RealType>::infinity(); }
     /** Returns the largest value that the distribution can produce. */
- RealType max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const
     { return std::numeric_limits<RealType>::infinity(); }
 
     /** Returns the parameters of the distribution. */
@@ -130,6 +130,12 @@
         _b = parm.b();
     }
 
+ /**
+ * Effects: Subsequent uses of the distribution do not depend
+ * on values produced by any engine prior to invoking reset.
+ */
+ void reset() { }
+
     /** Writes an @c extreme_value_distribution to a @c std::ostream. */
     BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, extreme_value_distribution, wd)
     {

Modified: trunk/boost/random/fisher_f_distribution.hpp
==============================================================================
--- trunk/boost/random/fisher_f_distribution.hpp (original)
+++ trunk/boost/random/fisher_f_distribution.hpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -119,10 +119,9 @@
     RealType n() const { return _impl_n.n(); }
 
     /** Returns the smallest value that the distribution can produce. */
- RealType min BOOST_PREVENT_MACRO_SUBSTITUTION ()
- { return 0; }
+ RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
     /** Returns the largest value that the distribution can produce. */
- RealType max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const
     { return std::numeric_limits<RealType>::infinity(); }
 
     /** Returns the parameters of the distribution. */
@@ -137,6 +136,12 @@
         _impl_n.param(n_param);
     }
 
+ /**
+ * Effects: Subsequent uses of the distribution do not depend
+ * on values produced by any engine prior to invoking reset.
+ */
+ void reset() { }
+
     /** Writes an @c fisher_f_distribution to a @c std::ostream. */
     BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, fisher_f_distribution, fd)
     {

Modified: trunk/boost/random/normal_distribution.hpp
==============================================================================
--- trunk/boost/random/normal_distribution.hpp (original)
+++ trunk/boost/random/normal_distribution.hpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -118,10 +118,10 @@
     RealType sigma() const { return _sigma; }
 
     /** Returns the smallest value that the distribution can produce. */
- RealType min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const
     { return -std::numeric_limits<RealType>::infinity(); }
     /** Returns the largest value that the distribution can produce. */
- RealType max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const
     { return std::numeric_limits<RealType>::infinity(); }
 
     /** Returns the parameters of the distribution. */

Modified: trunk/boost/random/piecewise_constant_distribution.hpp
==============================================================================
--- trunk/boost/random/piecewise_constant_distribution.hpp (original)
+++ trunk/boost/random/piecewise_constant_distribution.hpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -43,6 +43,9 @@
 
     class param_type {
     public:
+
+ typedef piecewise_constant_distribution distribution_type;
+
         /**
          * Constructs a @c param_type object, representing a distribution
          * that produces values uniformly distributed in the range [0, 1).

Modified: trunk/boost/random/student_t_distribution.hpp
==============================================================================
--- trunk/boost/random/student_t_distribution.hpp (original)
+++ trunk/boost/random/student_t_distribution.hpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -113,10 +113,10 @@
     RealType n() const { return _chi_squared.n(); }
 
     /** Returns the smallest value that the distribution can produce. */
- RealType min BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const
     { return -std::numeric_limits<RealType>::infinity(); }
     /** Returns the largest value that the distribution can produce. */
- RealType max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const
     { return std::numeric_limits<RealType>::infinity(); }
 
     /** Returns the parameters of the distribution. */

Modified: trunk/boost/random/weibull_distribution.hpp
==============================================================================
--- trunk/boost/random/weibull_distribution.hpp (original)
+++ trunk/boost/random/weibull_distribution.hpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -116,9 +116,9 @@
     RealType b() const { return _b; }
 
     /** Returns the smallest value that the distribution can produce. */
- RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () { return 0; }
+ RealType min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return 0; }
     /** Returns the largest value that the distribution can produce. */
- RealType max BOOST_PREVENT_MACRO_SUBSTITUTION ()
+ RealType max BOOST_PREVENT_MACRO_SUBSTITUTION () const
     { return std::numeric_limits<RealType>::infinity(); }
 
     /** Returns the parameters of the distribution. */
@@ -130,6 +130,12 @@
         _b = parm.b();
     }
 
+ /**
+ * Effects: Subsequent uses of the distribution do not depend
+ * on values produced by any engine prior to invoking reset.
+ */
+ void reset() { }
+
     /** Writes a @c weibull_distribution to a @c std::ostream. */
     BOOST_RANDOM_DETAIL_OSTREAM_OPERATOR(os, weibull_distribution, wd)
     {

Modified: trunk/libs/random/test/concepts.hpp
==============================================================================
--- trunk/libs/random/test/concepts.hpp (original)
+++ trunk/libs/random/test/concepts.hpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -14,6 +14,7 @@
 #include <boost/concept/requires.hpp>
 #include <boost/mpl/assert.hpp>
 #include <boost/type_traits/is_arithmetic.hpp>
+#include <boost/type_traits/is_same.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/static_assert.hpp>
 #include <istream>
@@ -34,7 +35,16 @@
         ((Mutable_RandomAccessIterator<Iter>))
         ((UnsignedInteger<typename Mutable_RandomAccessIterator<Iter>::value_type>)),
     (void))
- generate(Iter, Iter);
+ generate(Iter, Iter) {}
+};
+
+template<class R = unsigned, class Base = null_archetype<> >
+struct uniform_random_number_generator_archetype : Base
+{
+ typedef R result_type;
+ static R min() { return 0; }
+ static R max() { return 0; }
+ R operator()() { return 0; }
 };
 
 template<class SSeq>
@@ -71,6 +81,10 @@
     std::wostream wos;
 };
 
+// Type deduction will fail unless the arguments have the same type.
+template <typename T>
+void same_type(T const&, T const&) {}
+
 template <class E>
 struct RandomNumberEngine :
     DefaultConstructible<E>,
@@ -79,7 +93,7 @@
     EqualityComparable<E>,
     Streamable<E>
 {
- public:
+public:
     typedef typename E::result_type result_type;
 
     // relaxed from the standard
@@ -97,9 +111,9 @@
         same_type(E::min(), result_type());
         same_type(E::max(), result_type());
 
- E();
- E(s);
- E(q);
+ (void)E();
+ (void)E(s);
+ (void)E(q);
 
         e.seed();
         e.seed(s);
@@ -108,11 +122,11 @@
         e.discard(z);
 
         // extension
- E(sb, se);
+ (void)E(sb, se);
         e.seed(sb, se);
     }
     
- private:
+private:
     E e;
     E v;
     const E x;
@@ -121,10 +135,49 @@
     unsigned long long z;
     
     input_iterator_archetype<boost::uint32_t> sb, se;
+};
 
- // Type deduction will fail unless the arguments have the same type.
- template <typename T>
- void same_type(T const&, T const&) {}
+template<class D>
+struct RandomNumberDistribution :
+ DefaultConstructible<D>,
+ CopyConstructible<D>,
+ Assignable<D>,
+ EqualityComparable<D>,
+ Streamable<D>
+{
+public:
+ typedef typename D::result_type result_type;
+ typedef typename D::param_type param_type;
+ // backwards compatibility
+ typedef typename D::input_type input_type;
+
+ typedef param_type P;
+
+ BOOST_CONCEPT_ASSERT((DefaultConstructible<P>));
+ BOOST_CONCEPT_ASSERT((CopyConstructible<P>));
+ BOOST_CONCEPT_ASSERT((Assignable<P>));
+ BOOST_CONCEPT_ASSERT((EqualityComparable<P>));
+ BOOST_CONCEPT_ASSERT((Streamable<P>));
+
+ BOOST_MPL_ASSERT((boost::is_same<typename P::distribution_type, D>));
+
+ BOOST_CONCEPT_USAGE(RandomNumberDistribution)
+ {
+ (void)D(p);
+ d.reset();
+ same_type(x.param(), p);
+ d.param(p);
+ same_type(d(g), result_type());
+ same_type(d(g, p), result_type());
+ same_type(x.min(), result_type());
+ same_type(x.max(), result_type());
+ }
+
+private:
+ D d;
+ const D x;
+ const P p;
+ uniform_random_number_generator_archetype<> g;
 };
 
 }

Modified: trunk/libs/random/test/test_discrete_distribution.cpp
==============================================================================
--- trunk/libs/random/test/test_discrete_distribution.cpp (original)
+++ trunk/libs/random/test/test_discrete_distribution.cpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -14,10 +14,15 @@
 #include <boost/assign/list_of.hpp>
 #include <sstream>
 #include <vector>
+#include "concepts.hpp"
 
 #define BOOST_TEST_MAIN
 #include <boost/test/unit_test.hpp>
 
+using boost::random::test::RandomNumberDistribution;
+using boost::random::discrete_distribution;
+BOOST_CONCEPT_ASSERT((RandomNumberDistribution< discrete_distribution<> >));
+
 struct gen {
     double operator()(double arg) {
         if(arg < 100) return 100;

Modified: trunk/libs/random/test/test_distribution.ipp
==============================================================================
--- trunk/libs/random/test/test_distribution.ipp (original)
+++ trunk/libs/random/test/test_distribution.ipp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -11,10 +11,14 @@
 
 #include <boost/random/linear_congruential.hpp>
 #include <sstream>
+#include "concepts.hpp"
 
 #define BOOST_TEST_MAIN
 #include <boost/test/unit_test.hpp>
 
+using boost::random::test::RandomNumberDistribution;
+BOOST_CONCEPT_ASSERT((RandomNumberDistribution< BOOST_RANDOM_DISTRIBUTION >));
+
 BOOST_AUTO_TEST_CASE(test_constructors) {
     BOOST_RANDOM_DISTRIBUTION dist;
     BOOST_CHECK_EQUAL(dist.BOOST_RANDOM_ARG1(), BOOST_RANDOM_ARG1_DEFAULT);

Modified: trunk/libs/random/test/test_piecewise_constant_distribution.cpp
==============================================================================
--- trunk/libs/random/test/test_piecewise_constant_distribution.cpp (original)
+++ trunk/libs/random/test/test_piecewise_constant_distribution.cpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -14,10 +14,15 @@
 #include <boost/assign/list_of.hpp>
 #include <sstream>
 #include <vector>
+#include "concepts.hpp"
 
 #define BOOST_TEST_MAIN
 #include <boost/test/unit_test.hpp>
 
+using boost::random::test::RandomNumberDistribution;
+using boost::random::piecewise_constant_distribution;
+BOOST_CONCEPT_ASSERT((RandomNumberDistribution< piecewise_constant_distribution<> >));
+
 struct gen {
     double operator()(double arg) {
         if(arg < 100) return 100;

Modified: trunk/libs/random/test/test_piecewise_linear_distribution.cpp
==============================================================================
--- trunk/libs/random/test/test_piecewise_linear_distribution.cpp (original)
+++ trunk/libs/random/test/test_piecewise_linear_distribution.cpp 2011-01-12 14:53:31 EST (Wed, 12 Jan 2011)
@@ -14,10 +14,15 @@
 #include <boost/assign/list_of.hpp>
 #include <sstream>
 #include <vector>
+#include "concepts.hpp"
 
 #define BOOST_TEST_MAIN
 #include <boost/test/unit_test.hpp>
 
+using boost::random::test::RandomNumberDistribution;
+using boost::random::piecewise_linear_distribution;
+BOOST_CONCEPT_ASSERT((RandomNumberDistribution< piecewise_linear_distribution<> >));
+
 struct gen {
     double operator()(double arg) {
         if(arg < 97) return 100;


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk