From d1af74d0847a50574398c31e8732f86968f5b04e Mon Sep 17 00:00:00 2001 From: Reza Rastak Date: Mon, 30 Dec 2019 12:48:58 -0800 Subject: [PATCH] mu_parser functions modified to use std random number generators --- doc/news/changes/minor/20191230RezaRastak | 4 +++ source/base/function_parser.cc | 2 -- source/base/mu_parser_internal.cc | 27 ++++++++----------- source/base/tensor_function_parser.cc | 2 -- ...nction_parser_09.with_muparser=true.output | 2 +- ...nction_parser_10.with_muparser=true.output | 2 +- 6 files changed, 17 insertions(+), 22 deletions(-) create mode 100644 doc/news/changes/minor/20191230RezaRastak diff --git a/doc/news/changes/minor/20191230RezaRastak b/doc/news/changes/minor/20191230RezaRastak new file mode 100644 index 0000000000..a902da5b68 --- /dev/null +++ b/doc/news/changes/minor/20191230RezaRastak @@ -0,0 +1,4 @@ +Improved: mu_parser functions now use random number generation facilities +provided by the standard library. +
+(Reza Rastak, 2019/20/30) diff --git a/source/base/function_parser.cc b/source/base/function_parser.cc index 0a20249014..26bd537890 100644 --- a/source/base/function_parser.cc +++ b/source/base/function_parser.cc @@ -22,8 +22,6 @@ #include -#include - #include #include diff --git a/source/base/mu_parser_internal.cc b/source/base/mu_parser_internal.cc index 9c4b964f23..74b9890d6e 100644 --- a/source/base/mu_parser_internal.cc +++ b/source/base/mu_parser_internal.cc @@ -16,12 +16,11 @@ #include #include -#include - #include #include #include #include +#include #include @@ -121,20 +120,17 @@ namespace internal double mu_rand_seed(double seed) { - static Threads::Mutex rand_mutex; + static std::mutex rand_mutex; std::lock_guard lock(rand_mutex); - static boost::random::uniform_real_distribution<> uniform_distribution(0, - 1); + std::uniform_real_distribution<> uniform_distribution(0., 1.); - // for each seed an unique random number generator is created, + // for each seed a unique random number generator is created, // which is initialized with the seed itself - // we could use std::mt19937 but doing so results in compiler-dependent - // output. - static std::map rng_map; + static std::map rng_map; if (rng_map.find(seed) == rng_map.end()) - rng_map[seed] = boost::random::mt19937(static_cast(seed)); + rng_map[seed] = std::mt19937(static_cast(seed)); return uniform_distribution(rng_map[seed]); } @@ -143,12 +139,11 @@ namespace internal double mu_rand() { - static Threads::Mutex rand_mutex; - std::lock_guard lock(rand_mutex); - static boost::random::uniform_real_distribution<> uniform_distribution(0, - 1); - static boost::random::mt19937 rng( - static_cast(std::time(nullptr))); + static std::mutex rand_mutex; + std::lock_guard lock(rand_mutex); + std::uniform_real_distribution<> uniform_distribution(0., 1.); + const unsigned int seed = static_cast(std::time(nullptr)); + static std::mt19937 rng(seed); return uniform_distribution(rng); } diff --git a/source/base/tensor_function_parser.cc b/source/base/tensor_function_parser.cc index eb4cb8c13c..f77927125d 100644 --- a/source/base/tensor_function_parser.cc +++ b/source/base/tensor_function_parser.cc @@ -22,8 +22,6 @@ #include #include -#include - #include #include diff --git a/tests/base/function_parser_09.with_muparser=true.output b/tests/base/function_parser_09.with_muparser=true.output index 59f845a429..03a86172f4 100644 --- a/tests/base/function_parser_09.with_muparser=true.output +++ b/tests/base/function_parser_09.with_muparser=true.output @@ -1,3 +1,3 @@ DEAL::OK -DEAL::0.771321 +DEAL::0.298761 diff --git a/tests/base/function_parser_10.with_muparser=true.output b/tests/base/function_parser_10.with_muparser=true.output index 59f845a429..03a86172f4 100644 --- a/tests/base/function_parser_10.with_muparser=true.output +++ b/tests/base/function_parser_10.with_muparser=true.output @@ -1,3 +1,3 @@ DEAL::OK -DEAL::0.771321 +DEAL::0.298761 -- 2.39.5