Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72826 - in trunk: boost/random boost/random/detail libs/random/test
From: steven_at_[hidden]
Date: 2011-06-30 18:27:54


Author: steven_watanabe
Date: 2011-06-30 18:27:53 EDT (Thu, 30 Jun 2011)
New Revision: 72826
URL: http://svn.boost.org/trac/boost/changeset/72826

Log:
Replace the precision() member for floating point generators with a traits class. This function was intended to be an implementation detail, but user defined generators had to implement it.
Added:
   trunk/boost/random/detail/generator_bits.hpp (contents, props changed)
Text files modified:
   trunk/boost/random/detail/seed_impl.hpp | 3 ++-
   trunk/boost/random/detail/uniform_int_float.hpp | 5 ++++-
   trunk/boost/random/discard_block.hpp | 27 +++++++++++++++++----------
   trunk/boost/random/generate_canonical.hpp | 3 ++-
   trunk/boost/random/lagged_fibonacci.hpp | 29 +++++++++++++++++++----------
   trunk/boost/random/subtract_with_carry.hpp | 27 +++++++++++++++++----------
   trunk/libs/random/test/concepts.hpp | 11 -----------
   7 files changed, 61 insertions(+), 44 deletions(-)

Added: trunk/boost/random/detail/generator_bits.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/random/detail/generator_bits.hpp 2011-06-30 18:27:53 EDT (Thu, 30 Jun 2011)
@@ -0,0 +1,36 @@
+/* boost random/detail/generator_bits.hpp header file
+ *
+ * Copyright Steven Watanabe 2011
+ * Distributed under the Boost Software License, Version 1.0. (See
+ * accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org for most recent version including documentation.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
+#define BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP
+
+#include <boost/limits.hpp>
+
+namespace boost {
+namespace random {
+namespace detail {
+
+// This is a temporary measure that retains backwards
+// compatibility.
+template<class URNG>
+struct generator_bits {
+ static std::size_t value() {
+ return std::numeric_limits<typename URNG::result_type>::digits;
+ }
+};
+
+} // namespace detail
+} // namespace random
+} // namespace boost
+
+#endif // BOOST_RANDOM_DETAIL_GENERATOR_BITS_HPP

Modified: trunk/boost/random/detail/seed_impl.hpp
==============================================================================
--- trunk/boost/random/detail/seed_impl.hpp (original)
+++ trunk/boost/random/detail/seed_impl.hpp 2011-06-30 18:27:53 EDT (Thu, 30 Jun 2011)
@@ -27,6 +27,7 @@
 #include <boost/random/detail/const_mod.hpp>
 #include <boost/random/detail/integer_log2.hpp>
 #include <boost/random/detail/signed_unsigned_tools.hpp>
+#include <boost/random/detail/generator_bits.hpp>
 
 #include <boost/random/detail/disable_warnings.hpp>
 
@@ -87,7 +88,7 @@
 {
     using std::fmod;
     typedef typename Engine::result_type RealType;
- const int Bits = Engine::precision();
+ const int Bits = detail::generator_bits<Engine>::value();
     int remaining_bits = 0;
     boost::uint_least32_t saved_bits = 0;
     RealType multiplier = pow2<RealType>( Bits);

Modified: trunk/boost/random/detail/uniform_int_float.hpp
==============================================================================
--- trunk/boost/random/detail/uniform_int_float.hpp (original)
+++ trunk/boost/random/detail/uniform_int_float.hpp 2011-06-30 18:27:53 EDT (Thu, 30 Jun 2011)
@@ -19,6 +19,7 @@
 #include <boost/config.hpp>
 #include <boost/integer.hpp>
 #include <boost/random/detail/config.hpp>
+#include <boost/random/detail/generator_bits.hpp>
 
 #include <boost/random/detail/disable_warnings.hpp>
 
@@ -48,7 +49,9 @@
     static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
     {
         std::size_t digits = std::numeric_limits<result_type>::digits;
- if(URNG::precision() < digits) digits = URNG::precision();
+ if(detail::generator_bits<URNG>::value() < digits) {
+ digits = detail::generator_bits<URNG>::value();
+ }
         return (result_type(2) << (digits - 1)) - 1;
     }
     base_type& base() { return _rng; }

Modified: trunk/boost/random/discard_block.hpp
==============================================================================
--- trunk/boost/random/discard_block.hpp (original)
+++ trunk/boost/random/discard_block.hpp 2011-06-30 18:27:53 EDT (Thu, 30 Jun 2011)
@@ -144,16 +144,6 @@
     static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
     { return (base_type::max)(); }
 
- /**
- * INTERNAL ONLY
- * Returns the number of random bits.
- * This is not part of the standard, and I'm not sure that
- * it's the best solution, but something like this is needed
- * to implement generate_canonical. For now, mark it as
- * an implementation detail.
- */
- static std::size_t precision() { return base_type::precision(); }
-
 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
     /** Writes a \discard_block_engine to a @c std::ostream. */
     template<class CharT, class Traits>
@@ -226,6 +216,23 @@
 
 /// \endcond
 
+namespace detail {
+
+ template<class Engine>
+ struct generator_bits;
+
+ template<class URNG, std::size_t p, std::size_t r>
+ struct generator_bits<discard_block_engine<URNG, p, r> > {
+ static std::size_t value() { return generator_bits<URNG>::value(); }
+ };
+
+ template<class URNG, int p, int r>
+ struct generator_bits<discard_block<URNG, p, r> > {
+ static std::size_t value() { return generator_bits<URNG>::value(); }
+ };
+
+}
+
 } // namespace random
 
 } // namespace boost

Modified: trunk/boost/random/generate_canonical.hpp
==============================================================================
--- trunk/boost/random/generate_canonical.hpp (original)
+++ trunk/boost/random/generate_canonical.hpp 2011-06-30 18:27:53 EDT (Thu, 30 Jun 2011)
@@ -21,6 +21,7 @@
 #include <boost/type_traits/is_integral.hpp>
 #include <boost/math/special_functions.hpp>
 #include <boost/random/detail/signed_unsigned_tools.hpp>
+#include <boost/random/detail/generator_bits.hpp>
 
 namespace boost {
 namespace random {
@@ -56,7 +57,7 @@
     BOOST_ASSERT((g.max)() == 1);
     typedef typename URNG::result_type base_result;
     std::size_t digits = std::numeric_limits<RealType>::digits;
- std::size_t engine_bits = g.precision();
+ std::size_t engine_bits = detail::generator_bits<URNG>::value();
     std::size_t b = (std::min)(bits, digits);
     RealType R = pow(RealType(2), RealType(engine_bits));
     RealType mult = R;

Modified: trunk/boost/random/lagged_fibonacci.hpp
==============================================================================
--- trunk/boost/random/lagged_fibonacci.hpp (original)
+++ trunk/boost/random/lagged_fibonacci.hpp 2011-06-30 18:27:53 EDT (Thu, 30 Jun 2011)
@@ -324,16 +324,6 @@
     /** Returns the upper bound of the generators outputs. */
     static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () { return result_type(1); }
 
- /**
- * INTERNAL ONLY
- * Returns the number of random bits.
- * This is not part of the standard, and I'm not sure that
- * it's the best solution, but something like this is needed
- * to implement generate_canonical. For now, mark it as
- * an implementation detail.
- */
- static std::size_t precision() { return w; }
-
     /** Returns the next value of the generator. */
     result_type operator()()
     {
@@ -466,6 +456,25 @@
 
 /// \endcond
 
+namespace detail {
+
+template<class Engine>
+struct generator_bits;
+
+template<class RealType, int w, unsigned int p, unsigned int q>
+struct generator_bits<lagged_fibonacci_01_engine<RealType, w, p, q> >
+{
+ static std::size_t value() { return w; }
+};
+
+template<class RealType, int w, unsigned int p, unsigned int q>
+struct generator_bits<lagged_fibonacci_01<RealType, w, p, q> >
+{
+ static std::size_t value() { return w; }
+};
+
+}
+
 #ifdef BOOST_RANDOM_DOXYGEN
 namespace detail {
 /**

Modified: trunk/boost/random/subtract_with_carry.hpp
==============================================================================
--- trunk/boost/random/subtract_with_carry.hpp (original)
+++ trunk/boost/random/subtract_with_carry.hpp 2011-06-30 18:27:53 EDT (Thu, 30 Jun 2011)
@@ -427,16 +427,6 @@
     static result_type max BOOST_PREVENT_MACRO_SUBSTITUTION ()
     { return result_type(1); }
 
- /**
- * INTERNAL ONLY
- * Returns the number of random bits.
- * This is not part of the standard, and I'm not sure that
- * it's the best solution, but something like this is needed
- * to implement generate_canonical. For now, mark it as
- * an implementation detail.
- */
- static std::size_t precision() { return w; }
-
     /** Returns the next value of the generator. */
     result_type operator()()
     {
@@ -600,6 +590,23 @@
 
 /// \endcond
 
+namespace detail {
+
+template<class Engine>
+struct generator_bits;
+
+template<class RealType, std::size_t w, std::size_t s, std::size_t r>
+struct generator_bits<subtract_with_carry_01_engine<RealType, w, s, r> > {
+ static std::size_t value() { return w; }
+};
+
+template<class RealType, int w, unsigned s, unsigned r, int v>
+struct generator_bits<subtract_with_carry_01<RealType, w, s, r, v> > {
+ static std::size_t value() { return w; }
+};
+
+}
+
 } // namespace random
 } // namespace boost
 

Modified: trunk/libs/random/test/concepts.hpp
==============================================================================
--- trunk/libs/random/test/concepts.hpp (original)
+++ trunk/libs/random/test/concepts.hpp 2011-06-30 18:27:53 EDT (Thu, 30 Jun 2011)
@@ -130,8 +130,6 @@
         same_type((E::min)(), result_type());
         same_type((E::max)(), result_type());
 
- check_extra(boost::is_integral<result_type>());
-
         (void)E();
         (void)E(s);
         (void)E(q);
@@ -154,15 +152,6 @@
     seed_seq_archetype<> q;
     typename detail::seed_type<result_type>::type s;
     unsigned long long z;
-
- void check_extra(boost::mpl::true_ /*is_integral*/) {}
-
- void check_extra(boost::mpl::false_ /*is_integral*/)
- {
- // This is an undocumented extension, but we still need
- // to check for it.
- same_type(E::precision(), std::size_t(0));
- }
     
     input_iterator_archetype<boost::uint32_t> sb, se;
 };


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