Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64541 - in sandbox/SOC/2010/quasi_random: boost/random boost/random/detail libs/random/test
From: jvd_at_[hidden]
Date: 2010-08-02 11:33:02


Author: qrng
Date: 2010-08-02 11:32:58 EDT (Mon, 02 Aug 2010)
New Revision: 64541
URL: http://svn.boost.org/trac/boost/changeset/64541

Log:
Minor cosmetic fixes.

Text files modified:
   sandbox/SOC/2010/quasi_random/boost/random/detail/gray_coded_qrng_base.hpp | 35 +++++++++++++++++++++--------------
   sandbox/SOC/2010/quasi_random/boost/random/detail/qrng_base.hpp | 24 ++++++++++++------------
   sandbox/SOC/2010/quasi_random/boost/random/faure.hpp | 19 ++++++++-----------
   sandbox/SOC/2010/quasi_random/boost/random/niederreiter_base2.hpp | 2 +-
   sandbox/SOC/2010/quasi_random/boost/random/sobol.hpp | 2 +-
   sandbox/SOC/2010/quasi_random/libs/random/test/faure_validate.cpp | 2 ++
   6 files changed, 45 insertions(+), 39 deletions(-)

Modified: sandbox/SOC/2010/quasi_random/boost/random/detail/gray_coded_qrng_base.hpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/boost/random/detail/gray_coded_qrng_base.hpp (original)
+++ sandbox/SOC/2010/quasi_random/boost/random/detail/gray_coded_qrng_base.hpp 2010-08-02 11:32:58 EDT (Mon, 02 Aug 2010)
@@ -60,25 +60,31 @@
   {
     this->curr_elem = rhs.curr_elem;
     this->seq_count = rhs.seq_count;
- std::copy(rhs.quasi_state, rhs.quasi_state + base_t::dimension_value, this->quasi_state);
+ std::copy(rhs.quasi_state, rhs.quasi_state + base_t::dimension, this->quasi_state);
     // we do not copy lattice here!
     return *this;
   }
 
-protected:
- void reset_state()
+ //!Requirements: *this is mutable.
+ //!
+ //!Effects: Resets the quasi-random number generator state to
+ //!the one given by the default construction. Equivalent to u.seed(0).
+ //!
+ //!\brief Throws: nothing.
+ void seed()
   {
     this->curr_elem = 0;
     this->seq_count = 0;
- std::fill(this->quasi_state, this->quasi_state + base_t::dimension_value, 0);
+ this->clear_cached();
   }
 
+protected:
   void seed(std::size_t init, const char *msg)
   {
     this->curr_elem = 0;
     if ( init != this->seq_count )
     {
- base_t::derived().seed();
+ this->clear_cached(); // clears state
 
       this->seq_count = init;
       init ^= (init / 2);
@@ -92,21 +98,22 @@
 
 private:
 
- void compute_next_vector()
- {
- update_state(this->seq_count++, "compute_next_vector");
- }
-
- void update_state(std::size_t cnt, const char *msg)
+ void compute_next(std::size_t seq)
   {
     // Find the position of the least-significant zero in sequence count.
     // This is the bit that changes in the Gray-code representation as
     // the count is advanced.
     int r = 0;
- for( ; cnt & 1; cnt >>= 1 ) {
+ for( ; seq & 1; seq >>= 1 ) {
       ++r;
     }
- update_quasi(r, msg);
+ update_quasi(r, "compute_next");
+ }
+
+ // Initializes currently stored values to zero
+ void clear_cached()
+ {
+ std::fill(this->quasi_state, this->quasi_state + base_t::dimension, result_type());
   }
 
   void update_quasi(int r, const char* msg)
@@ -115,7 +122,7 @@
       boost::throw_exception( std::overflow_error(msg) );
 
     // Calculate the next state.
- for(std::size_t i = 0; i != base_t::dimension_value; ++i)
+ for(std::size_t i = 0; i != base_t::dimension; ++i)
       this->quasi_state[i] ^= this->lattice(r, i);
   }
 };

Modified: sandbox/SOC/2010/quasi_random/boost/random/detail/qrng_base.hpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/boost/random/detail/qrng_base.hpp (original)
+++ sandbox/SOC/2010/quasi_random/boost/random/detail/qrng_base.hpp 2010-08-02 11:32:58 EDT (Mon, 02 Aug 2010)
@@ -29,7 +29,7 @@
 {
 protected:
 
- BOOST_STATIC_CONSTANT(std::size_t, dimension_value = LatticeT::dimension_value);
+ BOOST_STATIC_CONSTANT(std::size_t, dimension = LatticeT::dimension_value);
 
 public:
 
@@ -62,7 +62,7 @@
   //!Throws: overflow_error.
   result_type operator()()
   {
- return curr_elem != dimension_value ? load_saved(): next_state();
+ return curr_elem != dimension ? load_saved(): next_state();
   }
 
   //!Requirements: *this is mutable.
@@ -73,13 +73,13 @@
   //!Throws: overflow_error.
   void discard(std::size_t z)
   {
- std::size_t vec_n = z / dimension_value;
- std::size_t elem_n = z - vec_n * dimension_value; // z % Dimension
- std::size_t vec_offset = vec_n + (curr_elem + elem_n) / dimension_value;
+ std::size_t vec_n = z / dimension;
+ std::size_t elem_n = z - vec_n * dimension; // z % Dimension
+ std::size_t vec_offset = vec_n + (curr_elem + elem_n) / dimension;
     // Discards vec_offset consecutive s-dimensional vectors
     discard_vector(vec_offset);
     // Sets up the proper position of the element-to-read
- curr_elem += (z - dimension_value * vec_offset);
+ curr_elem += (z - dimension * vec_offset);
   }
 
 protected:
@@ -114,10 +114,10 @@
   bool is_equal(const DerivedT& rhs) const
   {
     // compare normalized sequence position, but without the possible overflow
- // that would go with seq_count * dimension_value + curr_elem.
- return (seq_count + (curr_elem / dimension_value) ==
- rhs.seq_count + (rhs.curr_elem / dimension_value)) &&
- (curr_elem % dimension_value == rhs.curr_elem % dimension_value);
+ // that would go with seq_count * dimension + curr_elem.
+ return (seq_count + (curr_elem / dimension) ==
+ rhs.seq_count + (rhs.curr_elem / dimension)) &&
+ (curr_elem % dimension == rhs.curr_elem % dimension);
   }
 
 private:
@@ -130,7 +130,7 @@
 
   result_type next_state()
   {
- derived().compute_next_vector();
+ derived().compute_next(seq_count++);
 
     curr_elem = 0;
     return load_saved();
@@ -159,7 +159,7 @@
   LatticeT lattice;
   std::size_t curr_elem;
   std::size_t seq_count;
- result_type quasi_state[dimension_value];
+ result_type quasi_state[dimension];
 };
 
 }} // namespace detail::random

Modified: sandbox/SOC/2010/quasi_random/boost/random/faure.hpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/boost/random/faure.hpp (original)
+++ sandbox/SOC/2010/quasi_random/boost/random/faure.hpp 2010-08-02 11:32:58 EDT (Mon, 02 Aug 2010)
@@ -122,7 +122,7 @@
       resize(hisum);
 
     quasi[0] =
- compute_recip(seq, hisum, ytemp.rbegin(), ytemp.rend());
+ compute_recip(seq, hisum, ytemp.rbegin());
 
     // Find components using the Faure method.
     for( std::size_t k = 1; k < Dimension; ++k )
@@ -164,24 +164,21 @@
   }
 
   template<typename Iterator>
- inline static RealType compute_recip(std::size_t seq, std::size_t n,
- Iterator first, Iterator last)
+ inline static RealType compute_recip(std::size_t seq, std::size_t n, Iterator out)
   {
- //BOOST_ASSERT( std::distance(first, last) == n );
-
     // Here we do
     // Sum ( 0 <= J <= HISUM ) YTEMP(J) * QS**J
     // Sum ( 0 <= J <= HISUM ) YTEMP(J) / QS**(J+1)
     // in one go
- RealType v, r = RealType();
+ RealType r = RealType();
     std::size_t m, k = integer_pow(qs_base, n - 1);
- for( ; first != last; ++first, seq = m, k /= qs_base )
+ for( ; n != 0; --n, ++out, seq = m, k /= qs_base )
     {
       m = seq % k;
- v = (seq - m) / k;
+ RealType v = (seq - m) / k; // RealType <- IntType
       r += v;
       r *= inv_qs_base();
- *first = v; // saves double dereference
+ *out = v; // saves double dereference
     }
     return r;
   }
@@ -348,9 +345,9 @@
 
 private:
 /** @cond hide_private_members */
- void compute_next_vector()
+ void compute_next(std::size_t seq)
   {
- this->lattice.update(this->seq_count++, this->quasi_state);
+ this->lattice.update(seq, this->quasi_state);
   }
 /** @endcond */
 };

Modified: sandbox/SOC/2010/quasi_random/boost/random/niederreiter_base2.hpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/boost/random/niederreiter_base2.hpp (original)
+++ sandbox/SOC/2010/quasi_random/boost/random/niederreiter_base2.hpp 2010-08-02 11:32:58 EDT (Mon, 02 Aug 2010)
@@ -358,7 +358,7 @@
   //!\brief Throws: nothing.
   void seed()
   {
- base_t::reset_state();
+ base_t::seed();
   }
 
   //!Requirements: *this is mutable.

Modified: sandbox/SOC/2010/quasi_random/boost/random/sobol.hpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/boost/random/sobol.hpp (original)
+++ sandbox/SOC/2010/quasi_random/boost/random/sobol.hpp 2010-08-02 11:32:58 EDT (Mon, 02 Aug 2010)
@@ -348,7 +348,7 @@
   /** @copydoc boost::random::niederreiter_base2::seed() */
   void seed()
   {
- base_t::reset_state();
+ base_t::seed();
   }
 
   /** @copydoc boost::random::niederreiter_base2::seed(std::size_t) */

Modified: sandbox/SOC/2010/quasi_random/libs/random/test/faure_validate.cpp
==============================================================================
--- sandbox/SOC/2010/quasi_random/libs/random/test/faure_validate.cpp (original)
+++ sandbox/SOC/2010/quasi_random/libs/random/test/faure_validate.cpp 2010-08-02 11:32:58 EDT (Mon, 02 Aug 2010)
@@ -20,6 +20,8 @@
 // These tests compare our results with values produced by the original
 // version of ACM TOMS Algorithm 647, which is available in the
 // TOMS subdirectory in http://www.netlib.org
+//
+// For independently generated datasets look at http://people.sc.fsu.edu/~jburkardt/datasets/faure/
 
 
 // Spatial dimension: 2


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