Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- random -----------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_RANDOM |
| 11 | #define _LIBCPP_RANDOM |
| 12 | |
| 13 | /* |
| 14 | random synopsis |
| 15 | |
| 16 | #include <initializer_list> |
| 17 | |
| 18 | namespace std |
| 19 | { |
Christopher Di Bella | 6807407 | 2021-02-17 02:52:17 +0000 | [diff] [blame^] | 20 | // [rand.req.urng], uniform random bit generator requirements |
| 21 | template<class G> |
| 22 | concept uniform_random_bit_generator = see below; // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 23 | |
| 24 | // Engines |
| 25 | |
| 26 | template <class UIntType, UIntType a, UIntType c, UIntType m> |
| 27 | class linear_congruential_engine |
| 28 | { |
| 29 | public: |
| 30 | // types |
| 31 | typedef UIntType result_type; |
| 32 | |
| 33 | // engine characteristics |
| 34 | static constexpr result_type multiplier = a; |
| 35 | static constexpr result_type increment = c; |
| 36 | static constexpr result_type modulus = m; |
| 37 | static constexpr result_type min() { return c == 0u ? 1u: 0u;} |
| 38 | static constexpr result_type max() { return m - 1u;} |
| 39 | static constexpr result_type default_seed = 1u; |
| 40 | |
| 41 | // constructors and seeding functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 42 | explicit linear_congruential_engine(result_type s = default_seed); // before C++20 |
| 43 | linear_congruential_engine() : linear_congruential_engine(default_seed) {} // C++20 |
| 44 | explicit linear_congruential_engine(result_type s); // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | template<class Sseq> explicit linear_congruential_engine(Sseq& q); |
| 46 | void seed(result_type s = default_seed); |
| 47 | template<class Sseq> void seed(Sseq& q); |
| 48 | |
| 49 | // generating functions |
| 50 | result_type operator()(); |
| 51 | void discard(unsigned long long z); |
| 52 | }; |
| 53 | |
| 54 | template <class UIntType, UIntType a, UIntType c, UIntType m> |
| 55 | bool |
| 56 | operator==(const linear_congruential_engine<UIntType, a, c, m>& x, |
| 57 | const linear_congruential_engine<UIntType, a, c, m>& y); |
| 58 | |
| 59 | template <class UIntType, UIntType a, UIntType c, UIntType m> |
| 60 | bool |
| 61 | operator!=(const linear_congruential_engine<UIntType, a, c, m>& x, |
| 62 | const linear_congruential_engine<UIntType, a, c, m>& y); |
| 63 | |
| 64 | template <class charT, class traits, |
| 65 | class UIntType, UIntType a, UIntType c, UIntType m> |
| 66 | basic_ostream<charT, traits>& |
| 67 | operator<<(basic_ostream<charT, traits>& os, |
| 68 | const linear_congruential_engine<UIntType, a, c, m>& x); |
| 69 | |
| 70 | template <class charT, class traits, |
| 71 | class UIntType, UIntType a, UIntType c, UIntType m> |
| 72 | basic_istream<charT, traits>& |
| 73 | operator>>(basic_istream<charT, traits>& is, |
| 74 | linear_congruential_engine<UIntType, a, c, m>& x); |
| 75 | |
| 76 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 77 | UIntType a, size_t u, UIntType d, size_t s, |
| 78 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 79 | class mersenne_twister_engine |
| 80 | { |
| 81 | public: |
| 82 | // types |
| 83 | typedef UIntType result_type; |
| 84 | |
| 85 | // engine characteristics |
| 86 | static constexpr size_t word_size = w; |
| 87 | static constexpr size_t state_size = n; |
| 88 | static constexpr size_t shift_size = m; |
| 89 | static constexpr size_t mask_bits = r; |
| 90 | static constexpr result_type xor_mask = a; |
| 91 | static constexpr size_t tempering_u = u; |
| 92 | static constexpr result_type tempering_d = d; |
| 93 | static constexpr size_t tempering_s = s; |
| 94 | static constexpr result_type tempering_b = b; |
| 95 | static constexpr size_t tempering_t = t; |
| 96 | static constexpr result_type tempering_c = c; |
| 97 | static constexpr size_t tempering_l = l; |
| 98 | static constexpr result_type initialization_multiplier = f; |
| 99 | static constexpr result_type min () { return 0; } |
| 100 | static constexpr result_type max() { return 2^w - 1; } |
| 101 | static constexpr result_type default_seed = 5489u; |
| 102 | |
| 103 | // constructors and seeding functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 104 | explicit mersenne_twister_engine(result_type s = default_seed); // before C++20 |
| 105 | mersenne_twister_engine() : mersenne_twister_engine(default_seed) {} // C++20 |
| 106 | explicit mersenne_twister_engine(result_type s); // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 107 | template<class Sseq> explicit mersenne_twister_engine(Sseq& q); |
| 108 | void seed(result_type value = default_seed); |
| 109 | template<class Sseq> void seed(Sseq& q); |
| 110 | |
| 111 | // generating functions |
| 112 | result_type operator()(); |
| 113 | void discard(unsigned long long z); |
| 114 | }; |
| 115 | |
| 116 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 117 | UIntType a, size_t u, UIntType d, size_t s, |
| 118 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 119 | bool |
| 120 | operator==( |
| 121 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, |
| 122 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); |
| 123 | |
| 124 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 125 | UIntType a, size_t u, UIntType d, size_t s, |
| 126 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 127 | bool |
| 128 | operator!=( |
| 129 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, |
| 130 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); |
| 131 | |
| 132 | template <class charT, class traits, |
| 133 | class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 134 | UIntType a, size_t u, UIntType d, size_t s, |
| 135 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 136 | basic_ostream<charT, traits>& |
| 137 | operator<<(basic_ostream<charT, traits>& os, |
| 138 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); |
| 139 | |
| 140 | template <class charT, class traits, |
| 141 | class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 142 | UIntType a, size_t u, UIntType d, size_t s, |
| 143 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 144 | basic_istream<charT, traits>& |
| 145 | operator>>(basic_istream<charT, traits>& is, |
| 146 | mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); |
| 147 | |
| 148 | template<class UIntType, size_t w, size_t s, size_t r> |
| 149 | class subtract_with_carry_engine |
| 150 | { |
| 151 | public: |
| 152 | // types |
| 153 | typedef UIntType result_type; |
| 154 | |
| 155 | // engine characteristics |
| 156 | static constexpr size_t word_size = w; |
| 157 | static constexpr size_t short_lag = s; |
| 158 | static constexpr size_t long_lag = r; |
| 159 | static constexpr result_type min() { return 0; } |
| 160 | static constexpr result_type max() { return m-1; } |
| 161 | static constexpr result_type default_seed = 19780503u; |
| 162 | |
| 163 | // constructors and seeding functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 164 | explicit subtract_with_carry_engine(result_type value = default_seed); // before C++20 |
| 165 | subtract_with_carry_engine() : subtract_with_carry_engine(default_seed) {} // C++20 |
| 166 | explicit subtract_with_carry_engine(result_type value); // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 167 | template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); |
| 168 | void seed(result_type value = default_seed); |
| 169 | template<class Sseq> void seed(Sseq& q); |
| 170 | |
| 171 | // generating functions |
| 172 | result_type operator()(); |
| 173 | void discard(unsigned long long z); |
| 174 | }; |
| 175 | |
| 176 | template<class UIntType, size_t w, size_t s, size_t r> |
| 177 | bool |
| 178 | operator==( |
| 179 | const subtract_with_carry_engine<UIntType, w, s, r>& x, |
| 180 | const subtract_with_carry_engine<UIntType, w, s, r>& y); |
| 181 | |
| 182 | template<class UIntType, size_t w, size_t s, size_t r> |
| 183 | bool |
| 184 | operator!=( |
| 185 | const subtract_with_carry_engine<UIntType, w, s, r>& x, |
| 186 | const subtract_with_carry_engine<UIntType, w, s, r>& y); |
| 187 | |
| 188 | template <class charT, class traits, |
| 189 | class UIntType, size_t w, size_t s, size_t r> |
| 190 | basic_ostream<charT, traits>& |
| 191 | operator<<(basic_ostream<charT, traits>& os, |
| 192 | const subtract_with_carry_engine<UIntType, w, s, r>& x); |
| 193 | |
| 194 | template <class charT, class traits, |
| 195 | class UIntType, size_t w, size_t s, size_t r> |
| 196 | basic_istream<charT, traits>& |
| 197 | operator>>(basic_istream<charT, traits>& is, |
| 198 | subtract_with_carry_engine<UIntType, w, s, r>& x); |
| 199 | |
| 200 | template<class Engine, size_t p, size_t r> |
| 201 | class discard_block_engine |
| 202 | { |
| 203 | public: |
| 204 | // types |
| 205 | typedef typename Engine::result_type result_type; |
| 206 | |
| 207 | // engine characteristics |
| 208 | static constexpr size_t block_size = p; |
| 209 | static constexpr size_t used_block = r; |
| 210 | static constexpr result_type min() { return Engine::min(); } |
| 211 | static constexpr result_type max() { return Engine::max(); } |
| 212 | |
| 213 | // constructors and seeding functions |
| 214 | discard_block_engine(); |
| 215 | explicit discard_block_engine(const Engine& e); |
| 216 | explicit discard_block_engine(Engine&& e); |
| 217 | explicit discard_block_engine(result_type s); |
| 218 | template<class Sseq> explicit discard_block_engine(Sseq& q); |
| 219 | void seed(); |
| 220 | void seed(result_type s); |
| 221 | template<class Sseq> void seed(Sseq& q); |
| 222 | |
| 223 | // generating functions |
| 224 | result_type operator()(); |
| 225 | void discard(unsigned long long z); |
| 226 | |
| 227 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 228 | const Engine& base() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | template<class Engine, size_t p, size_t r> |
| 232 | bool |
| 233 | operator==( |
| 234 | const discard_block_engine<Engine, p, r>& x, |
| 235 | const discard_block_engine<Engine, p, r>& y); |
| 236 | |
| 237 | template<class Engine, size_t p, size_t r> |
| 238 | bool |
| 239 | operator!=( |
| 240 | const discard_block_engine<Engine, p, r>& x, |
| 241 | const discard_block_engine<Engine, p, r>& y); |
| 242 | |
| 243 | template <class charT, class traits, |
| 244 | class Engine, size_t p, size_t r> |
| 245 | basic_ostream<charT, traits>& |
| 246 | operator<<(basic_ostream<charT, traits>& os, |
| 247 | const discard_block_engine<Engine, p, r>& x); |
| 248 | |
| 249 | template <class charT, class traits, |
| 250 | class Engine, size_t p, size_t r> |
| 251 | basic_istream<charT, traits>& |
| 252 | operator>>(basic_istream<charT, traits>& is, |
| 253 | discard_block_engine<Engine, p, r>& x); |
| 254 | |
| 255 | template<class Engine, size_t w, class UIntType> |
| 256 | class independent_bits_engine |
| 257 | { |
| 258 | public: |
| 259 | // types |
| 260 | typedef UIntType result_type; |
| 261 | |
| 262 | // engine characteristics |
| 263 | static constexpr result_type min() { return 0; } |
| 264 | static constexpr result_type max() { return 2^w - 1; } |
| 265 | |
| 266 | // constructors and seeding functions |
| 267 | independent_bits_engine(); |
| 268 | explicit independent_bits_engine(const Engine& e); |
| 269 | explicit independent_bits_engine(Engine&& e); |
| 270 | explicit independent_bits_engine(result_type s); |
| 271 | template<class Sseq> explicit independent_bits_engine(Sseq& q); |
| 272 | void seed(); |
| 273 | void seed(result_type s); |
| 274 | template<class Sseq> void seed(Sseq& q); |
| 275 | |
| 276 | // generating functions |
| 277 | result_type operator()(); void discard(unsigned long long z); |
| 278 | |
| 279 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 280 | const Engine& base() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 281 | }; |
| 282 | |
| 283 | template<class Engine, size_t w, class UIntType> |
| 284 | bool |
| 285 | operator==( |
| 286 | const independent_bits_engine<Engine, w, UIntType>& x, |
| 287 | const independent_bits_engine<Engine, w, UIntType>& y); |
| 288 | |
| 289 | template<class Engine, size_t w, class UIntType> |
| 290 | bool |
| 291 | operator!=( |
| 292 | const independent_bits_engine<Engine, w, UIntType>& x, |
| 293 | const independent_bits_engine<Engine, w, UIntType>& y); |
| 294 | |
| 295 | template <class charT, class traits, |
| 296 | class Engine, size_t w, class UIntType> |
| 297 | basic_ostream<charT, traits>& |
| 298 | operator<<(basic_ostream<charT, traits>& os, |
| 299 | const independent_bits_engine<Engine, w, UIntType>& x); |
| 300 | |
| 301 | template <class charT, class traits, |
| 302 | class Engine, size_t w, class UIntType> |
| 303 | basic_istream<charT, traits>& |
| 304 | operator>>(basic_istream<charT, traits>& is, |
| 305 | independent_bits_engine<Engine, w, UIntType>& x); |
| 306 | |
| 307 | template<class Engine, size_t k> |
| 308 | class shuffle_order_engine |
| 309 | { |
| 310 | public: |
| 311 | // types |
| 312 | typedef typename Engine::result_type result_type; |
| 313 | |
| 314 | // engine characteristics |
| 315 | static constexpr size_t table_size = k; |
| 316 | static constexpr result_type min() { return Engine::min; } |
| 317 | static constexpr result_type max() { return Engine::max; } |
| 318 | |
| 319 | // constructors and seeding functions |
| 320 | shuffle_order_engine(); |
| 321 | explicit shuffle_order_engine(const Engine& e); |
| 322 | explicit shuffle_order_engine(Engine&& e); |
| 323 | explicit shuffle_order_engine(result_type s); |
| 324 | template<class Sseq> explicit shuffle_order_engine(Sseq& q); |
| 325 | void seed(); |
| 326 | void seed(result_type s); |
| 327 | template<class Sseq> void seed(Sseq& q); |
| 328 | |
| 329 | // generating functions |
| 330 | result_type operator()(); |
| 331 | void discard(unsigned long long z); |
| 332 | |
| 333 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 334 | const Engine& base() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
| 337 | template<class Engine, size_t k> |
| 338 | bool |
| 339 | operator==( |
| 340 | const shuffle_order_engine<Engine, k>& x, |
| 341 | const shuffle_order_engine<Engine, k>& y); |
| 342 | |
| 343 | template<class Engine, size_t k> |
| 344 | bool |
| 345 | operator!=( |
| 346 | const shuffle_order_engine<Engine, k>& x, |
| 347 | const shuffle_order_engine<Engine, k>& y); |
| 348 | |
| 349 | template <class charT, class traits, |
| 350 | class Engine, size_t k> |
| 351 | basic_ostream<charT, traits>& |
| 352 | operator<<(basic_ostream<charT, traits>& os, |
| 353 | const shuffle_order_engine<Engine, k>& x); |
| 354 | |
| 355 | template <class charT, class traits, |
| 356 | class Engine, size_t k> |
| 357 | basic_istream<charT, traits>& |
| 358 | operator>>(basic_istream<charT, traits>& is, |
| 359 | shuffle_order_engine<Engine, k>& x); |
| 360 | |
| 361 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> |
| 362 | minstd_rand0; |
| 363 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> |
| 364 | minstd_rand; |
| 365 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, |
| 366 | 0x9908b0df, |
| 367 | 11, 0xffffffff, |
| 368 | 7, 0x9d2c5680, |
| 369 | 15, 0xefc60000, |
| 370 | 18, 1812433253> mt19937; |
| 371 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, |
| 372 | 0xb5026f5aa96619e9, |
| 373 | 29, 0x5555555555555555, |
| 374 | 17, 0x71d67fffeda60000, |
| 375 | 37, 0xfff7eee000000000, |
| 376 | 43, 6364136223846793005> mt19937_64; |
| 377 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; |
| 378 | typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; |
| 379 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; |
| 380 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; |
| 381 | typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 382 | typedef minstd_rand default_random_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 383 | |
| 384 | // Generators |
| 385 | |
| 386 | class random_device |
| 387 | { |
| 388 | public: |
| 389 | // types |
| 390 | typedef unsigned int result_type; |
| 391 | |
| 392 | // generator characteristics |
| 393 | static constexpr result_type min() { return numeric_limits<result_type>::min(); } |
| 394 | static constexpr result_type max() { return numeric_limits<result_type>::max(); } |
| 395 | |
| 396 | // constructors |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 397 | explicit random_device(const string& token = implementation-defined); // before C++20 |
| 398 | random_device() : random_device(implementation-defined) {} // C++20 |
| 399 | explicit random_device(const string& token); // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 400 | |
| 401 | // generating functions |
| 402 | result_type operator()(); |
| 403 | |
| 404 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 405 | double entropy() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 406 | |
| 407 | // no copy functions |
| 408 | random_device(const random_device& ) = delete; |
| 409 | void operator=(const random_device& ) = delete; |
| 410 | }; |
| 411 | |
| 412 | // Utilities |
| 413 | |
| 414 | class seed_seq |
| 415 | { |
| 416 | public: |
| 417 | // types |
| 418 | typedef uint_least32_t result_type; |
| 419 | |
| 420 | // constructors |
| 421 | seed_seq(); |
| 422 | template<class T> |
| 423 | seed_seq(initializer_list<T> il); |
| 424 | template<class InputIterator> |
| 425 | seed_seq(InputIterator begin, InputIterator end); |
| 426 | |
| 427 | // generating functions |
| 428 | template<class RandomAccessIterator> |
| 429 | void generate(RandomAccessIterator begin, RandomAccessIterator end); |
| 430 | |
| 431 | // property functions |
| 432 | size_t size() const; |
| 433 | template<class OutputIterator> |
| 434 | void param(OutputIterator dest) const; |
| 435 | |
| 436 | // no copy functions |
| 437 | seed_seq(const seed_seq&) = delete; |
| 438 | void operator=(const seed_seq& ) = delete; |
| 439 | }; |
| 440 | |
| 441 | template<class RealType, size_t bits, class URNG> |
| 442 | RealType generate_canonical(URNG& g); |
| 443 | |
| 444 | // Distributions |
| 445 | |
| 446 | template<class IntType = int> |
| 447 | class uniform_int_distribution |
| 448 | { |
| 449 | public: |
| 450 | // types |
| 451 | typedef IntType result_type; |
| 452 | |
| 453 | class param_type |
| 454 | { |
| 455 | public: |
| 456 | typedef uniform_int_distribution distribution_type; |
| 457 | |
| 458 | explicit param_type(IntType a = 0, |
| 459 | IntType b = numeric_limits<IntType>::max()); |
| 460 | |
| 461 | result_type a() const; |
| 462 | result_type b() const; |
| 463 | |
| 464 | friend bool operator==(const param_type& x, const param_type& y); |
| 465 | friend bool operator!=(const param_type& x, const param_type& y); |
| 466 | }; |
| 467 | |
| 468 | // constructors and reset functions |
| 469 | explicit uniform_int_distribution(IntType a = 0, |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 470 | IntType b = numeric_limits<IntType>::max()); // before C++20 |
| 471 | uniform_int_distribution() : uniform_int_distribution(0) {} // C++20 |
| 472 | explicit uniform_int_distribution(IntType a, |
| 473 | IntType b = numeric_limits<IntType>::max()); // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 474 | explicit uniform_int_distribution(const param_type& parm); |
| 475 | void reset(); |
| 476 | |
| 477 | // generating functions |
| 478 | template<class URNG> result_type operator()(URNG& g); |
| 479 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 480 | |
| 481 | // property functions |
| 482 | result_type a() const; |
| 483 | result_type b() const; |
| 484 | |
| 485 | param_type param() const; |
| 486 | void param(const param_type& parm); |
| 487 | |
| 488 | result_type min() const; |
| 489 | result_type max() const; |
| 490 | |
| 491 | friend bool operator==(const uniform_int_distribution& x, |
| 492 | const uniform_int_distribution& y); |
| 493 | friend bool operator!=(const uniform_int_distribution& x, |
| 494 | const uniform_int_distribution& y); |
| 495 | |
| 496 | template <class charT, class traits> |
| 497 | friend |
| 498 | basic_ostream<charT, traits>& |
| 499 | operator<<(basic_ostream<charT, traits>& os, |
| 500 | const uniform_int_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 501 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 502 | template <class charT, class traits> |
| 503 | friend |
| 504 | basic_istream<charT, traits>& |
| 505 | operator>>(basic_istream<charT, traits>& is, |
| 506 | uniform_int_distribution& x); |
| 507 | }; |
| 508 | |
| 509 | template<class RealType = double> |
| 510 | class uniform_real_distribution |
| 511 | { |
| 512 | public: |
| 513 | // types |
| 514 | typedef RealType result_type; |
| 515 | |
| 516 | class param_type |
| 517 | { |
| 518 | public: |
| 519 | typedef uniform_real_distribution distribution_type; |
| 520 | |
| 521 | explicit param_type(RealType a = 0, |
| 522 | RealType b = 1); |
| 523 | |
| 524 | result_type a() const; |
| 525 | result_type b() const; |
| 526 | |
| 527 | friend bool operator==(const param_type& x, const param_type& y); |
| 528 | friend bool operator!=(const param_type& x, const param_type& y); |
| 529 | }; |
| 530 | |
| 531 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 532 | explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); // before C++20 |
| 533 | uniform_real_distribution() : uniform_real_distribution(0.0) {} // C++20 |
| 534 | explicit uniform_real_distribution(RealType a, RealType b = 1.0); // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 535 | explicit uniform_real_distribution(const param_type& parm); |
| 536 | void reset(); |
| 537 | |
| 538 | // generating functions |
| 539 | template<class URNG> result_type operator()(URNG& g); |
| 540 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 541 | |
| 542 | // property functions |
| 543 | result_type a() const; |
| 544 | result_type b() const; |
| 545 | |
| 546 | param_type param() const; |
| 547 | void param(const param_type& parm); |
| 548 | |
| 549 | result_type min() const; |
| 550 | result_type max() const; |
| 551 | |
| 552 | friend bool operator==(const uniform_real_distribution& x, |
| 553 | const uniform_real_distribution& y); |
| 554 | friend bool operator!=(const uniform_real_distribution& x, |
| 555 | const uniform_real_distribution& y); |
| 556 | |
| 557 | template <class charT, class traits> |
| 558 | friend |
| 559 | basic_ostream<charT, traits>& |
| 560 | operator<<(basic_ostream<charT, traits>& os, |
| 561 | const uniform_real_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 562 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 563 | template <class charT, class traits> |
| 564 | friend |
| 565 | basic_istream<charT, traits>& |
| 566 | operator>>(basic_istream<charT, traits>& is, |
| 567 | uniform_real_distribution& x); |
| 568 | }; |
| 569 | |
| 570 | class bernoulli_distribution |
| 571 | { |
| 572 | public: |
| 573 | // types |
| 574 | typedef bool result_type; |
| 575 | |
| 576 | class param_type |
| 577 | { |
| 578 | public: |
| 579 | typedef bernoulli_distribution distribution_type; |
| 580 | |
| 581 | explicit param_type(double p = 0.5); |
| 582 | |
| 583 | double p() const; |
| 584 | |
| 585 | friend bool operator==(const param_type& x, const param_type& y); |
| 586 | friend bool operator!=(const param_type& x, const param_type& y); |
| 587 | }; |
| 588 | |
| 589 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 590 | explicit bernoulli_distribution(double p = 0.5); // before C++20 |
| 591 | bernoulli_distribution() : bernoulli_distribution(0.5) {} // C++20 |
| 592 | explicit bernoulli_distribution(double p); // C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 593 | explicit bernoulli_distribution(const param_type& parm); |
| 594 | void reset(); |
| 595 | |
| 596 | // generating functions |
| 597 | template<class URNG> result_type operator()(URNG& g); |
| 598 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 599 | |
| 600 | // property functions |
| 601 | double p() const; |
| 602 | |
| 603 | param_type param() const; |
| 604 | void param(const param_type& parm); |
| 605 | |
| 606 | result_type min() const; |
| 607 | result_type max() const; |
| 608 | |
| 609 | friend bool operator==(const bernoulli_distribution& x, |
| 610 | const bernoulli_distribution& y); |
| 611 | friend bool operator!=(const bernoulli_distribution& x, |
| 612 | const bernoulli_distribution& y); |
| 613 | |
| 614 | template <class charT, class traits> |
| 615 | friend |
| 616 | basic_ostream<charT, traits>& |
| 617 | operator<<(basic_ostream<charT, traits>& os, |
| 618 | const bernoulli_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 619 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 620 | template <class charT, class traits> |
| 621 | friend |
| 622 | basic_istream<charT, traits>& |
| 623 | operator>>(basic_istream<charT, traits>& is, |
| 624 | bernoulli_distribution& x); |
| 625 | }; |
| 626 | |
| 627 | template<class IntType = int> |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 628 | class binomial_distribution |
| 629 | { |
| 630 | public: |
| 631 | // types |
| 632 | typedef IntType result_type; |
| 633 | |
| 634 | class param_type |
| 635 | { |
| 636 | public: |
| 637 | typedef binomial_distribution distribution_type; |
| 638 | |
| 639 | explicit param_type(IntType t = 1, double p = 0.5); |
| 640 | |
| 641 | IntType t() const; |
| 642 | double p() const; |
| 643 | |
| 644 | friend bool operator==(const param_type& x, const param_type& y); |
| 645 | friend bool operator!=(const param_type& x, const param_type& y); |
| 646 | }; |
| 647 | |
| 648 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 649 | explicit binomial_distribution(IntType t = 1, double p = 0.5); // before C++20 |
| 650 | binomial_distribution() : binomial_distribution(1) {} // C++20 |
| 651 | explicit binomial_distribution(IntType t, double p = 0.5); // C++20 |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 652 | explicit binomial_distribution(const param_type& parm); |
| 653 | void reset(); |
| 654 | |
| 655 | // generating functions |
| 656 | template<class URNG> result_type operator()(URNG& g); |
| 657 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 658 | |
| 659 | // property functions |
| 660 | IntType t() const; |
| 661 | double p() const; |
| 662 | |
| 663 | param_type param() const; |
| 664 | void param(const param_type& parm); |
| 665 | |
| 666 | result_type min() const; |
| 667 | result_type max() const; |
| 668 | |
| 669 | friend bool operator==(const binomial_distribution& x, |
| 670 | const binomial_distribution& y); |
| 671 | friend bool operator!=(const binomial_distribution& x, |
| 672 | const binomial_distribution& y); |
| 673 | |
| 674 | template <class charT, class traits> |
| 675 | friend |
| 676 | basic_ostream<charT, traits>& |
| 677 | operator<<(basic_ostream<charT, traits>& os, |
| 678 | const binomial_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 679 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 680 | template <class charT, class traits> |
| 681 | friend |
| 682 | basic_istream<charT, traits>& |
| 683 | operator>>(basic_istream<charT, traits>& is, |
| 684 | binomial_distribution& x); |
| 685 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 686 | |
| 687 | template<class IntType = int> |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 688 | class geometric_distribution |
| 689 | { |
| 690 | public: |
| 691 | // types |
| 692 | typedef IntType result_type; |
| 693 | |
| 694 | class param_type |
| 695 | { |
| 696 | public: |
| 697 | typedef geometric_distribution distribution_type; |
| 698 | |
| 699 | explicit param_type(double p = 0.5); |
| 700 | |
| 701 | double p() const; |
| 702 | |
| 703 | friend bool operator==(const param_type& x, const param_type& y); |
| 704 | friend bool operator!=(const param_type& x, const param_type& y); |
| 705 | }; |
| 706 | |
| 707 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 708 | explicit geometric_distribution(double p = 0.5); // before C++20 |
| 709 | geometric_distribution() : geometric_distribution(0.5) {} // C++20 |
| 710 | explicit geometric_distribution(double p); // C++20 |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 711 | explicit geometric_distribution(const param_type& parm); |
| 712 | void reset(); |
| 713 | |
| 714 | // generating functions |
| 715 | template<class URNG> result_type operator()(URNG& g); |
| 716 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 717 | |
| 718 | // property functions |
| 719 | double p() const; |
| 720 | |
| 721 | param_type param() const; |
| 722 | void param(const param_type& parm); |
| 723 | |
| 724 | result_type min() const; |
| 725 | result_type max() const; |
| 726 | |
| 727 | friend bool operator==(const geometric_distribution& x, |
| 728 | const geometric_distribution& y); |
| 729 | friend bool operator!=(const geometric_distribution& x, |
| 730 | const geometric_distribution& y); |
| 731 | |
| 732 | template <class charT, class traits> |
| 733 | friend |
| 734 | basic_ostream<charT, traits>& |
| 735 | operator<<(basic_ostream<charT, traits>& os, |
| 736 | const geometric_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 737 | |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 738 | template <class charT, class traits> |
| 739 | friend |
| 740 | basic_istream<charT, traits>& |
| 741 | operator>>(basic_istream<charT, traits>& is, |
| 742 | geometric_distribution& x); |
| 743 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 744 | |
| 745 | template<class IntType = int> |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 746 | class negative_binomial_distribution |
| 747 | { |
| 748 | public: |
| 749 | // types |
| 750 | typedef IntType result_type; |
| 751 | |
| 752 | class param_type |
| 753 | { |
| 754 | public: |
| 755 | typedef negative_binomial_distribution distribution_type; |
| 756 | |
| 757 | explicit param_type(result_type k = 1, double p = 0.5); |
| 758 | |
| 759 | result_type k() const; |
| 760 | double p() const; |
| 761 | |
| 762 | friend bool operator==(const param_type& x, const param_type& y); |
| 763 | friend bool operator!=(const param_type& x, const param_type& y); |
| 764 | }; |
| 765 | |
| 766 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 767 | explicit negative_binomial_distribution(IntType k = 1, double p = 0.5); // before C++20 |
| 768 | negative_binomial_distribution() : negative_binomial_distribution(1) {} // C++20 |
| 769 | explicit negative_binomial_distribution(IntType k, double p = 0.5); // C++20 |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 770 | explicit negative_binomial_distribution(const param_type& parm); |
| 771 | void reset(); |
| 772 | |
| 773 | // generating functions |
| 774 | template<class URNG> result_type operator()(URNG& g); |
| 775 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 776 | |
| 777 | // property functions |
| 778 | result_type k() const; |
| 779 | double p() const; |
| 780 | |
| 781 | param_type param() const; |
| 782 | void param(const param_type& parm); |
| 783 | |
| 784 | result_type min() const; |
| 785 | result_type max() const; |
| 786 | |
| 787 | friend bool operator==(const negative_binomial_distribution& x, |
| 788 | const negative_binomial_distribution& y); |
| 789 | friend bool operator!=(const negative_binomial_distribution& x, |
| 790 | const negative_binomial_distribution& y); |
| 791 | |
| 792 | template <class charT, class traits> |
| 793 | friend |
| 794 | basic_ostream<charT, traits>& |
| 795 | operator<<(basic_ostream<charT, traits>& os, |
| 796 | const negative_binomial_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 797 | |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 798 | template <class charT, class traits> |
| 799 | friend |
| 800 | basic_istream<charT, traits>& |
| 801 | operator>>(basic_istream<charT, traits>& is, |
| 802 | negative_binomial_distribution& x); |
| 803 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 804 | |
| 805 | template<class IntType = int> |
Howard Hinnant | 24a5f2a | 2010-05-14 21:38:54 +0000 | [diff] [blame] | 806 | class poisson_distribution |
| 807 | { |
| 808 | public: |
| 809 | // types |
| 810 | typedef IntType result_type; |
| 811 | |
| 812 | class param_type |
| 813 | { |
| 814 | public: |
| 815 | typedef poisson_distribution distribution_type; |
| 816 | |
| 817 | explicit param_type(double mean = 1.0); |
| 818 | |
| 819 | double mean() const; |
| 820 | |
| 821 | friend bool operator==(const param_type& x, const param_type& y); |
| 822 | friend bool operator!=(const param_type& x, const param_type& y); |
| 823 | }; |
| 824 | |
| 825 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 826 | explicit poisson_distribution(double mean = 1.0); // before C++20 |
| 827 | poisson_distribution() : poisson_distribution(1.0) {} // C++20 |
| 828 | explicit poisson_distribution(double mean); // C++20 |
Howard Hinnant | 24a5f2a | 2010-05-14 21:38:54 +0000 | [diff] [blame] | 829 | explicit poisson_distribution(const param_type& parm); |
| 830 | void reset(); |
| 831 | |
| 832 | // generating functions |
| 833 | template<class URNG> result_type operator()(URNG& g); |
| 834 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 835 | |
| 836 | // property functions |
| 837 | double mean() const; |
| 838 | |
| 839 | param_type param() const; |
| 840 | void param(const param_type& parm); |
| 841 | |
| 842 | result_type min() const; |
| 843 | result_type max() const; |
| 844 | |
| 845 | friend bool operator==(const poisson_distribution& x, |
| 846 | const poisson_distribution& y); |
| 847 | friend bool operator!=(const poisson_distribution& x, |
| 848 | const poisson_distribution& y); |
| 849 | |
| 850 | template <class charT, class traits> |
| 851 | friend |
| 852 | basic_ostream<charT, traits>& |
| 853 | operator<<(basic_ostream<charT, traits>& os, |
| 854 | const poisson_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 855 | |
Howard Hinnant | 24a5f2a | 2010-05-14 21:38:54 +0000 | [diff] [blame] | 856 | template <class charT, class traits> |
| 857 | friend |
| 858 | basic_istream<charT, traits>& |
| 859 | operator>>(basic_istream<charT, traits>& is, |
| 860 | poisson_distribution& x); |
| 861 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 862 | |
| 863 | template<class RealType = double> |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 864 | class exponential_distribution |
| 865 | { |
| 866 | public: |
| 867 | // types |
| 868 | typedef RealType result_type; |
| 869 | |
| 870 | class param_type |
| 871 | { |
| 872 | public: |
| 873 | typedef exponential_distribution distribution_type; |
| 874 | |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 875 | explicit param_type(result_type lambda = 1.0); |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 876 | |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 877 | result_type lambda() const; |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 878 | |
| 879 | friend bool operator==(const param_type& x, const param_type& y); |
| 880 | friend bool operator!=(const param_type& x, const param_type& y); |
| 881 | }; |
| 882 | |
| 883 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 884 | explicit exponential_distribution(RealType lambda = 1.0); // before C++20 |
| 885 | exponential_distribution() : exponential_distribution(1.0) {} // C++20 |
| 886 | explicit exponential_distribution(RealType lambda); // C++20 |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 887 | explicit exponential_distribution(const param_type& parm); |
| 888 | void reset(); |
| 889 | |
| 890 | // generating functions |
| 891 | template<class URNG> result_type operator()(URNG& g); |
| 892 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 893 | |
| 894 | // property functions |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 895 | result_type lambda() const; |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 896 | |
| 897 | param_type param() const; |
| 898 | void param(const param_type& parm); |
| 899 | |
| 900 | result_type min() const; |
| 901 | result_type max() const; |
| 902 | |
| 903 | friend bool operator==(const exponential_distribution& x, |
| 904 | const exponential_distribution& y); |
| 905 | friend bool operator!=(const exponential_distribution& x, |
| 906 | const exponential_distribution& y); |
| 907 | |
| 908 | template <class charT, class traits> |
| 909 | friend |
| 910 | basic_ostream<charT, traits>& |
| 911 | operator<<(basic_ostream<charT, traits>& os, |
| 912 | const exponential_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 913 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 914 | template <class charT, class traits> |
| 915 | friend |
| 916 | basic_istream<charT, traits>& |
| 917 | operator>>(basic_istream<charT, traits>& is, |
| 918 | exponential_distribution& x); |
| 919 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 920 | |
| 921 | template<class RealType = double> |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 922 | class gamma_distribution |
| 923 | { |
| 924 | public: |
| 925 | // types |
| 926 | typedef RealType result_type; |
| 927 | |
| 928 | class param_type |
| 929 | { |
| 930 | public: |
| 931 | typedef gamma_distribution distribution_type; |
| 932 | |
| 933 | explicit param_type(result_type alpha = 1, result_type beta = 1); |
| 934 | |
| 935 | result_type alpha() const; |
| 936 | result_type beta() const; |
| 937 | |
| 938 | friend bool operator==(const param_type& x, const param_type& y); |
| 939 | friend bool operator!=(const param_type& x, const param_type& y); |
| 940 | }; |
| 941 | |
| 942 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 943 | explicit gamma_distribution(RealType alpha = 0.0, RealType beta = 1.0); // before C++20 |
| 944 | gamma_distribution() : gamma_distribution(0.0) {} // C++20 |
| 945 | explicit gamma_distribution(RealType alpha, RealType beta = 1.0); // C++20 |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 946 | explicit gamma_distribution(const param_type& parm); |
| 947 | void reset(); |
| 948 | |
| 949 | // generating functions |
| 950 | template<class URNG> result_type operator()(URNG& g); |
| 951 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 952 | |
| 953 | // property functions |
| 954 | result_type alpha() const; |
| 955 | result_type beta() const; |
| 956 | |
| 957 | param_type param() const; |
| 958 | void param(const param_type& parm); |
| 959 | |
| 960 | result_type min() const; |
| 961 | result_type max() const; |
| 962 | |
| 963 | friend bool operator==(const gamma_distribution& x, |
| 964 | const gamma_distribution& y); |
| 965 | friend bool operator!=(const gamma_distribution& x, |
| 966 | const gamma_distribution& y); |
| 967 | |
| 968 | template <class charT, class traits> |
| 969 | friend |
| 970 | basic_ostream<charT, traits>& |
| 971 | operator<<(basic_ostream<charT, traits>& os, |
| 972 | const gamma_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 973 | |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 974 | template <class charT, class traits> |
| 975 | friend |
| 976 | basic_istream<charT, traits>& |
| 977 | operator>>(basic_istream<charT, traits>& is, |
| 978 | gamma_distribution& x); |
| 979 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 980 | |
| 981 | template<class RealType = double> |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 982 | class weibull_distribution |
| 983 | { |
| 984 | public: |
| 985 | // types |
| 986 | typedef RealType result_type; |
| 987 | |
| 988 | class param_type |
| 989 | { |
| 990 | public: |
| 991 | typedef weibull_distribution distribution_type; |
| 992 | |
| 993 | explicit param_type(result_type alpha = 1, result_type beta = 1); |
| 994 | |
| 995 | result_type a() const; |
| 996 | result_type b() const; |
| 997 | |
| 998 | friend bool operator==(const param_type& x, const param_type& y); |
| 999 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1000 | }; |
| 1001 | |
| 1002 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1003 | explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0); // before C++20 |
| 1004 | weibull_distribution() : weibull_distribution(1.0) {} // C++20 |
| 1005 | explicit weibull_distribution(RealType a, RealType b = 1.0); // C++20 |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 1006 | explicit weibull_distribution(const param_type& parm); |
| 1007 | void reset(); |
| 1008 | |
| 1009 | // generating functions |
| 1010 | template<class URNG> result_type operator()(URNG& g); |
| 1011 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1012 | |
| 1013 | // property functions |
| 1014 | result_type a() const; |
| 1015 | result_type b() const; |
| 1016 | |
| 1017 | param_type param() const; |
| 1018 | void param(const param_type& parm); |
| 1019 | |
| 1020 | result_type min() const; |
| 1021 | result_type max() const; |
| 1022 | |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 1023 | friend bool operator==(const weibull_distribution& x, |
| 1024 | const weibull_distribution& y); |
| 1025 | friend bool operator!=(const weibull_distribution& x, |
| 1026 | const weibull_distribution& y); |
| 1027 | |
| 1028 | template <class charT, class traits> |
| 1029 | friend |
| 1030 | basic_ostream<charT, traits>& |
| 1031 | operator<<(basic_ostream<charT, traits>& os, |
| 1032 | const weibull_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1033 | |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 1034 | template <class charT, class traits> |
| 1035 | friend |
| 1036 | basic_istream<charT, traits>& |
| 1037 | operator>>(basic_istream<charT, traits>& is, |
| 1038 | weibull_distribution& x); |
| 1039 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1040 | |
| 1041 | template<class RealType = double> |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 1042 | class extreme_value_distribution |
| 1043 | { |
| 1044 | public: |
| 1045 | // types |
| 1046 | typedef RealType result_type; |
| 1047 | |
| 1048 | class param_type |
| 1049 | { |
| 1050 | public: |
| 1051 | typedef extreme_value_distribution distribution_type; |
| 1052 | |
| 1053 | explicit param_type(result_type a = 0, result_type b = 1); |
| 1054 | |
| 1055 | result_type a() const; |
| 1056 | result_type b() const; |
| 1057 | |
| 1058 | friend bool operator==(const param_type& x, const param_type& y); |
| 1059 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1060 | }; |
| 1061 | |
| 1062 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1063 | explicit extreme_value_distribution(RealType a = 0.0, RealType b = 1.0); // before C++20 |
| 1064 | extreme_value_distribution() : extreme_value_distribution(0.0) {} // C++20 |
| 1065 | explicit extreme_value_distribution(RealType a, RealType b = 1.0); // C++20 |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 1066 | explicit extreme_value_distribution(const param_type& parm); |
| 1067 | void reset(); |
| 1068 | |
| 1069 | // generating functions |
| 1070 | template<class URNG> result_type operator()(URNG& g); |
| 1071 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1072 | |
| 1073 | // property functions |
| 1074 | result_type a() const; |
| 1075 | result_type b() const; |
| 1076 | |
| 1077 | param_type param() const; |
| 1078 | void param(const param_type& parm); |
| 1079 | |
| 1080 | result_type min() const; |
| 1081 | result_type max() const; |
| 1082 | |
| 1083 | friend bool operator==(const extreme_value_distribution& x, |
| 1084 | const extreme_value_distribution& y); |
| 1085 | friend bool operator!=(const extreme_value_distribution& x, |
| 1086 | const extreme_value_distribution& y); |
| 1087 | |
| 1088 | template <class charT, class traits> |
| 1089 | friend |
| 1090 | basic_ostream<charT, traits>& |
| 1091 | operator<<(basic_ostream<charT, traits>& os, |
| 1092 | const extreme_value_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1093 | |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 1094 | template <class charT, class traits> |
| 1095 | friend |
| 1096 | basic_istream<charT, traits>& |
| 1097 | operator>>(basic_istream<charT, traits>& is, |
| 1098 | extreme_value_distribution& x); |
| 1099 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1100 | |
| 1101 | template<class RealType = double> |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 1102 | class normal_distribution |
| 1103 | { |
| 1104 | public: |
| 1105 | // types |
| 1106 | typedef RealType result_type; |
| 1107 | |
| 1108 | class param_type |
| 1109 | { |
| 1110 | public: |
| 1111 | typedef normal_distribution distribution_type; |
| 1112 | |
| 1113 | explicit param_type(result_type mean = 0, result_type stddev = 1); |
| 1114 | |
| 1115 | result_type mean() const; |
| 1116 | result_type stddev() const; |
| 1117 | |
| 1118 | friend bool operator==(const param_type& x, const param_type& y); |
| 1119 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1120 | }; |
| 1121 | |
| 1122 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1123 | explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0); // before C++20 |
| 1124 | normal_distribution() : normal_distribution(0.0) {} // C++20 |
| 1125 | explicit normal_distribution(RealType mean, RealType stddev = 1.0); // C++20 |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 1126 | explicit normal_distribution(const param_type& parm); |
| 1127 | void reset(); |
| 1128 | |
| 1129 | // generating functions |
| 1130 | template<class URNG> result_type operator()(URNG& g); |
| 1131 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1132 | |
| 1133 | // property functions |
| 1134 | result_type mean() const; |
| 1135 | result_type stddev() const; |
| 1136 | |
| 1137 | param_type param() const; |
| 1138 | void param(const param_type& parm); |
| 1139 | |
| 1140 | result_type min() const; |
| 1141 | result_type max() const; |
| 1142 | |
| 1143 | friend bool operator==(const normal_distribution& x, |
| 1144 | const normal_distribution& y); |
| 1145 | friend bool operator!=(const normal_distribution& x, |
| 1146 | const normal_distribution& y); |
| 1147 | |
| 1148 | template <class charT, class traits> |
| 1149 | friend |
| 1150 | basic_ostream<charT, traits>& |
| 1151 | operator<<(basic_ostream<charT, traits>& os, |
| 1152 | const normal_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1153 | |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 1154 | template <class charT, class traits> |
| 1155 | friend |
| 1156 | basic_istream<charT, traits>& |
| 1157 | operator>>(basic_istream<charT, traits>& is, |
| 1158 | normal_distribution& x); |
| 1159 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1160 | |
| 1161 | template<class RealType = double> |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 1162 | class lognormal_distribution |
| 1163 | { |
| 1164 | public: |
| 1165 | // types |
| 1166 | typedef RealType result_type; |
| 1167 | |
| 1168 | class param_type |
| 1169 | { |
| 1170 | public: |
| 1171 | typedef lognormal_distribution distribution_type; |
| 1172 | |
| 1173 | explicit param_type(result_type m = 0, result_type s = 1); |
| 1174 | |
| 1175 | result_type m() const; |
| 1176 | result_type s() const; |
| 1177 | |
| 1178 | friend bool operator==(const param_type& x, const param_type& y); |
| 1179 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1180 | }; |
| 1181 | |
| 1182 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1183 | explicit lognormal_distribution(RealType mean = 0.0, RealType stddev = 1.0); // before C++20 |
| 1184 | lognormal_distribution() : lognormal_distribution(0.0) {} // C++20 |
| 1185 | explicit lognormal_distribution(RealType mean, RealType stddev = 1.0); // C++20 |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 1186 | explicit lognormal_distribution(const param_type& parm); |
| 1187 | void reset(); |
| 1188 | |
| 1189 | // generating functions |
| 1190 | template<class URNG> result_type operator()(URNG& g); |
| 1191 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1192 | |
| 1193 | // property functions |
| 1194 | result_type m() const; |
| 1195 | result_type s() const; |
| 1196 | |
| 1197 | param_type param() const; |
| 1198 | void param(const param_type& parm); |
| 1199 | |
| 1200 | result_type min() const; |
| 1201 | result_type max() const; |
| 1202 | |
| 1203 | friend bool operator==(const lognormal_distribution& x, |
| 1204 | const lognormal_distribution& y); |
| 1205 | friend bool operator!=(const lognormal_distribution& x, |
| 1206 | const lognormal_distribution& y); |
| 1207 | |
| 1208 | template <class charT, class traits> |
| 1209 | friend |
| 1210 | basic_ostream<charT, traits>& |
| 1211 | operator<<(basic_ostream<charT, traits>& os, |
| 1212 | const lognormal_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1213 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 1214 | template <class charT, class traits> |
| 1215 | friend |
| 1216 | basic_istream<charT, traits>& |
| 1217 | operator>>(basic_istream<charT, traits>& is, |
| 1218 | lognormal_distribution& x); |
| 1219 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1220 | |
| 1221 | template<class RealType = double> |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1222 | class chi_squared_distribution |
| 1223 | { |
| 1224 | public: |
| 1225 | // types |
| 1226 | typedef RealType result_type; |
| 1227 | |
| 1228 | class param_type |
| 1229 | { |
| 1230 | public: |
| 1231 | typedef chi_squared_distribution distribution_type; |
| 1232 | |
| 1233 | explicit param_type(result_type n = 1); |
| 1234 | |
| 1235 | result_type n() const; |
| 1236 | |
| 1237 | friend bool operator==(const param_type& x, const param_type& y); |
| 1238 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1239 | }; |
| 1240 | |
| 1241 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1242 | explicit chi_squared_distribution(RealType n = 1.0); // before C++20 |
| 1243 | chi_squared_distribution() : chi_squared_distribution(1.0) {} // C++20 |
| 1244 | explicit chi_squared_distribution(RealType n); // C++20 |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1245 | explicit chi_squared_distribution(const param_type& parm); |
| 1246 | void reset(); |
| 1247 | |
| 1248 | // generating functions |
| 1249 | template<class URNG> result_type operator()(URNG& g); |
| 1250 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1251 | |
| 1252 | // property functions |
| 1253 | result_type n() const; |
| 1254 | |
| 1255 | param_type param() const; |
| 1256 | void param(const param_type& parm); |
| 1257 | |
| 1258 | result_type min() const; |
| 1259 | result_type max() const; |
| 1260 | |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1261 | friend bool operator==(const chi_squared_distribution& x, |
| 1262 | const chi_squared_distribution& y); |
| 1263 | friend bool operator!=(const chi_squared_distribution& x, |
| 1264 | const chi_squared_distribution& y); |
| 1265 | |
| 1266 | template <class charT, class traits> |
| 1267 | friend |
| 1268 | basic_ostream<charT, traits>& |
| 1269 | operator<<(basic_ostream<charT, traits>& os, |
| 1270 | const chi_squared_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1271 | |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1272 | template <class charT, class traits> |
| 1273 | friend |
| 1274 | basic_istream<charT, traits>& |
| 1275 | operator>>(basic_istream<charT, traits>& is, |
| 1276 | chi_squared_distribution& x); |
| 1277 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1278 | |
| 1279 | template<class RealType = double> |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 1280 | class cauchy_distribution |
| 1281 | { |
| 1282 | public: |
| 1283 | // types |
| 1284 | typedef RealType result_type; |
| 1285 | |
| 1286 | class param_type |
| 1287 | { |
| 1288 | public: |
| 1289 | typedef cauchy_distribution distribution_type; |
| 1290 | |
| 1291 | explicit param_type(result_type a = 0, result_type b = 1); |
| 1292 | |
| 1293 | result_type a() const; |
| 1294 | result_type b() const; |
| 1295 | |
| 1296 | friend bool operator==(const param_type& x, const param_type& y); |
| 1297 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1298 | }; |
| 1299 | |
| 1300 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1301 | explicit cauchy_distribution(RealType a = 0.0, RealType b = 1.0); // before C++20 |
| 1302 | cauchy_distribution() : cauchy_distribution(0.0) {} // C++20 |
| 1303 | explicit cauchy_distribution(RealType a, RealType b = 1.0); // C++20 |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 1304 | explicit cauchy_distribution(const param_type& parm); |
| 1305 | void reset(); |
| 1306 | |
| 1307 | // generating functions |
| 1308 | template<class URNG> result_type operator()(URNG& g); |
| 1309 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1310 | |
| 1311 | // property functions |
| 1312 | result_type a() const; |
| 1313 | result_type b() const; |
| 1314 | |
| 1315 | param_type param() const; |
| 1316 | void param(const param_type& parm); |
| 1317 | |
| 1318 | result_type min() const; |
| 1319 | result_type max() const; |
| 1320 | |
| 1321 | friend bool operator==(const cauchy_distribution& x, |
| 1322 | const cauchy_distribution& y); |
| 1323 | friend bool operator!=(const cauchy_distribution& x, |
| 1324 | const cauchy_distribution& y); |
| 1325 | |
| 1326 | template <class charT, class traits> |
| 1327 | friend |
| 1328 | basic_ostream<charT, traits>& |
| 1329 | operator<<(basic_ostream<charT, traits>& os, |
| 1330 | const cauchy_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1331 | |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 1332 | template <class charT, class traits> |
| 1333 | friend |
| 1334 | basic_istream<charT, traits>& |
| 1335 | operator>>(basic_istream<charT, traits>& is, |
| 1336 | cauchy_distribution& x); |
| 1337 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1338 | |
| 1339 | template<class RealType = double> |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1340 | class fisher_f_distribution |
| 1341 | { |
| 1342 | public: |
| 1343 | // types |
| 1344 | typedef RealType result_type; |
| 1345 | |
| 1346 | class param_type |
| 1347 | { |
| 1348 | public: |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1349 | typedef fisher_f_distribution distribution_type; |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1350 | |
| 1351 | explicit param_type(result_type m = 1, result_type n = 1); |
| 1352 | |
| 1353 | result_type m() const; |
| 1354 | result_type n() const; |
| 1355 | |
| 1356 | friend bool operator==(const param_type& x, const param_type& y); |
| 1357 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1358 | }; |
| 1359 | |
| 1360 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1361 | explicit fisher_f_distribution(RealType m = 1.0, RealType n = 1.0); // before C++20 |
| 1362 | fisher_f_distribution() : fisher_f_distribution(1.0) {} // C++20 |
| 1363 | explicit fisher_f_distribution(RealType m, RealType n = 1.0); // C++20 |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1364 | explicit fisher_f_distribution(const param_type& parm); |
| 1365 | void reset(); |
| 1366 | |
| 1367 | // generating functions |
| 1368 | template<class URNG> result_type operator()(URNG& g); |
| 1369 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1370 | |
| 1371 | // property functions |
| 1372 | result_type m() const; |
| 1373 | result_type n() const; |
| 1374 | |
| 1375 | param_type param() const; |
| 1376 | void param(const param_type& parm); |
| 1377 | |
| 1378 | result_type min() const; |
| 1379 | result_type max() const; |
| 1380 | |
| 1381 | friend bool operator==(const fisher_f_distribution& x, |
| 1382 | const fisher_f_distribution& y); |
| 1383 | friend bool operator!=(const fisher_f_distribution& x, |
| 1384 | const fisher_f_distribution& y); |
| 1385 | |
| 1386 | template <class charT, class traits> |
| 1387 | friend |
| 1388 | basic_ostream<charT, traits>& |
| 1389 | operator<<(basic_ostream<charT, traits>& os, |
| 1390 | const fisher_f_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1391 | |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1392 | template <class charT, class traits> |
| 1393 | friend |
| 1394 | basic_istream<charT, traits>& |
| 1395 | operator>>(basic_istream<charT, traits>& is, |
| 1396 | fisher_f_distribution& x); |
| 1397 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1398 | |
| 1399 | template<class RealType = double> |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1400 | class student_t_distribution |
| 1401 | { |
| 1402 | public: |
| 1403 | // types |
| 1404 | typedef RealType result_type; |
| 1405 | |
| 1406 | class param_type |
| 1407 | { |
| 1408 | public: |
| 1409 | typedef student_t_distribution distribution_type; |
| 1410 | |
| 1411 | explicit param_type(result_type n = 1); |
| 1412 | |
| 1413 | result_type n() const; |
| 1414 | |
| 1415 | friend bool operator==(const param_type& x, const param_type& y); |
| 1416 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1417 | }; |
| 1418 | |
| 1419 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1420 | explicit student_t_distribution(RealType n = 1.0); // before C++20 |
| 1421 | student_t_distribution() : student_t_distribution(1.0) {} // C++20 |
| 1422 | explicit student_t_distribution(RealType n); // C++20 |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1423 | explicit student_t_distribution(const param_type& parm); |
| 1424 | void reset(); |
| 1425 | |
| 1426 | // generating functions |
| 1427 | template<class URNG> result_type operator()(URNG& g); |
| 1428 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1429 | |
| 1430 | // property functions |
| 1431 | result_type n() const; |
| 1432 | |
| 1433 | param_type param() const; |
| 1434 | void param(const param_type& parm); |
| 1435 | |
| 1436 | result_type min() const; |
| 1437 | result_type max() const; |
| 1438 | |
| 1439 | friend bool operator==(const student_t_distribution& x, |
| 1440 | const student_t_distribution& y); |
| 1441 | friend bool operator!=(const student_t_distribution& x, |
| 1442 | const student_t_distribution& y); |
| 1443 | |
| 1444 | template <class charT, class traits> |
| 1445 | friend |
| 1446 | basic_ostream<charT, traits>& |
| 1447 | operator<<(basic_ostream<charT, traits>& os, |
| 1448 | const student_t_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1449 | |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1450 | template <class charT, class traits> |
| 1451 | friend |
| 1452 | basic_istream<charT, traits>& |
| 1453 | operator>>(basic_istream<charT, traits>& is, |
| 1454 | student_t_distribution& x); |
| 1455 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1456 | |
| 1457 | template<class IntType = int> |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1458 | class discrete_distribution |
| 1459 | { |
| 1460 | public: |
| 1461 | // types |
| 1462 | typedef IntType result_type; |
| 1463 | |
| 1464 | class param_type |
| 1465 | { |
| 1466 | public: |
| 1467 | typedef discrete_distribution distribution_type; |
| 1468 | |
| 1469 | param_type(); |
| 1470 | template<class InputIterator> |
| 1471 | param_type(InputIterator firstW, InputIterator lastW); |
| 1472 | param_type(initializer_list<double> wl); |
| 1473 | template<class UnaryOperation> |
| 1474 | param_type(size_t nw, double xmin, double xmax, UnaryOperation fw); |
| 1475 | |
| 1476 | vector<double> probabilities() const; |
| 1477 | |
| 1478 | friend bool operator==(const param_type& x, const param_type& y); |
| 1479 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1480 | }; |
| 1481 | |
| 1482 | // constructor and reset functions |
| 1483 | discrete_distribution(); |
| 1484 | template<class InputIterator> |
| 1485 | discrete_distribution(InputIterator firstW, InputIterator lastW); |
| 1486 | discrete_distribution(initializer_list<double> wl); |
| 1487 | template<class UnaryOperation> |
| 1488 | discrete_distribution(size_t nw, double xmin, double xmax, |
| 1489 | UnaryOperation fw); |
| 1490 | explicit discrete_distribution(const param_type& parm); |
| 1491 | void reset(); |
| 1492 | |
| 1493 | // generating functions |
| 1494 | template<class URNG> result_type operator()(URNG& g); |
| 1495 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1496 | |
| 1497 | // property functions |
| 1498 | vector<double> probabilities() const; |
| 1499 | |
| 1500 | param_type param() const; |
| 1501 | void param(const param_type& parm); |
| 1502 | |
| 1503 | result_type min() const; |
| 1504 | result_type max() const; |
| 1505 | |
| 1506 | friend bool operator==(const discrete_distribution& x, |
| 1507 | const discrete_distribution& y); |
| 1508 | friend bool operator!=(const discrete_distribution& x, |
| 1509 | const discrete_distribution& y); |
| 1510 | |
| 1511 | template <class charT, class traits> |
| 1512 | friend |
| 1513 | basic_ostream<charT, traits>& |
| 1514 | operator<<(basic_ostream<charT, traits>& os, |
| 1515 | const discrete_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1516 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1517 | template <class charT, class traits> |
| 1518 | friend |
| 1519 | basic_istream<charT, traits>& |
| 1520 | operator>>(basic_istream<charT, traits>& is, |
| 1521 | discrete_distribution& x); |
| 1522 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1523 | |
| 1524 | template<class RealType = double> |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1525 | class piecewise_constant_distribution |
| 1526 | { |
| 1527 | // types |
| 1528 | typedef RealType result_type; |
| 1529 | |
| 1530 | class param_type |
| 1531 | { |
| 1532 | public: |
| 1533 | typedef piecewise_constant_distribution distribution_type; |
| 1534 | |
| 1535 | param_type(); |
| 1536 | template<class InputIteratorB, class InputIteratorW> |
| 1537 | param_type(InputIteratorB firstB, InputIteratorB lastB, |
| 1538 | InputIteratorW firstW); |
| 1539 | template<class UnaryOperation> |
| 1540 | param_type(initializer_list<result_type> bl, UnaryOperation fw); |
| 1541 | template<class UnaryOperation> |
| 1542 | param_type(size_t nw, result_type xmin, result_type xmax, |
| 1543 | UnaryOperation fw); |
| 1544 | |
| 1545 | vector<result_type> intervals() const; |
Howard Hinnant | a753356 | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1546 | vector<result_type> densities() const; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1547 | |
| 1548 | friend bool operator==(const param_type& x, const param_type& y); |
| 1549 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1550 | }; |
| 1551 | |
| 1552 | // constructor and reset functions |
| 1553 | piecewise_constant_distribution(); |
| 1554 | template<class InputIteratorB, class InputIteratorW> |
| 1555 | piecewise_constant_distribution(InputIteratorB firstB, |
| 1556 | InputIteratorB lastB, |
| 1557 | InputIteratorW firstW); |
| 1558 | template<class UnaryOperation> |
| 1559 | piecewise_constant_distribution(initializer_list<result_type> bl, |
| 1560 | UnaryOperation fw); |
| 1561 | template<class UnaryOperation> |
| 1562 | piecewise_constant_distribution(size_t nw, result_type xmin, |
| 1563 | result_type xmax, UnaryOperation fw); |
| 1564 | explicit piecewise_constant_distribution(const param_type& parm); |
| 1565 | void reset(); |
| 1566 | |
| 1567 | // generating functions |
| 1568 | template<class URNG> result_type operator()(URNG& g); |
| 1569 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1570 | |
| 1571 | // property functions |
| 1572 | vector<result_type> intervals() const; |
Howard Hinnant | a753356 | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1573 | vector<result_type> densities() const; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1574 | |
| 1575 | param_type param() const; |
| 1576 | void param(const param_type& parm); |
| 1577 | |
| 1578 | result_type min() const; |
| 1579 | result_type max() const; |
| 1580 | |
| 1581 | friend bool operator==(const piecewise_constant_distribution& x, |
| 1582 | const piecewise_constant_distribution& y); |
| 1583 | friend bool operator!=(const piecewise_constant_distribution& x, |
| 1584 | const piecewise_constant_distribution& y); |
| 1585 | |
| 1586 | template <class charT, class traits> |
| 1587 | friend |
| 1588 | basic_ostream<charT, traits>& |
| 1589 | operator<<(basic_ostream<charT, traits>& os, |
| 1590 | const piecewise_constant_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1591 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1592 | template <class charT, class traits> |
| 1593 | friend |
| 1594 | basic_istream<charT, traits>& |
| 1595 | operator>>(basic_istream<charT, traits>& is, |
| 1596 | piecewise_constant_distribution& x); |
| 1597 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1598 | |
| 1599 | template<class RealType = double> |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1600 | class piecewise_linear_distribution |
| 1601 | { |
| 1602 | // types |
| 1603 | typedef RealType result_type; |
| 1604 | |
| 1605 | class param_type |
| 1606 | { |
| 1607 | public: |
| 1608 | typedef piecewise_linear_distribution distribution_type; |
| 1609 | |
| 1610 | param_type(); |
| 1611 | template<class InputIteratorB, class InputIteratorW> |
| 1612 | param_type(InputIteratorB firstB, InputIteratorB lastB, |
| 1613 | InputIteratorW firstW); |
| 1614 | template<class UnaryOperation> |
| 1615 | param_type(initializer_list<result_type> bl, UnaryOperation fw); |
| 1616 | template<class UnaryOperation> |
| 1617 | param_type(size_t nw, result_type xmin, result_type xmax, |
| 1618 | UnaryOperation fw); |
| 1619 | |
| 1620 | vector<result_type> intervals() const; |
Howard Hinnant | a753356 | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1621 | vector<result_type> densities() const; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1622 | |
| 1623 | friend bool operator==(const param_type& x, const param_type& y); |
| 1624 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1625 | }; |
| 1626 | |
| 1627 | // constructor and reset functions |
| 1628 | piecewise_linear_distribution(); |
| 1629 | template<class InputIteratorB, class InputIteratorW> |
| 1630 | piecewise_linear_distribution(InputIteratorB firstB, |
| 1631 | InputIteratorB lastB, |
| 1632 | InputIteratorW firstW); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1633 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1634 | template<class UnaryOperation> |
| 1635 | piecewise_linear_distribution(initializer_list<result_type> bl, |
| 1636 | UnaryOperation fw); |
| 1637 | |
| 1638 | template<class UnaryOperation> |
| 1639 | piecewise_linear_distribution(size_t nw, result_type xmin, |
| 1640 | result_type xmax, UnaryOperation fw); |
| 1641 | |
| 1642 | explicit piecewise_linear_distribution(const param_type& parm); |
| 1643 | void reset(); |
| 1644 | |
| 1645 | // generating functions |
| 1646 | template<class URNG> result_type operator()(URNG& g); |
| 1647 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1648 | |
| 1649 | // property functions |
| 1650 | vector<result_type> intervals() const; |
Howard Hinnant | a753356 | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1651 | vector<result_type> densities() const; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1652 | |
| 1653 | param_type param() const; |
| 1654 | void param(const param_type& parm); |
| 1655 | |
| 1656 | result_type min() const; |
| 1657 | result_type max() const; |
| 1658 | |
| 1659 | friend bool operator==(const piecewise_linear_distribution& x, |
| 1660 | const piecewise_linear_distribution& y); |
| 1661 | friend bool operator!=(const piecewise_linear_distribution& x, |
| 1662 | const piecewise_linear_distribution& y); |
| 1663 | |
| 1664 | template <class charT, class traits> |
| 1665 | friend |
| 1666 | basic_ostream<charT, traits>& |
| 1667 | operator<<(basic_ostream<charT, traits>& os, |
| 1668 | const piecewise_linear_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1669 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1670 | template <class charT, class traits> |
| 1671 | friend |
| 1672 | basic_istream<charT, traits>& |
| 1673 | operator>>(basic_istream<charT, traits>& is, |
| 1674 | piecewise_linear_distribution& x); |
| 1675 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1676 | |
| 1677 | } // std |
| 1678 | */ |
| 1679 | |
| 1680 | #include <__config> |
| 1681 | #include <cstddef> |
Eric Fiselier | 90adc20 | 2015-01-23 22:22:36 +0000 | [diff] [blame] | 1682 | #include <cstdint> |
| 1683 | #include <cmath> |
Christopher Di Bella | 6807407 | 2021-02-17 02:52:17 +0000 | [diff] [blame^] | 1684 | #include <concepts> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1685 | #include <type_traits> |
| 1686 | #include <initializer_list> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1687 | #include <limits> |
| 1688 | #include <algorithm> |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1689 | #include <numeric> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1690 | #include <vector> |
| 1691 | #include <string> |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 1692 | #include <iosfwd> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1693 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 1694 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1695 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 1696 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1697 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 1698 | _LIBCPP_PUSH_MACROS |
| 1699 | #include <__undef_macros> |
| 1700 | |
| 1701 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1702 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 1703 | |
Christopher Di Bella | 6807407 | 2021-02-17 02:52:17 +0000 | [diff] [blame^] | 1704 | #if _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L |
| 1705 | |
| 1706 | // [rand.req.urng] |
| 1707 | template<class _Gen> |
| 1708 | concept uniform_random_bit_generator = |
| 1709 | invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>> && |
| 1710 | requires { |
| 1711 | { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>; |
| 1712 | { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>; |
| 1713 | requires bool_constant<(_Gen::min() < _Gen::max())>::value; |
| 1714 | }; |
| 1715 | |
| 1716 | #endif // _LIBCPP_STD_VER > 17 && defined(__cpp_concepts) && __cpp_concepts >= 201811L |
| 1717 | |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1718 | // __is_seed_sequence |
| 1719 | |
| 1720 | template <class _Sseq, class _Engine> |
| 1721 | struct __is_seed_sequence |
| 1722 | { |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1723 | static _LIBCPP_CONSTEXPR const bool value = |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1724 | !is_convertible<_Sseq, typename _Engine::result_type>::value && |
| 1725 | !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; |
| 1726 | }; |
| 1727 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1728 | // linear_congruential_engine |
| 1729 | |
| 1730 | template <unsigned long long __a, unsigned long long __c, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1731 | unsigned long long __m, unsigned long long _Mp, |
zoecarver | 68c3702 | 2020-11-10 18:23:22 -0800 | [diff] [blame] | 1732 | bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a), |
| 1733 | bool _OverflowOK = ((__m|__m-1) > __m), // m = 2^n |
| 1734 | bool _SchrageOK = (__a != 0 && __m != 0 && __m % __a <= __m / __a)> // r <= q |
| 1735 | struct __lce_alg_picker |
| 1736 | { |
| 1737 | static_assert(__a != 0 || __m != 0 || !_MightOverflow || _OverflowOK || _SchrageOK, |
| 1738 | "The current values of a, c, and m cannot generate a number " |
| 1739 | "within bounds of linear_congruential_engine."); |
| 1740 | |
| 1741 | static _LIBCPP_CONSTEXPR const bool __use_schrage = _MightOverflow && |
| 1742 | !_OverflowOK && |
| 1743 | _SchrageOK; |
| 1744 | }; |
| 1745 | |
| 1746 | template <unsigned long long __a, unsigned long long __c, |
| 1747 | unsigned long long __m, unsigned long long _Mp, |
| 1748 | bool _UseSchrage = __lce_alg_picker<__a, __c, __m, _Mp>::__use_schrage> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1749 | struct __lce_ta; |
| 1750 | |
| 1751 | // 64 |
| 1752 | |
| 1753 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> |
| 1754 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> |
| 1755 | { |
| 1756 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1757 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1758 | static result_type next(result_type __x) |
| 1759 | { |
| 1760 | // Schrage's algorithm |
| 1761 | const result_type __q = __m / __a; |
| 1762 | const result_type __r = __m % __a; |
| 1763 | const result_type __t0 = __a * (__x % __q); |
| 1764 | const result_type __t1 = __r * (__x / __q); |
| 1765 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1766 | __x += __c - (__x >= __m - __c) * __m; |
| 1767 | return __x; |
| 1768 | } |
| 1769 | }; |
| 1770 | |
| 1771 | template <unsigned long long __a, unsigned long long __m> |
| 1772 | struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> |
| 1773 | { |
| 1774 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1775 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1776 | static result_type next(result_type __x) |
| 1777 | { |
| 1778 | // Schrage's algorithm |
| 1779 | const result_type __q = __m / __a; |
| 1780 | const result_type __r = __m % __a; |
| 1781 | const result_type __t0 = __a * (__x % __q); |
| 1782 | const result_type __t1 = __r * (__x / __q); |
| 1783 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1784 | return __x; |
| 1785 | } |
| 1786 | }; |
| 1787 | |
| 1788 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> |
| 1789 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> |
| 1790 | { |
| 1791 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1793 | static result_type next(result_type __x) |
| 1794 | { |
| 1795 | return (__a * __x + __c) % __m; |
| 1796 | } |
| 1797 | }; |
| 1798 | |
| 1799 | template <unsigned long long __a, unsigned long long __c> |
| 1800 | struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> |
| 1801 | { |
| 1802 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1803 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1804 | static result_type next(result_type __x) |
| 1805 | { |
| 1806 | return __a * __x + __c; |
| 1807 | } |
| 1808 | }; |
| 1809 | |
| 1810 | // 32 |
| 1811 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1812 | template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> |
| 1813 | struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1814 | { |
| 1815 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1816 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1817 | static result_type next(result_type __x) |
| 1818 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1819 | const result_type __a = static_cast<result_type>(_Ap); |
| 1820 | const result_type __c = static_cast<result_type>(_Cp); |
| 1821 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1822 | // Schrage's algorithm |
| 1823 | const result_type __q = __m / __a; |
| 1824 | const result_type __r = __m % __a; |
| 1825 | const result_type __t0 = __a * (__x % __q); |
| 1826 | const result_type __t1 = __r * (__x / __q); |
| 1827 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1828 | __x += __c - (__x >= __m - __c) * __m; |
| 1829 | return __x; |
| 1830 | } |
| 1831 | }; |
| 1832 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1833 | template <unsigned long long _Ap, unsigned long long _Mp> |
| 1834 | struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1835 | { |
| 1836 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1837 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1838 | static result_type next(result_type __x) |
| 1839 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1840 | const result_type __a = static_cast<result_type>(_Ap); |
| 1841 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1842 | // Schrage's algorithm |
| 1843 | const result_type __q = __m / __a; |
| 1844 | const result_type __r = __m % __a; |
| 1845 | const result_type __t0 = __a * (__x % __q); |
| 1846 | const result_type __t1 = __r * (__x / __q); |
| 1847 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1848 | return __x; |
| 1849 | } |
| 1850 | }; |
| 1851 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1852 | template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> |
| 1853 | struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1854 | { |
| 1855 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1857 | static result_type next(result_type __x) |
| 1858 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1859 | const result_type __a = static_cast<result_type>(_Ap); |
| 1860 | const result_type __c = static_cast<result_type>(_Cp); |
| 1861 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1862 | return (__a * __x + __c) % __m; |
| 1863 | } |
| 1864 | }; |
| 1865 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1866 | template <unsigned long long _Ap, unsigned long long _Cp> |
| 1867 | struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1868 | { |
| 1869 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1870 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1871 | static result_type next(result_type __x) |
| 1872 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1873 | const result_type __a = static_cast<result_type>(_Ap); |
| 1874 | const result_type __c = static_cast<result_type>(_Cp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1875 | return __a * __x + __c; |
| 1876 | } |
| 1877 | }; |
| 1878 | |
| 1879 | // 16 |
| 1880 | |
| 1881 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> |
| 1882 | struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> |
| 1883 | { |
| 1884 | typedef unsigned short result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1885 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1886 | static result_type next(result_type __x) |
| 1887 | { |
| 1888 | return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); |
| 1889 | } |
| 1890 | }; |
| 1891 | |
| 1892 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1893 | class _LIBCPP_TEMPLATE_VIS linear_congruential_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1894 | |
| 1895 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1896 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1897 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1898 | basic_ostream<_CharT, _Traits>& |
| 1899 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1900 | const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1901 | |
| 1902 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1903 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1904 | basic_istream<_CharT, _Traits>& |
| 1905 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1906 | linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1907 | |
| 1908 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1909 | class _LIBCPP_TEMPLATE_VIS linear_congruential_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1910 | { |
| 1911 | public: |
| 1912 | // types |
| 1913 | typedef _UIntType result_type; |
| 1914 | |
Howard Hinnant | a741b24 | 2013-05-21 21:19:35 +0000 | [diff] [blame] | 1915 | private: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1916 | result_type __x_; |
| 1917 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1918 | static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1919 | |
| 1920 | static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); |
| 1921 | static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); |
zoecarver | 68c3702 | 2020-11-10 18:23:22 -0800 | [diff] [blame] | 1922 | static_assert(_VSTD::is_unsigned<_UIntType>::value, "_UIntType must be unsigned type"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1923 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1924 | static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; |
| 1925 | static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1926 | static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); |
| 1927 | |
| 1928 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1929 | static _LIBCPP_CONSTEXPR const result_type multiplier = __a; |
| 1930 | static _LIBCPP_CONSTEXPR const result_type increment = __c; |
| 1931 | static _LIBCPP_CONSTEXPR const result_type modulus = __m; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1932 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1933 | static _LIBCPP_CONSTEXPR result_type min() {return _Min;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1934 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1935 | static _LIBCPP_CONSTEXPR result_type max() {return _Max;} |
| 1936 | static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1937 | |
| 1938 | // constructors and seeding functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1939 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1940 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 1941 | linear_congruential_engine() : linear_congruential_engine(default_seed) {} |
| 1942 | _LIBCPP_INLINE_VISIBILITY |
| 1943 | explicit linear_congruential_engine(result_type __s) { seed(__s); } |
| 1944 | #else |
| 1945 | _LIBCPP_INLINE_VISIBILITY |
| 1946 | explicit linear_congruential_engine(result_type __s = default_seed) { |
| 1947 | seed(__s); |
| 1948 | } |
| 1949 | #endif |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1950 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1951 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1952 | explicit linear_congruential_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1953 | typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1954 | {seed(__q);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1955 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1956 | void seed(result_type __s = default_seed) |
| 1957 | {seed(integral_constant<bool, __m == 0>(), |
| 1958 | integral_constant<bool, __c == 0>(), __s);} |
| 1959 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1960 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1961 | typename enable_if |
| 1962 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1963 | __is_seed_sequence<_Sseq, linear_congruential_engine>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1964 | void |
| 1965 | >::type |
| 1966 | seed(_Sseq& __q) |
| 1967 | {__seed(__q, integral_constant<unsigned, |
| 1968 | 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 |
Howard Hinnant | a0c4f7c | 2013-05-21 21:05:12 +0000 | [diff] [blame] | 1969 | : (__m > 0x100000000ull))>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1970 | |
| 1971 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1972 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1973 | result_type operator()() |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1974 | {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1975 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1976 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 1977 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1978 | friend _LIBCPP_INLINE_VISIBILITY |
| 1979 | bool operator==(const linear_congruential_engine& __x, |
| 1980 | const linear_congruential_engine& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1981 | {return __x.__x_ == __y.__x_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1982 | friend _LIBCPP_INLINE_VISIBILITY |
| 1983 | bool operator!=(const linear_congruential_engine& __x, |
| 1984 | const linear_congruential_engine& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1985 | {return !(__x == __y);} |
| 1986 | |
| 1987 | private: |
| 1988 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1989 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1990 | void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1991 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1992 | void seed(true_type, false_type, result_type __s) {__x_ = __s;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1993 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1994 | void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? |
| 1995 | 1 : __s % __m;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1996 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1997 | void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} |
| 1998 | |
| 1999 | template<class _Sseq> |
| 2000 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 2001 | template<class _Sseq> |
| 2002 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 2003 | |
| 2004 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2005 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2006 | friend |
| 2007 | basic_ostream<_CharT, _Traits>& |
| 2008 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2009 | const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2010 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2011 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2012 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2013 | friend |
| 2014 | basic_istream<_CharT, _Traits>& |
| 2015 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2016 | linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2017 | }; |
| 2018 | |
| 2019 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2020 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 2021 | linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; |
| 2022 | |
| 2023 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 2024 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 2025 | linear_congruential_engine<_UIntType, __a, __c, __m>::increment; |
| 2026 | |
| 2027 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 2028 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 2029 | linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; |
| 2030 | |
| 2031 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 2032 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 2033 | linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; |
| 2034 | |
| 2035 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2036 | template<class _Sseq> |
| 2037 | void |
| 2038 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, |
| 2039 | integral_constant<unsigned, 1>) |
| 2040 | { |
| 2041 | const unsigned __k = 1; |
| 2042 | uint32_t __ar[__k+3]; |
| 2043 | __q.generate(__ar, __ar + __k + 3); |
| 2044 | result_type __s = static_cast<result_type>(__ar[3] % __m); |
| 2045 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; |
| 2046 | } |
| 2047 | |
| 2048 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 2049 | template<class _Sseq> |
| 2050 | void |
| 2051 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, |
| 2052 | integral_constant<unsigned, 2>) |
| 2053 | { |
| 2054 | const unsigned __k = 2; |
| 2055 | uint32_t __ar[__k+3]; |
| 2056 | __q.generate(__ar, __ar + __k + 3); |
| 2057 | result_type __s = static_cast<result_type>((__ar[3] + |
Howard Hinnant | a0c4f7c | 2013-05-21 21:05:12 +0000 | [diff] [blame] | 2058 | ((uint64_t)__ar[4] << 32)) % __m); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2059 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; |
| 2060 | } |
| 2061 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2062 | template <class _CharT, class _Traits, |
| 2063 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2064 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2065 | basic_ostream<_CharT, _Traits>& |
| 2066 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 2067 | const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) |
| 2068 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2069 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2070 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2071 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2072 | __os.fill(__os.widen(' ')); |
| 2073 | return __os << __x.__x_; |
| 2074 | } |
| 2075 | |
| 2076 | template <class _CharT, class _Traits, |
| 2077 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 2078 | basic_istream<_CharT, _Traits>& |
| 2079 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 2080 | linear_congruential_engine<_UIntType, __a, __c, __m>& __x) |
| 2081 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2082 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2083 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2084 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2085 | _UIntType __t; |
| 2086 | __is >> __t; |
| 2087 | if (!__is.fail()) |
| 2088 | __x.__x_ = __t; |
| 2089 | return __is; |
| 2090 | } |
| 2091 | |
| 2092 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> |
| 2093 | minstd_rand0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2094 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> |
| 2095 | minstd_rand; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 2096 | typedef minstd_rand default_random_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2097 | // mersenne_twister_engine |
| 2098 | |
| 2099 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2100 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2101 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2102 | class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2103 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2104 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2105 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2106 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2107 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2108 | operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2109 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2110 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2111 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2112 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2113 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2114 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2115 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 2116 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2117 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2118 | operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2119 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2120 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2121 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2122 | |
| 2123 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2124 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2125 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2126 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2127 | basic_ostream<_CharT, _Traits>& |
| 2128 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2129 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2130 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2131 | |
| 2132 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2133 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2134 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2135 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2136 | basic_istream<_CharT, _Traits>& |
| 2137 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2138 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2139 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2140 | |
| 2141 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2142 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2143 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2144 | class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2145 | { |
| 2146 | public: |
| 2147 | // types |
| 2148 | typedef _UIntType result_type; |
| 2149 | |
| 2150 | private: |
| 2151 | result_type __x_[__n]; |
| 2152 | size_t __i_; |
| 2153 | |
| 2154 | static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); |
| 2155 | static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2156 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2157 | static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); |
| 2158 | static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); |
| 2159 | static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); |
| 2160 | static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); |
| 2161 | static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); |
| 2162 | static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); |
| 2163 | static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); |
| 2164 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2165 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 2166 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 2167 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2168 | static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); |
| 2169 | static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2170 | static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2171 | static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2172 | static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2173 | static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2174 | |
| 2175 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2176 | static _LIBCPP_CONSTEXPR const size_t word_size = __w; |
| 2177 | static _LIBCPP_CONSTEXPR const size_t state_size = __n; |
| 2178 | static _LIBCPP_CONSTEXPR const size_t shift_size = __m; |
| 2179 | static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; |
| 2180 | static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; |
| 2181 | static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; |
| 2182 | static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; |
| 2183 | static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; |
| 2184 | static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; |
| 2185 | static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; |
| 2186 | static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; |
| 2187 | static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; |
| 2188 | static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2189 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2190 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2191 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2192 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
| 2193 | static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2194 | |
| 2195 | // constructors and seeding functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 2196 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2197 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 2198 | mersenne_twister_engine() : mersenne_twister_engine(default_seed) {} |
| 2199 | _LIBCPP_INLINE_VISIBILITY |
| 2200 | explicit mersenne_twister_engine(result_type __sd) { seed(__sd); } |
| 2201 | #else |
| 2202 | _LIBCPP_INLINE_VISIBILITY |
| 2203 | explicit mersenne_twister_engine(result_type __sd = default_seed) { |
| 2204 | seed(__sd); |
| 2205 | } |
| 2206 | #endif |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2207 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2208 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2209 | explicit mersenne_twister_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2210 | typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2211 | {seed(__q);} |
| 2212 | void seed(result_type __sd = default_seed); |
| 2213 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2214 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2215 | typename enable_if |
| 2216 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2217 | __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2218 | void |
| 2219 | >::type |
| 2220 | seed(_Sseq& __q) |
| 2221 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2222 | |
| 2223 | // generating functions |
| 2224 | result_type operator()(); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2225 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2226 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2227 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2228 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2229 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2230 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2231 | friend |
| 2232 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2233 | operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2234 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2235 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2236 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2237 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2238 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2239 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2240 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2241 | friend |
| 2242 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2243 | operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2244 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2245 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2246 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2247 | |
| 2248 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2249 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2250 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2251 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2252 | friend |
| 2253 | basic_ostream<_CharT, _Traits>& |
| 2254 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2255 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2256 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2257 | |
| 2258 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2259 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2260 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2261 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2262 | friend |
| 2263 | basic_istream<_CharT, _Traits>& |
| 2264 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2265 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2266 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2267 | private: |
| 2268 | |
| 2269 | template<class _Sseq> |
| 2270 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 2271 | template<class _Sseq> |
| 2272 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 2273 | |
| 2274 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2275 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2276 | static |
| 2277 | typename enable_if |
| 2278 | < |
| 2279 | __count < __w, |
| 2280 | result_type |
| 2281 | >::type |
| 2282 | __lshift(result_type __x) {return (__x << __count) & _Max;} |
| 2283 | |
| 2284 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2285 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2286 | static |
| 2287 | typename enable_if |
| 2288 | < |
| 2289 | (__count >= __w), |
| 2290 | result_type |
| 2291 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2292 | __lshift(result_type) {return result_type(0);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2293 | |
| 2294 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2295 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2296 | static |
| 2297 | typename enable_if |
| 2298 | < |
| 2299 | __count < _Dt, |
| 2300 | result_type |
| 2301 | >::type |
| 2302 | __rshift(result_type __x) {return __x >> __count;} |
| 2303 | |
| 2304 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2306 | static |
| 2307 | typename enable_if |
| 2308 | < |
| 2309 | (__count >= _Dt), |
| 2310 | result_type |
| 2311 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2312 | __rshift(result_type) {return result_type(0);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2313 | }; |
| 2314 | |
| 2315 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2316 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2317 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2318 | _LIBCPP_CONSTEXPR const size_t |
| 2319 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; |
| 2320 | |
| 2321 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2322 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2323 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2324 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2325 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; |
| 2326 | |
| 2327 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2328 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2329 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2330 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2331 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; |
| 2332 | |
| 2333 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2334 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2335 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2336 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2337 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; |
| 2338 | |
| 2339 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2340 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2341 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2342 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2343 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; |
| 2344 | |
| 2345 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2346 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2347 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2348 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2349 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; |
| 2350 | |
| 2351 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2352 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2353 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2354 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2355 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; |
| 2356 | |
| 2357 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2358 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2359 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2360 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2361 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; |
| 2362 | |
| 2363 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2364 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2365 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2366 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2367 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; |
| 2368 | |
| 2369 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2370 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2371 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2372 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2373 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; |
| 2374 | |
| 2375 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2376 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2377 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2378 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2379 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; |
| 2380 | |
| 2381 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2382 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2383 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2384 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2385 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; |
| 2386 | |
| 2387 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2388 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2389 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2390 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2391 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; |
| 2392 | |
| 2393 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2394 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2395 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2396 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2397 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; |
| 2398 | |
| 2399 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2400 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2401 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2402 | void |
| 2403 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2404 | __t, __c, __l, __f>::seed(result_type __sd) |
Marshall Clow | c189463 | 2017-09-11 18:10:33 +0000 | [diff] [blame] | 2405 | _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2406 | { // __w >= 2 |
| 2407 | __x_[0] = __sd & _Max; |
| 2408 | for (size_t __i = 1; __i < __n; ++__i) |
| 2409 | __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; |
| 2410 | __i_ = 0; |
| 2411 | } |
| 2412 | |
| 2413 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2414 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2415 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2416 | template<class _Sseq> |
| 2417 | void |
| 2418 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2419 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) |
| 2420 | { |
| 2421 | const unsigned __k = 1; |
| 2422 | uint32_t __ar[__n * __k]; |
| 2423 | __q.generate(__ar, __ar + __n * __k); |
| 2424 | for (size_t __i = 0; __i < __n; ++__i) |
| 2425 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); |
| 2426 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2427 | (result_type(1) << __r) - result_type(1); |
| 2428 | __i_ = 0; |
| 2429 | if ((__x_[0] & ~__mask) == 0) |
| 2430 | { |
| 2431 | for (size_t __i = 1; __i < __n; ++__i) |
| 2432 | if (__x_[__i] != 0) |
| 2433 | return; |
Hubert Tong | ca5b776 | 2018-08-16 23:56:54 +0000 | [diff] [blame] | 2434 | __x_[0] = result_type(1) << (__w - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2439 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2440 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2441 | template<class _Sseq> |
| 2442 | void |
| 2443 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2444 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) |
| 2445 | { |
| 2446 | const unsigned __k = 2; |
| 2447 | uint32_t __ar[__n * __k]; |
| 2448 | __q.generate(__ar, __ar + __n * __k); |
| 2449 | for (size_t __i = 0; __i < __n; ++__i) |
| 2450 | __x_[__i] = static_cast<result_type>( |
| 2451 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); |
| 2452 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2453 | (result_type(1) << __r) - result_type(1); |
| 2454 | __i_ = 0; |
| 2455 | if ((__x_[0] & ~__mask) == 0) |
| 2456 | { |
| 2457 | for (size_t __i = 1; __i < __n; ++__i) |
| 2458 | if (__x_[__i] != 0) |
| 2459 | return; |
Hubert Tong | ca5b776 | 2018-08-16 23:56:54 +0000 | [diff] [blame] | 2460 | __x_[0] = result_type(1) << (__w - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2465 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2466 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2467 | _UIntType |
| 2468 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2469 | __t, __c, __l, __f>::operator()() |
| 2470 | { |
| 2471 | const size_t __j = (__i_ + 1) % __n; |
| 2472 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2473 | (result_type(1) << __r) - result_type(1); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2474 | const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2475 | const size_t __k = (__i_ + __m) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2476 | __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2477 | result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); |
| 2478 | __i_ = __j; |
| 2479 | __z ^= __lshift<__s>(__z) & __b; |
| 2480 | __z ^= __lshift<__t>(__z) & __c; |
| 2481 | return __z ^ __rshift<__l>(__z); |
| 2482 | } |
| 2483 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2484 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2485 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2486 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2487 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2488 | operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2489 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2490 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2491 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2492 | { |
| 2493 | if (__x.__i_ == __y.__i_) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2494 | return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2495 | if (__x.__i_ == 0 || __y.__i_ == 0) |
| 2496 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2497 | size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2498 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2499 | __y.__x_ + __y.__i_)) |
| 2500 | return false; |
| 2501 | if (__x.__i_ == 0) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2502 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); |
| 2503 | return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2504 | } |
| 2505 | if (__x.__i_ < __y.__i_) |
| 2506 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2507 | size_t __j = _Np - __y.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2508 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2509 | __y.__x_ + __y.__i_)) |
| 2510 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2511 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2512 | __y.__x_)) |
| 2513 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2514 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2515 | __y.__x_ + (_Np - (__x.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2516 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2517 | size_t __j = _Np - __x.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2518 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2519 | __x.__x_ + __x.__i_)) |
| 2520 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2521 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2522 | __x.__x_)) |
| 2523 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2524 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2525 | __x.__x_ + (_Np - (__y.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2526 | } |
| 2527 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2528 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2529 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2530 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2531 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2532 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2533 | operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2534 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2535 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2536 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2537 | { |
| 2538 | return !(__x == __y); |
| 2539 | } |
| 2540 | |
| 2541 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2542 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2543 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2544 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2545 | basic_ostream<_CharT, _Traits>& |
| 2546 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2547 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2548 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2549 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2550 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2551 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2552 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2553 | _CharT __sp = __os.widen(' '); |
| 2554 | __os.fill(__sp); |
| 2555 | __os << __x.__x_[__x.__i_]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2556 | for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2557 | __os << __sp << __x.__x_[__j]; |
| 2558 | for (size_t __j = 0; __j < __x.__i_; ++__j) |
| 2559 | __os << __sp << __x.__x_[__j]; |
| 2560 | return __os; |
| 2561 | } |
| 2562 | |
| 2563 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2564 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2565 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2566 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2567 | basic_istream<_CharT, _Traits>& |
| 2568 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2569 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2570 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2571 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2572 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2573 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2574 | __is.flags(_Istream::dec | _Istream::skipws); |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2575 | _UInt __t[_Np]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2576 | for (size_t __i = 0; __i < _Np; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2577 | __is >> __t[__i]; |
| 2578 | if (!__is.fail()) |
| 2579 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2580 | for (size_t __i = 0; __i < _Np; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2581 | __x.__x_[__i] = __t[__i]; |
| 2582 | __x.__i_ = 0; |
| 2583 | } |
| 2584 | return __is; |
| 2585 | } |
| 2586 | |
| 2587 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, |
| 2588 | 0x9908b0df, 11, 0xffffffff, |
| 2589 | 7, 0x9d2c5680, |
| 2590 | 15, 0xefc60000, |
| 2591 | 18, 1812433253> mt19937; |
| 2592 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, |
| 2593 | 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, |
| 2594 | 17, 0x71d67fffeda60000ULL, |
| 2595 | 37, 0xfff7eee000000000ULL, |
| 2596 | 43, 6364136223846793005ULL> mt19937_64; |
| 2597 | |
| 2598 | // subtract_with_carry_engine |
| 2599 | |
| 2600 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2601 | class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2602 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2603 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2604 | bool |
| 2605 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2606 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2607 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2608 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2609 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 2610 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2611 | bool |
| 2612 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2613 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2614 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2615 | |
| 2616 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2617 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2618 | basic_ostream<_CharT, _Traits>& |
| 2619 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2620 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2621 | |
| 2622 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2623 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2624 | basic_istream<_CharT, _Traits>& |
| 2625 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2626 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2627 | |
| 2628 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2629 | class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2630 | { |
| 2631 | public: |
| 2632 | // types |
| 2633 | typedef _UIntType result_type; |
| 2634 | |
| 2635 | private: |
| 2636 | result_type __x_[__r]; |
| 2637 | result_type __c_; |
| 2638 | size_t __i_; |
| 2639 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2640 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2641 | static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); |
| 2642 | static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); |
| 2643 | static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); |
| 2644 | static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); |
| 2645 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2646 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 2647 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 2648 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2649 | static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); |
| 2650 | |
| 2651 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2652 | static _LIBCPP_CONSTEXPR const size_t word_size = __w; |
| 2653 | static _LIBCPP_CONSTEXPR const size_t short_lag = __s; |
| 2654 | static _LIBCPP_CONSTEXPR const size_t long_lag = __r; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2655 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2656 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2657 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2658 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
| 2659 | static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2660 | |
| 2661 | // constructors and seeding functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 2662 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2663 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 2664 | subtract_with_carry_engine() : subtract_with_carry_engine(default_seed) {} |
| 2665 | _LIBCPP_INLINE_VISIBILITY |
| 2666 | explicit subtract_with_carry_engine(result_type __sd) { seed(__sd); } |
| 2667 | #else |
| 2668 | _LIBCPP_INLINE_VISIBILITY |
| 2669 | explicit subtract_with_carry_engine(result_type __sd = default_seed) { |
| 2670 | seed(__sd); |
| 2671 | } |
| 2672 | #endif |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2673 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2674 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2675 | explicit subtract_with_carry_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2676 | typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2677 | {seed(__q);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2678 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2679 | void seed(result_type __sd = default_seed) |
| 2680 | {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2681 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2682 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2683 | typename enable_if |
| 2684 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2685 | __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2686 | void |
| 2687 | >::type |
| 2688 | seed(_Sseq& __q) |
| 2689 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2690 | |
| 2691 | // generating functions |
| 2692 | result_type operator()(); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2693 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2694 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2695 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2696 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2697 | friend |
| 2698 | bool |
| 2699 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2700 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2701 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2702 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2703 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2704 | friend |
| 2705 | bool |
| 2706 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2707 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2708 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2709 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2710 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2711 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2712 | friend |
| 2713 | basic_ostream<_CharT, _Traits>& |
| 2714 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2715 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2716 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2717 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2718 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2719 | friend |
| 2720 | basic_istream<_CharT, _Traits>& |
| 2721 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2722 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2723 | |
| 2724 | private: |
| 2725 | |
| 2726 | void seed(result_type __sd, integral_constant<unsigned, 1>); |
| 2727 | void seed(result_type __sd, integral_constant<unsigned, 2>); |
| 2728 | template<class _Sseq> |
| 2729 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 2730 | template<class _Sseq> |
| 2731 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 2732 | }; |
| 2733 | |
| 2734 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2735 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; |
| 2736 | |
| 2737 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2738 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; |
| 2739 | |
| 2740 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2741 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; |
| 2742 | |
| 2743 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2744 | _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type |
| 2745 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; |
| 2746 | |
| 2747 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2748 | void |
| 2749 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, |
| 2750 | integral_constant<unsigned, 1>) |
| 2751 | { |
| 2752 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> |
| 2753 | __e(__sd == 0u ? default_seed : __sd); |
| 2754 | for (size_t __i = 0; __i < __r; ++__i) |
| 2755 | __x_[__i] = static_cast<result_type>(__e() & _Max); |
| 2756 | __c_ = __x_[__r-1] == 0; |
| 2757 | __i_ = 0; |
| 2758 | } |
| 2759 | |
| 2760 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2761 | void |
| 2762 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, |
| 2763 | integral_constant<unsigned, 2>) |
| 2764 | { |
| 2765 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> |
| 2766 | __e(__sd == 0u ? default_seed : __sd); |
| 2767 | for (size_t __i = 0; __i < __r; ++__i) |
Howard Hinnant | 93072c1 | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2768 | { |
| 2769 | result_type __e0 = __e(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2770 | __x_[__i] = static_cast<result_type>( |
Howard Hinnant | 93072c1 | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2771 | (__e0 + ((uint64_t)__e() << 32)) & _Max); |
| 2772 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2773 | __c_ = __x_[__r-1] == 0; |
| 2774 | __i_ = 0; |
| 2775 | } |
| 2776 | |
| 2777 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2778 | template<class _Sseq> |
| 2779 | void |
| 2780 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, |
| 2781 | integral_constant<unsigned, 1>) |
| 2782 | { |
| 2783 | const unsigned __k = 1; |
| 2784 | uint32_t __ar[__r * __k]; |
| 2785 | __q.generate(__ar, __ar + __r * __k); |
| 2786 | for (size_t __i = 0; __i < __r; ++__i) |
| 2787 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); |
| 2788 | __c_ = __x_[__r-1] == 0; |
| 2789 | __i_ = 0; |
| 2790 | } |
| 2791 | |
| 2792 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2793 | template<class _Sseq> |
| 2794 | void |
| 2795 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, |
| 2796 | integral_constant<unsigned, 2>) |
| 2797 | { |
| 2798 | const unsigned __k = 2; |
| 2799 | uint32_t __ar[__r * __k]; |
| 2800 | __q.generate(__ar, __ar + __r * __k); |
| 2801 | for (size_t __i = 0; __i < __r; ++__i) |
| 2802 | __x_[__i] = static_cast<result_type>( |
| 2803 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); |
| 2804 | __c_ = __x_[__r-1] == 0; |
| 2805 | __i_ = 0; |
| 2806 | } |
| 2807 | |
| 2808 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2809 | _UIntType |
| 2810 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() |
| 2811 | { |
| 2812 | const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; |
| 2813 | result_type& __xr = __x_[__i_]; |
| 2814 | result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; |
| 2815 | __xr = (__xs - __xr - __c_) & _Max; |
| 2816 | __c_ = __new_c; |
| 2817 | __i_ = (__i_ + 1) % __r; |
| 2818 | return __xr; |
| 2819 | } |
| 2820 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2821 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2822 | bool |
| 2823 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2824 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2825 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2826 | { |
| 2827 | if (__x.__c_ != __y.__c_) |
| 2828 | return false; |
| 2829 | if (__x.__i_ == __y.__i_) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2830 | return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2831 | if (__x.__i_ == 0 || __y.__i_ == 0) |
| 2832 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2833 | size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2834 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2835 | __y.__x_ + __y.__i_)) |
| 2836 | return false; |
| 2837 | if (__x.__i_ == 0) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2838 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); |
| 2839 | return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2840 | } |
| 2841 | if (__x.__i_ < __y.__i_) |
| 2842 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2843 | size_t __j = _Rp - __y.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2844 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2845 | __y.__x_ + __y.__i_)) |
| 2846 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2847 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2848 | __y.__x_)) |
| 2849 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2850 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2851 | __y.__x_ + (_Rp - (__x.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2852 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2853 | size_t __j = _Rp - __x.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2854 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2855 | __x.__x_ + __x.__i_)) |
| 2856 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2857 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2858 | __x.__x_)) |
| 2859 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2860 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2861 | __x.__x_ + (_Rp - (__y.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2862 | } |
| 2863 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2864 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2865 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2866 | bool |
| 2867 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2868 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2869 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2870 | { |
| 2871 | return !(__x == __y); |
| 2872 | } |
| 2873 | |
| 2874 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2875 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2876 | basic_ostream<_CharT, _Traits>& |
| 2877 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2878 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2879 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2880 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2881 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2882 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2883 | _CharT __sp = __os.widen(' '); |
| 2884 | __os.fill(__sp); |
| 2885 | __os << __x.__x_[__x.__i_]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2886 | for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2887 | __os << __sp << __x.__x_[__j]; |
| 2888 | for (size_t __j = 0; __j < __x.__i_; ++__j) |
| 2889 | __os << __sp << __x.__x_[__j]; |
| 2890 | __os << __sp << __x.__c_; |
| 2891 | return __os; |
| 2892 | } |
| 2893 | |
| 2894 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2895 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2896 | basic_istream<_CharT, _Traits>& |
| 2897 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2898 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2899 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2900 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2901 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2902 | __is.flags(_Istream::dec | _Istream::skipws); |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2903 | _UInt __t[_Rp+1]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2904 | for (size_t __i = 0; __i < _Rp+1; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2905 | __is >> __t[__i]; |
| 2906 | if (!__is.fail()) |
| 2907 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2908 | for (size_t __i = 0; __i < _Rp; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2909 | __x.__x_[__i] = __t[__i]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2910 | __x.__c_ = __t[_Rp]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2911 | __x.__i_ = 0; |
| 2912 | } |
| 2913 | return __is; |
| 2914 | } |
| 2915 | |
| 2916 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; |
| 2917 | typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; |
| 2918 | |
| 2919 | // discard_block_engine |
| 2920 | |
| 2921 | template<class _Engine, size_t __p, size_t __r> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2922 | class _LIBCPP_TEMPLATE_VIS discard_block_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2923 | { |
| 2924 | _Engine __e_; |
| 2925 | int __n_; |
| 2926 | |
| 2927 | static_assert( 0 < __r, "discard_block_engine invalid parameters"); |
| 2928 | static_assert(__r <= __p, "discard_block_engine invalid parameters"); |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 2929 | static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2930 | public: |
| 2931 | // types |
| 2932 | typedef typename _Engine::result_type result_type; |
| 2933 | |
| 2934 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2935 | static _LIBCPP_CONSTEXPR const size_t block_size = __p; |
| 2936 | static _LIBCPP_CONSTEXPR const size_t used_block = __r; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2937 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2938 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2939 | static const result_type _Min = _Engine::_Min; |
| 2940 | static const result_type _Max = _Engine::_Max; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2941 | #else |
| 2942 | static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); |
| 2943 | static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); |
| 2944 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2945 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2946 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2947 | static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2948 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2949 | static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2950 | |
| 2951 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2952 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2953 | discard_block_engine() : __n_(0) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2954 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2955 | explicit discard_block_engine(const _Engine& __e) |
| 2956 | : __e_(__e), __n_(0) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2957 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2958 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2959 | explicit discard_block_engine(_Engine&& __e) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2960 | : __e_(_VSTD::move(__e)), __n_(0) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2961 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2962 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2963 | explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2964 | template<class _Sseq> |
| 2965 | _LIBCPP_INLINE_VISIBILITY |
| 2966 | explicit discard_block_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2967 | typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2968 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2969 | : __e_(__q), __n_(0) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2970 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2971 | void seed() {__e_.seed(); __n_ = 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2972 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2973 | void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2974 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2975 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2976 | typename enable_if |
| 2977 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2978 | __is_seed_sequence<_Sseq, discard_block_engine>::value, |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2979 | void |
| 2980 | >::type |
| 2981 | seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2982 | |
| 2983 | // generating functions |
| 2984 | result_type operator()(); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2985 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2986 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2987 | |
| 2988 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2989 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 2990 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2991 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2992 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2993 | friend |
| 2994 | bool |
| 2995 | operator==( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2996 | const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2997 | const discard_block_engine<_Eng, _Pp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2998 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2999 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3000 | friend |
| 3001 | bool |
| 3002 | operator!=( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3003 | const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 3004 | const discard_block_engine<_Eng, _Pp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3005 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3006 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3007 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3008 | friend |
| 3009 | basic_ostream<_CharT, _Traits>& |
| 3010 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3011 | const discard_block_engine<_Eng, _Pp, _Rp>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3012 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3013 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3014 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3015 | friend |
| 3016 | basic_istream<_CharT, _Traits>& |
| 3017 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3018 | discard_block_engine<_Eng, _Pp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3019 | }; |
| 3020 | |
| 3021 | template<class _Engine, size_t __p, size_t __r> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3022 | _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; |
| 3023 | |
| 3024 | template<class _Engine, size_t __p, size_t __r> |
| 3025 | _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; |
| 3026 | |
| 3027 | template<class _Engine, size_t __p, size_t __r> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3028 | typename discard_block_engine<_Engine, __p, __r>::result_type |
| 3029 | discard_block_engine<_Engine, __p, __r>::operator()() |
| 3030 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 3031 | if (__n_ >= static_cast<int>(__r)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3032 | { |
| 3033 | __e_.discard(__p - __r); |
| 3034 | __n_ = 0; |
| 3035 | } |
| 3036 | ++__n_; |
| 3037 | return __e_(); |
| 3038 | } |
| 3039 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3040 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3041 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3042 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3043 | operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 3044 | const discard_block_engine<_Eng, _Pp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3045 | { |
| 3046 | return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; |
| 3047 | } |
| 3048 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3049 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3050 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3051 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3052 | operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 3053 | const discard_block_engine<_Eng, _Pp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3054 | { |
| 3055 | return !(__x == __y); |
| 3056 | } |
| 3057 | |
| 3058 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3059 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3060 | basic_ostream<_CharT, _Traits>& |
| 3061 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3062 | const discard_block_engine<_Eng, _Pp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3063 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3064 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3065 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 3066 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3067 | _CharT __sp = __os.widen(' '); |
| 3068 | __os.fill(__sp); |
| 3069 | return __os << __x.__e_ << __sp << __x.__n_; |
| 3070 | } |
| 3071 | |
| 3072 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3073 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3074 | basic_istream<_CharT, _Traits>& |
| 3075 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3076 | discard_block_engine<_Eng, _Pp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3077 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3078 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3079 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3080 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3081 | _Eng __e; |
| 3082 | int __n; |
| 3083 | __is >> __e >> __n; |
| 3084 | if (!__is.fail()) |
| 3085 | { |
| 3086 | __x.__e_ = __e; |
| 3087 | __x.__n_ = __n; |
| 3088 | } |
| 3089 | return __is; |
| 3090 | } |
| 3091 | |
| 3092 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; |
| 3093 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; |
| 3094 | |
| 3095 | // independent_bits_engine |
| 3096 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3097 | template<class _Engine, size_t __w, class _UIntType> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3098 | class _LIBCPP_TEMPLATE_VIS independent_bits_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3099 | { |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3100 | template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3101 | class __get_n |
| 3102 | { |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3103 | static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3104 | static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); |
| 3105 | static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3106 | static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3107 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3108 | static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3109 | }; |
| 3110 | public: |
| 3111 | // types |
| 3112 | typedef _UIntType result_type; |
| 3113 | |
| 3114 | private: |
| 3115 | _Engine __e_; |
| 3116 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3117 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3118 | static_assert( 0 < __w, "independent_bits_engine invalid parameters"); |
| 3119 | static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); |
| 3120 | |
| 3121 | typedef typename _Engine::result_type _Engine_result_type; |
| 3122 | typedef typename conditional |
| 3123 | < |
| 3124 | sizeof(_Engine_result_type) <= sizeof(result_type), |
| 3125 | result_type, |
| 3126 | _Engine_result_type |
| 3127 | >::type _Working_result_type; |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3128 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3129 | static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3130 | + _Working_result_type(1); |
| 3131 | #else |
| 3132 | static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() |
| 3133 | + _Working_result_type(1); |
| 3134 | #endif |
| 3135 | static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; |
| 3136 | static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; |
| 3137 | static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; |
| 3138 | static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; |
| 3139 | static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; |
| 3140 | static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; |
| 3141 | static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : |
| 3142 | (_Rp >> __w0) << __w0; |
| 3143 | static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : |
| 3144 | (_Rp >> (__w0+1)) << (__w0+1); |
| 3145 | static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3146 | _Engine_result_type(~0) >> (_EDt - __w0) : |
| 3147 | _Engine_result_type(0); |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3148 | static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3149 | _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : |
| 3150 | _Engine_result_type(~0); |
| 3151 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3152 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 3153 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 3154 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3155 | static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); |
| 3156 | |
| 3157 | // engine characteristics |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3158 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3159 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3160 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3161 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3162 | |
| 3163 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3164 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3165 | independent_bits_engine() {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3166 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3167 | explicit independent_bits_engine(const _Engine& __e) |
| 3168 | : __e_(__e) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3169 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3170 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3171 | explicit independent_bits_engine(_Engine&& __e) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3172 | : __e_(_VSTD::move(__e)) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3173 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3174 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3175 | explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3176 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3177 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3178 | explicit independent_bits_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3179 | typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3180 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3181 | : __e_(__q) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3182 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3183 | void seed() {__e_.seed();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3184 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3185 | void seed(result_type __sd) {__e_.seed(__sd);} |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3186 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3187 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3188 | typename enable_if |
| 3189 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3190 | __is_seed_sequence<_Sseq, independent_bits_engine>::value, |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3191 | void |
| 3192 | >::type |
| 3193 | seed(_Sseq& __q) {__e_.seed(__q);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3194 | |
| 3195 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3196 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3197 | result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3198 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3199 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 3200 | |
| 3201 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3202 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3203 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3204 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3205 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3206 | friend |
| 3207 | bool |
| 3208 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3209 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3210 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3211 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3212 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3213 | friend |
| 3214 | bool |
| 3215 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3216 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3217 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3218 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3219 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3220 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3221 | friend |
| 3222 | basic_ostream<_CharT, _Traits>& |
| 3223 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3224 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3225 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3226 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3227 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3228 | friend |
| 3229 | basic_istream<_CharT, _Traits>& |
| 3230 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3231 | independent_bits_engine<_Eng, _Wp, _UInt>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3232 | |
| 3233 | private: |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3234 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | fe77858 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3235 | result_type __eval(false_type); |
| 3236 | result_type __eval(true_type); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3237 | |
| 3238 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3239 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3240 | static |
| 3241 | typename enable_if |
| 3242 | < |
| 3243 | __count < _Dt, |
| 3244 | result_type |
| 3245 | >::type |
| 3246 | __lshift(result_type __x) {return __x << __count;} |
| 3247 | |
| 3248 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3249 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3250 | static |
| 3251 | typename enable_if |
| 3252 | < |
| 3253 | (__count >= _Dt), |
| 3254 | result_type |
| 3255 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3256 | __lshift(result_type) {return result_type(0);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3257 | }; |
| 3258 | |
| 3259 | template<class _Engine, size_t __w, class _UIntType> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3260 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3261 | _UIntType |
Marshall Clow | fe77858 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3262 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3263 | { |
| 3264 | return static_cast<result_type>(__e_() & __mask0); |
| 3265 | } |
| 3266 | |
| 3267 | template<class _Engine, size_t __w, class _UIntType> |
| 3268 | _UIntType |
Marshall Clow | fe77858 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3269 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3270 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3271 | result_type _Sp = 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3272 | for (size_t __k = 0; __k < __n0; ++__k) |
| 3273 | { |
| 3274 | _Engine_result_type __u; |
| 3275 | do |
| 3276 | { |
| 3277 | __u = __e_() - _Engine::min(); |
| 3278 | } while (__u >= __y0); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3279 | _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3280 | } |
| 3281 | for (size_t __k = __n0; __k < __n; ++__k) |
| 3282 | { |
| 3283 | _Engine_result_type __u; |
| 3284 | do |
| 3285 | { |
| 3286 | __u = __e_() - _Engine::min(); |
| 3287 | } while (__u >= __y1); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3288 | _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3289 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3290 | return _Sp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3291 | } |
| 3292 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3293 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3294 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3295 | bool |
| 3296 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3297 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3298 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3299 | { |
| 3300 | return __x.base() == __y.base(); |
| 3301 | } |
| 3302 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3303 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3304 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3305 | bool |
| 3306 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3307 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3308 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3309 | { |
| 3310 | return !(__x == __y); |
| 3311 | } |
| 3312 | |
| 3313 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3314 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3315 | basic_ostream<_CharT, _Traits>& |
| 3316 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3317 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3318 | { |
| 3319 | return __os << __x.base(); |
| 3320 | } |
| 3321 | |
| 3322 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3323 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3324 | basic_istream<_CharT, _Traits>& |
| 3325 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3326 | independent_bits_engine<_Eng, _Wp, _UInt>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3327 | { |
| 3328 | _Eng __e; |
| 3329 | __is >> __e; |
| 3330 | if (!__is.fail()) |
| 3331 | __x.__e_ = __e; |
| 3332 | return __is; |
| 3333 | } |
| 3334 | |
| 3335 | // shuffle_order_engine |
| 3336 | |
| 3337 | template <uint64_t _Xp, uint64_t _Yp> |
| 3338 | struct __ugcd |
| 3339 | { |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3340 | static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3341 | }; |
| 3342 | |
| 3343 | template <uint64_t _Xp> |
| 3344 | struct __ugcd<_Xp, 0> |
| 3345 | { |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3346 | static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3347 | }; |
| 3348 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3349 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3350 | class __uratio |
| 3351 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3352 | static_assert(_Dp != 0, "__uratio divide by 0"); |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3353 | static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3354 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3355 | static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; |
| 3356 | static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3357 | |
| 3358 | typedef __uratio<num, den> type; |
| 3359 | }; |
| 3360 | |
| 3361 | template<class _Engine, size_t __k> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3362 | class _LIBCPP_TEMPLATE_VIS shuffle_order_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3363 | { |
| 3364 | static_assert(0 < __k, "shuffle_order_engine invalid parameters"); |
| 3365 | public: |
| 3366 | // types |
| 3367 | typedef typename _Engine::result_type result_type; |
| 3368 | |
| 3369 | private: |
| 3370 | _Engine __e_; |
| 3371 | result_type _V_[__k]; |
| 3372 | result_type _Y_; |
| 3373 | |
| 3374 | public: |
| 3375 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3376 | static _LIBCPP_CONSTEXPR const size_t table_size = __k; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3377 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3378 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3379 | static const result_type _Min = _Engine::_Min; |
| 3380 | static const result_type _Max = _Engine::_Max; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3381 | #else |
| 3382 | static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); |
| 3383 | static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); |
| 3384 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3385 | static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3386 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3387 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3388 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3389 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3390 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3391 | static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3392 | |
| 3393 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3394 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3395 | shuffle_order_engine() {__init();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3396 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3397 | explicit shuffle_order_engine(const _Engine& __e) |
| 3398 | : __e_(__e) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3399 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3400 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3401 | explicit shuffle_order_engine(_Engine&& __e) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3402 | : __e_(_VSTD::move(__e)) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3403 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3404 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3405 | explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3406 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3407 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3408 | explicit shuffle_order_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3409 | typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3410 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3411 | : __e_(__q) {__init();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3412 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3413 | void seed() {__e_.seed(); __init();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3414 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3415 | void seed(result_type __sd) {__e_.seed(__sd); __init();} |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3416 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3417 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3418 | typename enable_if |
| 3419 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3420 | __is_seed_sequence<_Sseq, shuffle_order_engine>::value, |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3421 | void |
| 3422 | >::type |
| 3423 | seed(_Sseq& __q) {__e_.seed(__q); __init();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3424 | |
| 3425 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3426 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3427 | result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3428 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3429 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 3430 | |
| 3431 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3432 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3433 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3434 | |
| 3435 | private: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3436 | template<class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3437 | friend |
| 3438 | bool |
| 3439 | operator==( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3440 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3441 | const shuffle_order_engine<_Eng, _Kp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3442 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3443 | template<class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3444 | friend |
| 3445 | bool |
| 3446 | operator!=( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3447 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3448 | const shuffle_order_engine<_Eng, _Kp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3449 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3450 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3451 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3452 | friend |
| 3453 | basic_ostream<_CharT, _Traits>& |
| 3454 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3455 | const shuffle_order_engine<_Eng, _Kp>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3456 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3457 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3458 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3459 | friend |
| 3460 | basic_istream<_CharT, _Traits>& |
| 3461 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3462 | shuffle_order_engine<_Eng, _Kp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3463 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3464 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3465 | void __init() |
| 3466 | { |
| 3467 | for (size_t __i = 0; __i < __k; ++__i) |
| 3468 | _V_[__i] = __e_(); |
| 3469 | _Y_ = __e_(); |
| 3470 | } |
| 3471 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3472 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3473 | result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3474 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3475 | result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3476 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3477 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3478 | result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3479 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3480 | result_type __eval2(true_type) {return __evalf<__k, 0>();} |
| 3481 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3482 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3483 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3484 | typename enable_if |
| 3485 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3486 | (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3487 | result_type |
| 3488 | >::type |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3489 | __eval(__uratio<_Np, _Dp>) |
| 3490 | {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3491 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3492 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3493 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3494 | typename enable_if |
| 3495 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3496 | __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3497 | result_type |
| 3498 | >::type |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3499 | __eval(__uratio<_Np, _Dp>) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3500 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3501 | const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min) |
| 3502 | / __uratio<_Np, _Dp>::den); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3503 | _Y_ = _V_[__j]; |
| 3504 | _V_[__j] = __e_(); |
| 3505 | return _Y_; |
| 3506 | } |
| 3507 | |
| 3508 | template <uint64_t __n, uint64_t __d> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3509 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3510 | result_type __evalf() |
| 3511 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3512 | const double _Fp = __d == 0 ? |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3513 | __n / (2. * 0x8000000000000000ull) : |
| 3514 | __n / (double)__d; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3515 | const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3516 | _Y_ = _V_[__j]; |
| 3517 | _V_[__j] = __e_(); |
| 3518 | return _Y_; |
| 3519 | } |
| 3520 | }; |
| 3521 | |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3522 | template<class _Engine, size_t __k> |
| 3523 | _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; |
| 3524 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3525 | template<class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3526 | bool |
| 3527 | operator==( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3528 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3529 | const shuffle_order_engine<_Eng, _Kp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3530 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3531 | return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) && |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3532 | __x.__e_ == __y.__e_; |
| 3533 | } |
| 3534 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3535 | template<class _Eng, size_t _Kp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3536 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3537 | bool |
| 3538 | operator!=( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3539 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3540 | const shuffle_order_engine<_Eng, _Kp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3541 | { |
| 3542 | return !(__x == __y); |
| 3543 | } |
| 3544 | |
| 3545 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3546 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3547 | basic_ostream<_CharT, _Traits>& |
| 3548 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3549 | const shuffle_order_engine<_Eng, _Kp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3550 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3551 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3552 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 3553 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3554 | _CharT __sp = __os.widen(' '); |
| 3555 | __os.fill(__sp); |
| 3556 | __os << __x.__e_ << __sp << __x._V_[0]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3557 | for (size_t __i = 1; __i < _Kp; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3558 | __os << __sp << __x._V_[__i]; |
| 3559 | return __os << __sp << __x._Y_; |
| 3560 | } |
| 3561 | |
| 3562 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3563 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3564 | basic_istream<_CharT, _Traits>& |
| 3565 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3566 | shuffle_order_engine<_Eng, _Kp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3567 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3568 | typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3569 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3570 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3571 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3572 | _Eng __e; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3573 | result_type _Vp[_Kp+1]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3574 | __is >> __e; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3575 | for (size_t __i = 0; __i < _Kp+1; ++__i) |
| 3576 | __is >> _Vp[__i]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3577 | if (!__is.fail()) |
| 3578 | { |
| 3579 | __x.__e_ = __e; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3580 | for (size_t __i = 0; __i < _Kp; ++__i) |
| 3581 | __x._V_[__i] = _Vp[__i]; |
| 3582 | __x._Y_ = _Vp[_Kp]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3583 | } |
| 3584 | return __is; |
| 3585 | } |
| 3586 | |
| 3587 | typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; |
| 3588 | |
| 3589 | // random_device |
| 3590 | |
Louis Dionne | 3777e68 | 2020-10-15 10:32:09 -0400 | [diff] [blame] | 3591 | #if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE) |
| 3592 | |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 3593 | class _LIBCPP_TYPE_VIS random_device |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3594 | { |
Ed Schouten | dcf3740 | 2015-03-10 07:46:06 +0000 | [diff] [blame] | 3595 | #ifdef _LIBCPP_USING_DEV_RANDOM |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3596 | int __f_; |
Ed Schouten | dcf3740 | 2015-03-10 07:46:06 +0000 | [diff] [blame] | 3597 | #endif // defined(_LIBCPP_USING_DEV_RANDOM) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3598 | public: |
| 3599 | // types |
| 3600 | typedef unsigned result_type; |
| 3601 | |
| 3602 | // generator characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3603 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 3604 | static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3605 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3606 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 664183b | 2012-04-02 00:40:41 +0000 | [diff] [blame] | 3607 | static _LIBCPP_CONSTEXPR result_type min() { return _Min;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3608 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 664183b | 2012-04-02 00:40:41 +0000 | [diff] [blame] | 3609 | static _LIBCPP_CONSTEXPR result_type max() { return _Max;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3610 | |
| 3611 | // constructors |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 3612 | #ifndef _LIBCPP_CXX03_LANG |
| 3613 | random_device() : random_device("/dev/urandom") {} |
| 3614 | explicit random_device(const string& __token); |
| 3615 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3616 | explicit random_device(const string& __token = "/dev/urandom"); |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 3617 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3618 | ~random_device(); |
| 3619 | |
| 3620 | // generating functions |
| 3621 | result_type operator()(); |
| 3622 | |
| 3623 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3624 | double entropy() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3625 | |
| 3626 | private: |
| 3627 | // no copy functions |
| 3628 | random_device(const random_device&); // = delete; |
| 3629 | random_device& operator=(const random_device&); // = delete; |
| 3630 | }; |
| 3631 | |
Louis Dionne | 3777e68 | 2020-10-15 10:32:09 -0400 | [diff] [blame] | 3632 | #endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE |
| 3633 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3634 | // seed_seq |
| 3635 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3636 | class _LIBCPP_TEMPLATE_VIS seed_seq |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3637 | { |
| 3638 | public: |
| 3639 | // types |
| 3640 | typedef uint32_t result_type; |
| 3641 | |
| 3642 | private: |
| 3643 | vector<result_type> __v_; |
| 3644 | |
| 3645 | template<class _InputIterator> |
| 3646 | void init(_InputIterator __first, _InputIterator __last); |
| 3647 | public: |
| 3648 | // constructors |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3649 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4b6b809 | 2013-10-23 05:56:47 +0000 | [diff] [blame] | 3650 | seed_seq() _NOEXCEPT {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3651 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3652 | template<class _Tp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3653 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3654 | seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3655 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3656 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3657 | template<class _InputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3658 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3659 | seed_seq(_InputIterator __first, _InputIterator __last) |
| 3660 | {init(__first, __last);} |
| 3661 | |
| 3662 | // generating functions |
| 3663 | template<class _RandomAccessIterator> |
| 3664 | void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); |
| 3665 | |
| 3666 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3667 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4b6b809 | 2013-10-23 05:56:47 +0000 | [diff] [blame] | 3668 | size_t size() const _NOEXCEPT {return __v_.size();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3669 | template<class _OutputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3670 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3671 | void param(_OutputIterator __dest) const |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3672 | {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3673 | |
| 3674 | private: |
| 3675 | // no copy functions |
| 3676 | seed_seq(const seed_seq&); // = delete; |
| 3677 | void operator=(const seed_seq&); // = delete; |
| 3678 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3679 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3680 | static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3681 | }; |
| 3682 | |
| 3683 | template<class _InputIterator> |
| 3684 | void |
| 3685 | seed_seq::init(_InputIterator __first, _InputIterator __last) |
| 3686 | { |
| 3687 | for (_InputIterator __s = __first; __s != __last; ++__s) |
| 3688 | __v_.push_back(*__s & 0xFFFFFFFF); |
| 3689 | } |
| 3690 | |
| 3691 | template<class _RandomAccessIterator> |
| 3692 | void |
| 3693 | seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) |
| 3694 | { |
| 3695 | if (__first != __last) |
| 3696 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3697 | _VSTD::fill(__first, __last, 0x8b8b8b8b); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3698 | const size_t __n = static_cast<size_t>(__last - __first); |
| 3699 | const size_t __s = __v_.size(); |
| 3700 | const size_t __t = (__n >= 623) ? 11 |
| 3701 | : (__n >= 68) ? 7 |
| 3702 | : (__n >= 39) ? 5 |
| 3703 | : (__n >= 7) ? 3 |
| 3704 | : (__n - 1) / 2; |
| 3705 | const size_t __p = (__n - __t) / 2; |
| 3706 | const size_t __q = __p + __t; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3707 | const size_t __m = _VSTD::max(__s + 1, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3708 | // __k = 0; |
| 3709 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3710 | result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3711 | ^ __first[__n - 1]); |
| 3712 | __first[__p] += __r; |
| 3713 | __r += __s; |
| 3714 | __first[__q] += __r; |
| 3715 | __first[0] = __r; |
| 3716 | } |
| 3717 | for (size_t __k = 1; __k <= __s; ++__k) |
| 3718 | { |
| 3719 | const size_t __kmodn = __k % __n; |
| 3720 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3721 | result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3722 | ^ __first[(__k - 1) % __n]); |
| 3723 | __first[__kpmodn] += __r; |
| 3724 | __r += __kmodn + __v_[__k-1]; |
| 3725 | __first[(__k + __q) % __n] += __r; |
| 3726 | __first[__kmodn] = __r; |
| 3727 | } |
| 3728 | for (size_t __k = __s + 1; __k < __m; ++__k) |
| 3729 | { |
| 3730 | const size_t __kmodn = __k % __n; |
| 3731 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3732 | result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3733 | ^ __first[(__k - 1) % __n]); |
| 3734 | __first[__kpmodn] += __r; |
| 3735 | __r += __kmodn; |
| 3736 | __first[(__k + __q) % __n] += __r; |
| 3737 | __first[__kmodn] = __r; |
| 3738 | } |
| 3739 | for (size_t __k = __m; __k < __m + __n; ++__k) |
| 3740 | { |
| 3741 | const size_t __kmodn = __k % __n; |
| 3742 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3743 | result_type __r = 1566083941 * _Tp(__first[__kmodn] + |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3744 | __first[__kpmodn] + |
| 3745 | __first[(__k - 1) % __n]); |
| 3746 | __first[__kpmodn] ^= __r; |
| 3747 | __r -= __kmodn; |
| 3748 | __first[(__k + __q) % __n] ^= __r; |
| 3749 | __first[__kmodn] = __r; |
| 3750 | } |
| 3751 | } |
| 3752 | } |
| 3753 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3754 | // generate_canonical |
| 3755 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3756 | template<class _RealType, size_t __bits, class _URNG> |
| 3757 | _RealType |
| 3758 | generate_canonical(_URNG& __g) |
| 3759 | { |
| 3760 | const size_t _Dt = numeric_limits<_RealType>::digits; |
| 3761 | const size_t __b = _Dt < __bits ? _Dt : __bits; |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3762 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3763 | const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3764 | #else |
| 3765 | const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; |
| 3766 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3767 | const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); |
Louis Dionne | 2422bdb | 2019-08-20 15:39:20 +0000 | [diff] [blame] | 3768 | const _RealType _Rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3769 | _RealType __base = _Rp; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3770 | _RealType _Sp = __g() - _URNG::min(); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3771 | for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3772 | _Sp += (__g() - _URNG::min()) * __base; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3773 | return _Sp / __base; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3774 | } |
| 3775 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3776 | // uniform_int_distribution |
| 3777 | |
Howard Hinnant | 578ac0f | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 3778 | // in <algorithm> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3779 | |
| 3780 | template <class _CharT, class _Traits, class _IT> |
| 3781 | basic_ostream<_CharT, _Traits>& |
| 3782 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 3783 | const uniform_int_distribution<_IT>& __x) |
| 3784 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3785 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3786 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 3787 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3788 | _CharT __sp = __os.widen(' '); |
| 3789 | __os.fill(__sp); |
| 3790 | return __os << __x.a() << __sp << __x.b(); |
| 3791 | } |
| 3792 | |
| 3793 | template <class _CharT, class _Traits, class _IT> |
| 3794 | basic_istream<_CharT, _Traits>& |
| 3795 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 3796 | uniform_int_distribution<_IT>& __x) |
| 3797 | { |
| 3798 | typedef uniform_int_distribution<_IT> _Eng; |
| 3799 | typedef typename _Eng::result_type result_type; |
| 3800 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3801 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3802 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3803 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3804 | result_type __a; |
| 3805 | result_type __b; |
| 3806 | __is >> __a >> __b; |
| 3807 | if (!__is.fail()) |
| 3808 | __x.param(param_type(__a, __b)); |
| 3809 | return __is; |
| 3810 | } |
| 3811 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3812 | // uniform_real_distribution |
| 3813 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3814 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3815 | class _LIBCPP_TEMPLATE_VIS uniform_real_distribution |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3816 | { |
| 3817 | public: |
| 3818 | // types |
| 3819 | typedef _RealType result_type; |
| 3820 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3821 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3822 | { |
| 3823 | result_type __a_; |
| 3824 | result_type __b_; |
| 3825 | public: |
| 3826 | typedef uniform_real_distribution distribution_type; |
| 3827 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3828 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3829 | explicit param_type(result_type __a = 0, |
| 3830 | result_type __b = 1) |
| 3831 | : __a_(__a), __b_(__b) {} |
| 3832 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3833 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3834 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3835 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3836 | result_type b() const {return __b_;} |
| 3837 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3838 | friend _LIBCPP_INLINE_VISIBILITY |
| 3839 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3840 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3841 | friend _LIBCPP_INLINE_VISIBILITY |
| 3842 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3843 | {return !(__x == __y);} |
| 3844 | }; |
| 3845 | |
| 3846 | private: |
| 3847 | param_type __p_; |
| 3848 | |
| 3849 | public: |
| 3850 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 3851 | #ifndef _LIBCPP_CXX03_LANG |
| 3852 | _LIBCPP_INLINE_VISIBILITY |
| 3853 | uniform_real_distribution() : uniform_real_distribution(0) {} |
| 3854 | explicit uniform_real_distribution(result_type __a, result_type __b = 1) |
| 3855 | : __p_(param_type(__a, __b)) {} |
| 3856 | #else |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3857 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3858 | explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) |
| 3859 | : __p_(param_type(__a, __b)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 3860 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3861 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3862 | explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3863 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3864 | void reset() {} |
| 3865 | |
| 3866 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3867 | template<class _URNG> |
| 3868 | _LIBCPP_INLINE_VISIBILITY |
| 3869 | result_type operator()(_URNG& __g) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3870 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3871 | template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3872 | |
| 3873 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3874 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3875 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3876 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3877 | result_type b() const {return __p_.b();} |
| 3878 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3879 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3880 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3881 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3882 | void param(const param_type& __p) {__p_ = __p;} |
| 3883 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3884 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3885 | result_type min() const {return a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3886 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3887 | result_type max() const {return b();} |
| 3888 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3889 | friend _LIBCPP_INLINE_VISIBILITY |
| 3890 | bool operator==(const uniform_real_distribution& __x, |
| 3891 | const uniform_real_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3892 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3893 | friend _LIBCPP_INLINE_VISIBILITY |
| 3894 | bool operator!=(const uniform_real_distribution& __x, |
| 3895 | const uniform_real_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3896 | {return !(__x == __y);} |
| 3897 | }; |
| 3898 | |
| 3899 | template<class _RealType> |
| 3900 | template<class _URNG> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3901 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3902 | typename uniform_real_distribution<_RealType>::result_type |
| 3903 | uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 3904 | { |
| 3905 | return (__p.b() - __p.a()) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3906 | * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3907 | + __p.a(); |
| 3908 | } |
| 3909 | |
| 3910 | template <class _CharT, class _Traits, class _RT> |
| 3911 | basic_ostream<_CharT, _Traits>& |
| 3912 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 3913 | const uniform_real_distribution<_RT>& __x) |
| 3914 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3915 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3916 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 3917 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 3918 | _OStream::scientific); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3919 | _CharT __sp = __os.widen(' '); |
| 3920 | __os.fill(__sp); |
| 3921 | return __os << __x.a() << __sp << __x.b(); |
| 3922 | } |
| 3923 | |
| 3924 | template <class _CharT, class _Traits, class _RT> |
| 3925 | basic_istream<_CharT, _Traits>& |
| 3926 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 3927 | uniform_real_distribution<_RT>& __x) |
| 3928 | { |
| 3929 | typedef uniform_real_distribution<_RT> _Eng; |
| 3930 | typedef typename _Eng::result_type result_type; |
| 3931 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3932 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3933 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3934 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3935 | result_type __a; |
| 3936 | result_type __b; |
| 3937 | __is >> __a >> __b; |
| 3938 | if (!__is.fail()) |
| 3939 | __x.param(param_type(__a, __b)); |
| 3940 | return __is; |
| 3941 | } |
| 3942 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3943 | // bernoulli_distribution |
| 3944 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3945 | class _LIBCPP_TEMPLATE_VIS bernoulli_distribution |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3946 | { |
| 3947 | public: |
| 3948 | // types |
| 3949 | typedef bool result_type; |
| 3950 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3951 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3952 | { |
| 3953 | double __p_; |
| 3954 | public: |
| 3955 | typedef bernoulli_distribution distribution_type; |
| 3956 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3957 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3958 | explicit param_type(double __p = 0.5) : __p_(__p) {} |
| 3959 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3960 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3961 | double p() const {return __p_;} |
| 3962 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3963 | friend _LIBCPP_INLINE_VISIBILITY |
| 3964 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3965 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3966 | friend _LIBCPP_INLINE_VISIBILITY |
| 3967 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3968 | {return !(__x == __y);} |
| 3969 | }; |
| 3970 | |
| 3971 | private: |
| 3972 | param_type __p_; |
| 3973 | |
| 3974 | public: |
| 3975 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 3976 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3977 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 3978 | bernoulli_distribution() : bernoulli_distribution(0.5) {} |
| 3979 | _LIBCPP_INLINE_VISIBILITY |
| 3980 | explicit bernoulli_distribution(double __p) : __p_(param_type(__p)) {} |
| 3981 | #else |
| 3982 | _LIBCPP_INLINE_VISIBILITY |
| 3983 | explicit bernoulli_distribution(double __p = 0.5) : __p_(param_type(__p)) {} |
| 3984 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3985 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3986 | explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3987 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3988 | void reset() {} |
| 3989 | |
| 3990 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3991 | template<class _URNG> |
| 3992 | _LIBCPP_INLINE_VISIBILITY |
| 3993 | result_type operator()(_URNG& __g) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3994 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3995 | template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3996 | |
| 3997 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3998 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3999 | double p() const {return __p_.p();} |
| 4000 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4001 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4002 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4003 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4004 | void param(const param_type& __p) {__p_ = __p;} |
| 4005 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4006 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4007 | result_type min() const {return false;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4008 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4009 | result_type max() const {return true;} |
| 4010 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4011 | friend _LIBCPP_INLINE_VISIBILITY |
| 4012 | bool operator==(const bernoulli_distribution& __x, |
| 4013 | const bernoulli_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4014 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4015 | friend _LIBCPP_INLINE_VISIBILITY |
| 4016 | bool operator!=(const bernoulli_distribution& __x, |
| 4017 | const bernoulli_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4018 | {return !(__x == __y);} |
| 4019 | }; |
| 4020 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4021 | template<class _URNG> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 4022 | inline |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4023 | bernoulli_distribution::result_type |
| 4024 | bernoulli_distribution::operator()(_URNG& __g, const param_type& __p) |
| 4025 | { |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 4026 | uniform_real_distribution<double> __gen; |
| 4027 | return __gen(__g) < __p.p(); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4028 | } |
| 4029 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4030 | template <class _CharT, class _Traits> |
| 4031 | basic_ostream<_CharT, _Traits>& |
| 4032 | operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) |
| 4033 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4034 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4035 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4036 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4037 | _OStream::scientific); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4038 | _CharT __sp = __os.widen(' '); |
| 4039 | __os.fill(__sp); |
| 4040 | return __os << __x.p(); |
| 4041 | } |
| 4042 | |
| 4043 | template <class _CharT, class _Traits> |
| 4044 | basic_istream<_CharT, _Traits>& |
| 4045 | operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) |
| 4046 | { |
| 4047 | typedef bernoulli_distribution _Eng; |
| 4048 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4049 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4050 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4051 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4052 | double __p; |
| 4053 | __is >> __p; |
| 4054 | if (!__is.fail()) |
| 4055 | __x.param(param_type(__p)); |
| 4056 | return __is; |
| 4057 | } |
| 4058 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4059 | // binomial_distribution |
| 4060 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4061 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4062 | class _LIBCPP_TEMPLATE_VIS binomial_distribution |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4063 | { |
| 4064 | public: |
| 4065 | // types |
| 4066 | typedef _IntType result_type; |
| 4067 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4068 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4069 | { |
| 4070 | result_type __t_; |
| 4071 | double __p_; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4072 | double __pr_; |
| 4073 | double __odds_ratio_; |
| 4074 | result_type __r0_; |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4075 | public: |
| 4076 | typedef binomial_distribution distribution_type; |
| 4077 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4078 | explicit param_type(result_type __t = 1, double __p = 0.5); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4079 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4080 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4081 | result_type t() const {return __t_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4082 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4083 | double p() const {return __p_;} |
| 4084 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4085 | friend _LIBCPP_INLINE_VISIBILITY |
| 4086 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4087 | {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4088 | friend _LIBCPP_INLINE_VISIBILITY |
| 4089 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4090 | {return !(__x == __y);} |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4091 | |
| 4092 | friend class binomial_distribution; |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4093 | }; |
| 4094 | |
| 4095 | private: |
| 4096 | param_type __p_; |
| 4097 | |
| 4098 | public: |
| 4099 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4100 | #ifndef _LIBCPP_CXX03_LANG |
| 4101 | _LIBCPP_INLINE_VISIBILITY |
| 4102 | binomial_distribution() : binomial_distribution(1) {} |
| 4103 | _LIBCPP_INLINE_VISIBILITY |
| 4104 | explicit binomial_distribution(result_type __t, double __p = 0.5) |
| 4105 | : __p_(param_type(__t, __p)) {} |
| 4106 | #else |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4107 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4108 | explicit binomial_distribution(result_type __t = 1, double __p = 0.5) |
| 4109 | : __p_(param_type(__t, __p)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4110 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4111 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4112 | explicit binomial_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4113 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4114 | void reset() {} |
| 4115 | |
| 4116 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4117 | template<class _URNG> |
| 4118 | _LIBCPP_INLINE_VISIBILITY |
| 4119 | result_type operator()(_URNG& __g) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4120 | {return (*this)(__g, __p_);} |
| 4121 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4122 | |
| 4123 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4124 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4125 | result_type t() const {return __p_.t();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4126 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4127 | double p() const {return __p_.p();} |
| 4128 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4129 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4130 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4131 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4132 | void param(const param_type& __p) {__p_ = __p;} |
| 4133 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4134 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4135 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4136 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4137 | result_type max() const {return t();} |
| 4138 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4139 | friend _LIBCPP_INLINE_VISIBILITY |
| 4140 | bool operator==(const binomial_distribution& __x, |
| 4141 | const binomial_distribution& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4142 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4143 | friend _LIBCPP_INLINE_VISIBILITY |
| 4144 | bool operator!=(const binomial_distribution& __x, |
| 4145 | const binomial_distribution& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4146 | {return !(__x == __y);} |
| 4147 | }; |
| 4148 | |
Martin Storsjö | 408cee7 | 2020-12-01 13:37:16 +0200 | [diff] [blame] | 4149 | #ifndef _LIBCPP_MSVCRT_LIKE |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4150 | extern "C" double lgamma_r(double, int *); |
Eric Fiselier | 651ca6e | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4151 | #endif |
| 4152 | |
| 4153 | inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { |
Martin Storsjö | 408cee7 | 2020-12-01 13:37:16 +0200 | [diff] [blame] | 4154 | #if defined(_LIBCPP_MSVCRT_LIKE) |
Eric Fiselier | 651ca6e | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4155 | return lgamma(__d); |
| 4156 | #else |
| 4157 | int __sign; |
| 4158 | return lgamma_r(__d, &__sign); |
| 4159 | #endif |
| 4160 | } |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4161 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4162 | template<class _IntType> |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4163 | binomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4164 | : __t_(__t), __p_(__p) |
| 4165 | { |
| 4166 | if (0 < __p_ && __p_ < 1) |
| 4167 | { |
| 4168 | __r0_ = static_cast<result_type>((__t_ + 1) * __p_); |
Eric Fiselier | 651ca6e | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4169 | __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - |
| 4170 | __libcpp_lgamma(__r0_ + 1.) - |
| 4171 | __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4172 | (__t_ - __r0_) * _VSTD::log(1 - __p_)); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4173 | __odds_ratio_ = __p_ / (1 - __p_); |
| 4174 | } |
| 4175 | } |
| 4176 | |
Marshall Clow | f97a84f | 2014-09-17 18:33:58 +0000 | [diff] [blame] | 4177 | // Reference: Kemp, C.D. (1986). `A modal method for generating binomial |
| 4178 | // variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4179 | template<class _IntType> |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4180 | template<class _URNG> |
| 4181 | _IntType |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4182 | binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4183 | { |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4184 | if (__pr.__t_ == 0 || __pr.__p_ == 0) |
| 4185 | return 0; |
| 4186 | if (__pr.__p_ == 1) |
| 4187 | return __pr.__t_; |
| 4188 | uniform_real_distribution<double> __gen; |
| 4189 | double __u = __gen(__g) - __pr.__pr_; |
| 4190 | if (__u < 0) |
| 4191 | return __pr.__r0_; |
| 4192 | double __pu = __pr.__pr_; |
| 4193 | double __pd = __pu; |
| 4194 | result_type __ru = __pr.__r0_; |
| 4195 | result_type __rd = __ru; |
| 4196 | while (true) |
| 4197 | { |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4198 | bool __break = true; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4199 | if (__rd >= 1) |
| 4200 | { |
| 4201 | __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); |
| 4202 | __u -= __pd; |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4203 | __break = false; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4204 | if (__u < 0) |
| 4205 | return __rd - 1; |
| 4206 | } |
Marshall Clow | f97a84f | 2014-09-17 18:33:58 +0000 | [diff] [blame] | 4207 | if ( __rd != 0 ) |
| 4208 | --__rd; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4209 | ++__ru; |
| 4210 | if (__ru <= __pr.__t_) |
| 4211 | { |
| 4212 | __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; |
| 4213 | __u -= __pu; |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4214 | __break = false; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4215 | if (__u < 0) |
| 4216 | return __ru; |
| 4217 | } |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4218 | if (__break) |
| 4219 | return 0; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4220 | } |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | template <class _CharT, class _Traits, class _IntType> |
| 4224 | basic_ostream<_CharT, _Traits>& |
| 4225 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4226 | const binomial_distribution<_IntType>& __x) |
| 4227 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4228 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4229 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4230 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4231 | _OStream::scientific); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4232 | _CharT __sp = __os.widen(' '); |
| 4233 | __os.fill(__sp); |
| 4234 | return __os << __x.t() << __sp << __x.p(); |
| 4235 | } |
| 4236 | |
| 4237 | template <class _CharT, class _Traits, class _IntType> |
| 4238 | basic_istream<_CharT, _Traits>& |
| 4239 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4240 | binomial_distribution<_IntType>& __x) |
| 4241 | { |
| 4242 | typedef binomial_distribution<_IntType> _Eng; |
| 4243 | typedef typename _Eng::result_type result_type; |
| 4244 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4245 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4246 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4247 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4248 | result_type __t; |
| 4249 | double __p; |
| 4250 | __is >> __t >> __p; |
| 4251 | if (!__is.fail()) |
| 4252 | __x.param(param_type(__t, __p)); |
| 4253 | return __is; |
| 4254 | } |
| 4255 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4256 | // exponential_distribution |
| 4257 | |
| 4258 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4259 | class _LIBCPP_TEMPLATE_VIS exponential_distribution |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4260 | { |
| 4261 | public: |
| 4262 | // types |
| 4263 | typedef _RealType result_type; |
| 4264 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4265 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4266 | { |
| 4267 | result_type __lambda_; |
| 4268 | public: |
| 4269 | typedef exponential_distribution distribution_type; |
| 4270 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4271 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4272 | explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} |
| 4273 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4274 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4275 | result_type lambda() const {return __lambda_;} |
| 4276 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4277 | friend _LIBCPP_INLINE_VISIBILITY |
| 4278 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4279 | {return __x.__lambda_ == __y.__lambda_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4280 | friend _LIBCPP_INLINE_VISIBILITY |
| 4281 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4282 | {return !(__x == __y);} |
| 4283 | }; |
| 4284 | |
| 4285 | private: |
| 4286 | param_type __p_; |
| 4287 | |
| 4288 | public: |
| 4289 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4290 | #ifndef _LIBCPP_CXX03_LANG |
| 4291 | _LIBCPP_INLINE_VISIBILITY |
| 4292 | exponential_distribution() : exponential_distribution(1) {} |
| 4293 | _LIBCPP_INLINE_VISIBILITY |
| 4294 | explicit exponential_distribution(result_type __lambda) |
| 4295 | : __p_(param_type(__lambda)) {} |
| 4296 | #else |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4297 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4298 | explicit exponential_distribution(result_type __lambda = 1) |
| 4299 | : __p_(param_type(__lambda)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4300 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4301 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4302 | explicit exponential_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4303 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4304 | void reset() {} |
| 4305 | |
| 4306 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4307 | template<class _URNG> |
| 4308 | _LIBCPP_INLINE_VISIBILITY |
| 4309 | result_type operator()(_URNG& __g) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4310 | {return (*this)(__g, __p_);} |
| 4311 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4312 | |
| 4313 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4314 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4315 | result_type lambda() const {return __p_.lambda();} |
| 4316 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4317 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4318 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4319 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4320 | void param(const param_type& __p) {__p_ = __p;} |
| 4321 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4322 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4323 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 021f990 | 2010-05-16 17:56:20 +0000 | [diff] [blame] | 4325 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4326 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4327 | friend _LIBCPP_INLINE_VISIBILITY |
| 4328 | bool operator==(const exponential_distribution& __x, |
| 4329 | const exponential_distribution& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4330 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4331 | friend _LIBCPP_INLINE_VISIBILITY |
| 4332 | bool operator!=(const exponential_distribution& __x, |
| 4333 | const exponential_distribution& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4334 | {return !(__x == __y);} |
| 4335 | }; |
| 4336 | |
| 4337 | template <class _RealType> |
| 4338 | template<class _URNG> |
| 4339 | _RealType |
| 4340 | exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4341 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4342 | return -_VSTD::log |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4343 | ( |
| 4344 | result_type(1) - |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4345 | _VSTD::generate_canonical<result_type, |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4346 | numeric_limits<result_type>::digits>(__g) |
| 4347 | ) |
| 4348 | / __p.lambda(); |
| 4349 | } |
| 4350 | |
| 4351 | template <class _CharT, class _Traits, class _RealType> |
| 4352 | basic_ostream<_CharT, _Traits>& |
| 4353 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4354 | const exponential_distribution<_RealType>& __x) |
| 4355 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4356 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4357 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4358 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4359 | _OStream::scientific); |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4360 | return __os << __x.lambda(); |
| 4361 | } |
| 4362 | |
| 4363 | template <class _CharT, class _Traits, class _RealType> |
| 4364 | basic_istream<_CharT, _Traits>& |
| 4365 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4366 | exponential_distribution<_RealType>& __x) |
| 4367 | { |
| 4368 | typedef exponential_distribution<_RealType> _Eng; |
| 4369 | typedef typename _Eng::result_type result_type; |
| 4370 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4371 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4372 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4373 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4374 | result_type __lambda; |
| 4375 | __is >> __lambda; |
| 4376 | if (!__is.fail()) |
| 4377 | __x.param(param_type(__lambda)); |
| 4378 | return __is; |
| 4379 | } |
| 4380 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4381 | // normal_distribution |
| 4382 | |
| 4383 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4384 | class _LIBCPP_TEMPLATE_VIS normal_distribution |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4385 | { |
| 4386 | public: |
| 4387 | // types |
| 4388 | typedef _RealType result_type; |
| 4389 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4390 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4391 | { |
| 4392 | result_type __mean_; |
| 4393 | result_type __stddev_; |
| 4394 | public: |
| 4395 | typedef normal_distribution distribution_type; |
| 4396 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4397 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4398 | explicit param_type(result_type __mean = 0, result_type __stddev = 1) |
| 4399 | : __mean_(__mean), __stddev_(__stddev) {} |
| 4400 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4401 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4402 | result_type mean() const {return __mean_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4403 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4404 | result_type stddev() const {return __stddev_;} |
| 4405 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4406 | friend _LIBCPP_INLINE_VISIBILITY |
| 4407 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4408 | {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4409 | friend _LIBCPP_INLINE_VISIBILITY |
| 4410 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4411 | {return !(__x == __y);} |
| 4412 | }; |
| 4413 | |
| 4414 | private: |
| 4415 | param_type __p_; |
| 4416 | result_type _V_; |
| 4417 | bool _V_hot_; |
| 4418 | |
| 4419 | public: |
| 4420 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4421 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4422 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4423 | normal_distribution() : normal_distribution(0) {} |
| 4424 | _LIBCPP_INLINE_VISIBILITY |
| 4425 | explicit normal_distribution(result_type __mean, result_type __stddev = 1) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4426 | : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4427 | #else |
| 4428 | _LIBCPP_INLINE_VISIBILITY |
| 4429 | explicit normal_distribution(result_type __mean = 0, |
| 4430 | result_type __stddev = 1) |
| 4431 | : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} |
| 4432 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4433 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4434 | explicit normal_distribution(const param_type& __p) |
| 4435 | : __p_(__p), _V_hot_(false) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4436 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4437 | void reset() {_V_hot_ = false;} |
| 4438 | |
| 4439 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4440 | template<class _URNG> |
| 4441 | _LIBCPP_INLINE_VISIBILITY |
| 4442 | result_type operator()(_URNG& __g) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4443 | {return (*this)(__g, __p_);} |
| 4444 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4445 | |
| 4446 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4447 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4448 | result_type mean() const {return __p_.mean();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4449 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4450 | result_type stddev() const {return __p_.stddev();} |
| 4451 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4452 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4453 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4454 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4455 | void param(const param_type& __p) {__p_ = __p;} |
| 4456 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4457 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4458 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4459 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4460 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4461 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4462 | friend _LIBCPP_INLINE_VISIBILITY |
| 4463 | bool operator==(const normal_distribution& __x, |
| 4464 | const normal_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4465 | {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && |
| 4466 | (!__x._V_hot_ || __x._V_ == __y._V_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4467 | friend _LIBCPP_INLINE_VISIBILITY |
| 4468 | bool operator!=(const normal_distribution& __x, |
| 4469 | const normal_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4470 | {return !(__x == __y);} |
| 4471 | |
| 4472 | template <class _CharT, class _Traits, class _RT> |
| 4473 | friend |
| 4474 | basic_ostream<_CharT, _Traits>& |
| 4475 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4476 | const normal_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4477 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4478 | template <class _CharT, class _Traits, class _RT> |
| 4479 | friend |
| 4480 | basic_istream<_CharT, _Traits>& |
| 4481 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4482 | normal_distribution<_RT>& __x); |
| 4483 | }; |
| 4484 | |
| 4485 | template <class _RealType> |
| 4486 | template<class _URNG> |
| 4487 | _RealType |
| 4488 | normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4489 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4490 | result_type _Up; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4491 | if (_V_hot_) |
| 4492 | { |
| 4493 | _V_hot_ = false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4494 | _Up = _V_; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4495 | } |
| 4496 | else |
| 4497 | { |
| 4498 | uniform_real_distribution<result_type> _Uni(-1, 1); |
| 4499 | result_type __u; |
| 4500 | result_type __v; |
| 4501 | result_type __s; |
| 4502 | do |
| 4503 | { |
| 4504 | __u = _Uni(__g); |
| 4505 | __v = _Uni(__g); |
| 4506 | __s = __u * __u + __v * __v; |
| 4507 | } while (__s > 1 || __s == 0); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4508 | result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); |
| 4509 | _V_ = __v * _Fp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4510 | _V_hot_ = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4511 | _Up = __u * _Fp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4512 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4513 | return _Up * __p.stddev() + __p.mean(); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4514 | } |
| 4515 | |
| 4516 | template <class _CharT, class _Traits, class _RT> |
| 4517 | basic_ostream<_CharT, _Traits>& |
| 4518 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4519 | const normal_distribution<_RT>& __x) |
| 4520 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4521 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4522 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4523 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4524 | _OStream::scientific); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4525 | _CharT __sp = __os.widen(' '); |
| 4526 | __os.fill(__sp); |
| 4527 | __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; |
| 4528 | if (__x._V_hot_) |
| 4529 | __os << __sp << __x._V_; |
| 4530 | return __os; |
| 4531 | } |
| 4532 | |
| 4533 | template <class _CharT, class _Traits, class _RT> |
| 4534 | basic_istream<_CharT, _Traits>& |
| 4535 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4536 | normal_distribution<_RT>& __x) |
| 4537 | { |
| 4538 | typedef normal_distribution<_RT> _Eng; |
| 4539 | typedef typename _Eng::result_type result_type; |
| 4540 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4541 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4542 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4543 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4544 | result_type __mean; |
| 4545 | result_type __stddev; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4546 | result_type _Vp = 0; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4547 | bool _V_hot = false; |
| 4548 | __is >> __mean >> __stddev >> _V_hot; |
| 4549 | if (_V_hot) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4550 | __is >> _Vp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4551 | if (!__is.fail()) |
| 4552 | { |
| 4553 | __x.param(param_type(__mean, __stddev)); |
| 4554 | __x._V_hot_ = _V_hot; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4555 | __x._V_ = _Vp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4556 | } |
| 4557 | return __is; |
| 4558 | } |
| 4559 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4560 | // lognormal_distribution |
| 4561 | |
| 4562 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4563 | class _LIBCPP_TEMPLATE_VIS lognormal_distribution |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4564 | { |
| 4565 | public: |
| 4566 | // types |
| 4567 | typedef _RealType result_type; |
| 4568 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4569 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4570 | { |
| 4571 | normal_distribution<result_type> __nd_; |
| 4572 | public: |
| 4573 | typedef lognormal_distribution distribution_type; |
| 4574 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4575 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4576 | explicit param_type(result_type __m = 0, result_type __s = 1) |
| 4577 | : __nd_(__m, __s) {} |
| 4578 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4579 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4580 | result_type m() const {return __nd_.mean();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4581 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4582 | result_type s() const {return __nd_.stddev();} |
| 4583 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4584 | friend _LIBCPP_INLINE_VISIBILITY |
| 4585 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4586 | {return __x.__nd_ == __y.__nd_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4587 | friend _LIBCPP_INLINE_VISIBILITY |
| 4588 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4589 | {return !(__x == __y);} |
| 4590 | friend class lognormal_distribution; |
| 4591 | |
| 4592 | template <class _CharT, class _Traits, class _RT> |
| 4593 | friend |
| 4594 | basic_ostream<_CharT, _Traits>& |
| 4595 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4596 | const lognormal_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4597 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4598 | template <class _CharT, class _Traits, class _RT> |
| 4599 | friend |
| 4600 | basic_istream<_CharT, _Traits>& |
| 4601 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4602 | lognormal_distribution<_RT>& __x); |
| 4603 | }; |
| 4604 | |
| 4605 | private: |
| 4606 | param_type __p_; |
| 4607 | |
| 4608 | public: |
| 4609 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4610 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4611 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4612 | lognormal_distribution() : lognormal_distribution(0) {} |
| 4613 | _LIBCPP_INLINE_VISIBILITY |
| 4614 | explicit lognormal_distribution(result_type __m, result_type __s = 1) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4615 | : __p_(param_type(__m, __s)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4616 | #else |
| 4617 | _LIBCPP_INLINE_VISIBILITY |
| 4618 | explicit lognormal_distribution(result_type __m = 0, |
| 4619 | result_type __s = 1) |
| 4620 | : __p_(param_type(__m, __s)) {} |
| 4621 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4622 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4623 | explicit lognormal_distribution(const param_type& __p) |
| 4624 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4625 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4626 | void reset() {__p_.__nd_.reset();} |
| 4627 | |
| 4628 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4629 | template<class _URNG> |
| 4630 | _LIBCPP_INLINE_VISIBILITY |
| 4631 | result_type operator()(_URNG& __g) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4632 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4633 | template<class _URNG> |
| 4634 | _LIBCPP_INLINE_VISIBILITY |
| 4635 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4636 | {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4637 | |
| 4638 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4639 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4640 | result_type m() const {return __p_.m();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4641 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4642 | result_type s() const {return __p_.s();} |
| 4643 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4644 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4645 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4646 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 4647 | void param(const param_type& __p) {__p_ = __p;} |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4648 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4649 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4650 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4651 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4652 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4653 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4654 | friend _LIBCPP_INLINE_VISIBILITY |
| 4655 | bool operator==(const lognormal_distribution& __x, |
| 4656 | const lognormal_distribution& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4657 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4658 | friend _LIBCPP_INLINE_VISIBILITY |
| 4659 | bool operator!=(const lognormal_distribution& __x, |
| 4660 | const lognormal_distribution& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4661 | {return !(__x == __y);} |
| 4662 | |
| 4663 | template <class _CharT, class _Traits, class _RT> |
| 4664 | friend |
| 4665 | basic_ostream<_CharT, _Traits>& |
| 4666 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4667 | const lognormal_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4668 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4669 | template <class _CharT, class _Traits, class _RT> |
| 4670 | friend |
| 4671 | basic_istream<_CharT, _Traits>& |
| 4672 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4673 | lognormal_distribution<_RT>& __x); |
| 4674 | }; |
| 4675 | |
| 4676 | template <class _CharT, class _Traits, class _RT> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4677 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4678 | basic_ostream<_CharT, _Traits>& |
| 4679 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4680 | const lognormal_distribution<_RT>& __x) |
| 4681 | { |
| 4682 | return __os << __x.__p_.__nd_; |
| 4683 | } |
| 4684 | |
| 4685 | template <class _CharT, class _Traits, class _RT> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4686 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4687 | basic_istream<_CharT, _Traits>& |
| 4688 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4689 | lognormal_distribution<_RT>& __x) |
| 4690 | { |
| 4691 | return __is >> __x.__p_.__nd_; |
| 4692 | } |
| 4693 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4694 | // poisson_distribution |
| 4695 | |
| 4696 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4697 | class _LIBCPP_TEMPLATE_VIS poisson_distribution |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4698 | { |
| 4699 | public: |
| 4700 | // types |
| 4701 | typedef _IntType result_type; |
| 4702 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4703 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4704 | { |
| 4705 | double __mean_; |
| 4706 | double __s_; |
| 4707 | double __d_; |
| 4708 | double __l_; |
| 4709 | double __omega_; |
| 4710 | double __c0_; |
| 4711 | double __c1_; |
| 4712 | double __c2_; |
| 4713 | double __c3_; |
| 4714 | double __c_; |
| 4715 | |
| 4716 | public: |
| 4717 | typedef poisson_distribution distribution_type; |
| 4718 | |
| 4719 | explicit param_type(double __mean = 1.0); |
| 4720 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4721 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4722 | double mean() const {return __mean_;} |
| 4723 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4724 | friend _LIBCPP_INLINE_VISIBILITY |
| 4725 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4726 | {return __x.__mean_ == __y.__mean_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4727 | friend _LIBCPP_INLINE_VISIBILITY |
| 4728 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4729 | {return !(__x == __y);} |
| 4730 | |
| 4731 | friend class poisson_distribution; |
| 4732 | }; |
| 4733 | |
| 4734 | private: |
| 4735 | param_type __p_; |
| 4736 | |
| 4737 | public: |
| 4738 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4739 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4740 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4741 | poisson_distribution() : poisson_distribution(1.0) {} |
| 4742 | _LIBCPP_INLINE_VISIBILITY |
| 4743 | explicit poisson_distribution(double __mean) |
| 4744 | : __p_(__mean) {} |
| 4745 | #else |
| 4746 | _LIBCPP_INLINE_VISIBILITY |
| 4747 | explicit poisson_distribution(double __mean = 1.0) |
| 4748 | : __p_(__mean) {} |
| 4749 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4750 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4751 | explicit poisson_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4752 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4753 | void reset() {} |
| 4754 | |
| 4755 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4756 | template<class _URNG> |
| 4757 | _LIBCPP_INLINE_VISIBILITY |
| 4758 | result_type operator()(_URNG& __g) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4759 | {return (*this)(__g, __p_);} |
| 4760 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4761 | |
| 4762 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4763 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4764 | double mean() const {return __p_.mean();} |
| 4765 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4766 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4767 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4768 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4769 | void param(const param_type& __p) {__p_ = __p;} |
| 4770 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4771 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4772 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4773 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4774 | result_type max() const {return numeric_limits<result_type>::max();} |
| 4775 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4776 | friend _LIBCPP_INLINE_VISIBILITY |
| 4777 | bool operator==(const poisson_distribution& __x, |
| 4778 | const poisson_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4779 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4780 | friend _LIBCPP_INLINE_VISIBILITY |
| 4781 | bool operator!=(const poisson_distribution& __x, |
| 4782 | const poisson_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4783 | {return !(__x == __y);} |
| 4784 | }; |
| 4785 | |
| 4786 | template<class _IntType> |
| 4787 | poisson_distribution<_IntType>::param_type::param_type(double __mean) |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4788 | // According to the standard `inf` is a valid input, but it causes the |
| 4789 | // distribution to hang, so we replace it with the maximum representable |
| 4790 | // mean. |
| 4791 | : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4792 | { |
| 4793 | if (__mean_ < 10) |
| 4794 | { |
| 4795 | __s_ = 0; |
| 4796 | __d_ = 0; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4797 | __l_ = _VSTD::exp(-__mean_); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4798 | __omega_ = 0; |
| 4799 | __c3_ = 0; |
| 4800 | __c2_ = 0; |
| 4801 | __c1_ = 0; |
| 4802 | __c0_ = 0; |
| 4803 | __c_ = 0; |
| 4804 | } |
| 4805 | else |
| 4806 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4807 | __s_ = _VSTD::sqrt(__mean_); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4808 | __d_ = 6 * __mean_ * __mean_; |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4809 | __l_ = _VSTD::trunc(__mean_ - 1.1484); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4810 | __omega_ = .3989423 / __s_; |
| 4811 | double __b1_ = .4166667E-1 / __mean_; |
| 4812 | double __b2_ = .3 * __b1_ * __b1_; |
| 4813 | __c3_ = .1428571 * __b1_ * __b2_; |
| 4814 | __c2_ = __b2_ - 15. * __c3_; |
| 4815 | __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; |
| 4816 | __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; |
| 4817 | __c_ = .1069 / __mean_; |
| 4818 | } |
| 4819 | } |
| 4820 | |
| 4821 | template <class _IntType> |
| 4822 | template<class _URNG> |
| 4823 | _IntType |
| 4824 | poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) |
| 4825 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4826 | double __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4827 | uniform_real_distribution<double> __urd; |
Howard Hinnant | a5fb7ac | 2011-04-14 15:59:22 +0000 | [diff] [blame] | 4828 | if (__pr.__mean_ < 10) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4829 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4830 | __tx = 0; |
| 4831 | for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4832 | __p *= __urd(__urng); |
| 4833 | } |
| 4834 | else |
| 4835 | { |
| 4836 | double __difmuk; |
| 4837 | double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); |
| 4838 | double __u; |
| 4839 | if (__g > 0) |
| 4840 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4841 | __tx = _VSTD::trunc(__g); |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4842 | if (__tx >= __pr.__l_) |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4843 | return _VSTD::__clamp_to_integral<result_type>(__tx); |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4844 | __difmuk = __pr.__mean_ - __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4845 | __u = __urd(__urng); |
| 4846 | if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4847 | return _VSTD::__clamp_to_integral<result_type>(__tx); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4848 | } |
| 4849 | exponential_distribution<double> __edist; |
| 4850 | for (bool __using_exp_dist = false; true; __using_exp_dist = true) |
| 4851 | { |
| 4852 | double __e; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4853 | if (__using_exp_dist || __g <= 0) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4854 | { |
| 4855 | double __t; |
| 4856 | do |
| 4857 | { |
| 4858 | __e = __edist(__urng); |
| 4859 | __u = __urd(__urng); |
| 4860 | __u += __u - 1; |
| 4861 | __t = 1.8 + (__u < 0 ? -__e : __e); |
| 4862 | } while (__t <= -.6744); |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4863 | __tx = _VSTD::trunc(__pr.__mean_ + __pr.__s_ * __t); |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4864 | __difmuk = __pr.__mean_ - __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4865 | __using_exp_dist = true; |
| 4866 | } |
| 4867 | double __px; |
| 4868 | double __py; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4869 | if (__tx < 10 && __tx >= 0) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4870 | { |
Marshall Clow | c7e36e8 | 2018-01-16 14:54:36 +0000 | [diff] [blame] | 4871 | const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4872 | 40320, 362880}; |
| 4873 | __px = -__pr.__mean_; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4874 | __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)]; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4875 | } |
| 4876 | else |
| 4877 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4878 | double __del = .8333333E-1 / __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4879 | __del -= 4.8 * __del * __del * __del; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4880 | double __v = __difmuk / __tx; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4881 | if (_VSTD::abs(__v) > 0.25) |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4882 | __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4883 | else |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4884 | __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) * |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4885 | __v + .1421878) * __v + -.1661269) * __v + .2000118) * |
| 4886 | __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4887 | __py = .3989423 / _VSTD::sqrt(__tx); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4888 | } |
| 4889 | double __r = (0.5 - __difmuk) / __pr.__s_; |
| 4890 | double __r2 = __r * __r; |
| 4891 | double __fx = -0.5 * __r2; |
| 4892 | double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * |
| 4893 | __r2 + __pr.__c1_) * __r2 + __pr.__c0_); |
| 4894 | if (__using_exp_dist) |
| 4895 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4896 | if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - |
| 4897 | __fy * _VSTD::exp(__fx + __e)) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4898 | break; |
| 4899 | } |
| 4900 | else |
| 4901 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4902 | if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4903 | break; |
| 4904 | } |
| 4905 | } |
| 4906 | } |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4907 | return _VSTD::__clamp_to_integral<result_type>(__tx); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4908 | } |
| 4909 | |
| 4910 | template <class _CharT, class _Traits, class _IntType> |
| 4911 | basic_ostream<_CharT, _Traits>& |
| 4912 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4913 | const poisson_distribution<_IntType>& __x) |
| 4914 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4915 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4916 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4917 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4918 | _OStream::scientific); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4919 | return __os << __x.mean(); |
| 4920 | } |
| 4921 | |
| 4922 | template <class _CharT, class _Traits, class _IntType> |
| 4923 | basic_istream<_CharT, _Traits>& |
| 4924 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4925 | poisson_distribution<_IntType>& __x) |
| 4926 | { |
| 4927 | typedef poisson_distribution<_IntType> _Eng; |
| 4928 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4929 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4930 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4931 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4932 | double __mean; |
| 4933 | __is >> __mean; |
| 4934 | if (!__is.fail()) |
| 4935 | __x.param(param_type(__mean)); |
| 4936 | return __is; |
| 4937 | } |
| 4938 | |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4939 | // weibull_distribution |
| 4940 | |
| 4941 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4942 | class _LIBCPP_TEMPLATE_VIS weibull_distribution |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4943 | { |
| 4944 | public: |
| 4945 | // types |
| 4946 | typedef _RealType result_type; |
| 4947 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4948 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4949 | { |
| 4950 | result_type __a_; |
| 4951 | result_type __b_; |
| 4952 | public: |
| 4953 | typedef weibull_distribution distribution_type; |
| 4954 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4955 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4956 | explicit param_type(result_type __a = 1, result_type __b = 1) |
| 4957 | : __a_(__a), __b_(__b) {} |
| 4958 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4959 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4960 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4961 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4962 | result_type b() const {return __b_;} |
| 4963 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4964 | friend _LIBCPP_INLINE_VISIBILITY |
| 4965 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4966 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4967 | friend _LIBCPP_INLINE_VISIBILITY |
| 4968 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4969 | {return !(__x == __y);} |
| 4970 | }; |
| 4971 | |
| 4972 | private: |
| 4973 | param_type __p_; |
| 4974 | |
| 4975 | public: |
| 4976 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4977 | #ifndef _LIBCPP_CXX03_LANG |
| 4978 | _LIBCPP_INLINE_VISIBILITY |
| 4979 | weibull_distribution() : weibull_distribution(1) {} |
| 4980 | _LIBCPP_INLINE_VISIBILITY |
| 4981 | explicit weibull_distribution(result_type __a, result_type __b = 1) |
| 4982 | : __p_(param_type(__a, __b)) {} |
| 4983 | #else |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4984 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4985 | explicit weibull_distribution(result_type __a = 1, result_type __b = 1) |
| 4986 | : __p_(param_type(__a, __b)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 4987 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4988 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4989 | explicit weibull_distribution(const param_type& __p) |
| 4990 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4991 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4992 | void reset() {} |
| 4993 | |
| 4994 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4995 | template<class _URNG> |
| 4996 | _LIBCPP_INLINE_VISIBILITY |
| 4997 | result_type operator()(_URNG& __g) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4998 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4999 | template<class _URNG> |
| 5000 | _LIBCPP_INLINE_VISIBILITY |
| 5001 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5002 | {return __p.b() * |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5003 | _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5004 | |
| 5005 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5006 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5007 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5008 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5009 | result_type b() const {return __p_.b();} |
| 5010 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5011 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5012 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5013 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5014 | void param(const param_type& __p) {__p_ = __p;} |
| 5015 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5016 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5017 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5018 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5019 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 5020 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5021 | friend _LIBCPP_INLINE_VISIBILITY |
| 5022 | bool operator==(const weibull_distribution& __x, |
| 5023 | const weibull_distribution& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5024 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5025 | friend _LIBCPP_INLINE_VISIBILITY |
| 5026 | bool operator!=(const weibull_distribution& __x, |
| 5027 | const weibull_distribution& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5028 | {return !(__x == __y);} |
| 5029 | }; |
| 5030 | |
| 5031 | template <class _CharT, class _Traits, class _RT> |
| 5032 | basic_ostream<_CharT, _Traits>& |
| 5033 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5034 | const weibull_distribution<_RT>& __x) |
| 5035 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5036 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5037 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5038 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5039 | _OStream::scientific); |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5040 | _CharT __sp = __os.widen(' '); |
| 5041 | __os.fill(__sp); |
| 5042 | __os << __x.a() << __sp << __x.b(); |
| 5043 | return __os; |
| 5044 | } |
| 5045 | |
| 5046 | template <class _CharT, class _Traits, class _RT> |
| 5047 | basic_istream<_CharT, _Traits>& |
| 5048 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5049 | weibull_distribution<_RT>& __x) |
| 5050 | { |
| 5051 | typedef weibull_distribution<_RT> _Eng; |
| 5052 | typedef typename _Eng::result_type result_type; |
| 5053 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5054 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5055 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5056 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 5057 | result_type __a; |
| 5058 | result_type __b; |
| 5059 | __is >> __a >> __b; |
| 5060 | if (!__is.fail()) |
| 5061 | __x.param(param_type(__a, __b)); |
| 5062 | return __is; |
| 5063 | } |
| 5064 | |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5065 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5066 | class _LIBCPP_TEMPLATE_VIS extreme_value_distribution |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5067 | { |
| 5068 | public: |
| 5069 | // types |
| 5070 | typedef _RealType result_type; |
| 5071 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5072 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5073 | { |
| 5074 | result_type __a_; |
| 5075 | result_type __b_; |
| 5076 | public: |
| 5077 | typedef extreme_value_distribution distribution_type; |
| 5078 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5079 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5080 | explicit param_type(result_type __a = 0, result_type __b = 1) |
| 5081 | : __a_(__a), __b_(__b) {} |
| 5082 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5083 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5084 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5085 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5086 | result_type b() const {return __b_;} |
| 5087 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5088 | friend _LIBCPP_INLINE_VISIBILITY |
| 5089 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5090 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5091 | friend _LIBCPP_INLINE_VISIBILITY |
| 5092 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5093 | {return !(__x == __y);} |
| 5094 | }; |
| 5095 | |
| 5096 | private: |
| 5097 | param_type __p_; |
| 5098 | |
| 5099 | public: |
| 5100 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5101 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5102 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5103 | extreme_value_distribution() : extreme_value_distribution(0) {} |
| 5104 | _LIBCPP_INLINE_VISIBILITY |
| 5105 | explicit extreme_value_distribution(result_type __a, result_type __b = 1) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5106 | : __p_(param_type(__a, __b)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5107 | #else |
| 5108 | _LIBCPP_INLINE_VISIBILITY |
| 5109 | explicit extreme_value_distribution(result_type __a = 0, |
| 5110 | result_type __b = 1) |
| 5111 | : __p_(param_type(__a, __b)) {} |
| 5112 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5113 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5114 | explicit extreme_value_distribution(const param_type& __p) |
| 5115 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5116 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5117 | void reset() {} |
| 5118 | |
| 5119 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5120 | template<class _URNG> |
| 5121 | _LIBCPP_INLINE_VISIBILITY |
| 5122 | result_type operator()(_URNG& __g) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5123 | {return (*this)(__g, __p_);} |
| 5124 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5125 | |
| 5126 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5127 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5128 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5129 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5130 | result_type b() const {return __p_.b();} |
| 5131 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5132 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5133 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5134 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5135 | void param(const param_type& __p) {__p_ = __p;} |
| 5136 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5138 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5139 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5140 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 5141 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5142 | friend _LIBCPP_INLINE_VISIBILITY |
| 5143 | bool operator==(const extreme_value_distribution& __x, |
| 5144 | const extreme_value_distribution& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5145 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5146 | friend _LIBCPP_INLINE_VISIBILITY |
| 5147 | bool operator!=(const extreme_value_distribution& __x, |
| 5148 | const extreme_value_distribution& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5149 | {return !(__x == __y);} |
| 5150 | }; |
| 5151 | |
| 5152 | template<class _RealType> |
| 5153 | template<class _URNG> |
| 5154 | _RealType |
| 5155 | extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5156 | { |
| 5157 | return __p.a() - __p.b() * |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5158 | _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | template <class _CharT, class _Traits, class _RT> |
| 5162 | basic_ostream<_CharT, _Traits>& |
| 5163 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5164 | const extreme_value_distribution<_RT>& __x) |
| 5165 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5166 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5167 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5168 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5169 | _OStream::scientific); |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5170 | _CharT __sp = __os.widen(' '); |
| 5171 | __os.fill(__sp); |
| 5172 | __os << __x.a() << __sp << __x.b(); |
| 5173 | return __os; |
| 5174 | } |
| 5175 | |
| 5176 | template <class _CharT, class _Traits, class _RT> |
| 5177 | basic_istream<_CharT, _Traits>& |
| 5178 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5179 | extreme_value_distribution<_RT>& __x) |
| 5180 | { |
| 5181 | typedef extreme_value_distribution<_RT> _Eng; |
| 5182 | typedef typename _Eng::result_type result_type; |
| 5183 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5184 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5185 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5186 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5187 | result_type __a; |
| 5188 | result_type __b; |
| 5189 | __is >> __a >> __b; |
| 5190 | if (!__is.fail()) |
| 5191 | __x.param(param_type(__a, __b)); |
| 5192 | return __is; |
| 5193 | } |
| 5194 | |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5195 | // gamma_distribution |
| 5196 | |
| 5197 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5198 | class _LIBCPP_TEMPLATE_VIS gamma_distribution |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5199 | { |
| 5200 | public: |
| 5201 | // types |
| 5202 | typedef _RealType result_type; |
| 5203 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5204 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5205 | { |
| 5206 | result_type __alpha_; |
| 5207 | result_type __beta_; |
| 5208 | public: |
| 5209 | typedef gamma_distribution distribution_type; |
| 5210 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5211 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5212 | explicit param_type(result_type __alpha = 1, result_type __beta = 1) |
| 5213 | : __alpha_(__alpha), __beta_(__beta) {} |
| 5214 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5215 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5216 | result_type alpha() const {return __alpha_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5217 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5218 | result_type beta() const {return __beta_;} |
| 5219 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5220 | friend _LIBCPP_INLINE_VISIBILITY |
| 5221 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5222 | {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5223 | friend _LIBCPP_INLINE_VISIBILITY |
| 5224 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5225 | {return !(__x == __y);} |
| 5226 | }; |
| 5227 | |
| 5228 | private: |
| 5229 | param_type __p_; |
| 5230 | |
| 5231 | public: |
| 5232 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5233 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5234 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5235 | gamma_distribution() : gamma_distribution(1) {} |
| 5236 | _LIBCPP_INLINE_VISIBILITY |
| 5237 | explicit gamma_distribution(result_type __alpha, result_type __beta = 1) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5238 | : __p_(param_type(__alpha, __beta)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5239 | #else |
| 5240 | _LIBCPP_INLINE_VISIBILITY |
| 5241 | explicit gamma_distribution(result_type __alpha = 1, |
| 5242 | result_type __beta = 1) |
| 5243 | : __p_(param_type(__alpha, __beta)) {} |
| 5244 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5245 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5246 | explicit gamma_distribution(const param_type& __p) |
| 5247 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5248 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5249 | void reset() {} |
| 5250 | |
| 5251 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5252 | template<class _URNG> |
| 5253 | _LIBCPP_INLINE_VISIBILITY |
| 5254 | result_type operator()(_URNG& __g) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5255 | {return (*this)(__g, __p_);} |
| 5256 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5257 | |
| 5258 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5259 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5260 | result_type alpha() const {return __p_.alpha();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5261 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5262 | result_type beta() const {return __p_.beta();} |
| 5263 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5264 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5265 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5266 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5267 | void param(const param_type& __p) {__p_ = __p;} |
| 5268 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5269 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5270 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5271 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5272 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5273 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5274 | friend _LIBCPP_INLINE_VISIBILITY |
| 5275 | bool operator==(const gamma_distribution& __x, |
| 5276 | const gamma_distribution& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5277 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5278 | friend _LIBCPP_INLINE_VISIBILITY |
| 5279 | bool operator!=(const gamma_distribution& __x, |
| 5280 | const gamma_distribution& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5281 | {return !(__x == __y);} |
| 5282 | }; |
| 5283 | |
| 5284 | template <class _RealType> |
| 5285 | template<class _URNG> |
| 5286 | _RealType |
| 5287 | gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5288 | { |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5289 | result_type __a = __p.alpha(); |
| 5290 | uniform_real_distribution<result_type> __gen(0, 1); |
| 5291 | exponential_distribution<result_type> __egen; |
| 5292 | result_type __x; |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5293 | if (__a == 1) |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5294 | __x = __egen(__g); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5295 | else if (__a > 1) |
| 5296 | { |
| 5297 | const result_type __b = __a - 1; |
| 5298 | const result_type __c = 3 * __a - result_type(0.75); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5299 | while (true) |
| 5300 | { |
| 5301 | const result_type __u = __gen(__g); |
| 5302 | const result_type __v = __gen(__g); |
| 5303 | const result_type __w = __u * (1 - __u); |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5304 | if (__w != 0) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5305 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5306 | const result_type __y = _VSTD::sqrt(__c / __w) * |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5307 | (__u - result_type(0.5)); |
| 5308 | __x = __b + __y; |
| 5309 | if (__x >= 0) |
| 5310 | { |
| 5311 | const result_type __z = 64 * __w * __w * __w * __v * __v; |
| 5312 | if (__z <= 1 - 2 * __y * __y / __x) |
| 5313 | break; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5314 | if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5315 | break; |
| 5316 | } |
| 5317 | } |
| 5318 | } |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5319 | } |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5320 | else // __a < 1 |
| 5321 | { |
| 5322 | while (true) |
| 5323 | { |
| 5324 | const result_type __u = __gen(__g); |
| 5325 | const result_type __es = __egen(__g); |
| 5326 | if (__u <= 1 - __a) |
| 5327 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5328 | __x = _VSTD::pow(__u, 1 / __a); |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5329 | if (__x <= __es) |
| 5330 | break; |
| 5331 | } |
| 5332 | else |
| 5333 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5334 | const result_type __e = -_VSTD::log((1-__u)/__a); |
| 5335 | __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5336 | if (__x <= __e + __es) |
| 5337 | break; |
| 5338 | } |
| 5339 | } |
| 5340 | } |
| 5341 | return __x * __p.beta(); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5342 | } |
| 5343 | |
| 5344 | template <class _CharT, class _Traits, class _RT> |
| 5345 | basic_ostream<_CharT, _Traits>& |
| 5346 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5347 | const gamma_distribution<_RT>& __x) |
| 5348 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5349 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5350 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5351 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5352 | _OStream::scientific); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5353 | _CharT __sp = __os.widen(' '); |
| 5354 | __os.fill(__sp); |
| 5355 | __os << __x.alpha() << __sp << __x.beta(); |
| 5356 | return __os; |
| 5357 | } |
| 5358 | |
| 5359 | template <class _CharT, class _Traits, class _RT> |
| 5360 | basic_istream<_CharT, _Traits>& |
| 5361 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5362 | gamma_distribution<_RT>& __x) |
| 5363 | { |
| 5364 | typedef gamma_distribution<_RT> _Eng; |
| 5365 | typedef typename _Eng::result_type result_type; |
| 5366 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5367 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5368 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5369 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5370 | result_type __alpha; |
| 5371 | result_type __beta; |
| 5372 | __is >> __alpha >> __beta; |
| 5373 | if (!__is.fail()) |
| 5374 | __x.param(param_type(__alpha, __beta)); |
| 5375 | return __is; |
| 5376 | } |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 5377 | |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5378 | // negative_binomial_distribution |
| 5379 | |
| 5380 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5381 | class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5382 | { |
| 5383 | public: |
| 5384 | // types |
| 5385 | typedef _IntType result_type; |
| 5386 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5387 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5388 | { |
| 5389 | result_type __k_; |
| 5390 | double __p_; |
| 5391 | public: |
| 5392 | typedef negative_binomial_distribution distribution_type; |
| 5393 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5394 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5395 | explicit param_type(result_type __k = 1, double __p = 0.5) |
| 5396 | : __k_(__k), __p_(__p) {} |
| 5397 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5398 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5399 | result_type k() const {return __k_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5400 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5401 | double p() const {return __p_;} |
| 5402 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5403 | friend _LIBCPP_INLINE_VISIBILITY |
| 5404 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5405 | {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5406 | friend _LIBCPP_INLINE_VISIBILITY |
| 5407 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5408 | {return !(__x == __y);} |
| 5409 | }; |
| 5410 | |
| 5411 | private: |
| 5412 | param_type __p_; |
| 5413 | |
| 5414 | public: |
| 5415 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5416 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5417 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5418 | negative_binomial_distribution() : negative_binomial_distribution(1) {} |
| 5419 | _LIBCPP_INLINE_VISIBILITY |
| 5420 | explicit negative_binomial_distribution(result_type __k, double __p = 0.5) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5421 | : __p_(__k, __p) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5422 | #else |
| 5423 | _LIBCPP_INLINE_VISIBILITY |
| 5424 | explicit negative_binomial_distribution(result_type __k = 1, |
| 5425 | double __p = 0.5) |
| 5426 | : __p_(__k, __p) {} |
| 5427 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5428 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5429 | explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5430 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5431 | void reset() {} |
| 5432 | |
| 5433 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5434 | template<class _URNG> |
| 5435 | _LIBCPP_INLINE_VISIBILITY |
| 5436 | result_type operator()(_URNG& __g) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5437 | {return (*this)(__g, __p_);} |
| 5438 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5439 | |
| 5440 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5441 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5442 | result_type k() const {return __p_.k();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5443 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5444 | double p() const {return __p_.p();} |
| 5445 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5446 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5447 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5449 | void param(const param_type& __p) {__p_ = __p;} |
| 5450 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5451 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5452 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5453 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5454 | result_type max() const {return numeric_limits<result_type>::max();} |
| 5455 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5456 | friend _LIBCPP_INLINE_VISIBILITY |
| 5457 | bool operator==(const negative_binomial_distribution& __x, |
| 5458 | const negative_binomial_distribution& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5459 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5460 | friend _LIBCPP_INLINE_VISIBILITY |
| 5461 | bool operator!=(const negative_binomial_distribution& __x, |
| 5462 | const negative_binomial_distribution& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5463 | {return !(__x == __y);} |
| 5464 | }; |
| 5465 | |
| 5466 | template <class _IntType> |
| 5467 | template<class _URNG> |
| 5468 | _IntType |
| 5469 | negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) |
| 5470 | { |
| 5471 | result_type __k = __pr.k(); |
| 5472 | double __p = __pr.p(); |
| 5473 | if (__k <= 21 * __p) |
| 5474 | { |
| 5475 | bernoulli_distribution __gen(__p); |
| 5476 | result_type __f = 0; |
| 5477 | result_type __s = 0; |
| 5478 | while (__s < __k) |
| 5479 | { |
| 5480 | if (__gen(__urng)) |
| 5481 | ++__s; |
| 5482 | else |
| 5483 | ++__f; |
| 5484 | } |
| 5485 | return __f; |
| 5486 | } |
| 5487 | return poisson_distribution<result_type>(gamma_distribution<double> |
| 5488 | (__k, (1-__p)/__p)(__urng))(__urng); |
| 5489 | } |
| 5490 | |
| 5491 | template <class _CharT, class _Traits, class _IntType> |
| 5492 | basic_ostream<_CharT, _Traits>& |
| 5493 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5494 | const negative_binomial_distribution<_IntType>& __x) |
| 5495 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5496 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5497 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5498 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5499 | _OStream::scientific); |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5500 | _CharT __sp = __os.widen(' '); |
| 5501 | __os.fill(__sp); |
| 5502 | return __os << __x.k() << __sp << __x.p(); |
| 5503 | } |
| 5504 | |
| 5505 | template <class _CharT, class _Traits, class _IntType> |
| 5506 | basic_istream<_CharT, _Traits>& |
| 5507 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5508 | negative_binomial_distribution<_IntType>& __x) |
| 5509 | { |
| 5510 | typedef negative_binomial_distribution<_IntType> _Eng; |
| 5511 | typedef typename _Eng::result_type result_type; |
| 5512 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5513 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5514 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5515 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5516 | result_type __k; |
| 5517 | double __p; |
| 5518 | __is >> __k >> __p; |
| 5519 | if (!__is.fail()) |
| 5520 | __x.param(param_type(__k, __p)); |
| 5521 | return __is; |
| 5522 | } |
| 5523 | |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5524 | // geometric_distribution |
| 5525 | |
| 5526 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5527 | class _LIBCPP_TEMPLATE_VIS geometric_distribution |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5528 | { |
| 5529 | public: |
| 5530 | // types |
| 5531 | typedef _IntType result_type; |
| 5532 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5533 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5534 | { |
| 5535 | double __p_; |
| 5536 | public: |
| 5537 | typedef geometric_distribution distribution_type; |
| 5538 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5540 | explicit param_type(double __p = 0.5) : __p_(__p) {} |
| 5541 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5543 | double p() const {return __p_;} |
| 5544 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5545 | friend _LIBCPP_INLINE_VISIBILITY |
| 5546 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5547 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5548 | friend _LIBCPP_INLINE_VISIBILITY |
| 5549 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5550 | {return !(__x == __y);} |
| 5551 | }; |
| 5552 | |
| 5553 | private: |
| 5554 | param_type __p_; |
| 5555 | |
| 5556 | public: |
| 5557 | // constructors and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5558 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5559 | _LIBCPP_INLINE_VISIBILITY |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5560 | geometric_distribution() : geometric_distribution(0.5) {} |
| 5561 | _LIBCPP_INLINE_VISIBILITY |
| 5562 | explicit geometric_distribution(double __p) |
| 5563 | : __p_(__p) {} |
| 5564 | #else |
| 5565 | _LIBCPP_INLINE_VISIBILITY |
| 5566 | explicit geometric_distribution(double __p = 0.5) |
| 5567 | : __p_(__p) {} |
| 5568 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5569 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5570 | explicit geometric_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5571 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5572 | void reset() {} |
| 5573 | |
| 5574 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5575 | template<class _URNG> |
| 5576 | _LIBCPP_INLINE_VISIBILITY |
| 5577 | result_type operator()(_URNG& __g) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5578 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5579 | template<class _URNG> |
| 5580 | _LIBCPP_INLINE_VISIBILITY |
| 5581 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5582 | {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} |
| 5583 | |
| 5584 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5585 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5586 | double p() const {return __p_.p();} |
| 5587 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5588 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5589 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5590 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5591 | void param(const param_type& __p) {__p_ = __p;} |
| 5592 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5593 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5594 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5595 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5596 | result_type max() const {return numeric_limits<result_type>::max();} |
| 5597 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5598 | friend _LIBCPP_INLINE_VISIBILITY |
| 5599 | bool operator==(const geometric_distribution& __x, |
| 5600 | const geometric_distribution& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5601 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5602 | friend _LIBCPP_INLINE_VISIBILITY |
| 5603 | bool operator!=(const geometric_distribution& __x, |
| 5604 | const geometric_distribution& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5605 | {return !(__x == __y);} |
| 5606 | }; |
| 5607 | |
| 5608 | template <class _CharT, class _Traits, class _IntType> |
| 5609 | basic_ostream<_CharT, _Traits>& |
| 5610 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5611 | const geometric_distribution<_IntType>& __x) |
| 5612 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5613 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5614 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5615 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5616 | _OStream::scientific); |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5617 | return __os << __x.p(); |
| 5618 | } |
| 5619 | |
| 5620 | template <class _CharT, class _Traits, class _IntType> |
| 5621 | basic_istream<_CharT, _Traits>& |
| 5622 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5623 | geometric_distribution<_IntType>& __x) |
| 5624 | { |
| 5625 | typedef geometric_distribution<_IntType> _Eng; |
| 5626 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5627 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5628 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5629 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5630 | double __p; |
| 5631 | __is >> __p; |
| 5632 | if (!__is.fail()) |
| 5633 | __x.param(param_type(__p)); |
| 5634 | return __is; |
| 5635 | } |
| 5636 | |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5637 | // chi_squared_distribution |
| 5638 | |
| 5639 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5640 | class _LIBCPP_TEMPLATE_VIS chi_squared_distribution |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5641 | { |
| 5642 | public: |
| 5643 | // types |
| 5644 | typedef _RealType result_type; |
| 5645 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5646 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5647 | { |
| 5648 | result_type __n_; |
| 5649 | public: |
| 5650 | typedef chi_squared_distribution distribution_type; |
| 5651 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5652 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5653 | explicit param_type(result_type __n = 1) : __n_(__n) {} |
| 5654 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5655 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5656 | result_type n() const {return __n_;} |
| 5657 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5658 | friend _LIBCPP_INLINE_VISIBILITY |
| 5659 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5660 | {return __x.__n_ == __y.__n_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5661 | friend _LIBCPP_INLINE_VISIBILITY |
| 5662 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5663 | {return !(__x == __y);} |
| 5664 | }; |
| 5665 | |
| 5666 | private: |
| 5667 | param_type __p_; |
| 5668 | |
| 5669 | public: |
| 5670 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5671 | #ifndef _LIBCPP_CXX03_LANG |
| 5672 | _LIBCPP_INLINE_VISIBILITY |
| 5673 | chi_squared_distribution() : chi_squared_distribution(1) {} |
| 5674 | _LIBCPP_INLINE_VISIBILITY |
| 5675 | explicit chi_squared_distribution(result_type __n) |
| 5676 | : __p_(param_type(__n)) {} |
| 5677 | #else |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5678 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5679 | explicit chi_squared_distribution(result_type __n = 1) |
| 5680 | : __p_(param_type(__n)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5681 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5682 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5683 | explicit chi_squared_distribution(const param_type& __p) |
| 5684 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5685 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5686 | void reset() {} |
| 5687 | |
| 5688 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5689 | template<class _URNG> |
| 5690 | _LIBCPP_INLINE_VISIBILITY |
| 5691 | result_type operator()(_URNG& __g) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5692 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5693 | template<class _URNG> |
| 5694 | _LIBCPP_INLINE_VISIBILITY |
| 5695 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5696 | {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} |
| 5697 | |
| 5698 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5699 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5700 | result_type n() const {return __p_.n();} |
| 5701 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5702 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5703 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5704 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5705 | void param(const param_type& __p) {__p_ = __p;} |
| 5706 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5707 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5708 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5709 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5710 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5711 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5712 | friend _LIBCPP_INLINE_VISIBILITY |
| 5713 | bool operator==(const chi_squared_distribution& __x, |
| 5714 | const chi_squared_distribution& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5715 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5716 | friend _LIBCPP_INLINE_VISIBILITY |
| 5717 | bool operator!=(const chi_squared_distribution& __x, |
| 5718 | const chi_squared_distribution& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5719 | {return !(__x == __y);} |
| 5720 | }; |
| 5721 | |
| 5722 | template <class _CharT, class _Traits, class _RT> |
| 5723 | basic_ostream<_CharT, _Traits>& |
| 5724 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5725 | const chi_squared_distribution<_RT>& __x) |
| 5726 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5727 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5728 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5729 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5730 | _OStream::scientific); |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5731 | __os << __x.n(); |
| 5732 | return __os; |
| 5733 | } |
| 5734 | |
| 5735 | template <class _CharT, class _Traits, class _RT> |
| 5736 | basic_istream<_CharT, _Traits>& |
| 5737 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5738 | chi_squared_distribution<_RT>& __x) |
| 5739 | { |
| 5740 | typedef chi_squared_distribution<_RT> _Eng; |
| 5741 | typedef typename _Eng::result_type result_type; |
| 5742 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5743 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5744 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5745 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5746 | result_type __n; |
| 5747 | __is >> __n; |
| 5748 | if (!__is.fail()) |
| 5749 | __x.param(param_type(__n)); |
| 5750 | return __is; |
| 5751 | } |
| 5752 | |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5753 | // cauchy_distribution |
| 5754 | |
| 5755 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5756 | class _LIBCPP_TEMPLATE_VIS cauchy_distribution |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5757 | { |
| 5758 | public: |
| 5759 | // types |
| 5760 | typedef _RealType result_type; |
| 5761 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5762 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5763 | { |
| 5764 | result_type __a_; |
| 5765 | result_type __b_; |
| 5766 | public: |
| 5767 | typedef cauchy_distribution distribution_type; |
| 5768 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5769 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5770 | explicit param_type(result_type __a = 0, result_type __b = 1) |
| 5771 | : __a_(__a), __b_(__b) {} |
| 5772 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5773 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5774 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5775 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5776 | result_type b() const {return __b_;} |
| 5777 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5778 | friend _LIBCPP_INLINE_VISIBILITY |
| 5779 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5780 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5781 | friend _LIBCPP_INLINE_VISIBILITY |
| 5782 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5783 | {return !(__x == __y);} |
| 5784 | }; |
| 5785 | |
| 5786 | private: |
| 5787 | param_type __p_; |
| 5788 | |
| 5789 | public: |
| 5790 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5791 | #ifndef _LIBCPP_CXX03_LANG |
| 5792 | _LIBCPP_INLINE_VISIBILITY |
| 5793 | cauchy_distribution() : cauchy_distribution(0) {} |
| 5794 | _LIBCPP_INLINE_VISIBILITY |
| 5795 | explicit cauchy_distribution(result_type __a, result_type __b = 1) |
| 5796 | : __p_(param_type(__a, __b)) {} |
| 5797 | #else |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5799 | explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) |
| 5800 | : __p_(param_type(__a, __b)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5801 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5803 | explicit cauchy_distribution(const param_type& __p) |
| 5804 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5805 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5806 | void reset() {} |
| 5807 | |
| 5808 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5809 | template<class _URNG> |
| 5810 | _LIBCPP_INLINE_VISIBILITY |
| 5811 | result_type operator()(_URNG& __g) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5812 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5813 | template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5814 | |
| 5815 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5816 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5817 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5818 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5819 | result_type b() const {return __p_.b();} |
| 5820 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5821 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5822 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5823 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5824 | void param(const param_type& __p) {__p_ = __p;} |
| 5825 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5826 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5827 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5828 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5829 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5830 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5831 | friend _LIBCPP_INLINE_VISIBILITY |
| 5832 | bool operator==(const cauchy_distribution& __x, |
| 5833 | const cauchy_distribution& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5834 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5835 | friend _LIBCPP_INLINE_VISIBILITY |
| 5836 | bool operator!=(const cauchy_distribution& __x, |
| 5837 | const cauchy_distribution& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5838 | {return !(__x == __y);} |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5839 | }; |
| 5840 | |
| 5841 | template <class _RealType> |
| 5842 | template<class _URNG> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5843 | inline |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5844 | _RealType |
| 5845 | cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5846 | { |
| 5847 | uniform_real_distribution<result_type> __gen; |
| 5848 | // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5849 | return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5850 | } |
| 5851 | |
| 5852 | template <class _CharT, class _Traits, class _RT> |
| 5853 | basic_ostream<_CharT, _Traits>& |
| 5854 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5855 | const cauchy_distribution<_RT>& __x) |
| 5856 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5857 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5858 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5859 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5860 | _OStream::scientific); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5861 | _CharT __sp = __os.widen(' '); |
| 5862 | __os.fill(__sp); |
| 5863 | __os << __x.a() << __sp << __x.b(); |
| 5864 | return __os; |
| 5865 | } |
| 5866 | |
| 5867 | template <class _CharT, class _Traits, class _RT> |
| 5868 | basic_istream<_CharT, _Traits>& |
| 5869 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5870 | cauchy_distribution<_RT>& __x) |
| 5871 | { |
| 5872 | typedef cauchy_distribution<_RT> _Eng; |
| 5873 | typedef typename _Eng::result_type result_type; |
| 5874 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5875 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5876 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5877 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5878 | result_type __a; |
| 5879 | result_type __b; |
| 5880 | __is >> __a >> __b; |
| 5881 | if (!__is.fail()) |
| 5882 | __x.param(param_type(__a, __b)); |
| 5883 | return __is; |
| 5884 | } |
| 5885 | |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5886 | // fisher_f_distribution |
| 5887 | |
| 5888 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5889 | class _LIBCPP_TEMPLATE_VIS fisher_f_distribution |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5890 | { |
| 5891 | public: |
| 5892 | // types |
| 5893 | typedef _RealType result_type; |
| 5894 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5895 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5896 | { |
| 5897 | result_type __m_; |
| 5898 | result_type __n_; |
| 5899 | public: |
| 5900 | typedef fisher_f_distribution distribution_type; |
| 5901 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5902 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5903 | explicit param_type(result_type __m = 1, result_type __n = 1) |
| 5904 | : __m_(__m), __n_(__n) {} |
| 5905 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5906 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5907 | result_type m() const {return __m_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5908 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5909 | result_type n() const {return __n_;} |
| 5910 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5911 | friend _LIBCPP_INLINE_VISIBILITY |
| 5912 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5913 | {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5914 | friend _LIBCPP_INLINE_VISIBILITY |
| 5915 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5916 | {return !(__x == __y);} |
| 5917 | }; |
| 5918 | |
| 5919 | private: |
| 5920 | param_type __p_; |
| 5921 | |
| 5922 | public: |
| 5923 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5924 | #ifndef _LIBCPP_CXX03_LANG |
| 5925 | _LIBCPP_INLINE_VISIBILITY |
| 5926 | fisher_f_distribution() : fisher_f_distribution(1) {} |
| 5927 | _LIBCPP_INLINE_VISIBILITY |
| 5928 | explicit fisher_f_distribution(result_type __m, result_type __n = 1) |
| 5929 | : __p_(param_type(__m, __n)) {} |
| 5930 | #else |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5931 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5932 | explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) |
| 5933 | : __p_(param_type(__m, __n)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5934 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5935 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5936 | explicit fisher_f_distribution(const param_type& __p) |
| 5937 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5938 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5939 | void reset() {} |
| 5940 | |
| 5941 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5942 | template<class _URNG> |
| 5943 | _LIBCPP_INLINE_VISIBILITY |
| 5944 | result_type operator()(_URNG& __g) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5945 | {return (*this)(__g, __p_);} |
| 5946 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5947 | |
| 5948 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5949 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5950 | result_type m() const {return __p_.m();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5951 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5952 | result_type n() const {return __p_.n();} |
| 5953 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5954 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5955 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5956 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5957 | void param(const param_type& __p) {__p_ = __p;} |
| 5958 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5959 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5960 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5961 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5962 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5963 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5964 | friend _LIBCPP_INLINE_VISIBILITY |
| 5965 | bool operator==(const fisher_f_distribution& __x, |
| 5966 | const fisher_f_distribution& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5967 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5968 | friend _LIBCPP_INLINE_VISIBILITY |
| 5969 | bool operator!=(const fisher_f_distribution& __x, |
| 5970 | const fisher_f_distribution& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5971 | {return !(__x == __y);} |
| 5972 | }; |
| 5973 | |
| 5974 | template <class _RealType> |
| 5975 | template<class _URNG> |
| 5976 | _RealType |
| 5977 | fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5978 | { |
| 5979 | gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); |
| 5980 | gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); |
| 5981 | return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); |
| 5982 | } |
| 5983 | |
| 5984 | template <class _CharT, class _Traits, class _RT> |
| 5985 | basic_ostream<_CharT, _Traits>& |
| 5986 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5987 | const fisher_f_distribution<_RT>& __x) |
| 5988 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5989 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5990 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5991 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5992 | _OStream::scientific); |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5993 | _CharT __sp = __os.widen(' '); |
| 5994 | __os.fill(__sp); |
| 5995 | __os << __x.m() << __sp << __x.n(); |
| 5996 | return __os; |
| 5997 | } |
| 5998 | |
| 5999 | template <class _CharT, class _Traits, class _RT> |
| 6000 | basic_istream<_CharT, _Traits>& |
| 6001 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6002 | fisher_f_distribution<_RT>& __x) |
| 6003 | { |
| 6004 | typedef fisher_f_distribution<_RT> _Eng; |
| 6005 | typedef typename _Eng::result_type result_type; |
| 6006 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6007 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6008 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6009 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 6010 | result_type __m; |
| 6011 | result_type __n; |
| 6012 | __is >> __m >> __n; |
| 6013 | if (!__is.fail()) |
| 6014 | __x.param(param_type(__m, __n)); |
| 6015 | return __is; |
| 6016 | } |
| 6017 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6018 | // student_t_distribution |
| 6019 | |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6020 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6021 | class _LIBCPP_TEMPLATE_VIS student_t_distribution |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6022 | { |
| 6023 | public: |
| 6024 | // types |
| 6025 | typedef _RealType result_type; |
| 6026 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6027 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6028 | { |
| 6029 | result_type __n_; |
| 6030 | public: |
| 6031 | typedef student_t_distribution distribution_type; |
| 6032 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6033 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6034 | explicit param_type(result_type __n = 1) : __n_(__n) {} |
| 6035 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6036 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6037 | result_type n() const {return __n_;} |
| 6038 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6039 | friend _LIBCPP_INLINE_VISIBILITY |
| 6040 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6041 | {return __x.__n_ == __y.__n_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6042 | friend _LIBCPP_INLINE_VISIBILITY |
| 6043 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6044 | {return !(__x == __y);} |
| 6045 | }; |
| 6046 | |
| 6047 | private: |
| 6048 | param_type __p_; |
| 6049 | normal_distribution<result_type> __nd_; |
| 6050 | |
| 6051 | public: |
| 6052 | // constructor and reset functions |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 6053 | #ifndef _LIBCPP_CXX03_LANG |
| 6054 | _LIBCPP_INLINE_VISIBILITY |
| 6055 | student_t_distribution() : student_t_distribution(1) {} |
| 6056 | _LIBCPP_INLINE_VISIBILITY |
| 6057 | explicit student_t_distribution(result_type __n) |
| 6058 | : __p_(param_type(__n)) {} |
| 6059 | #else |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6060 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6061 | explicit student_t_distribution(result_type __n = 1) |
| 6062 | : __p_(param_type(__n)) {} |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 6063 | #endif |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6064 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6065 | explicit student_t_distribution(const param_type& __p) |
| 6066 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6067 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6068 | void reset() {__nd_.reset();} |
| 6069 | |
| 6070 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6071 | template<class _URNG> |
| 6072 | _LIBCPP_INLINE_VISIBILITY |
| 6073 | result_type operator()(_URNG& __g) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6074 | {return (*this)(__g, __p_);} |
| 6075 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6076 | |
| 6077 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6078 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6079 | result_type n() const {return __p_.n();} |
| 6080 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6081 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6082 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6083 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6084 | void param(const param_type& __p) {__p_ = __p;} |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6085 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6086 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6087 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6088 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6089 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 6090 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6091 | friend _LIBCPP_INLINE_VISIBILITY |
| 6092 | bool operator==(const student_t_distribution& __x, |
| 6093 | const student_t_distribution& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6094 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6095 | friend _LIBCPP_INLINE_VISIBILITY |
| 6096 | bool operator!=(const student_t_distribution& __x, |
| 6097 | const student_t_distribution& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6098 | {return !(__x == __y);} |
| 6099 | }; |
| 6100 | |
| 6101 | template <class _RealType> |
| 6102 | template<class _URNG> |
| 6103 | _RealType |
| 6104 | student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 6105 | { |
| 6106 | gamma_distribution<result_type> __gd(__p.n() * .5, 2); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6107 | return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6108 | } |
| 6109 | |
| 6110 | template <class _CharT, class _Traits, class _RT> |
| 6111 | basic_ostream<_CharT, _Traits>& |
| 6112 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6113 | const student_t_distribution<_RT>& __x) |
| 6114 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6115 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6116 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6117 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6118 | _OStream::scientific); |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6119 | __os << __x.n(); |
| 6120 | return __os; |
| 6121 | } |
| 6122 | |
| 6123 | template <class _CharT, class _Traits, class _RT> |
| 6124 | basic_istream<_CharT, _Traits>& |
| 6125 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6126 | student_t_distribution<_RT>& __x) |
| 6127 | { |
| 6128 | typedef student_t_distribution<_RT> _Eng; |
| 6129 | typedef typename _Eng::result_type result_type; |
| 6130 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6131 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6132 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6133 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 6134 | result_type __n; |
| 6135 | __is >> __n; |
| 6136 | if (!__is.fail()) |
| 6137 | __x.param(param_type(__n)); |
| 6138 | return __is; |
| 6139 | } |
| 6140 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6141 | // discrete_distribution |
| 6142 | |
| 6143 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6144 | class _LIBCPP_TEMPLATE_VIS discrete_distribution |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6145 | { |
| 6146 | public: |
| 6147 | // types |
| 6148 | typedef _IntType result_type; |
| 6149 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6150 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6151 | { |
| 6152 | vector<double> __p_; |
| 6153 | public: |
| 6154 | typedef discrete_distribution distribution_type; |
| 6155 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6156 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6157 | param_type() {} |
| 6158 | template<class _InputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6159 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6160 | param_type(_InputIterator __f, _InputIterator __l) |
| 6161 | : __p_(__f, __l) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6162 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6163 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6164 | param_type(initializer_list<double> __wl) |
| 6165 | : __p_(__wl.begin(), __wl.end()) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6166 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6167 | template<class _UnaryOperation> |
| 6168 | param_type(size_t __nw, double __xmin, double __xmax, |
| 6169 | _UnaryOperation __fw); |
| 6170 | |
| 6171 | vector<double> probabilities() const; |
| 6172 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6173 | friend _LIBCPP_INLINE_VISIBILITY |
| 6174 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6175 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6176 | friend _LIBCPP_INLINE_VISIBILITY |
| 6177 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6178 | {return !(__x == __y);} |
| 6179 | |
| 6180 | private: |
| 6181 | void __init(); |
| 6182 | |
| 6183 | friend class discrete_distribution; |
| 6184 | |
| 6185 | template <class _CharT, class _Traits, class _IT> |
| 6186 | friend |
| 6187 | basic_ostream<_CharT, _Traits>& |
| 6188 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6189 | const discrete_distribution<_IT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6190 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6191 | template <class _CharT, class _Traits, class _IT> |
| 6192 | friend |
| 6193 | basic_istream<_CharT, _Traits>& |
| 6194 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6195 | discrete_distribution<_IT>& __x); |
| 6196 | }; |
| 6197 | |
| 6198 | private: |
| 6199 | param_type __p_; |
| 6200 | |
| 6201 | public: |
| 6202 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6203 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6204 | discrete_distribution() {} |
| 6205 | template<class _InputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6206 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6207 | discrete_distribution(_InputIterator __f, _InputIterator __l) |
| 6208 | : __p_(__f, __l) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6209 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6210 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6211 | discrete_distribution(initializer_list<double> __wl) |
| 6212 | : __p_(__wl) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6213 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6214 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6215 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6216 | discrete_distribution(size_t __nw, double __xmin, double __xmax, |
| 6217 | _UnaryOperation __fw) |
| 6218 | : __p_(__nw, __xmin, __xmax, __fw) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6219 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 6220 | explicit discrete_distribution(const param_type& __p) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6221 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6222 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6223 | void reset() {} |
| 6224 | |
| 6225 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6226 | template<class _URNG> |
| 6227 | _LIBCPP_INLINE_VISIBILITY |
| 6228 | result_type operator()(_URNG& __g) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6229 | {return (*this)(__g, __p_);} |
| 6230 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6231 | |
| 6232 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6233 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6234 | vector<double> probabilities() const {return __p_.probabilities();} |
| 6235 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6236 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6237 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6238 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6239 | void param(const param_type& __p) {__p_ = __p;} |
| 6240 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6241 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6242 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6243 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6244 | result_type max() const {return __p_.__p_.size();} |
| 6245 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6246 | friend _LIBCPP_INLINE_VISIBILITY |
| 6247 | bool operator==(const discrete_distribution& __x, |
| 6248 | const discrete_distribution& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6249 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6250 | friend _LIBCPP_INLINE_VISIBILITY |
| 6251 | bool operator!=(const discrete_distribution& __x, |
| 6252 | const discrete_distribution& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6253 | {return !(__x == __y);} |
| 6254 | |
| 6255 | template <class _CharT, class _Traits, class _IT> |
| 6256 | friend |
| 6257 | basic_ostream<_CharT, _Traits>& |
| 6258 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6259 | const discrete_distribution<_IT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6260 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6261 | template <class _CharT, class _Traits, class _IT> |
| 6262 | friend |
| 6263 | basic_istream<_CharT, _Traits>& |
| 6264 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6265 | discrete_distribution<_IT>& __x); |
| 6266 | }; |
| 6267 | |
| 6268 | template<class _IntType> |
| 6269 | template<class _UnaryOperation> |
| 6270 | discrete_distribution<_IntType>::param_type::param_type(size_t __nw, |
| 6271 | double __xmin, |
| 6272 | double __xmax, |
| 6273 | _UnaryOperation __fw) |
| 6274 | { |
| 6275 | if (__nw > 1) |
| 6276 | { |
| 6277 | __p_.reserve(__nw - 1); |
| 6278 | double __d = (__xmax - __xmin) / __nw; |
| 6279 | double __d2 = __d / 2; |
| 6280 | for (size_t __k = 0; __k < __nw; ++__k) |
| 6281 | __p_.push_back(__fw(__xmin + __k * __d + __d2)); |
| 6282 | __init(); |
| 6283 | } |
| 6284 | } |
| 6285 | |
| 6286 | template<class _IntType> |
| 6287 | void |
| 6288 | discrete_distribution<_IntType>::param_type::__init() |
| 6289 | { |
| 6290 | if (!__p_.empty()) |
| 6291 | { |
| 6292 | if (__p_.size() > 1) |
| 6293 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6294 | double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); |
| 6295 | for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6296 | __i < __e; ++__i) |
| 6297 | *__i /= __s; |
| 6298 | vector<double> __t(__p_.size() - 1); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6299 | _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6300 | swap(__p_, __t); |
| 6301 | } |
| 6302 | else |
| 6303 | { |
| 6304 | __p_.clear(); |
| 6305 | __p_.shrink_to_fit(); |
| 6306 | } |
| 6307 | } |
| 6308 | } |
| 6309 | |
| 6310 | template<class _IntType> |
| 6311 | vector<double> |
| 6312 | discrete_distribution<_IntType>::param_type::probabilities() const |
| 6313 | { |
| 6314 | size_t __n = __p_.size(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6315 | _VSTD::vector<double> __p(__n+1); |
| 6316 | _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6317 | if (__n > 0) |
| 6318 | __p[__n] = 1 - __p_[__n-1]; |
| 6319 | else |
| 6320 | __p[0] = 1; |
| 6321 | return __p; |
| 6322 | } |
| 6323 | |
| 6324 | template<class _IntType> |
| 6325 | template<class _URNG> |
| 6326 | _IntType |
| 6327 | discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) |
| 6328 | { |
| 6329 | uniform_real_distribution<double> __gen; |
| 6330 | return static_cast<_IntType>( |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6331 | _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6332 | __p.__p_.begin()); |
| 6333 | } |
| 6334 | |
| 6335 | template <class _CharT, class _Traits, class _IT> |
| 6336 | basic_ostream<_CharT, _Traits>& |
| 6337 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6338 | const discrete_distribution<_IT>& __x) |
| 6339 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6340 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6341 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6342 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6343 | _OStream::scientific); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6344 | _CharT __sp = __os.widen(' '); |
| 6345 | __os.fill(__sp); |
| 6346 | size_t __n = __x.__p_.__p_.size(); |
| 6347 | __os << __n; |
| 6348 | for (size_t __i = 0; __i < __n; ++__i) |
| 6349 | __os << __sp << __x.__p_.__p_[__i]; |
| 6350 | return __os; |
| 6351 | } |
| 6352 | |
| 6353 | template <class _CharT, class _Traits, class _IT> |
| 6354 | basic_istream<_CharT, _Traits>& |
| 6355 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6356 | discrete_distribution<_IT>& __x) |
| 6357 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6358 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6359 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6360 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6361 | size_t __n; |
| 6362 | __is >> __n; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6363 | vector<double> __p(__n); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6364 | for (size_t __i = 0; __i < __n; ++__i) |
| 6365 | __is >> __p[__i]; |
| 6366 | if (!__is.fail()) |
| 6367 | swap(__x.__p_.__p_, __p); |
| 6368 | return __is; |
| 6369 | } |
| 6370 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6371 | // piecewise_constant_distribution |
| 6372 | |
| 6373 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6374 | class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6375 | { |
| 6376 | public: |
| 6377 | // types |
| 6378 | typedef _RealType result_type; |
| 6379 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6380 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6381 | { |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6382 | vector<result_type> __b_; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6383 | vector<result_type> __densities_; |
| 6384 | vector<result_type> __areas_; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6385 | public: |
| 6386 | typedef piecewise_constant_distribution distribution_type; |
| 6387 | |
| 6388 | param_type(); |
| 6389 | template<class _InputIteratorB, class _InputIteratorW> |
| 6390 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, |
| 6391 | _InputIteratorW __fW); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6392 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6393 | template<class _UnaryOperation> |
| 6394 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6395 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6396 | template<class _UnaryOperation> |
| 6397 | param_type(size_t __nw, result_type __xmin, result_type __xmax, |
| 6398 | _UnaryOperation __fw); |
Eric Fiselier | b9f37ca | 2019-12-12 20:48:11 -0500 | [diff] [blame] | 6399 | param_type(param_type const&) = default; |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6400 | param_type & operator=(const param_type& __rhs); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6401 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6402 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6403 | vector<result_type> intervals() const {return __b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6404 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6405 | vector<result_type> densities() const {return __densities_;} |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6406 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6407 | friend _LIBCPP_INLINE_VISIBILITY |
| 6408 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6409 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6410 | friend _LIBCPP_INLINE_VISIBILITY |
| 6411 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6412 | {return !(__x == __y);} |
| 6413 | |
| 6414 | private: |
| 6415 | void __init(); |
| 6416 | |
| 6417 | friend class piecewise_constant_distribution; |
| 6418 | |
| 6419 | template <class _CharT, class _Traits, class _RT> |
| 6420 | friend |
| 6421 | basic_ostream<_CharT, _Traits>& |
| 6422 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6423 | const piecewise_constant_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6424 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6425 | template <class _CharT, class _Traits, class _RT> |
| 6426 | friend |
| 6427 | basic_istream<_CharT, _Traits>& |
| 6428 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6429 | piecewise_constant_distribution<_RT>& __x); |
| 6430 | }; |
| 6431 | |
| 6432 | private: |
| 6433 | param_type __p_; |
| 6434 | |
| 6435 | public: |
| 6436 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6437 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6438 | piecewise_constant_distribution() {} |
| 6439 | template<class _InputIteratorB, class _InputIteratorW> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6440 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6441 | piecewise_constant_distribution(_InputIteratorB __fB, |
| 6442 | _InputIteratorB __lB, |
| 6443 | _InputIteratorW __fW) |
| 6444 | : __p_(__fB, __lB, __fW) {} |
| 6445 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6446 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6447 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6449 | piecewise_constant_distribution(initializer_list<result_type> __bl, |
| 6450 | _UnaryOperation __fw) |
| 6451 | : __p_(__bl, __fw) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6452 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6453 | |
| 6454 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6455 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6456 | piecewise_constant_distribution(size_t __nw, result_type __xmin, |
| 6457 | result_type __xmax, _UnaryOperation __fw) |
| 6458 | : __p_(__nw, __xmin, __xmax, __fw) {} |
| 6459 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6460 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6461 | explicit piecewise_constant_distribution(const param_type& __p) |
| 6462 | : __p_(__p) {} |
| 6463 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6464 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6465 | void reset() {} |
| 6466 | |
| 6467 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6468 | template<class _URNG> |
| 6469 | _LIBCPP_INLINE_VISIBILITY |
| 6470 | result_type operator()(_URNG& __g) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6471 | {return (*this)(__g, __p_);} |
| 6472 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6473 | |
| 6474 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6475 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6476 | vector<result_type> intervals() const {return __p_.intervals();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6477 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6478 | vector<result_type> densities() const {return __p_.densities();} |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6479 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6480 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6481 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6482 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6483 | void param(const param_type& __p) {__p_ = __p;} |
| 6484 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6485 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6486 | result_type min() const {return __p_.__b_.front();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6487 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6488 | result_type max() const {return __p_.__b_.back();} |
| 6489 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6490 | friend _LIBCPP_INLINE_VISIBILITY |
| 6491 | bool operator==(const piecewise_constant_distribution& __x, |
| 6492 | const piecewise_constant_distribution& __y) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6493 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6494 | friend _LIBCPP_INLINE_VISIBILITY |
| 6495 | bool operator!=(const piecewise_constant_distribution& __x, |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6496 | const piecewise_constant_distribution& __y) |
| 6497 | {return !(__x == __y);} |
| 6498 | |
| 6499 | template <class _CharT, class _Traits, class _RT> |
| 6500 | friend |
| 6501 | basic_ostream<_CharT, _Traits>& |
| 6502 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6503 | const piecewise_constant_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6504 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6505 | template <class _CharT, class _Traits, class _RT> |
| 6506 | friend |
| 6507 | basic_istream<_CharT, _Traits>& |
| 6508 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6509 | piecewise_constant_distribution<_RT>& __x); |
| 6510 | }; |
| 6511 | |
| 6512 | template<class _RealType> |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6513 | typename piecewise_constant_distribution<_RealType>::param_type & |
| 6514 | piecewise_constant_distribution<_RealType>::param_type::operator= |
| 6515 | (const param_type& __rhs) |
| 6516 | { |
| 6517 | // These can throw |
| 6518 | __b_.reserve (__rhs.__b_.size ()); |
| 6519 | __densities_.reserve(__rhs.__densities_.size()); |
| 6520 | __areas_.reserve (__rhs.__areas_.size()); |
| 6521 | |
| 6522 | // These can not throw |
| 6523 | __b_ = __rhs.__b_; |
| 6524 | __densities_ = __rhs.__densities_; |
| 6525 | __areas_ = __rhs.__areas_; |
| 6526 | return *this; |
| 6527 | } |
| 6528 | |
| 6529 | template<class _RealType> |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6530 | void |
| 6531 | piecewise_constant_distribution<_RealType>::param_type::__init() |
| 6532 | { |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6533 | // __densities_ contains non-normalized areas |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6534 | result_type __total_area = _VSTD::accumulate(__densities_.begin(), |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6535 | __densities_.end(), |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6536 | result_type()); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6537 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
| 6538 | __densities_[__i] /= __total_area; |
| 6539 | // __densities_ contains normalized areas |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6540 | __areas_.assign(__densities_.size(), result_type()); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6541 | _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6542 | __areas_.begin() + 1); |
| 6543 | // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] |
| 6544 | __densities_.back() = 1 - __areas_.back(); // correct round off error |
| 6545 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
| 6546 | __densities_[__i] /= (__b_[__i+1] - __b_[__i]); |
| 6547 | // __densities_ now contains __densities_ |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6548 | } |
| 6549 | |
| 6550 | template<class _RealType> |
| 6551 | piecewise_constant_distribution<_RealType>::param_type::param_type() |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6552 | : __b_(2), |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6553 | __densities_(1, 1.0), |
| 6554 | __areas_(1, 0.0) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6555 | { |
| 6556 | __b_[1] = 1; |
| 6557 | } |
| 6558 | |
| 6559 | template<class _RealType> |
| 6560 | template<class _InputIteratorB, class _InputIteratorW> |
| 6561 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6562 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) |
| 6563 | : __b_(__fB, __lB) |
| 6564 | { |
| 6565 | if (__b_.size() < 2) |
| 6566 | { |
| 6567 | __b_.resize(2); |
| 6568 | __b_[0] = 0; |
| 6569 | __b_[1] = 1; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6570 | __densities_.assign(1, 1.0); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6571 | __areas_.assign(1, 0.0); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6572 | } |
| 6573 | else |
| 6574 | { |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6575 | __densities_.reserve(__b_.size() - 1); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6576 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6577 | __densities_.push_back(*__fW); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6578 | __init(); |
| 6579 | } |
| 6580 | } |
| 6581 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6582 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6583 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6584 | template<class _RealType> |
| 6585 | template<class _UnaryOperation> |
| 6586 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6587 | initializer_list<result_type> __bl, _UnaryOperation __fw) |
| 6588 | : __b_(__bl.begin(), __bl.end()) |
| 6589 | { |
| 6590 | if (__b_.size() < 2) |
| 6591 | { |
| 6592 | __b_.resize(2); |
| 6593 | __b_[0] = 0; |
| 6594 | __b_[1] = 1; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6595 | __densities_.assign(1, 1.0); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6596 | __areas_.assign(1, 0.0); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6597 | } |
| 6598 | else |
| 6599 | { |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6600 | __densities_.reserve(__b_.size() - 1); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6601 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6602 | __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6603 | __init(); |
| 6604 | } |
| 6605 | } |
| 6606 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6607 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6608 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6609 | template<class _RealType> |
| 6610 | template<class _UnaryOperation> |
| 6611 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6612 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) |
| 6613 | : __b_(__nw == 0 ? 2 : __nw + 1) |
| 6614 | { |
| 6615 | size_t __n = __b_.size() - 1; |
| 6616 | result_type __d = (__xmax - __xmin) / __n; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6617 | __densities_.reserve(__n); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6618 | for (size_t __i = 0; __i < __n; ++__i) |
| 6619 | { |
| 6620 | __b_[__i] = __xmin + __i * __d; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6621 | __densities_.push_back(__fw(__b_[__i] + __d*.5)); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6622 | } |
| 6623 | __b_[__n] = __xmax; |
| 6624 | __init(); |
| 6625 | } |
| 6626 | |
| 6627 | template<class _RealType> |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6628 | template<class _URNG> |
| 6629 | _RealType |
| 6630 | piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 6631 | { |
| 6632 | typedef uniform_real_distribution<result_type> _Gen; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6633 | result_type __u = _Gen()(__g); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6634 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6635 | __u) - __p.__areas_.begin() - 1; |
| 6636 | return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6637 | } |
| 6638 | |
| 6639 | template <class _CharT, class _Traits, class _RT> |
| 6640 | basic_ostream<_CharT, _Traits>& |
| 6641 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6642 | const piecewise_constant_distribution<_RT>& __x) |
| 6643 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6644 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6645 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6646 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6647 | _OStream::scientific); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6648 | _CharT __sp = __os.widen(' '); |
| 6649 | __os.fill(__sp); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6650 | size_t __n = __x.__p_.__b_.size(); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6651 | __os << __n; |
| 6652 | for (size_t __i = 0; __i < __n; ++__i) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6653 | __os << __sp << __x.__p_.__b_[__i]; |
| 6654 | __n = __x.__p_.__densities_.size(); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6655 | __os << __sp << __n; |
| 6656 | for (size_t __i = 0; __i < __n; ++__i) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6657 | __os << __sp << __x.__p_.__densities_[__i]; |
| 6658 | __n = __x.__p_.__areas_.size(); |
| 6659 | __os << __sp << __n; |
| 6660 | for (size_t __i = 0; __i < __n; ++__i) |
| 6661 | __os << __sp << __x.__p_.__areas_[__i]; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6662 | return __os; |
| 6663 | } |
| 6664 | |
| 6665 | template <class _CharT, class _Traits, class _RT> |
| 6666 | basic_istream<_CharT, _Traits>& |
| 6667 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6668 | piecewise_constant_distribution<_RT>& __x) |
| 6669 | { |
| 6670 | typedef piecewise_constant_distribution<_RT> _Eng; |
| 6671 | typedef typename _Eng::result_type result_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6672 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6673 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6674 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6675 | size_t __n; |
| 6676 | __is >> __n; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6677 | vector<result_type> __b(__n); |
| 6678 | for (size_t __i = 0; __i < __n; ++__i) |
| 6679 | __is >> __b[__i]; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6680 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6681 | vector<result_type> __densities(__n); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6682 | for (size_t __i = 0; __i < __n; ++__i) |
| 6683 | __is >> __densities[__i]; |
| 6684 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6685 | vector<result_type> __areas(__n); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6686 | for (size_t __i = 0; __i < __n; ++__i) |
| 6687 | __is >> __areas[__i]; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6688 | if (!__is.fail()) |
| 6689 | { |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6690 | swap(__x.__p_.__b_, __b); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6691 | swap(__x.__p_.__densities_, __densities); |
| 6692 | swap(__x.__p_.__areas_, __areas); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6693 | } |
| 6694 | return __is; |
| 6695 | } |
| 6696 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6697 | // piecewise_linear_distribution |
| 6698 | |
| 6699 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6700 | class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6701 | { |
| 6702 | public: |
| 6703 | // types |
| 6704 | typedef _RealType result_type; |
| 6705 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6706 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6707 | { |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6708 | vector<result_type> __b_; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6709 | vector<result_type> __densities_; |
| 6710 | vector<result_type> __areas_; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6711 | public: |
| 6712 | typedef piecewise_linear_distribution distribution_type; |
| 6713 | |
| 6714 | param_type(); |
| 6715 | template<class _InputIteratorB, class _InputIteratorW> |
| 6716 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, |
| 6717 | _InputIteratorW __fW); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6718 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6719 | template<class _UnaryOperation> |
| 6720 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6721 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6722 | template<class _UnaryOperation> |
| 6723 | param_type(size_t __nw, result_type __xmin, result_type __xmax, |
| 6724 | _UnaryOperation __fw); |
Eric Fiselier | b9f37ca | 2019-12-12 20:48:11 -0500 | [diff] [blame] | 6725 | param_type(param_type const&) = default; |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6726 | param_type & operator=(const param_type& __rhs); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6727 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6728 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6729 | vector<result_type> intervals() const {return __b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6730 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6731 | vector<result_type> densities() const {return __densities_;} |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6732 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6733 | friend _LIBCPP_INLINE_VISIBILITY |
| 6734 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6735 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6736 | friend _LIBCPP_INLINE_VISIBILITY |
| 6737 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6738 | {return !(__x == __y);} |
| 6739 | |
| 6740 | private: |
| 6741 | void __init(); |
| 6742 | |
| 6743 | friend class piecewise_linear_distribution; |
| 6744 | |
| 6745 | template <class _CharT, class _Traits, class _RT> |
| 6746 | friend |
| 6747 | basic_ostream<_CharT, _Traits>& |
| 6748 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6749 | const piecewise_linear_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6750 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6751 | template <class _CharT, class _Traits, class _RT> |
| 6752 | friend |
| 6753 | basic_istream<_CharT, _Traits>& |
| 6754 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6755 | piecewise_linear_distribution<_RT>& __x); |
| 6756 | }; |
| 6757 | |
| 6758 | private: |
| 6759 | param_type __p_; |
| 6760 | |
| 6761 | public: |
| 6762 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6763 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6764 | piecewise_linear_distribution() {} |
| 6765 | template<class _InputIteratorB, class _InputIteratorW> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6766 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6767 | piecewise_linear_distribution(_InputIteratorB __fB, |
| 6768 | _InputIteratorB __lB, |
| 6769 | _InputIteratorW __fW) |
| 6770 | : __p_(__fB, __lB, __fW) {} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6771 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6772 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6773 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6774 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6775 | piecewise_linear_distribution(initializer_list<result_type> __bl, |
| 6776 | _UnaryOperation __fw) |
| 6777 | : __p_(__bl, __fw) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6778 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6779 | |
| 6780 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6781 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6782 | piecewise_linear_distribution(size_t __nw, result_type __xmin, |
| 6783 | result_type __xmax, _UnaryOperation __fw) |
| 6784 | : __p_(__nw, __xmin, __xmax, __fw) {} |
| 6785 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6786 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6787 | explicit piecewise_linear_distribution(const param_type& __p) |
| 6788 | : __p_(__p) {} |
| 6789 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6790 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6791 | void reset() {} |
| 6792 | |
| 6793 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6794 | template<class _URNG> |
| 6795 | _LIBCPP_INLINE_VISIBILITY |
| 6796 | result_type operator()(_URNG& __g) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6797 | {return (*this)(__g, __p_);} |
| 6798 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6799 | |
| 6800 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6801 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6802 | vector<result_type> intervals() const {return __p_.intervals();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6803 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6804 | vector<result_type> densities() const {return __p_.densities();} |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6805 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6806 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6807 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6808 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6809 | void param(const param_type& __p) {__p_ = __p;} |
| 6810 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6811 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6812 | result_type min() const {return __p_.__b_.front();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6813 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6814 | result_type max() const {return __p_.__b_.back();} |
| 6815 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6816 | friend _LIBCPP_INLINE_VISIBILITY |
| 6817 | bool operator==(const piecewise_linear_distribution& __x, |
| 6818 | const piecewise_linear_distribution& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6819 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6820 | friend _LIBCPP_INLINE_VISIBILITY |
| 6821 | bool operator!=(const piecewise_linear_distribution& __x, |
| 6822 | const piecewise_linear_distribution& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6823 | {return !(__x == __y);} |
| 6824 | |
| 6825 | template <class _CharT, class _Traits, class _RT> |
| 6826 | friend |
| 6827 | basic_ostream<_CharT, _Traits>& |
| 6828 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6829 | const piecewise_linear_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6830 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6831 | template <class _CharT, class _Traits, class _RT> |
| 6832 | friend |
| 6833 | basic_istream<_CharT, _Traits>& |
| 6834 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6835 | piecewise_linear_distribution<_RT>& __x); |
| 6836 | }; |
| 6837 | |
| 6838 | template<class _RealType> |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6839 | typename piecewise_linear_distribution<_RealType>::param_type & |
| 6840 | piecewise_linear_distribution<_RealType>::param_type::operator= |
| 6841 | (const param_type& __rhs) |
| 6842 | { |
| 6843 | // These can throw |
| 6844 | __b_.reserve (__rhs.__b_.size ()); |
| 6845 | __densities_.reserve(__rhs.__densities_.size()); |
| 6846 | __areas_.reserve (__rhs.__areas_.size()); |
| 6847 | |
| 6848 | // These can not throw |
| 6849 | __b_ = __rhs.__b_; |
| 6850 | __densities_ = __rhs.__densities_; |
| 6851 | __areas_ = __rhs.__areas_; |
| 6852 | return *this; |
| 6853 | } |
| 6854 | |
| 6855 | |
| 6856 | template<class _RealType> |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6857 | void |
| 6858 | piecewise_linear_distribution<_RealType>::param_type::__init() |
| 6859 | { |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6860 | __areas_.assign(__densities_.size() - 1, result_type()); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6861 | result_type _Sp = 0; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6862 | for (size_t __i = 0; __i < __areas_.size(); ++__i) |
| 6863 | { |
| 6864 | __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * |
| 6865 | (__b_[__i+1] - __b_[__i]) * .5; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6866 | _Sp += __areas_[__i]; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6867 | } |
| 6868 | for (size_t __i = __areas_.size(); __i > 1;) |
| 6869 | { |
| 6870 | --__i; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6871 | __areas_[__i] = __areas_[__i-1] / _Sp; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6872 | } |
| 6873 | __areas_[0] = 0; |
| 6874 | for (size_t __i = 1; __i < __areas_.size(); ++__i) |
| 6875 | __areas_[__i] += __areas_[__i-1]; |
| 6876 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6877 | __densities_[__i] /= _Sp; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6878 | } |
| 6879 | |
| 6880 | template<class _RealType> |
| 6881 | piecewise_linear_distribution<_RealType>::param_type::param_type() |
| 6882 | : __b_(2), |
| 6883 | __densities_(2, 1.0), |
| 6884 | __areas_(1, 0.0) |
| 6885 | { |
| 6886 | __b_[1] = 1; |
| 6887 | } |
| 6888 | |
| 6889 | template<class _RealType> |
| 6890 | template<class _InputIteratorB, class _InputIteratorW> |
| 6891 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6892 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) |
| 6893 | : __b_(__fB, __lB) |
| 6894 | { |
| 6895 | if (__b_.size() < 2) |
| 6896 | { |
| 6897 | __b_.resize(2); |
| 6898 | __b_[0] = 0; |
| 6899 | __b_[1] = 1; |
| 6900 | __densities_.assign(2, 1.0); |
| 6901 | __areas_.assign(1, 0.0); |
| 6902 | } |
| 6903 | else |
| 6904 | { |
| 6905 | __densities_.reserve(__b_.size()); |
| 6906 | for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) |
| 6907 | __densities_.push_back(*__fW); |
| 6908 | __init(); |
| 6909 | } |
| 6910 | } |
| 6911 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6912 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6913 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6914 | template<class _RealType> |
| 6915 | template<class _UnaryOperation> |
| 6916 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6917 | initializer_list<result_type> __bl, _UnaryOperation __fw) |
| 6918 | : __b_(__bl.begin(), __bl.end()) |
| 6919 | { |
| 6920 | if (__b_.size() < 2) |
| 6921 | { |
| 6922 | __b_.resize(2); |
| 6923 | __b_[0] = 0; |
| 6924 | __b_[1] = 1; |
| 6925 | __densities_.assign(2, 1.0); |
| 6926 | __areas_.assign(1, 0.0); |
| 6927 | } |
| 6928 | else |
| 6929 | { |
| 6930 | __densities_.reserve(__b_.size()); |
| 6931 | for (size_t __i = 0; __i < __b_.size(); ++__i) |
| 6932 | __densities_.push_back(__fw(__b_[__i])); |
| 6933 | __init(); |
| 6934 | } |
| 6935 | } |
| 6936 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6937 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6938 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6939 | template<class _RealType> |
| 6940 | template<class _UnaryOperation> |
| 6941 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6942 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) |
| 6943 | : __b_(__nw == 0 ? 2 : __nw + 1) |
| 6944 | { |
| 6945 | size_t __n = __b_.size() - 1; |
| 6946 | result_type __d = (__xmax - __xmin) / __n; |
| 6947 | __densities_.reserve(__b_.size()); |
| 6948 | for (size_t __i = 0; __i < __n; ++__i) |
| 6949 | { |
| 6950 | __b_[__i] = __xmin + __i * __d; |
| 6951 | __densities_.push_back(__fw(__b_[__i])); |
| 6952 | } |
| 6953 | __b_[__n] = __xmax; |
| 6954 | __densities_.push_back(__fw(__b_[__n])); |
| 6955 | __init(); |
| 6956 | } |
| 6957 | |
| 6958 | template<class _RealType> |
| 6959 | template<class _URNG> |
| 6960 | _RealType |
| 6961 | piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 6962 | { |
| 6963 | typedef uniform_real_distribution<result_type> _Gen; |
| 6964 | result_type __u = _Gen()(__g); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6965 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6966 | __u) - __p.__areas_.begin() - 1; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6967 | __u -= __p.__areas_[__k]; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6968 | const result_type __dk = __p.__densities_[__k]; |
| 6969 | const result_type __dk1 = __p.__densities_[__k+1]; |
| 6970 | const result_type __deltad = __dk1 - __dk; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6971 | const result_type __bk = __p.__b_[__k]; |
| 6972 | if (__deltad == 0) |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6973 | return __u / __dk + __bk; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6974 | const result_type __bk1 = __p.__b_[__k+1]; |
| 6975 | const result_type __deltab = __bk1 - __bk; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6976 | return (__bk * __dk1 - __bk1 * __dk + |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6977 | _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6978 | __deltad; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6979 | } |
| 6980 | |
| 6981 | template <class _CharT, class _Traits, class _RT> |
| 6982 | basic_ostream<_CharT, _Traits>& |
| 6983 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6984 | const piecewise_linear_distribution<_RT>& __x) |
| 6985 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6986 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6987 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6988 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6989 | _OStream::scientific); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6990 | _CharT __sp = __os.widen(' '); |
| 6991 | __os.fill(__sp); |
| 6992 | size_t __n = __x.__p_.__b_.size(); |
| 6993 | __os << __n; |
| 6994 | for (size_t __i = 0; __i < __n; ++__i) |
| 6995 | __os << __sp << __x.__p_.__b_[__i]; |
| 6996 | __n = __x.__p_.__densities_.size(); |
| 6997 | __os << __sp << __n; |
| 6998 | for (size_t __i = 0; __i < __n; ++__i) |
| 6999 | __os << __sp << __x.__p_.__densities_[__i]; |
| 7000 | __n = __x.__p_.__areas_.size(); |
| 7001 | __os << __sp << __n; |
| 7002 | for (size_t __i = 0; __i < __n; ++__i) |
| 7003 | __os << __sp << __x.__p_.__areas_[__i]; |
| 7004 | return __os; |
| 7005 | } |
| 7006 | |
| 7007 | template <class _CharT, class _Traits, class _RT> |
| 7008 | basic_istream<_CharT, _Traits>& |
| 7009 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 7010 | piecewise_linear_distribution<_RT>& __x) |
| 7011 | { |
| 7012 | typedef piecewise_linear_distribution<_RT> _Eng; |
| 7013 | typedef typename _Eng::result_type result_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 7014 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 7015 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 7016 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 7017 | size_t __n; |
| 7018 | __is >> __n; |
| 7019 | vector<result_type> __b(__n); |
| 7020 | for (size_t __i = 0; __i < __n; ++__i) |
| 7021 | __is >> __b[__i]; |
| 7022 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 7023 | vector<result_type> __densities(__n); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 7024 | for (size_t __i = 0; __i < __n; ++__i) |
| 7025 | __is >> __densities[__i]; |
| 7026 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 7027 | vector<result_type> __areas(__n); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 7028 | for (size_t __i = 0; __i < __n; ++__i) |
| 7029 | __is >> __areas[__i]; |
| 7030 | if (!__is.fail()) |
| 7031 | { |
| 7032 | swap(__x.__p_.__b_, __b); |
| 7033 | swap(__x.__p_.__densities_, __densities); |
| 7034 | swap(__x.__p_.__areas_, __areas); |
| 7035 | } |
| 7036 | return __is; |
| 7037 | } |
| 7038 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7039 | _LIBCPP_END_NAMESPACE_STD |
| 7040 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 7041 | _LIBCPP_POP_MACROS |
| 7042 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7043 | #endif // _LIBCPP_RANDOM |