summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/random/extra
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/boost/libs/random/extra
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/random/extra')
-rw-r--r--src/boost/libs/random/extra/Jamfile.v210
-rw-r--r--src/boost/libs/random/extra/haertel.hpp156
-rw-r--r--src/boost/libs/random/extra/test_haertel.cpp62
3 files changed, 228 insertions, 0 deletions
diff --git a/src/boost/libs/random/extra/Jamfile.v2 b/src/boost/libs/random/extra/Jamfile.v2
new file mode 100644
index 000000000..a0ee2af3b
--- /dev/null
+++ b/src/boost/libs/random/extra/Jamfile.v2
@@ -0,0 +1,10 @@
+# Jamfile.v2
+#
+# Copyright (c) 2009
+# Steven Watanabe
+#
+# 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)
+
+run test_haertel.cpp ;
diff --git a/src/boost/libs/random/extra/haertel.hpp b/src/boost/libs/random/extra/haertel.hpp
new file mode 100644
index 000000000..c318d805b
--- /dev/null
+++ b/src/boost/libs/random/extra/haertel.hpp
@@ -0,0 +1,156 @@
+/* haertel.hpp file
+ *
+ * Copyright Jens Maurer 2000, 2002
+ * 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)
+ *
+ * $Id$
+ *
+ * Revision history
+ */
+
+/*
+ * NOTE: This is not part of the official boost submission. It exists
+ * only as a collection of ideas.
+ */
+
+#ifndef BOOST_RANDOM_HAERTEL_HPP
+#define BOOST_RANDOM_HAERTEL_HPP
+
+#include <boost/cstdint.hpp>
+#include <boost/random/linear_congruential.hpp>
+#include <boost/random/inversive_congruential.hpp>
+
+namespace boost {
+namespace random {
+
+// Wikramaratna 1989 ACORN
+template<class IntType, int k, IntType m, IntType val>
+class additive_congruential
+{
+public:
+ typedef IntType result_type;
+#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
+ static const bool has_fixed_range = true;
+ static const result_type min_value = 0;
+ static const result_type max_value = m-1;
+#else
+ enum {
+ has_fixed_range = true,
+ min_value = 0,
+ max_value = m-1
+ };
+#endif
+ template<class InputIterator>
+ explicit additive_congruential(InputIterator start) { seed(start); }
+ template<class InputIterator>
+ void seed(InputIterator start)
+ {
+ for(int i = 0; i <= k; ++i, ++start)
+ values[i] = *start;
+ }
+
+ result_type operator()()
+ {
+ for(int i = 1; i <= k; ++i) {
+ IntType tmp = values[i-1] + values[i];
+ if(tmp >= m)
+ tmp -= m;
+ values[i] = tmp;
+ }
+ return values[k];
+ }
+ result_type validation() const { return val; }
+private:
+ IntType values[k+1];
+};
+
+
+template<class IntType, int r, int s, IntType m, IntType val>
+class lagged_fibonacci_int
+{
+public:
+ typedef IntType result_type;
+#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
+ static const bool has_fixed_range = true;
+ static const result_type min_value = 0;
+ static const result_type max_value = m-1;
+#else
+ enum {
+ has_fixed_range = true,
+ min_value = 0,
+ max_value = m-1
+ };
+#endif
+ explicit lagged_fibonacci_int(IntType start) { seed(start); }
+ template<class Generator>
+ explicit lagged_fibonacci_int(Generator & gen) { seed(gen); }
+ void seed(IntType start)
+ {
+ linear_congruential<uint32_t, 299375077, 0, 0, 0> init;
+ seed(init);
+ }
+ template<class Generator>
+ void seed(Generator & gen)
+ {
+ assert(r > s);
+ for(int i = 0; i < 607; ++i)
+ values[i] = gen();
+ current = 0;
+ lag = r-s;
+ }
+
+ result_type operator()()
+ {
+ result_type tmp = values[current] + values[lag];
+ if(tmp >= m)
+ tmp -= m;
+ values[current] = tmp;
+ ++current;
+ if(current >= r)
+ current = 0;
+ ++lag;
+ if(lag >= r)
+ lag = 0;
+ return tmp;
+ }
+ result_type validation() const { return val; }
+private:
+ result_type values[r];
+ int current, lag;
+};
+
+} // namespace random
+} // namespace boost
+
+// distributions from Haertel's dissertation
+// (additional parameterizations of the basic templates)
+namespace Haertel {
+ typedef boost::random::linear_congruential<boost::uint64_t, 45965, 453816691,
+ (boost::uint64_t(1)<<31), 0> LCG_Af2;
+ typedef boost::random::linear_congruential<boost::uint64_t, 211936855, 0,
+ (boost::uint64_t(1)<<29)-3, 0> LCG_Die1;
+ typedef boost::random::linear_congruential<boost::uint32_t, 2824527309u, 0,
+ 0, 0> LCG_Fis;
+ typedef boost::random::linear_congruential<boost::uint64_t, 950706376u, 0,
+ (boost::uint64_t(1)<<31)-1, 0> LCG_FM;
+ typedef boost::random::linear_congruential<boost::int32_t, 51081, 0,
+ 2147483647, 0> LCG_Hae;
+ typedef boost::random::linear_congruential<boost::uint32_t, 69069, 1,
+ 0, 0> LCG_VAX;
+ typedef boost::random::inversive_congruential<boost::int64_t, 240318, 197,
+ 1000081, 0> NLG_Inv1;
+ typedef boost::random::inversive_congruential<boost::int64_t, 15707262,
+ 13262967, (1<<24)-17, 0> NLG_Inv2;
+ typedef boost::random::inversive_congruential<boost::int32_t, 1, 1,
+ 2147483647, 0> NLG_Inv4;
+ typedef boost::random::inversive_congruential<boost::int32_t, 1, 2,
+ 1<<30, 0> NLG_Inv5;
+ typedef boost::random::additive_congruential<boost::int32_t, 6,
+ (1<<30)-35, 0> MRG_Acorn7;
+ typedef boost::random::lagged_fibonacci_int<boost::uint32_t, 607, 273,
+ 0, 0> MRG_Fib2;
+} // namespace Haertel
+
+#endif
diff --git a/src/boost/libs/random/extra/test_haertel.cpp b/src/boost/libs/random/extra/test_haertel.cpp
new file mode 100644
index 000000000..e5beb265e
--- /dev/null
+++ b/src/boost/libs/random/extra/test_haertel.cpp
@@ -0,0 +1,62 @@
+/* haertel.hpp file
+ *
+ * Copyright Jens Maurer 2000, 2002
+ * 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)
+ *
+ * $Id$
+ *
+ * Revision history
+ */
+
+#include <string>
+#include <iostream>
+
+#include <boost/format.hpp>
+
+#include "haertel.hpp"
+
+#define BOOST_TEST_MAIN
+#include <boost/test/included/unit_test.hpp>
+
+template<class Gen, class T>
+inline void check_validation(Gen & gen, T value, const std::string & name)
+{
+ for(int i = 0; i < 100000-1; ++i)
+ gen();
+
+ typename Gen::result_type actual = gen();
+ BOOST_CHECK_MESSAGE(value == actual,
+ boost::str(boost::format("%s: check value == gen() failed [%d != %d]") %
+ name % value % actual));
+}
+
+// we have validation after 100000 steps with Haertel's generators
+template<class Gen, class T>
+void validate(T value, const std::string & name)
+{
+ Gen gen(1234567);
+ check_validation(gen, value, name);
+}
+
+BOOST_AUTO_TEST_CASE(test_haertel)
+{
+ using namespace Haertel;
+ validate<LCG_Af2>(183269031u, "LCG_Af2");
+ validate<LCG_Die1>(522319944u, "LCG_Die1");
+ validate<LCG_Fis>(-2065162233u, "LCG_Fis");
+ validate<LCG_FM>(581815473u, "LCG_FM");
+ validate<LCG_Hae>(28931709, "LCG_Hae");
+ validate<LCG_VAX>(1508154087u, "LCG_VAX");
+ validate<NLG_Inv2>(6666884, "NLG_Inv2");
+ validate<NLG_Inv4>(1521640076, "NLG_Inv4");
+ validate<NLG_Inv5>(641840839, "NLG_Inv5");
+ static const int acorn7_init[]
+ = { 1234567, 7654321, 246810, 108642, 13579, 97531, 555555 };
+ MRG_Acorn7 acorn7(acorn7_init);
+ check_validation(acorn7, 874294697, "MRG_Acorn7");
+ // This currently fails. I don't want to touch it until
+ // I trace the source of this generator. --SJW
+ validate<MRG_Fib2>(1234567u, "MRG_Fib2");
+}