[mlpack-git] master: use std random module instead of boost (35bd45c)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:17:05 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit 35bd45ca1f0019ffe21694255b6c7afcb9e76daa
Author: Vladimir Glazachev <glazachev.vladimir at gmail.com>
Date:   Fri Feb 27 22:40:07 2015 +0400

    use std random module instead of boost


>---------------------------------------------------------------

35bd45ca1f0019ffe21694255b6c7afcb9e76daa
 src/mlpack/core/math/random.cpp | 33 ++++++-----------------
 src/mlpack/core/math/random.hpp | 59 +++++------------------------------------
 2 files changed, 15 insertions(+), 77 deletions(-)

diff --git a/src/mlpack/core/math/random.cpp b/src/mlpack/core/math/random.cpp
index 7f05b1d..8b3e683 100644
--- a/src/mlpack/core/math/random.cpp
+++ b/src/mlpack/core/math/random.cpp
@@ -1,36 +1,19 @@
 /**
  * @file random.cpp
  *
- * Declarations of global Boost random number generators.
+ * Declarations of global random number generators.
  */
-#include <boost/random.hpp>
-#include <boost/version.hpp>
+#include <random>
 
 namespace mlpack {
 namespace math {
 
-#if BOOST_VERSION >= 104700
-  // Global random object.
-  boost::random::mt19937 randGen;
-  // Global uniform distribution.
-  boost::random::uniform_01<> randUniformDist;
-  // Global normal distribution.
-  boost::random::normal_distribution<> randNormalDist;
-#else
-  // Global random object.
-  boost::mt19937 randGen;
-
-  #if BOOST_VERSION >= 103900
-    // Global uniform distribution.
-    boost::uniform_01<> randUniformDist;
-  #else
-    // Pre-1.39 Boost.Random did not give default template parameter values.
-    boost::uniform_01<boost::mt19937, double> randUniformDist(randGen);
-  #endif
-
-  // Global normal distribution.
-  boost::normal_distribution<> randNormalDist;
-#endif
+// Global random object.
+std::mt19937 randGen;
+// Global uniform distribution.
+std::uniform_real_distribution<> randUniformDist(0.0, 1.0);
+// Global normal distribution.
+std::normal_distribution<> randNormalDist(0.0, 1.0);
 
 }; // namespace math
 }; // namespace mlpack
diff --git a/src/mlpack/core/math/random.hpp b/src/mlpack/core/math/random.hpp
index bb4b1f1..a62c826 100644
--- a/src/mlpack/core/math/random.hpp
+++ b/src/mlpack/core/math/random.hpp
@@ -7,36 +7,17 @@
 #define __MLPACK_CORE_MATH_RANDOM_HPP
 
 #include <mlpack/prereqs.hpp>
-#include <boost/random.hpp>
+#include <random>
 
 namespace mlpack {
 namespace math /** Miscellaneous math routines. */ {
 
-// Annoying Boost versioning issues.
-#include <boost/version.hpp>
-
-#if BOOST_VERSION >= 104700
-  // Global random object.
-  extern boost::random::mt19937 randGen;
-  // Global uniform distribution.
-  extern boost::random::uniform_01<> randUniformDist;
-  // Global normal distribution.
-  extern boost::random::normal_distribution<> randNormalDist;
-#else
-  // Global random object.
-  extern boost::mt19937 randGen;
-
-  #if BOOST_VERSION >= 103900
-    // Global uniform distribution.
-    extern boost::uniform_01<> randUniformDist;
-  #else
-    // Pre-1.39 Boost.Random did not give default template parameter values.
-    extern boost::uniform_01<boost::mt19937, double> randUniformDist;
-  #endif
-
-  // Global normal distribution.
-  extern boost::normal_distribution<> randNormalDist;
-#endif
+// Global random object.
+extern std::mt19937 randGen;
+// Global uniform distribution.
+extern std::uniform_real_distribution<> randUniformDist;
+// Global normal distribution.
+extern std::normal_distribution<> randNormalDist;
 
 /**
  * Set the random seed used by the random functions (Random() and RandInt()).
@@ -62,13 +43,7 @@ inline void RandomSeed(const size_t seed)
  */
 inline double Random()
 {
-#if BOOST_VERSION >= 103900
   return randUniformDist(randGen);
-#else
-  // Before Boost 1.39, we did not give the random object when we wanted a
-  // random number; that gets given at construction time.
-  return randUniformDist();
-#endif
 }
 
 /**
@@ -76,13 +51,7 @@ inline double Random()
  */
 inline double Random(const double lo, const double hi)
 {
-#if BOOST_VERSION >= 103900
   return lo + (hi - lo) * randUniformDist(randGen);
-#else
-  // Before Boost 1.39, we did not give the random object when we wanted a
-  // random number; that gets given at construction time.
-  return lo + (hi - lo) * randUniformDist();
-#endif
 }
 
 /**
@@ -90,13 +59,7 @@ inline double Random(const double lo, const double hi)
  */
 inline int RandInt(const int hiExclusive)
 {
-#if BOOST_VERSION >= 103900
   return (int) std::floor((double) hiExclusive * randUniformDist(randGen));
-#else
-  // Before Boost 1.39, we did not give the random object when we wanted a
-  // random number; that gets given at construction time.
-  return (int) std::floor((double) hiExclusive * randUniformDist());
-#endif
 }
 
 /**
@@ -104,16 +67,8 @@ inline int RandInt(const int hiExclusive)
  */
 inline int RandInt(const int lo, const int hiExclusive)
 {
-#if BOOST_VERSION >= 103900
   return lo + (int) std::floor((double) (hiExclusive - lo)
                                * randUniformDist(randGen));
-#else
-  // Before Boost 1.39, we did not give the random object when we wanted a
-  // random number; that gets given at construction time.
-  return lo + (int) std::floor((double) (hiExclusive - lo)
-                               * randUniformDist());
-#endif
-
 }
 
 /**



More information about the mlpack-git mailing list