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 | { |
| 20 | |
| 21 | // Engines |
| 22 | |
| 23 | template <class UIntType, UIntType a, UIntType c, UIntType m> |
| 24 | class linear_congruential_engine |
| 25 | { |
| 26 | public: |
| 27 | // types |
| 28 | typedef UIntType result_type; |
| 29 | |
| 30 | // engine characteristics |
| 31 | static constexpr result_type multiplier = a; |
| 32 | static constexpr result_type increment = c; |
| 33 | static constexpr result_type modulus = m; |
| 34 | static constexpr result_type min() { return c == 0u ? 1u: 0u;} |
| 35 | static constexpr result_type max() { return m - 1u;} |
| 36 | static constexpr result_type default_seed = 1u; |
| 37 | |
| 38 | // constructors and seeding functions |
| 39 | explicit linear_congruential_engine(result_type s = default_seed); |
| 40 | template<class Sseq> explicit linear_congruential_engine(Sseq& q); |
| 41 | void seed(result_type s = default_seed); |
| 42 | template<class Sseq> void seed(Sseq& q); |
| 43 | |
| 44 | // generating functions |
| 45 | result_type operator()(); |
| 46 | void discard(unsigned long long z); |
| 47 | }; |
| 48 | |
| 49 | template <class UIntType, UIntType a, UIntType c, UIntType m> |
| 50 | bool |
| 51 | operator==(const linear_congruential_engine<UIntType, a, c, m>& x, |
| 52 | const linear_congruential_engine<UIntType, a, c, m>& y); |
| 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 charT, class traits, |
| 60 | class UIntType, UIntType a, UIntType c, UIntType m> |
| 61 | basic_ostream<charT, traits>& |
| 62 | operator<<(basic_ostream<charT, traits>& os, |
| 63 | const linear_congruential_engine<UIntType, a, c, m>& x); |
| 64 | |
| 65 | template <class charT, class traits, |
| 66 | class UIntType, UIntType a, UIntType c, UIntType m> |
| 67 | basic_istream<charT, traits>& |
| 68 | operator>>(basic_istream<charT, traits>& is, |
| 69 | linear_congruential_engine<UIntType, a, c, m>& x); |
| 70 | |
| 71 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 72 | UIntType a, size_t u, UIntType d, size_t s, |
| 73 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 74 | class mersenne_twister_engine |
| 75 | { |
| 76 | public: |
| 77 | // types |
| 78 | typedef UIntType result_type; |
| 79 | |
| 80 | // engine characteristics |
| 81 | static constexpr size_t word_size = w; |
| 82 | static constexpr size_t state_size = n; |
| 83 | static constexpr size_t shift_size = m; |
| 84 | static constexpr size_t mask_bits = r; |
| 85 | static constexpr result_type xor_mask = a; |
| 86 | static constexpr size_t tempering_u = u; |
| 87 | static constexpr result_type tempering_d = d; |
| 88 | static constexpr size_t tempering_s = s; |
| 89 | static constexpr result_type tempering_b = b; |
| 90 | static constexpr size_t tempering_t = t; |
| 91 | static constexpr result_type tempering_c = c; |
| 92 | static constexpr size_t tempering_l = l; |
| 93 | static constexpr result_type initialization_multiplier = f; |
| 94 | static constexpr result_type min () { return 0; } |
| 95 | static constexpr result_type max() { return 2^w - 1; } |
| 96 | static constexpr result_type default_seed = 5489u; |
| 97 | |
| 98 | // constructors and seeding functions |
| 99 | explicit mersenne_twister_engine(result_type value = default_seed); |
| 100 | template<class Sseq> explicit mersenne_twister_engine(Sseq& q); |
| 101 | void seed(result_type value = default_seed); |
| 102 | template<class Sseq> void seed(Sseq& q); |
| 103 | |
| 104 | // generating functions |
| 105 | result_type operator()(); |
| 106 | void discard(unsigned long long z); |
| 107 | }; |
| 108 | |
| 109 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 110 | UIntType a, size_t u, UIntType d, size_t s, |
| 111 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 112 | bool |
| 113 | operator==( |
| 114 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, |
| 115 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); |
| 116 | |
| 117 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 118 | UIntType a, size_t u, UIntType d, size_t s, |
| 119 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 120 | bool |
| 121 | operator!=( |
| 122 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, |
| 123 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); |
| 124 | |
| 125 | template <class charT, class traits, |
| 126 | class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 127 | UIntType a, size_t u, UIntType d, size_t s, |
| 128 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 129 | basic_ostream<charT, traits>& |
| 130 | operator<<(basic_ostream<charT, traits>& os, |
| 131 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); |
| 132 | |
| 133 | template <class charT, class traits, |
| 134 | class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 135 | UIntType a, size_t u, UIntType d, size_t s, |
| 136 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 137 | basic_istream<charT, traits>& |
| 138 | operator>>(basic_istream<charT, traits>& is, |
| 139 | mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); |
| 140 | |
| 141 | template<class UIntType, size_t w, size_t s, size_t r> |
| 142 | class subtract_with_carry_engine |
| 143 | { |
| 144 | public: |
| 145 | // types |
| 146 | typedef UIntType result_type; |
| 147 | |
| 148 | // engine characteristics |
| 149 | static constexpr size_t word_size = w; |
| 150 | static constexpr size_t short_lag = s; |
| 151 | static constexpr size_t long_lag = r; |
| 152 | static constexpr result_type min() { return 0; } |
| 153 | static constexpr result_type max() { return m-1; } |
| 154 | static constexpr result_type default_seed = 19780503u; |
| 155 | |
| 156 | // constructors and seeding functions |
| 157 | explicit subtract_with_carry_engine(result_type value = default_seed); |
| 158 | template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); |
| 159 | void seed(result_type value = default_seed); |
| 160 | template<class Sseq> void seed(Sseq& q); |
| 161 | |
| 162 | // generating functions |
| 163 | result_type operator()(); |
| 164 | void discard(unsigned long long z); |
| 165 | }; |
| 166 | |
| 167 | template<class UIntType, size_t w, size_t s, size_t r> |
| 168 | bool |
| 169 | operator==( |
| 170 | const subtract_with_carry_engine<UIntType, w, s, r>& x, |
| 171 | const subtract_with_carry_engine<UIntType, w, s, r>& y); |
| 172 | |
| 173 | template<class UIntType, size_t w, size_t s, size_t r> |
| 174 | bool |
| 175 | operator!=( |
| 176 | const subtract_with_carry_engine<UIntType, w, s, r>& x, |
| 177 | const subtract_with_carry_engine<UIntType, w, s, r>& y); |
| 178 | |
| 179 | template <class charT, class traits, |
| 180 | class UIntType, size_t w, size_t s, size_t r> |
| 181 | basic_ostream<charT, traits>& |
| 182 | operator<<(basic_ostream<charT, traits>& os, |
| 183 | const subtract_with_carry_engine<UIntType, w, s, r>& x); |
| 184 | |
| 185 | template <class charT, class traits, |
| 186 | class UIntType, size_t w, size_t s, size_t r> |
| 187 | basic_istream<charT, traits>& |
| 188 | operator>>(basic_istream<charT, traits>& is, |
| 189 | subtract_with_carry_engine<UIntType, w, s, r>& x); |
| 190 | |
| 191 | template<class Engine, size_t p, size_t r> |
| 192 | class discard_block_engine |
| 193 | { |
| 194 | public: |
| 195 | // types |
| 196 | typedef typename Engine::result_type result_type; |
| 197 | |
| 198 | // engine characteristics |
| 199 | static constexpr size_t block_size = p; |
| 200 | static constexpr size_t used_block = r; |
| 201 | static constexpr result_type min() { return Engine::min(); } |
| 202 | static constexpr result_type max() { return Engine::max(); } |
| 203 | |
| 204 | // constructors and seeding functions |
| 205 | discard_block_engine(); |
| 206 | explicit discard_block_engine(const Engine& e); |
| 207 | explicit discard_block_engine(Engine&& e); |
| 208 | explicit discard_block_engine(result_type s); |
| 209 | template<class Sseq> explicit discard_block_engine(Sseq& q); |
| 210 | void seed(); |
| 211 | void seed(result_type s); |
| 212 | template<class Sseq> void seed(Sseq& q); |
| 213 | |
| 214 | // generating functions |
| 215 | result_type operator()(); |
| 216 | void discard(unsigned long long z); |
| 217 | |
| 218 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 219 | const Engine& base() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | template<class Engine, size_t p, size_t r> |
| 223 | bool |
| 224 | operator==( |
| 225 | const discard_block_engine<Engine, p, r>& x, |
| 226 | const discard_block_engine<Engine, p, r>& y); |
| 227 | |
| 228 | template<class Engine, size_t p, size_t r> |
| 229 | bool |
| 230 | operator!=( |
| 231 | const discard_block_engine<Engine, p, r>& x, |
| 232 | const discard_block_engine<Engine, p, r>& y); |
| 233 | |
| 234 | template <class charT, class traits, |
| 235 | class Engine, size_t p, size_t r> |
| 236 | basic_ostream<charT, traits>& |
| 237 | operator<<(basic_ostream<charT, traits>& os, |
| 238 | const discard_block_engine<Engine, p, r>& x); |
| 239 | |
| 240 | template <class charT, class traits, |
| 241 | class Engine, size_t p, size_t r> |
| 242 | basic_istream<charT, traits>& |
| 243 | operator>>(basic_istream<charT, traits>& is, |
| 244 | discard_block_engine<Engine, p, r>& x); |
| 245 | |
| 246 | template<class Engine, size_t w, class UIntType> |
| 247 | class independent_bits_engine |
| 248 | { |
| 249 | public: |
| 250 | // types |
| 251 | typedef UIntType result_type; |
| 252 | |
| 253 | // engine characteristics |
| 254 | static constexpr result_type min() { return 0; } |
| 255 | static constexpr result_type max() { return 2^w - 1; } |
| 256 | |
| 257 | // constructors and seeding functions |
| 258 | independent_bits_engine(); |
| 259 | explicit independent_bits_engine(const Engine& e); |
| 260 | explicit independent_bits_engine(Engine&& e); |
| 261 | explicit independent_bits_engine(result_type s); |
| 262 | template<class Sseq> explicit independent_bits_engine(Sseq& q); |
| 263 | void seed(); |
| 264 | void seed(result_type s); |
| 265 | template<class Sseq> void seed(Sseq& q); |
| 266 | |
| 267 | // generating functions |
| 268 | result_type operator()(); void discard(unsigned long long z); |
| 269 | |
| 270 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 271 | const Engine& base() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | template<class Engine, size_t w, class UIntType> |
| 275 | bool |
| 276 | operator==( |
| 277 | const independent_bits_engine<Engine, w, UIntType>& x, |
| 278 | const independent_bits_engine<Engine, w, UIntType>& y); |
| 279 | |
| 280 | template<class Engine, size_t w, class UIntType> |
| 281 | bool |
| 282 | operator!=( |
| 283 | const independent_bits_engine<Engine, w, UIntType>& x, |
| 284 | const independent_bits_engine<Engine, w, UIntType>& y); |
| 285 | |
| 286 | template <class charT, class traits, |
| 287 | class Engine, size_t w, class UIntType> |
| 288 | basic_ostream<charT, traits>& |
| 289 | operator<<(basic_ostream<charT, traits>& os, |
| 290 | const independent_bits_engine<Engine, w, UIntType>& x); |
| 291 | |
| 292 | template <class charT, class traits, |
| 293 | class Engine, size_t w, class UIntType> |
| 294 | basic_istream<charT, traits>& |
| 295 | operator>>(basic_istream<charT, traits>& is, |
| 296 | independent_bits_engine<Engine, w, UIntType>& x); |
| 297 | |
| 298 | template<class Engine, size_t k> |
| 299 | class shuffle_order_engine |
| 300 | { |
| 301 | public: |
| 302 | // types |
| 303 | typedef typename Engine::result_type result_type; |
| 304 | |
| 305 | // engine characteristics |
| 306 | static constexpr size_t table_size = k; |
| 307 | static constexpr result_type min() { return Engine::min; } |
| 308 | static constexpr result_type max() { return Engine::max; } |
| 309 | |
| 310 | // constructors and seeding functions |
| 311 | shuffle_order_engine(); |
| 312 | explicit shuffle_order_engine(const Engine& e); |
| 313 | explicit shuffle_order_engine(Engine&& e); |
| 314 | explicit shuffle_order_engine(result_type s); |
| 315 | template<class Sseq> explicit shuffle_order_engine(Sseq& q); |
| 316 | void seed(); |
| 317 | void seed(result_type s); |
| 318 | template<class Sseq> void seed(Sseq& q); |
| 319 | |
| 320 | // generating functions |
| 321 | result_type operator()(); |
| 322 | void discard(unsigned long long z); |
| 323 | |
| 324 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 325 | const Engine& base() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 326 | }; |
| 327 | |
| 328 | template<class Engine, size_t k> |
| 329 | bool |
| 330 | operator==( |
| 331 | const shuffle_order_engine<Engine, k>& x, |
| 332 | const shuffle_order_engine<Engine, k>& y); |
| 333 | |
| 334 | template<class Engine, size_t k> |
| 335 | bool |
| 336 | operator!=( |
| 337 | const shuffle_order_engine<Engine, k>& x, |
| 338 | const shuffle_order_engine<Engine, k>& y); |
| 339 | |
| 340 | template <class charT, class traits, |
| 341 | class Engine, size_t k> |
| 342 | basic_ostream<charT, traits>& |
| 343 | operator<<(basic_ostream<charT, traits>& os, |
| 344 | const shuffle_order_engine<Engine, k>& x); |
| 345 | |
| 346 | template <class charT, class traits, |
| 347 | class Engine, size_t k> |
| 348 | basic_istream<charT, traits>& |
| 349 | operator>>(basic_istream<charT, traits>& is, |
| 350 | shuffle_order_engine<Engine, k>& x); |
| 351 | |
| 352 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> |
| 353 | minstd_rand0; |
| 354 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> |
| 355 | minstd_rand; |
| 356 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, |
| 357 | 0x9908b0df, |
| 358 | 11, 0xffffffff, |
| 359 | 7, 0x9d2c5680, |
| 360 | 15, 0xefc60000, |
| 361 | 18, 1812433253> mt19937; |
| 362 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, |
| 363 | 0xb5026f5aa96619e9, |
| 364 | 29, 0x5555555555555555, |
| 365 | 17, 0x71d67fffeda60000, |
| 366 | 37, 0xfff7eee000000000, |
| 367 | 43, 6364136223846793005> mt19937_64; |
| 368 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; |
| 369 | typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; |
| 370 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; |
| 371 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; |
| 372 | typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 373 | typedef minstd_rand default_random_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 374 | |
| 375 | // Generators |
| 376 | |
| 377 | class random_device |
| 378 | { |
| 379 | public: |
| 380 | // types |
| 381 | typedef unsigned int result_type; |
| 382 | |
| 383 | // generator characteristics |
| 384 | static constexpr result_type min() { return numeric_limits<result_type>::min(); } |
| 385 | static constexpr result_type max() { return numeric_limits<result_type>::max(); } |
| 386 | |
| 387 | // constructors |
| 388 | explicit random_device(const string& token = "/dev/urandom"); |
| 389 | |
| 390 | // generating functions |
| 391 | result_type operator()(); |
| 392 | |
| 393 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 394 | double entropy() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 395 | |
| 396 | // no copy functions |
| 397 | random_device(const random_device& ) = delete; |
| 398 | void operator=(const random_device& ) = delete; |
| 399 | }; |
| 400 | |
| 401 | // Utilities |
| 402 | |
| 403 | class seed_seq |
| 404 | { |
| 405 | public: |
| 406 | // types |
| 407 | typedef uint_least32_t result_type; |
| 408 | |
| 409 | // constructors |
| 410 | seed_seq(); |
| 411 | template<class T> |
| 412 | seed_seq(initializer_list<T> il); |
| 413 | template<class InputIterator> |
| 414 | seed_seq(InputIterator begin, InputIterator end); |
| 415 | |
| 416 | // generating functions |
| 417 | template<class RandomAccessIterator> |
| 418 | void generate(RandomAccessIterator begin, RandomAccessIterator end); |
| 419 | |
| 420 | // property functions |
| 421 | size_t size() const; |
| 422 | template<class OutputIterator> |
| 423 | void param(OutputIterator dest) const; |
| 424 | |
| 425 | // no copy functions |
| 426 | seed_seq(const seed_seq&) = delete; |
| 427 | void operator=(const seed_seq& ) = delete; |
| 428 | }; |
| 429 | |
| 430 | template<class RealType, size_t bits, class URNG> |
| 431 | RealType generate_canonical(URNG& g); |
| 432 | |
| 433 | // Distributions |
| 434 | |
| 435 | template<class IntType = int> |
| 436 | class uniform_int_distribution |
| 437 | { |
| 438 | public: |
| 439 | // types |
| 440 | typedef IntType result_type; |
| 441 | |
| 442 | class param_type |
| 443 | { |
| 444 | public: |
| 445 | typedef uniform_int_distribution distribution_type; |
| 446 | |
| 447 | explicit param_type(IntType a = 0, |
| 448 | IntType b = numeric_limits<IntType>::max()); |
| 449 | |
| 450 | result_type a() const; |
| 451 | result_type b() const; |
| 452 | |
| 453 | friend bool operator==(const param_type& x, const param_type& y); |
| 454 | friend bool operator!=(const param_type& x, const param_type& y); |
| 455 | }; |
| 456 | |
| 457 | // constructors and reset functions |
| 458 | explicit uniform_int_distribution(IntType a = 0, |
| 459 | IntType b = numeric_limits<IntType>::max()); |
| 460 | explicit uniform_int_distribution(const param_type& parm); |
| 461 | void reset(); |
| 462 | |
| 463 | // generating functions |
| 464 | template<class URNG> result_type operator()(URNG& g); |
| 465 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 466 | |
| 467 | // property functions |
| 468 | result_type a() const; |
| 469 | result_type b() const; |
| 470 | |
| 471 | param_type param() const; |
| 472 | void param(const param_type& parm); |
| 473 | |
| 474 | result_type min() const; |
| 475 | result_type max() const; |
| 476 | |
| 477 | friend bool operator==(const uniform_int_distribution& x, |
| 478 | const uniform_int_distribution& y); |
| 479 | friend bool operator!=(const uniform_int_distribution& x, |
| 480 | const uniform_int_distribution& y); |
| 481 | |
| 482 | template <class charT, class traits> |
| 483 | friend |
| 484 | basic_ostream<charT, traits>& |
| 485 | operator<<(basic_ostream<charT, traits>& os, |
| 486 | const uniform_int_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 487 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 488 | template <class charT, class traits> |
| 489 | friend |
| 490 | basic_istream<charT, traits>& |
| 491 | operator>>(basic_istream<charT, traits>& is, |
| 492 | uniform_int_distribution& x); |
| 493 | }; |
| 494 | |
| 495 | template<class RealType = double> |
| 496 | class uniform_real_distribution |
| 497 | { |
| 498 | public: |
| 499 | // types |
| 500 | typedef RealType result_type; |
| 501 | |
| 502 | class param_type |
| 503 | { |
| 504 | public: |
| 505 | typedef uniform_real_distribution distribution_type; |
| 506 | |
| 507 | explicit param_type(RealType a = 0, |
| 508 | RealType b = 1); |
| 509 | |
| 510 | result_type a() const; |
| 511 | result_type b() const; |
| 512 | |
| 513 | friend bool operator==(const param_type& x, const param_type& y); |
| 514 | friend bool operator!=(const param_type& x, const param_type& y); |
| 515 | }; |
| 516 | |
| 517 | // constructors and reset functions |
| 518 | explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); |
| 519 | explicit uniform_real_distribution(const param_type& parm); |
| 520 | void reset(); |
| 521 | |
| 522 | // generating functions |
| 523 | template<class URNG> result_type operator()(URNG& g); |
| 524 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 525 | |
| 526 | // property functions |
| 527 | result_type a() const; |
| 528 | result_type b() const; |
| 529 | |
| 530 | param_type param() const; |
| 531 | void param(const param_type& parm); |
| 532 | |
| 533 | result_type min() const; |
| 534 | result_type max() const; |
| 535 | |
| 536 | friend bool operator==(const uniform_real_distribution& x, |
| 537 | const uniform_real_distribution& y); |
| 538 | friend bool operator!=(const uniform_real_distribution& x, |
| 539 | const uniform_real_distribution& y); |
| 540 | |
| 541 | template <class charT, class traits> |
| 542 | friend |
| 543 | basic_ostream<charT, traits>& |
| 544 | operator<<(basic_ostream<charT, traits>& os, |
| 545 | const uniform_real_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 546 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 547 | template <class charT, class traits> |
| 548 | friend |
| 549 | basic_istream<charT, traits>& |
| 550 | operator>>(basic_istream<charT, traits>& is, |
| 551 | uniform_real_distribution& x); |
| 552 | }; |
| 553 | |
| 554 | class bernoulli_distribution |
| 555 | { |
| 556 | public: |
| 557 | // types |
| 558 | typedef bool result_type; |
| 559 | |
| 560 | class param_type |
| 561 | { |
| 562 | public: |
| 563 | typedef bernoulli_distribution distribution_type; |
| 564 | |
| 565 | explicit param_type(double p = 0.5); |
| 566 | |
| 567 | double p() const; |
| 568 | |
| 569 | friend bool operator==(const param_type& x, const param_type& y); |
| 570 | friend bool operator!=(const param_type& x, const param_type& y); |
| 571 | }; |
| 572 | |
| 573 | // constructors and reset functions |
| 574 | explicit bernoulli_distribution(double p = 0.5); |
| 575 | explicit bernoulli_distribution(const param_type& parm); |
| 576 | void reset(); |
| 577 | |
| 578 | // generating functions |
| 579 | template<class URNG> result_type operator()(URNG& g); |
| 580 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 581 | |
| 582 | // property functions |
| 583 | double p() const; |
| 584 | |
| 585 | param_type param() const; |
| 586 | void param(const param_type& parm); |
| 587 | |
| 588 | result_type min() const; |
| 589 | result_type max() const; |
| 590 | |
| 591 | friend bool operator==(const bernoulli_distribution& x, |
| 592 | const bernoulli_distribution& y); |
| 593 | friend bool operator!=(const bernoulli_distribution& x, |
| 594 | const bernoulli_distribution& y); |
| 595 | |
| 596 | template <class charT, class traits> |
| 597 | friend |
| 598 | basic_ostream<charT, traits>& |
| 599 | operator<<(basic_ostream<charT, traits>& os, |
| 600 | const bernoulli_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 601 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 602 | template <class charT, class traits> |
| 603 | friend |
| 604 | basic_istream<charT, traits>& |
| 605 | operator>>(basic_istream<charT, traits>& is, |
| 606 | bernoulli_distribution& x); |
| 607 | }; |
| 608 | |
| 609 | template<class IntType = int> |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 610 | class binomial_distribution |
| 611 | { |
| 612 | public: |
| 613 | // types |
| 614 | typedef IntType result_type; |
| 615 | |
| 616 | class param_type |
| 617 | { |
| 618 | public: |
| 619 | typedef binomial_distribution distribution_type; |
| 620 | |
| 621 | explicit param_type(IntType t = 1, double p = 0.5); |
| 622 | |
| 623 | IntType t() const; |
| 624 | double p() const; |
| 625 | |
| 626 | friend bool operator==(const param_type& x, const param_type& y); |
| 627 | friend bool operator!=(const param_type& x, const param_type& y); |
| 628 | }; |
| 629 | |
| 630 | // constructors and reset functions |
| 631 | explicit binomial_distribution(IntType t = 1, double p = 0.5); |
| 632 | explicit binomial_distribution(const param_type& parm); |
| 633 | void reset(); |
| 634 | |
| 635 | // generating functions |
| 636 | template<class URNG> result_type operator()(URNG& g); |
| 637 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 638 | |
| 639 | // property functions |
| 640 | IntType t() const; |
| 641 | double p() const; |
| 642 | |
| 643 | param_type param() const; |
| 644 | void param(const param_type& parm); |
| 645 | |
| 646 | result_type min() const; |
| 647 | result_type max() const; |
| 648 | |
| 649 | friend bool operator==(const binomial_distribution& x, |
| 650 | const binomial_distribution& y); |
| 651 | friend bool operator!=(const binomial_distribution& x, |
| 652 | const binomial_distribution& y); |
| 653 | |
| 654 | template <class charT, class traits> |
| 655 | friend |
| 656 | basic_ostream<charT, traits>& |
| 657 | operator<<(basic_ostream<charT, traits>& os, |
| 658 | const binomial_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 659 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 660 | template <class charT, class traits> |
| 661 | friend |
| 662 | basic_istream<charT, traits>& |
| 663 | operator>>(basic_istream<charT, traits>& is, |
| 664 | binomial_distribution& x); |
| 665 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 666 | |
| 667 | template<class IntType = int> |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 668 | class geometric_distribution |
| 669 | { |
| 670 | public: |
| 671 | // types |
| 672 | typedef IntType result_type; |
| 673 | |
| 674 | class param_type |
| 675 | { |
| 676 | public: |
| 677 | typedef geometric_distribution distribution_type; |
| 678 | |
| 679 | explicit param_type(double p = 0.5); |
| 680 | |
| 681 | double p() const; |
| 682 | |
| 683 | friend bool operator==(const param_type& x, const param_type& y); |
| 684 | friend bool operator!=(const param_type& x, const param_type& y); |
| 685 | }; |
| 686 | |
| 687 | // constructors and reset functions |
| 688 | explicit geometric_distribution(double p = 0.5); |
| 689 | explicit geometric_distribution(const param_type& parm); |
| 690 | void reset(); |
| 691 | |
| 692 | // generating functions |
| 693 | template<class URNG> result_type operator()(URNG& g); |
| 694 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 695 | |
| 696 | // property functions |
| 697 | double p() const; |
| 698 | |
| 699 | param_type param() const; |
| 700 | void param(const param_type& parm); |
| 701 | |
| 702 | result_type min() const; |
| 703 | result_type max() const; |
| 704 | |
| 705 | friend bool operator==(const geometric_distribution& x, |
| 706 | const geometric_distribution& y); |
| 707 | friend bool operator!=(const geometric_distribution& x, |
| 708 | const geometric_distribution& y); |
| 709 | |
| 710 | template <class charT, class traits> |
| 711 | friend |
| 712 | basic_ostream<charT, traits>& |
| 713 | operator<<(basic_ostream<charT, traits>& os, |
| 714 | const geometric_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 715 | |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 716 | template <class charT, class traits> |
| 717 | friend |
| 718 | basic_istream<charT, traits>& |
| 719 | operator>>(basic_istream<charT, traits>& is, |
| 720 | geometric_distribution& x); |
| 721 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 722 | |
| 723 | template<class IntType = int> |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 724 | class negative_binomial_distribution |
| 725 | { |
| 726 | public: |
| 727 | // types |
| 728 | typedef IntType result_type; |
| 729 | |
| 730 | class param_type |
| 731 | { |
| 732 | public: |
| 733 | typedef negative_binomial_distribution distribution_type; |
| 734 | |
| 735 | explicit param_type(result_type k = 1, double p = 0.5); |
| 736 | |
| 737 | result_type k() const; |
| 738 | double p() const; |
| 739 | |
| 740 | friend bool operator==(const param_type& x, const param_type& y); |
| 741 | friend bool operator!=(const param_type& x, const param_type& y); |
| 742 | }; |
| 743 | |
| 744 | // constructor and reset functions |
| 745 | explicit negative_binomial_distribution(result_type k = 1, double p = 0.5); |
| 746 | explicit negative_binomial_distribution(const param_type& parm); |
| 747 | void reset(); |
| 748 | |
| 749 | // generating functions |
| 750 | template<class URNG> result_type operator()(URNG& g); |
| 751 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 752 | |
| 753 | // property functions |
| 754 | result_type k() const; |
| 755 | double p() const; |
| 756 | |
| 757 | param_type param() const; |
| 758 | void param(const param_type& parm); |
| 759 | |
| 760 | result_type min() const; |
| 761 | result_type max() const; |
| 762 | |
| 763 | friend bool operator==(const negative_binomial_distribution& x, |
| 764 | const negative_binomial_distribution& y); |
| 765 | friend bool operator!=(const negative_binomial_distribution& x, |
| 766 | const negative_binomial_distribution& y); |
| 767 | |
| 768 | template <class charT, class traits> |
| 769 | friend |
| 770 | basic_ostream<charT, traits>& |
| 771 | operator<<(basic_ostream<charT, traits>& os, |
| 772 | const negative_binomial_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 773 | |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 774 | template <class charT, class traits> |
| 775 | friend |
| 776 | basic_istream<charT, traits>& |
| 777 | operator>>(basic_istream<charT, traits>& is, |
| 778 | negative_binomial_distribution& x); |
| 779 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 780 | |
| 781 | template<class IntType = int> |
Howard Hinnant | 24a5f2a | 2010-05-14 21:38:54 +0000 | [diff] [blame] | 782 | class poisson_distribution |
| 783 | { |
| 784 | public: |
| 785 | // types |
| 786 | typedef IntType result_type; |
| 787 | |
| 788 | class param_type |
| 789 | { |
| 790 | public: |
| 791 | typedef poisson_distribution distribution_type; |
| 792 | |
| 793 | explicit param_type(double mean = 1.0); |
| 794 | |
| 795 | double mean() const; |
| 796 | |
| 797 | friend bool operator==(const param_type& x, const param_type& y); |
| 798 | friend bool operator!=(const param_type& x, const param_type& y); |
| 799 | }; |
| 800 | |
| 801 | // constructors and reset functions |
| 802 | explicit poisson_distribution(double mean = 1.0); |
| 803 | explicit poisson_distribution(const param_type& parm); |
| 804 | void reset(); |
| 805 | |
| 806 | // generating functions |
| 807 | template<class URNG> result_type operator()(URNG& g); |
| 808 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 809 | |
| 810 | // property functions |
| 811 | double mean() const; |
| 812 | |
| 813 | param_type param() const; |
| 814 | void param(const param_type& parm); |
| 815 | |
| 816 | result_type min() const; |
| 817 | result_type max() const; |
| 818 | |
| 819 | friend bool operator==(const poisson_distribution& x, |
| 820 | const poisson_distribution& y); |
| 821 | friend bool operator!=(const poisson_distribution& x, |
| 822 | const poisson_distribution& y); |
| 823 | |
| 824 | template <class charT, class traits> |
| 825 | friend |
| 826 | basic_ostream<charT, traits>& |
| 827 | operator<<(basic_ostream<charT, traits>& os, |
| 828 | const poisson_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 829 | |
Howard Hinnant | 24a5f2a | 2010-05-14 21:38:54 +0000 | [diff] [blame] | 830 | template <class charT, class traits> |
| 831 | friend |
| 832 | basic_istream<charT, traits>& |
| 833 | operator>>(basic_istream<charT, traits>& is, |
| 834 | poisson_distribution& x); |
| 835 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 836 | |
| 837 | template<class RealType = double> |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 838 | class exponential_distribution |
| 839 | { |
| 840 | public: |
| 841 | // types |
| 842 | typedef RealType result_type; |
| 843 | |
| 844 | class param_type |
| 845 | { |
| 846 | public: |
| 847 | typedef exponential_distribution distribution_type; |
| 848 | |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 849 | explicit param_type(result_type lambda = 1.0); |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 850 | |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 851 | result_type lambda() const; |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 852 | |
| 853 | friend bool operator==(const param_type& x, const param_type& y); |
| 854 | friend bool operator!=(const param_type& x, const param_type& y); |
| 855 | }; |
| 856 | |
| 857 | // constructors and reset functions |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 858 | explicit exponential_distribution(result_type lambda = 1.0); |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 859 | explicit exponential_distribution(const param_type& parm); |
| 860 | void reset(); |
| 861 | |
| 862 | // generating functions |
| 863 | template<class URNG> result_type operator()(URNG& g); |
| 864 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 865 | |
| 866 | // property functions |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 867 | result_type lambda() const; |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 868 | |
| 869 | param_type param() const; |
| 870 | void param(const param_type& parm); |
| 871 | |
| 872 | result_type min() const; |
| 873 | result_type max() const; |
| 874 | |
| 875 | friend bool operator==(const exponential_distribution& x, |
| 876 | const exponential_distribution& y); |
| 877 | friend bool operator!=(const exponential_distribution& x, |
| 878 | const exponential_distribution& y); |
| 879 | |
| 880 | template <class charT, class traits> |
| 881 | friend |
| 882 | basic_ostream<charT, traits>& |
| 883 | operator<<(basic_ostream<charT, traits>& os, |
| 884 | const exponential_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 885 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 886 | template <class charT, class traits> |
| 887 | friend |
| 888 | basic_istream<charT, traits>& |
| 889 | operator>>(basic_istream<charT, traits>& is, |
| 890 | exponential_distribution& x); |
| 891 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 892 | |
| 893 | template<class RealType = double> |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 894 | class gamma_distribution |
| 895 | { |
| 896 | public: |
| 897 | // types |
| 898 | typedef RealType result_type; |
| 899 | |
| 900 | class param_type |
| 901 | { |
| 902 | public: |
| 903 | typedef gamma_distribution distribution_type; |
| 904 | |
| 905 | explicit param_type(result_type alpha = 1, result_type beta = 1); |
| 906 | |
| 907 | result_type alpha() const; |
| 908 | result_type beta() const; |
| 909 | |
| 910 | friend bool operator==(const param_type& x, const param_type& y); |
| 911 | friend bool operator!=(const param_type& x, const param_type& y); |
| 912 | }; |
| 913 | |
| 914 | // constructors and reset functions |
| 915 | explicit gamma_distribution(result_type alpha = 1, result_type beta = 1); |
| 916 | explicit gamma_distribution(const param_type& parm); |
| 917 | void reset(); |
| 918 | |
| 919 | // generating functions |
| 920 | template<class URNG> result_type operator()(URNG& g); |
| 921 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 922 | |
| 923 | // property functions |
| 924 | result_type alpha() const; |
| 925 | result_type beta() const; |
| 926 | |
| 927 | param_type param() const; |
| 928 | void param(const param_type& parm); |
| 929 | |
| 930 | result_type min() const; |
| 931 | result_type max() const; |
| 932 | |
| 933 | friend bool operator==(const gamma_distribution& x, |
| 934 | const gamma_distribution& y); |
| 935 | friend bool operator!=(const gamma_distribution& x, |
| 936 | const gamma_distribution& y); |
| 937 | |
| 938 | template <class charT, class traits> |
| 939 | friend |
| 940 | basic_ostream<charT, traits>& |
| 941 | operator<<(basic_ostream<charT, traits>& os, |
| 942 | const gamma_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 943 | |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 944 | template <class charT, class traits> |
| 945 | friend |
| 946 | basic_istream<charT, traits>& |
| 947 | operator>>(basic_istream<charT, traits>& is, |
| 948 | gamma_distribution& x); |
| 949 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 950 | |
| 951 | template<class RealType = double> |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 952 | class weibull_distribution |
| 953 | { |
| 954 | public: |
| 955 | // types |
| 956 | typedef RealType result_type; |
| 957 | |
| 958 | class param_type |
| 959 | { |
| 960 | public: |
| 961 | typedef weibull_distribution distribution_type; |
| 962 | |
| 963 | explicit param_type(result_type alpha = 1, result_type beta = 1); |
| 964 | |
| 965 | result_type a() const; |
| 966 | result_type b() const; |
| 967 | |
| 968 | friend bool operator==(const param_type& x, const param_type& y); |
| 969 | friend bool operator!=(const param_type& x, const param_type& y); |
| 970 | }; |
| 971 | |
| 972 | // constructor and reset functions |
| 973 | explicit weibull_distribution(result_type a = 1, result_type b = 1); |
| 974 | explicit weibull_distribution(const param_type& parm); |
| 975 | void reset(); |
| 976 | |
| 977 | // generating functions |
| 978 | template<class URNG> result_type operator()(URNG& g); |
| 979 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 980 | |
| 981 | // property functions |
| 982 | result_type a() const; |
| 983 | result_type b() const; |
| 984 | |
| 985 | param_type param() const; |
| 986 | void param(const param_type& parm); |
| 987 | |
| 988 | result_type min() const; |
| 989 | result_type max() const; |
| 990 | |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 991 | friend bool operator==(const weibull_distribution& x, |
| 992 | const weibull_distribution& y); |
| 993 | friend bool operator!=(const weibull_distribution& x, |
| 994 | const weibull_distribution& y); |
| 995 | |
| 996 | template <class charT, class traits> |
| 997 | friend |
| 998 | basic_ostream<charT, traits>& |
| 999 | operator<<(basic_ostream<charT, traits>& os, |
| 1000 | const weibull_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1001 | |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 1002 | template <class charT, class traits> |
| 1003 | friend |
| 1004 | basic_istream<charT, traits>& |
| 1005 | operator>>(basic_istream<charT, traits>& is, |
| 1006 | weibull_distribution& x); |
| 1007 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1008 | |
| 1009 | template<class RealType = double> |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 1010 | class extreme_value_distribution |
| 1011 | { |
| 1012 | public: |
| 1013 | // types |
| 1014 | typedef RealType result_type; |
| 1015 | |
| 1016 | class param_type |
| 1017 | { |
| 1018 | public: |
| 1019 | typedef extreme_value_distribution distribution_type; |
| 1020 | |
| 1021 | explicit param_type(result_type a = 0, result_type b = 1); |
| 1022 | |
| 1023 | result_type a() const; |
| 1024 | result_type b() const; |
| 1025 | |
| 1026 | friend bool operator==(const param_type& x, const param_type& y); |
| 1027 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1028 | }; |
| 1029 | |
| 1030 | // constructor and reset functions |
| 1031 | explicit extreme_value_distribution(result_type a = 0, result_type b = 1); |
| 1032 | explicit extreme_value_distribution(const param_type& parm); |
| 1033 | void reset(); |
| 1034 | |
| 1035 | // generating functions |
| 1036 | template<class URNG> result_type operator()(URNG& g); |
| 1037 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1038 | |
| 1039 | // property functions |
| 1040 | result_type a() const; |
| 1041 | result_type b() const; |
| 1042 | |
| 1043 | param_type param() const; |
| 1044 | void param(const param_type& parm); |
| 1045 | |
| 1046 | result_type min() const; |
| 1047 | result_type max() const; |
| 1048 | |
| 1049 | friend bool operator==(const extreme_value_distribution& x, |
| 1050 | const extreme_value_distribution& y); |
| 1051 | friend bool operator!=(const extreme_value_distribution& x, |
| 1052 | const extreme_value_distribution& y); |
| 1053 | |
| 1054 | template <class charT, class traits> |
| 1055 | friend |
| 1056 | basic_ostream<charT, traits>& |
| 1057 | operator<<(basic_ostream<charT, traits>& os, |
| 1058 | const extreme_value_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1059 | |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 1060 | template <class charT, class traits> |
| 1061 | friend |
| 1062 | basic_istream<charT, traits>& |
| 1063 | operator>>(basic_istream<charT, traits>& is, |
| 1064 | extreme_value_distribution& x); |
| 1065 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1066 | |
| 1067 | template<class RealType = double> |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 1068 | class normal_distribution |
| 1069 | { |
| 1070 | public: |
| 1071 | // types |
| 1072 | typedef RealType result_type; |
| 1073 | |
| 1074 | class param_type |
| 1075 | { |
| 1076 | public: |
| 1077 | typedef normal_distribution distribution_type; |
| 1078 | |
| 1079 | explicit param_type(result_type mean = 0, result_type stddev = 1); |
| 1080 | |
| 1081 | result_type mean() const; |
| 1082 | result_type stddev() const; |
| 1083 | |
| 1084 | friend bool operator==(const param_type& x, const param_type& y); |
| 1085 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1086 | }; |
| 1087 | |
| 1088 | // constructors and reset functions |
| 1089 | explicit normal_distribution(result_type mean = 0, result_type stddev = 1); |
| 1090 | explicit normal_distribution(const param_type& parm); |
| 1091 | void reset(); |
| 1092 | |
| 1093 | // generating functions |
| 1094 | template<class URNG> result_type operator()(URNG& g); |
| 1095 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1096 | |
| 1097 | // property functions |
| 1098 | result_type mean() const; |
| 1099 | result_type stddev() const; |
| 1100 | |
| 1101 | param_type param() const; |
| 1102 | void param(const param_type& parm); |
| 1103 | |
| 1104 | result_type min() const; |
| 1105 | result_type max() const; |
| 1106 | |
| 1107 | friend bool operator==(const normal_distribution& x, |
| 1108 | const normal_distribution& y); |
| 1109 | friend bool operator!=(const normal_distribution& x, |
| 1110 | const normal_distribution& y); |
| 1111 | |
| 1112 | template <class charT, class traits> |
| 1113 | friend |
| 1114 | basic_ostream<charT, traits>& |
| 1115 | operator<<(basic_ostream<charT, traits>& os, |
| 1116 | const normal_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1117 | |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 1118 | template <class charT, class traits> |
| 1119 | friend |
| 1120 | basic_istream<charT, traits>& |
| 1121 | operator>>(basic_istream<charT, traits>& is, |
| 1122 | normal_distribution& x); |
| 1123 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1124 | |
| 1125 | template<class RealType = double> |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 1126 | class lognormal_distribution |
| 1127 | { |
| 1128 | public: |
| 1129 | // types |
| 1130 | typedef RealType result_type; |
| 1131 | |
| 1132 | class param_type |
| 1133 | { |
| 1134 | public: |
| 1135 | typedef lognormal_distribution distribution_type; |
| 1136 | |
| 1137 | explicit param_type(result_type m = 0, result_type s = 1); |
| 1138 | |
| 1139 | result_type m() const; |
| 1140 | result_type s() const; |
| 1141 | |
| 1142 | friend bool operator==(const param_type& x, const param_type& y); |
| 1143 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1144 | }; |
| 1145 | |
| 1146 | // constructor and reset functions |
| 1147 | explicit lognormal_distribution(result_type m = 0, result_type s = 1); |
| 1148 | explicit lognormal_distribution(const param_type& parm); |
| 1149 | void reset(); |
| 1150 | |
| 1151 | // generating functions |
| 1152 | template<class URNG> result_type operator()(URNG& g); |
| 1153 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1154 | |
| 1155 | // property functions |
| 1156 | result_type m() const; |
| 1157 | result_type s() const; |
| 1158 | |
| 1159 | param_type param() const; |
| 1160 | void param(const param_type& parm); |
| 1161 | |
| 1162 | result_type min() const; |
| 1163 | result_type max() const; |
| 1164 | |
| 1165 | friend bool operator==(const lognormal_distribution& x, |
| 1166 | const lognormal_distribution& y); |
| 1167 | friend bool operator!=(const lognormal_distribution& x, |
| 1168 | const lognormal_distribution& y); |
| 1169 | |
| 1170 | template <class charT, class traits> |
| 1171 | friend |
| 1172 | basic_ostream<charT, traits>& |
| 1173 | operator<<(basic_ostream<charT, traits>& os, |
| 1174 | const lognormal_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1175 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 1176 | template <class charT, class traits> |
| 1177 | friend |
| 1178 | basic_istream<charT, traits>& |
| 1179 | operator>>(basic_istream<charT, traits>& is, |
| 1180 | lognormal_distribution& x); |
| 1181 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1182 | |
| 1183 | template<class RealType = double> |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1184 | class chi_squared_distribution |
| 1185 | { |
| 1186 | public: |
| 1187 | // types |
| 1188 | typedef RealType result_type; |
| 1189 | |
| 1190 | class param_type |
| 1191 | { |
| 1192 | public: |
| 1193 | typedef chi_squared_distribution distribution_type; |
| 1194 | |
| 1195 | explicit param_type(result_type n = 1); |
| 1196 | |
| 1197 | result_type n() const; |
| 1198 | |
| 1199 | friend bool operator==(const param_type& x, const param_type& y); |
| 1200 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1201 | }; |
| 1202 | |
| 1203 | // constructor and reset functions |
| 1204 | explicit chi_squared_distribution(result_type n = 1); |
| 1205 | explicit chi_squared_distribution(const param_type& parm); |
| 1206 | void reset(); |
| 1207 | |
| 1208 | // generating functions |
| 1209 | template<class URNG> result_type operator()(URNG& g); |
| 1210 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1211 | |
| 1212 | // property functions |
| 1213 | result_type n() const; |
| 1214 | |
| 1215 | param_type param() const; |
| 1216 | void param(const param_type& parm); |
| 1217 | |
| 1218 | result_type min() const; |
| 1219 | result_type max() const; |
| 1220 | |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1221 | friend bool operator==(const chi_squared_distribution& x, |
| 1222 | const chi_squared_distribution& y); |
| 1223 | friend bool operator!=(const chi_squared_distribution& x, |
| 1224 | const chi_squared_distribution& y); |
| 1225 | |
| 1226 | template <class charT, class traits> |
| 1227 | friend |
| 1228 | basic_ostream<charT, traits>& |
| 1229 | operator<<(basic_ostream<charT, traits>& os, |
| 1230 | const chi_squared_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1231 | |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1232 | template <class charT, class traits> |
| 1233 | friend |
| 1234 | basic_istream<charT, traits>& |
| 1235 | operator>>(basic_istream<charT, traits>& is, |
| 1236 | chi_squared_distribution& x); |
| 1237 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1238 | |
| 1239 | template<class RealType = double> |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 1240 | class cauchy_distribution |
| 1241 | { |
| 1242 | public: |
| 1243 | // types |
| 1244 | typedef RealType result_type; |
| 1245 | |
| 1246 | class param_type |
| 1247 | { |
| 1248 | public: |
| 1249 | typedef cauchy_distribution distribution_type; |
| 1250 | |
| 1251 | explicit param_type(result_type a = 0, result_type b = 1); |
| 1252 | |
| 1253 | result_type a() const; |
| 1254 | result_type b() const; |
| 1255 | |
| 1256 | friend bool operator==(const param_type& x, const param_type& y); |
| 1257 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1258 | }; |
| 1259 | |
| 1260 | // constructor and reset functions |
| 1261 | explicit cauchy_distribution(result_type a = 0, result_type b = 1); |
| 1262 | explicit cauchy_distribution(const param_type& parm); |
| 1263 | void reset(); |
| 1264 | |
| 1265 | // generating functions |
| 1266 | template<class URNG> result_type operator()(URNG& g); |
| 1267 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1268 | |
| 1269 | // property functions |
| 1270 | result_type a() const; |
| 1271 | result_type b() const; |
| 1272 | |
| 1273 | param_type param() const; |
| 1274 | void param(const param_type& parm); |
| 1275 | |
| 1276 | result_type min() const; |
| 1277 | result_type max() const; |
| 1278 | |
| 1279 | friend bool operator==(const cauchy_distribution& x, |
| 1280 | const cauchy_distribution& y); |
| 1281 | friend bool operator!=(const cauchy_distribution& x, |
| 1282 | const cauchy_distribution& y); |
| 1283 | |
| 1284 | template <class charT, class traits> |
| 1285 | friend |
| 1286 | basic_ostream<charT, traits>& |
| 1287 | operator<<(basic_ostream<charT, traits>& os, |
| 1288 | const cauchy_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1289 | |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 1290 | template <class charT, class traits> |
| 1291 | friend |
| 1292 | basic_istream<charT, traits>& |
| 1293 | operator>>(basic_istream<charT, traits>& is, |
| 1294 | cauchy_distribution& x); |
| 1295 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1296 | |
| 1297 | template<class RealType = double> |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1298 | class fisher_f_distribution |
| 1299 | { |
| 1300 | public: |
| 1301 | // types |
| 1302 | typedef RealType result_type; |
| 1303 | |
| 1304 | class param_type |
| 1305 | { |
| 1306 | public: |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1307 | typedef fisher_f_distribution distribution_type; |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1308 | |
| 1309 | explicit param_type(result_type m = 1, result_type n = 1); |
| 1310 | |
| 1311 | result_type m() const; |
| 1312 | result_type n() const; |
| 1313 | |
| 1314 | friend bool operator==(const param_type& x, const param_type& y); |
| 1315 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1316 | }; |
| 1317 | |
| 1318 | // constructor and reset functions |
| 1319 | explicit fisher_f_distribution(result_type m = 1, result_type n = 1); |
| 1320 | explicit fisher_f_distribution(const param_type& parm); |
| 1321 | void reset(); |
| 1322 | |
| 1323 | // generating functions |
| 1324 | template<class URNG> result_type operator()(URNG& g); |
| 1325 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1326 | |
| 1327 | // property functions |
| 1328 | result_type m() const; |
| 1329 | result_type n() const; |
| 1330 | |
| 1331 | param_type param() const; |
| 1332 | void param(const param_type& parm); |
| 1333 | |
| 1334 | result_type min() const; |
| 1335 | result_type max() const; |
| 1336 | |
| 1337 | friend bool operator==(const fisher_f_distribution& x, |
| 1338 | const fisher_f_distribution& y); |
| 1339 | friend bool operator!=(const fisher_f_distribution& x, |
| 1340 | const fisher_f_distribution& y); |
| 1341 | |
| 1342 | template <class charT, class traits> |
| 1343 | friend |
| 1344 | basic_ostream<charT, traits>& |
| 1345 | operator<<(basic_ostream<charT, traits>& os, |
| 1346 | const fisher_f_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1347 | |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1348 | template <class charT, class traits> |
| 1349 | friend |
| 1350 | basic_istream<charT, traits>& |
| 1351 | operator>>(basic_istream<charT, traits>& is, |
| 1352 | fisher_f_distribution& x); |
| 1353 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1354 | |
| 1355 | template<class RealType = double> |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1356 | class student_t_distribution |
| 1357 | { |
| 1358 | public: |
| 1359 | // types |
| 1360 | typedef RealType result_type; |
| 1361 | |
| 1362 | class param_type |
| 1363 | { |
| 1364 | public: |
| 1365 | typedef student_t_distribution distribution_type; |
| 1366 | |
| 1367 | explicit param_type(result_type n = 1); |
| 1368 | |
| 1369 | result_type n() const; |
| 1370 | |
| 1371 | friend bool operator==(const param_type& x, const param_type& y); |
| 1372 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1373 | }; |
| 1374 | |
| 1375 | // constructor and reset functions |
| 1376 | explicit student_t_distribution(result_type n = 1); |
| 1377 | explicit student_t_distribution(const param_type& parm); |
| 1378 | void reset(); |
| 1379 | |
| 1380 | // generating functions |
| 1381 | template<class URNG> result_type operator()(URNG& g); |
| 1382 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1383 | |
| 1384 | // property functions |
| 1385 | result_type n() const; |
| 1386 | |
| 1387 | param_type param() const; |
| 1388 | void param(const param_type& parm); |
| 1389 | |
| 1390 | result_type min() const; |
| 1391 | result_type max() const; |
| 1392 | |
| 1393 | friend bool operator==(const student_t_distribution& x, |
| 1394 | const student_t_distribution& y); |
| 1395 | friend bool operator!=(const student_t_distribution& x, |
| 1396 | const student_t_distribution& y); |
| 1397 | |
| 1398 | template <class charT, class traits> |
| 1399 | friend |
| 1400 | basic_ostream<charT, traits>& |
| 1401 | operator<<(basic_ostream<charT, traits>& os, |
| 1402 | const student_t_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1403 | |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1404 | template <class charT, class traits> |
| 1405 | friend |
| 1406 | basic_istream<charT, traits>& |
| 1407 | operator>>(basic_istream<charT, traits>& is, |
| 1408 | student_t_distribution& x); |
| 1409 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1410 | |
| 1411 | template<class IntType = int> |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1412 | class discrete_distribution |
| 1413 | { |
| 1414 | public: |
| 1415 | // types |
| 1416 | typedef IntType result_type; |
| 1417 | |
| 1418 | class param_type |
| 1419 | { |
| 1420 | public: |
| 1421 | typedef discrete_distribution distribution_type; |
| 1422 | |
| 1423 | param_type(); |
| 1424 | template<class InputIterator> |
| 1425 | param_type(InputIterator firstW, InputIterator lastW); |
| 1426 | param_type(initializer_list<double> wl); |
| 1427 | template<class UnaryOperation> |
| 1428 | param_type(size_t nw, double xmin, double xmax, UnaryOperation fw); |
| 1429 | |
| 1430 | vector<double> probabilities() const; |
| 1431 | |
| 1432 | friend bool operator==(const param_type& x, const param_type& y); |
| 1433 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1434 | }; |
| 1435 | |
| 1436 | // constructor and reset functions |
| 1437 | discrete_distribution(); |
| 1438 | template<class InputIterator> |
| 1439 | discrete_distribution(InputIterator firstW, InputIterator lastW); |
| 1440 | discrete_distribution(initializer_list<double> wl); |
| 1441 | template<class UnaryOperation> |
| 1442 | discrete_distribution(size_t nw, double xmin, double xmax, |
| 1443 | UnaryOperation fw); |
| 1444 | explicit discrete_distribution(const param_type& parm); |
| 1445 | void reset(); |
| 1446 | |
| 1447 | // generating functions |
| 1448 | template<class URNG> result_type operator()(URNG& g); |
| 1449 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1450 | |
| 1451 | // property functions |
| 1452 | vector<double> probabilities() const; |
| 1453 | |
| 1454 | param_type param() const; |
| 1455 | void param(const param_type& parm); |
| 1456 | |
| 1457 | result_type min() const; |
| 1458 | result_type max() const; |
| 1459 | |
| 1460 | friend bool operator==(const discrete_distribution& x, |
| 1461 | const discrete_distribution& y); |
| 1462 | friend bool operator!=(const discrete_distribution& x, |
| 1463 | const discrete_distribution& y); |
| 1464 | |
| 1465 | template <class charT, class traits> |
| 1466 | friend |
| 1467 | basic_ostream<charT, traits>& |
| 1468 | operator<<(basic_ostream<charT, traits>& os, |
| 1469 | const discrete_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1470 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1471 | template <class charT, class traits> |
| 1472 | friend |
| 1473 | basic_istream<charT, traits>& |
| 1474 | operator>>(basic_istream<charT, traits>& is, |
| 1475 | discrete_distribution& x); |
| 1476 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1477 | |
| 1478 | template<class RealType = double> |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1479 | class piecewise_constant_distribution |
| 1480 | { |
| 1481 | // types |
| 1482 | typedef RealType result_type; |
| 1483 | |
| 1484 | class param_type |
| 1485 | { |
| 1486 | public: |
| 1487 | typedef piecewise_constant_distribution distribution_type; |
| 1488 | |
| 1489 | param_type(); |
| 1490 | template<class InputIteratorB, class InputIteratorW> |
| 1491 | param_type(InputIteratorB firstB, InputIteratorB lastB, |
| 1492 | InputIteratorW firstW); |
| 1493 | template<class UnaryOperation> |
| 1494 | param_type(initializer_list<result_type> bl, UnaryOperation fw); |
| 1495 | template<class UnaryOperation> |
| 1496 | param_type(size_t nw, result_type xmin, result_type xmax, |
| 1497 | UnaryOperation fw); |
| 1498 | |
| 1499 | vector<result_type> intervals() const; |
Howard Hinnant | a753356 | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1500 | vector<result_type> densities() const; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1501 | |
| 1502 | friend bool operator==(const param_type& x, const param_type& y); |
| 1503 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1504 | }; |
| 1505 | |
| 1506 | // constructor and reset functions |
| 1507 | piecewise_constant_distribution(); |
| 1508 | template<class InputIteratorB, class InputIteratorW> |
| 1509 | piecewise_constant_distribution(InputIteratorB firstB, |
| 1510 | InputIteratorB lastB, |
| 1511 | InputIteratorW firstW); |
| 1512 | template<class UnaryOperation> |
| 1513 | piecewise_constant_distribution(initializer_list<result_type> bl, |
| 1514 | UnaryOperation fw); |
| 1515 | template<class UnaryOperation> |
| 1516 | piecewise_constant_distribution(size_t nw, result_type xmin, |
| 1517 | result_type xmax, UnaryOperation fw); |
| 1518 | explicit piecewise_constant_distribution(const param_type& parm); |
| 1519 | void reset(); |
| 1520 | |
| 1521 | // generating functions |
| 1522 | template<class URNG> result_type operator()(URNG& g); |
| 1523 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1524 | |
| 1525 | // property functions |
| 1526 | vector<result_type> intervals() const; |
Howard Hinnant | a753356 | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1527 | vector<result_type> densities() const; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1528 | |
| 1529 | param_type param() const; |
| 1530 | void param(const param_type& parm); |
| 1531 | |
| 1532 | result_type min() const; |
| 1533 | result_type max() const; |
| 1534 | |
| 1535 | friend bool operator==(const piecewise_constant_distribution& x, |
| 1536 | const piecewise_constant_distribution& y); |
| 1537 | friend bool operator!=(const piecewise_constant_distribution& x, |
| 1538 | const piecewise_constant_distribution& y); |
| 1539 | |
| 1540 | template <class charT, class traits> |
| 1541 | friend |
| 1542 | basic_ostream<charT, traits>& |
| 1543 | operator<<(basic_ostream<charT, traits>& os, |
| 1544 | const piecewise_constant_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1545 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1546 | template <class charT, class traits> |
| 1547 | friend |
| 1548 | basic_istream<charT, traits>& |
| 1549 | operator>>(basic_istream<charT, traits>& is, |
| 1550 | piecewise_constant_distribution& x); |
| 1551 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1552 | |
| 1553 | template<class RealType = double> |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1554 | class piecewise_linear_distribution |
| 1555 | { |
| 1556 | // types |
| 1557 | typedef RealType result_type; |
| 1558 | |
| 1559 | class param_type |
| 1560 | { |
| 1561 | public: |
| 1562 | typedef piecewise_linear_distribution distribution_type; |
| 1563 | |
| 1564 | param_type(); |
| 1565 | template<class InputIteratorB, class InputIteratorW> |
| 1566 | param_type(InputIteratorB firstB, InputIteratorB lastB, |
| 1567 | InputIteratorW firstW); |
| 1568 | template<class UnaryOperation> |
| 1569 | param_type(initializer_list<result_type> bl, UnaryOperation fw); |
| 1570 | template<class UnaryOperation> |
| 1571 | param_type(size_t nw, result_type xmin, result_type xmax, |
| 1572 | UnaryOperation fw); |
| 1573 | |
| 1574 | vector<result_type> intervals() const; |
Howard Hinnant | a753356 | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1575 | vector<result_type> densities() const; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1576 | |
| 1577 | friend bool operator==(const param_type& x, const param_type& y); |
| 1578 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1579 | }; |
| 1580 | |
| 1581 | // constructor and reset functions |
| 1582 | piecewise_linear_distribution(); |
| 1583 | template<class InputIteratorB, class InputIteratorW> |
| 1584 | piecewise_linear_distribution(InputIteratorB firstB, |
| 1585 | InputIteratorB lastB, |
| 1586 | InputIteratorW firstW); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1587 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1588 | template<class UnaryOperation> |
| 1589 | piecewise_linear_distribution(initializer_list<result_type> bl, |
| 1590 | UnaryOperation fw); |
| 1591 | |
| 1592 | template<class UnaryOperation> |
| 1593 | piecewise_linear_distribution(size_t nw, result_type xmin, |
| 1594 | result_type xmax, UnaryOperation fw); |
| 1595 | |
| 1596 | explicit piecewise_linear_distribution(const param_type& parm); |
| 1597 | void reset(); |
| 1598 | |
| 1599 | // generating functions |
| 1600 | template<class URNG> result_type operator()(URNG& g); |
| 1601 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1602 | |
| 1603 | // property functions |
| 1604 | vector<result_type> intervals() const; |
Howard Hinnant | a753356 | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1605 | vector<result_type> densities() const; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1606 | |
| 1607 | param_type param() const; |
| 1608 | void param(const param_type& parm); |
| 1609 | |
| 1610 | result_type min() const; |
| 1611 | result_type max() const; |
| 1612 | |
| 1613 | friend bool operator==(const piecewise_linear_distribution& x, |
| 1614 | const piecewise_linear_distribution& y); |
| 1615 | friend bool operator!=(const piecewise_linear_distribution& x, |
| 1616 | const piecewise_linear_distribution& y); |
| 1617 | |
| 1618 | template <class charT, class traits> |
| 1619 | friend |
| 1620 | basic_ostream<charT, traits>& |
| 1621 | operator<<(basic_ostream<charT, traits>& os, |
| 1622 | const piecewise_linear_distribution& x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1623 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1624 | template <class charT, class traits> |
| 1625 | friend |
| 1626 | basic_istream<charT, traits>& |
| 1627 | operator>>(basic_istream<charT, traits>& is, |
| 1628 | piecewise_linear_distribution& x); |
| 1629 | }; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1630 | |
| 1631 | } // std |
| 1632 | */ |
| 1633 | |
| 1634 | #include <__config> |
| 1635 | #include <cstddef> |
Eric Fiselier | 90adc20 | 2015-01-23 22:22:36 +0000 | [diff] [blame] | 1636 | #include <cstdint> |
| 1637 | #include <cmath> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1638 | #include <type_traits> |
| 1639 | #include <initializer_list> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1640 | #include <limits> |
| 1641 | #include <algorithm> |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1642 | #include <numeric> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1643 | #include <vector> |
| 1644 | #include <string> |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 1645 | #include <iosfwd> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1646 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 1647 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1648 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 1649 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1650 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 1651 | _LIBCPP_PUSH_MACROS |
| 1652 | #include <__undef_macros> |
| 1653 | |
| 1654 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1655 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 1656 | |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1657 | // __is_seed_sequence |
| 1658 | |
| 1659 | template <class _Sseq, class _Engine> |
| 1660 | struct __is_seed_sequence |
| 1661 | { |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1662 | static _LIBCPP_CONSTEXPR const bool value = |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1663 | !is_convertible<_Sseq, typename _Engine::result_type>::value && |
| 1664 | !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; |
| 1665 | }; |
| 1666 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1667 | // linear_congruential_engine |
| 1668 | |
| 1669 | template <unsigned long long __a, unsigned long long __c, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1670 | unsigned long long __m, unsigned long long _Mp, |
| 1671 | bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a)> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1672 | struct __lce_ta; |
| 1673 | |
| 1674 | // 64 |
| 1675 | |
| 1676 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> |
| 1677 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> |
| 1678 | { |
| 1679 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1680 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1681 | static result_type next(result_type __x) |
| 1682 | { |
| 1683 | // Schrage's algorithm |
| 1684 | const result_type __q = __m / __a; |
| 1685 | const result_type __r = __m % __a; |
| 1686 | const result_type __t0 = __a * (__x % __q); |
| 1687 | const result_type __t1 = __r * (__x / __q); |
| 1688 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1689 | __x += __c - (__x >= __m - __c) * __m; |
| 1690 | return __x; |
| 1691 | } |
| 1692 | }; |
| 1693 | |
| 1694 | template <unsigned long long __a, unsigned long long __m> |
| 1695 | struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> |
| 1696 | { |
| 1697 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1698 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1699 | static result_type next(result_type __x) |
| 1700 | { |
| 1701 | // Schrage's algorithm |
| 1702 | const result_type __q = __m / __a; |
| 1703 | const result_type __r = __m % __a; |
| 1704 | const result_type __t0 = __a * (__x % __q); |
| 1705 | const result_type __t1 = __r * (__x / __q); |
| 1706 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1707 | return __x; |
| 1708 | } |
| 1709 | }; |
| 1710 | |
| 1711 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> |
| 1712 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> |
| 1713 | { |
| 1714 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1715 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1716 | static result_type next(result_type __x) |
| 1717 | { |
| 1718 | return (__a * __x + __c) % __m; |
| 1719 | } |
| 1720 | }; |
| 1721 | |
| 1722 | template <unsigned long long __a, unsigned long long __c> |
| 1723 | struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> |
| 1724 | { |
| 1725 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1726 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1727 | static result_type next(result_type __x) |
| 1728 | { |
| 1729 | return __a * __x + __c; |
| 1730 | } |
| 1731 | }; |
| 1732 | |
| 1733 | // 32 |
| 1734 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1735 | template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> |
| 1736 | struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1737 | { |
| 1738 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1739 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1740 | static result_type next(result_type __x) |
| 1741 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1742 | const result_type __a = static_cast<result_type>(_Ap); |
| 1743 | const result_type __c = static_cast<result_type>(_Cp); |
| 1744 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1745 | // Schrage's algorithm |
| 1746 | const result_type __q = __m / __a; |
| 1747 | const result_type __r = __m % __a; |
| 1748 | const result_type __t0 = __a * (__x % __q); |
| 1749 | const result_type __t1 = __r * (__x / __q); |
| 1750 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1751 | __x += __c - (__x >= __m - __c) * __m; |
| 1752 | return __x; |
| 1753 | } |
| 1754 | }; |
| 1755 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1756 | template <unsigned long long _Ap, unsigned long long _Mp> |
| 1757 | struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1758 | { |
| 1759 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1760 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1761 | static result_type next(result_type __x) |
| 1762 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1763 | const result_type __a = static_cast<result_type>(_Ap); |
| 1764 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1765 | // Schrage's algorithm |
| 1766 | const result_type __q = __m / __a; |
| 1767 | const result_type __r = __m % __a; |
| 1768 | const result_type __t0 = __a * (__x % __q); |
| 1769 | const result_type __t1 = __r * (__x / __q); |
| 1770 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1771 | return __x; |
| 1772 | } |
| 1773 | }; |
| 1774 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1775 | template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> |
| 1776 | struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1777 | { |
| 1778 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1779 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1780 | static result_type next(result_type __x) |
| 1781 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1782 | const result_type __a = static_cast<result_type>(_Ap); |
| 1783 | const result_type __c = static_cast<result_type>(_Cp); |
| 1784 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1785 | return (__a * __x + __c) % __m; |
| 1786 | } |
| 1787 | }; |
| 1788 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1789 | template <unsigned long long _Ap, unsigned long long _Cp> |
| 1790 | struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1791 | { |
| 1792 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1793 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1794 | static result_type next(result_type __x) |
| 1795 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1796 | const result_type __a = static_cast<result_type>(_Ap); |
| 1797 | const result_type __c = static_cast<result_type>(_Cp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1798 | return __a * __x + __c; |
| 1799 | } |
| 1800 | }; |
| 1801 | |
| 1802 | // 16 |
| 1803 | |
| 1804 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> |
| 1805 | struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> |
| 1806 | { |
| 1807 | typedef unsigned short result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1808 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1809 | static result_type next(result_type __x) |
| 1810 | { |
| 1811 | return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); |
| 1812 | } |
| 1813 | }; |
| 1814 | |
| 1815 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1816 | class _LIBCPP_TEMPLATE_VIS linear_congruential_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1817 | |
| 1818 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1819 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1820 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1821 | basic_ostream<_CharT, _Traits>& |
| 1822 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1823 | const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1824 | |
| 1825 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1826 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1827 | basic_istream<_CharT, _Traits>& |
| 1828 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1829 | linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1830 | |
| 1831 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1832 | class _LIBCPP_TEMPLATE_VIS linear_congruential_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1833 | { |
| 1834 | public: |
| 1835 | // types |
| 1836 | typedef _UIntType result_type; |
| 1837 | |
Howard Hinnant | a741b24 | 2013-05-21 21:19:35 +0000 | [diff] [blame] | 1838 | private: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1839 | result_type __x_; |
| 1840 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1841 | static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1842 | |
| 1843 | static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); |
| 1844 | static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); |
| 1845 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1846 | static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; |
| 1847 | static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1848 | static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); |
| 1849 | |
| 1850 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1851 | static _LIBCPP_CONSTEXPR const result_type multiplier = __a; |
| 1852 | static _LIBCPP_CONSTEXPR const result_type increment = __c; |
| 1853 | static _LIBCPP_CONSTEXPR const result_type modulus = __m; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1854 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1855 | static _LIBCPP_CONSTEXPR result_type min() {return _Min;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1857 | static _LIBCPP_CONSTEXPR result_type max() {return _Max;} |
| 1858 | static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1859 | |
| 1860 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1861 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1862 | explicit linear_congruential_engine(result_type __s = default_seed) |
| 1863 | {seed(__s);} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1864 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1865 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1866 | explicit linear_congruential_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1867 | 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] | 1868 | {seed(__q);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1869 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1870 | void seed(result_type __s = default_seed) |
| 1871 | {seed(integral_constant<bool, __m == 0>(), |
| 1872 | integral_constant<bool, __c == 0>(), __s);} |
| 1873 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1874 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1875 | typename enable_if |
| 1876 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1877 | __is_seed_sequence<_Sseq, linear_congruential_engine>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1878 | void |
| 1879 | >::type |
| 1880 | seed(_Sseq& __q) |
| 1881 | {__seed(__q, integral_constant<unsigned, |
| 1882 | 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 |
Howard Hinnant | a0c4f7c | 2013-05-21 21:05:12 +0000 | [diff] [blame] | 1883 | : (__m > 0x100000000ull))>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1884 | |
| 1885 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1886 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1887 | result_type operator()() |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1888 | {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] | 1889 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1890 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 1891 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1892 | friend _LIBCPP_INLINE_VISIBILITY |
| 1893 | bool operator==(const linear_congruential_engine& __x, |
| 1894 | const linear_congruential_engine& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1895 | {return __x.__x_ == __y.__x_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1896 | friend _LIBCPP_INLINE_VISIBILITY |
| 1897 | bool operator!=(const linear_congruential_engine& __x, |
| 1898 | const linear_congruential_engine& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1899 | {return !(__x == __y);} |
| 1900 | |
| 1901 | private: |
| 1902 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1903 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1904 | 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] | 1905 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1906 | void seed(true_type, false_type, result_type __s) {__x_ = __s;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1907 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1908 | void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? |
| 1909 | 1 : __s % __m;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1910 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1911 | void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} |
| 1912 | |
| 1913 | template<class _Sseq> |
| 1914 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 1915 | template<class _Sseq> |
| 1916 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 1917 | |
| 1918 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1919 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1920 | friend |
| 1921 | basic_ostream<_CharT, _Traits>& |
| 1922 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1923 | const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1924 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1925 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1926 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1927 | friend |
| 1928 | basic_istream<_CharT, _Traits>& |
| 1929 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1930 | linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1931 | }; |
| 1932 | |
| 1933 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 1934 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1935 | linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; |
| 1936 | |
| 1937 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1938 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1939 | linear_congruential_engine<_UIntType, __a, __c, __m>::increment; |
| 1940 | |
| 1941 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1942 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1943 | linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; |
| 1944 | |
| 1945 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1946 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1947 | linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; |
| 1948 | |
| 1949 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1950 | template<class _Sseq> |
| 1951 | void |
| 1952 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, |
| 1953 | integral_constant<unsigned, 1>) |
| 1954 | { |
| 1955 | const unsigned __k = 1; |
| 1956 | uint32_t __ar[__k+3]; |
| 1957 | __q.generate(__ar, __ar + __k + 3); |
| 1958 | result_type __s = static_cast<result_type>(__ar[3] % __m); |
| 1959 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; |
| 1960 | } |
| 1961 | |
| 1962 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1963 | template<class _Sseq> |
| 1964 | void |
| 1965 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, |
| 1966 | integral_constant<unsigned, 2>) |
| 1967 | { |
| 1968 | const unsigned __k = 2; |
| 1969 | uint32_t __ar[__k+3]; |
| 1970 | __q.generate(__ar, __ar + __k + 3); |
| 1971 | result_type __s = static_cast<result_type>((__ar[3] + |
Howard Hinnant | a0c4f7c | 2013-05-21 21:05:12 +0000 | [diff] [blame] | 1972 | ((uint64_t)__ar[4] << 32)) % __m); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1973 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; |
| 1974 | } |
| 1975 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1976 | template <class _CharT, class _Traits, |
| 1977 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1978 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1979 | basic_ostream<_CharT, _Traits>& |
| 1980 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 1981 | const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) |
| 1982 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 1983 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 1984 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 1985 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1986 | __os.fill(__os.widen(' ')); |
| 1987 | return __os << __x.__x_; |
| 1988 | } |
| 1989 | |
| 1990 | template <class _CharT, class _Traits, |
| 1991 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1992 | basic_istream<_CharT, _Traits>& |
| 1993 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 1994 | linear_congruential_engine<_UIntType, __a, __c, __m>& __x) |
| 1995 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 1996 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 1997 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 1998 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1999 | _UIntType __t; |
| 2000 | __is >> __t; |
| 2001 | if (!__is.fail()) |
| 2002 | __x.__x_ = __t; |
| 2003 | return __is; |
| 2004 | } |
| 2005 | |
| 2006 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> |
| 2007 | minstd_rand0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2008 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> |
| 2009 | minstd_rand; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 2010 | typedef minstd_rand default_random_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2011 | // mersenne_twister_engine |
| 2012 | |
| 2013 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2014 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2015 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2016 | class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2017 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2018 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2019 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2020 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2021 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2022 | 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] | 2023 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2024 | 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] | 2025 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2026 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2027 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2028 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2029 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 2030 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2031 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2032 | 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] | 2033 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2034 | 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] | 2035 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2036 | |
| 2037 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2038 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2039 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2040 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2041 | basic_ostream<_CharT, _Traits>& |
| 2042 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2043 | 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] | 2044 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2045 | |
| 2046 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2047 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2048 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2049 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2050 | basic_istream<_CharT, _Traits>& |
| 2051 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2052 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2053 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2054 | |
| 2055 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2056 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2057 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2058 | class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2059 | { |
| 2060 | public: |
| 2061 | // types |
| 2062 | typedef _UIntType result_type; |
| 2063 | |
| 2064 | private: |
| 2065 | result_type __x_[__n]; |
| 2066 | size_t __i_; |
| 2067 | |
| 2068 | static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); |
| 2069 | static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2070 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2071 | static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); |
| 2072 | static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); |
| 2073 | static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); |
| 2074 | static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); |
| 2075 | static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); |
| 2076 | static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); |
| 2077 | static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); |
| 2078 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2079 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 2080 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 2081 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2082 | static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); |
| 2083 | static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2084 | static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2085 | static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2086 | static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2087 | static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2088 | |
| 2089 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2090 | static _LIBCPP_CONSTEXPR const size_t word_size = __w; |
| 2091 | static _LIBCPP_CONSTEXPR const size_t state_size = __n; |
| 2092 | static _LIBCPP_CONSTEXPR const size_t shift_size = __m; |
| 2093 | static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; |
| 2094 | static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; |
| 2095 | static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; |
| 2096 | static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; |
| 2097 | static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; |
| 2098 | static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; |
| 2099 | static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; |
| 2100 | static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; |
| 2101 | static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; |
| 2102 | static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2103 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2104 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2105 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2106 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
| 2107 | static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2108 | |
| 2109 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2110 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2111 | explicit mersenne_twister_engine(result_type __sd = default_seed) |
| 2112 | {seed(__sd);} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2113 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2114 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2115 | explicit mersenne_twister_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2116 | 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] | 2117 | {seed(__q);} |
| 2118 | void seed(result_type __sd = default_seed); |
| 2119 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2120 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2121 | typename enable_if |
| 2122 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2123 | __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2124 | void |
| 2125 | >::type |
| 2126 | seed(_Sseq& __q) |
| 2127 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2128 | |
| 2129 | // generating functions |
| 2130 | result_type operator()(); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2131 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2132 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2133 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2134 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2135 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2136 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2137 | friend |
| 2138 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2139 | 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] | 2140 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2141 | 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] | 2142 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2143 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2144 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2145 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2146 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2147 | friend |
| 2148 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2149 | 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] | 2150 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2151 | 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] | 2152 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2153 | |
| 2154 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2155 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2156 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2157 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2158 | friend |
| 2159 | basic_ostream<_CharT, _Traits>& |
| 2160 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2161 | 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] | 2162 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2163 | |
| 2164 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2165 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2166 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2167 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2168 | friend |
| 2169 | basic_istream<_CharT, _Traits>& |
| 2170 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2171 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2172 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2173 | private: |
| 2174 | |
| 2175 | template<class _Sseq> |
| 2176 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 2177 | template<class _Sseq> |
| 2178 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 2179 | |
| 2180 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2181 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2182 | static |
| 2183 | typename enable_if |
| 2184 | < |
| 2185 | __count < __w, |
| 2186 | result_type |
| 2187 | >::type |
| 2188 | __lshift(result_type __x) {return (__x << __count) & _Max;} |
| 2189 | |
| 2190 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2191 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2192 | static |
| 2193 | typename enable_if |
| 2194 | < |
| 2195 | (__count >= __w), |
| 2196 | result_type |
| 2197 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2198 | __lshift(result_type) {return result_type(0);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2199 | |
| 2200 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2201 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2202 | static |
| 2203 | typename enable_if |
| 2204 | < |
| 2205 | __count < _Dt, |
| 2206 | result_type |
| 2207 | >::type |
| 2208 | __rshift(result_type __x) {return __x >> __count;} |
| 2209 | |
| 2210 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2211 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2212 | static |
| 2213 | typename enable_if |
| 2214 | < |
| 2215 | (__count >= _Dt), |
| 2216 | result_type |
| 2217 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2218 | __rshift(result_type) {return result_type(0);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2219 | }; |
| 2220 | |
| 2221 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2222 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2223 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2224 | _LIBCPP_CONSTEXPR const size_t |
| 2225 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; |
| 2226 | |
| 2227 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2228 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2229 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2230 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2231 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; |
| 2232 | |
| 2233 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2234 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2235 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2236 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2237 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; |
| 2238 | |
| 2239 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2240 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2241 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2242 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2243 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; |
| 2244 | |
| 2245 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2246 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2247 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2248 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2249 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; |
| 2250 | |
| 2251 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2252 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2253 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2254 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2255 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; |
| 2256 | |
| 2257 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2258 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2259 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2260 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2261 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; |
| 2262 | |
| 2263 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2264 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2265 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2266 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2267 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; |
| 2268 | |
| 2269 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2270 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2271 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2272 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2273 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; |
| 2274 | |
| 2275 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2276 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2277 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2278 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2279 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; |
| 2280 | |
| 2281 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2282 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2283 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2284 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2285 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; |
| 2286 | |
| 2287 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2288 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2289 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2290 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2291 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; |
| 2292 | |
| 2293 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2294 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2295 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2296 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2297 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; |
| 2298 | |
| 2299 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2300 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2301 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2302 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2303 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; |
| 2304 | |
| 2305 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2306 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2307 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2308 | void |
| 2309 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2310 | __t, __c, __l, __f>::seed(result_type __sd) |
Marshall Clow | c189463 | 2017-09-11 18:10:33 +0000 | [diff] [blame] | 2311 | _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2312 | { // __w >= 2 |
| 2313 | __x_[0] = __sd & _Max; |
| 2314 | for (size_t __i = 1; __i < __n; ++__i) |
| 2315 | __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; |
| 2316 | __i_ = 0; |
| 2317 | } |
| 2318 | |
| 2319 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2320 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2321 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2322 | template<class _Sseq> |
| 2323 | void |
| 2324 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2325 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) |
| 2326 | { |
| 2327 | const unsigned __k = 1; |
| 2328 | uint32_t __ar[__n * __k]; |
| 2329 | __q.generate(__ar, __ar + __n * __k); |
| 2330 | for (size_t __i = 0; __i < __n; ++__i) |
| 2331 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); |
| 2332 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2333 | (result_type(1) << __r) - result_type(1); |
| 2334 | __i_ = 0; |
| 2335 | if ((__x_[0] & ~__mask) == 0) |
| 2336 | { |
| 2337 | for (size_t __i = 1; __i < __n; ++__i) |
| 2338 | if (__x_[__i] != 0) |
| 2339 | return; |
Hubert Tong | ca5b776 | 2018-08-16 23:56:54 +0000 | [diff] [blame] | 2340 | __x_[0] = result_type(1) << (__w - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2345 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2346 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2347 | template<class _Sseq> |
| 2348 | void |
| 2349 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2350 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) |
| 2351 | { |
| 2352 | const unsigned __k = 2; |
| 2353 | uint32_t __ar[__n * __k]; |
| 2354 | __q.generate(__ar, __ar + __n * __k); |
| 2355 | for (size_t __i = 0; __i < __n; ++__i) |
| 2356 | __x_[__i] = static_cast<result_type>( |
| 2357 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); |
| 2358 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2359 | (result_type(1) << __r) - result_type(1); |
| 2360 | __i_ = 0; |
| 2361 | if ((__x_[0] & ~__mask) == 0) |
| 2362 | { |
| 2363 | for (size_t __i = 1; __i < __n; ++__i) |
| 2364 | if (__x_[__i] != 0) |
| 2365 | return; |
Hubert Tong | ca5b776 | 2018-08-16 23:56:54 +0000 | [diff] [blame] | 2366 | __x_[0] = result_type(1) << (__w - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2371 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2372 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2373 | _UIntType |
| 2374 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2375 | __t, __c, __l, __f>::operator()() |
| 2376 | { |
| 2377 | const size_t __j = (__i_ + 1) % __n; |
| 2378 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2379 | (result_type(1) << __r) - result_type(1); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2380 | const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2381 | const size_t __k = (__i_ + __m) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2382 | __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2383 | result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); |
| 2384 | __i_ = __j; |
| 2385 | __z ^= __lshift<__s>(__z) & __b; |
| 2386 | __z ^= __lshift<__t>(__z) & __c; |
| 2387 | return __z ^ __rshift<__l>(__z); |
| 2388 | } |
| 2389 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2390 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2391 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2392 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2393 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2394 | 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] | 2395 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2396 | 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] | 2397 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2398 | { |
| 2399 | if (__x.__i_ == __y.__i_) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2400 | return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2401 | if (__x.__i_ == 0 || __y.__i_ == 0) |
| 2402 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2403 | size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2404 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2405 | __y.__x_ + __y.__i_)) |
| 2406 | return false; |
| 2407 | if (__x.__i_ == 0) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2408 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); |
| 2409 | return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2410 | } |
| 2411 | if (__x.__i_ < __y.__i_) |
| 2412 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2413 | size_t __j = _Np - __y.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2414 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2415 | __y.__x_ + __y.__i_)) |
| 2416 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2417 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2418 | __y.__x_)) |
| 2419 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2420 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2421 | __y.__x_ + (_Np - (__x.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2422 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2423 | size_t __j = _Np - __x.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2424 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2425 | __x.__x_ + __x.__i_)) |
| 2426 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2427 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2428 | __x.__x_)) |
| 2429 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2430 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2431 | __x.__x_ + (_Np - (__y.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2432 | } |
| 2433 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2434 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2435 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2436 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2437 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2438 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2439 | 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] | 2440 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2441 | 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] | 2442 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2443 | { |
| 2444 | return !(__x == __y); |
| 2445 | } |
| 2446 | |
| 2447 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2448 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2449 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2450 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2451 | basic_ostream<_CharT, _Traits>& |
| 2452 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2453 | 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] | 2454 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2455 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2456 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 2457 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2458 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2459 | _CharT __sp = __os.widen(' '); |
| 2460 | __os.fill(__sp); |
| 2461 | __os << __x.__x_[__x.__i_]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2462 | for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2463 | __os << __sp << __x.__x_[__j]; |
| 2464 | for (size_t __j = 0; __j < __x.__i_; ++__j) |
| 2465 | __os << __sp << __x.__x_[__j]; |
| 2466 | return __os; |
| 2467 | } |
| 2468 | |
| 2469 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2470 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2471 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2472 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2473 | basic_istream<_CharT, _Traits>& |
| 2474 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2475 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2476 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2477 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2478 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 2479 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2480 | __is.flags(_Istream::dec | _Istream::skipws); |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2481 | _UInt __t[_Np]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2482 | for (size_t __i = 0; __i < _Np; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2483 | __is >> __t[__i]; |
| 2484 | if (!__is.fail()) |
| 2485 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2486 | for (size_t __i = 0; __i < _Np; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2487 | __x.__x_[__i] = __t[__i]; |
| 2488 | __x.__i_ = 0; |
| 2489 | } |
| 2490 | return __is; |
| 2491 | } |
| 2492 | |
| 2493 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, |
| 2494 | 0x9908b0df, 11, 0xffffffff, |
| 2495 | 7, 0x9d2c5680, |
| 2496 | 15, 0xefc60000, |
| 2497 | 18, 1812433253> mt19937; |
| 2498 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, |
| 2499 | 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, |
| 2500 | 17, 0x71d67fffeda60000ULL, |
| 2501 | 37, 0xfff7eee000000000ULL, |
| 2502 | 43, 6364136223846793005ULL> mt19937_64; |
| 2503 | |
| 2504 | // subtract_with_carry_engine |
| 2505 | |
| 2506 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2507 | class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2508 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2509 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2510 | bool |
| 2511 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2512 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2513 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2514 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2515 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 2516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2517 | bool |
| 2518 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2519 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2520 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2521 | |
| 2522 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2523 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2524 | basic_ostream<_CharT, _Traits>& |
| 2525 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2526 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2527 | |
| 2528 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2529 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2530 | basic_istream<_CharT, _Traits>& |
| 2531 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2532 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2533 | |
| 2534 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2535 | class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2536 | { |
| 2537 | public: |
| 2538 | // types |
| 2539 | typedef _UIntType result_type; |
| 2540 | |
| 2541 | private: |
| 2542 | result_type __x_[__r]; |
| 2543 | result_type __c_; |
| 2544 | size_t __i_; |
| 2545 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2546 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2547 | static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); |
| 2548 | static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); |
| 2549 | static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); |
| 2550 | static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); |
| 2551 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2552 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 2553 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 2554 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2555 | static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); |
| 2556 | |
| 2557 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2558 | static _LIBCPP_CONSTEXPR const size_t word_size = __w; |
| 2559 | static _LIBCPP_CONSTEXPR const size_t short_lag = __s; |
| 2560 | static _LIBCPP_CONSTEXPR const size_t long_lag = __r; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2561 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2562 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2563 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2564 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
| 2565 | static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2566 | |
| 2567 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2568 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2569 | explicit subtract_with_carry_engine(result_type __sd = default_seed) |
| 2570 | {seed(__sd);} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2571 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2572 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2573 | explicit subtract_with_carry_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2574 | 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] | 2575 | {seed(__q);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2577 | void seed(result_type __sd = default_seed) |
| 2578 | {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2579 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2581 | typename enable_if |
| 2582 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2583 | __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2584 | void |
| 2585 | >::type |
| 2586 | seed(_Sseq& __q) |
| 2587 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2588 | |
| 2589 | // generating functions |
| 2590 | result_type operator()(); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2591 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2592 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2593 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2594 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2595 | friend |
| 2596 | bool |
| 2597 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2598 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2599 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2600 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2601 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2602 | friend |
| 2603 | bool |
| 2604 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2605 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2606 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2607 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2608 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2609 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2610 | friend |
| 2611 | basic_ostream<_CharT, _Traits>& |
| 2612 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2613 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2614 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2615 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2616 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2617 | friend |
| 2618 | basic_istream<_CharT, _Traits>& |
| 2619 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2620 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2621 | |
| 2622 | private: |
| 2623 | |
| 2624 | void seed(result_type __sd, integral_constant<unsigned, 1>); |
| 2625 | void seed(result_type __sd, integral_constant<unsigned, 2>); |
| 2626 | template<class _Sseq> |
| 2627 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 2628 | template<class _Sseq> |
| 2629 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 2630 | }; |
| 2631 | |
| 2632 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2633 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; |
| 2634 | |
| 2635 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2636 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; |
| 2637 | |
| 2638 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2639 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; |
| 2640 | |
| 2641 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2642 | _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type |
| 2643 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; |
| 2644 | |
| 2645 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2646 | void |
| 2647 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, |
| 2648 | integral_constant<unsigned, 1>) |
| 2649 | { |
| 2650 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> |
| 2651 | __e(__sd == 0u ? default_seed : __sd); |
| 2652 | for (size_t __i = 0; __i < __r; ++__i) |
| 2653 | __x_[__i] = static_cast<result_type>(__e() & _Max); |
| 2654 | __c_ = __x_[__r-1] == 0; |
| 2655 | __i_ = 0; |
| 2656 | } |
| 2657 | |
| 2658 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2659 | void |
| 2660 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, |
| 2661 | integral_constant<unsigned, 2>) |
| 2662 | { |
| 2663 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> |
| 2664 | __e(__sd == 0u ? default_seed : __sd); |
| 2665 | for (size_t __i = 0; __i < __r; ++__i) |
Howard Hinnant | 93072c1 | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2666 | { |
| 2667 | result_type __e0 = __e(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2668 | __x_[__i] = static_cast<result_type>( |
Howard Hinnant | 93072c1 | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2669 | (__e0 + ((uint64_t)__e() << 32)) & _Max); |
| 2670 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2671 | __c_ = __x_[__r-1] == 0; |
| 2672 | __i_ = 0; |
| 2673 | } |
| 2674 | |
| 2675 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2676 | template<class _Sseq> |
| 2677 | void |
| 2678 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, |
| 2679 | integral_constant<unsigned, 1>) |
| 2680 | { |
| 2681 | const unsigned __k = 1; |
| 2682 | uint32_t __ar[__r * __k]; |
| 2683 | __q.generate(__ar, __ar + __r * __k); |
| 2684 | for (size_t __i = 0; __i < __r; ++__i) |
| 2685 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); |
| 2686 | __c_ = __x_[__r-1] == 0; |
| 2687 | __i_ = 0; |
| 2688 | } |
| 2689 | |
| 2690 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2691 | template<class _Sseq> |
| 2692 | void |
| 2693 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, |
| 2694 | integral_constant<unsigned, 2>) |
| 2695 | { |
| 2696 | const unsigned __k = 2; |
| 2697 | uint32_t __ar[__r * __k]; |
| 2698 | __q.generate(__ar, __ar + __r * __k); |
| 2699 | for (size_t __i = 0; __i < __r; ++__i) |
| 2700 | __x_[__i] = static_cast<result_type>( |
| 2701 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); |
| 2702 | __c_ = __x_[__r-1] == 0; |
| 2703 | __i_ = 0; |
| 2704 | } |
| 2705 | |
| 2706 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2707 | _UIntType |
| 2708 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() |
| 2709 | { |
| 2710 | const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; |
| 2711 | result_type& __xr = __x_[__i_]; |
| 2712 | result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; |
| 2713 | __xr = (__xs - __xr - __c_) & _Max; |
| 2714 | __c_ = __new_c; |
| 2715 | __i_ = (__i_ + 1) % __r; |
| 2716 | return __xr; |
| 2717 | } |
| 2718 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2719 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2720 | bool |
| 2721 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2722 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2723 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2724 | { |
| 2725 | if (__x.__c_ != __y.__c_) |
| 2726 | return false; |
| 2727 | if (__x.__i_ == __y.__i_) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2728 | return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2729 | if (__x.__i_ == 0 || __y.__i_ == 0) |
| 2730 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2731 | size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2732 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2733 | __y.__x_ + __y.__i_)) |
| 2734 | return false; |
| 2735 | if (__x.__i_ == 0) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2736 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); |
| 2737 | return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2738 | } |
| 2739 | if (__x.__i_ < __y.__i_) |
| 2740 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2741 | size_t __j = _Rp - __y.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2742 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2743 | __y.__x_ + __y.__i_)) |
| 2744 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2745 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2746 | __y.__x_)) |
| 2747 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2748 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2749 | __y.__x_ + (_Rp - (__x.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2750 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2751 | size_t __j = _Rp - __x.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2752 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2753 | __x.__x_ + __x.__i_)) |
| 2754 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2755 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2756 | __x.__x_)) |
| 2757 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2758 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2759 | __x.__x_ + (_Rp - (__y.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2760 | } |
| 2761 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2762 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2763 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2764 | bool |
| 2765 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2766 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2767 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2768 | { |
| 2769 | return !(__x == __y); |
| 2770 | } |
| 2771 | |
| 2772 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2773 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2774 | basic_ostream<_CharT, _Traits>& |
| 2775 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2776 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2777 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2778 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 2779 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2780 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2781 | _CharT __sp = __os.widen(' '); |
| 2782 | __os.fill(__sp); |
| 2783 | __os << __x.__x_[__x.__i_]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2784 | for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2785 | __os << __sp << __x.__x_[__j]; |
| 2786 | for (size_t __j = 0; __j < __x.__i_; ++__j) |
| 2787 | __os << __sp << __x.__x_[__j]; |
| 2788 | __os << __sp << __x.__c_; |
| 2789 | return __os; |
| 2790 | } |
| 2791 | |
| 2792 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2793 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2794 | basic_istream<_CharT, _Traits>& |
| 2795 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2796 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2797 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2798 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 2799 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2800 | __is.flags(_Istream::dec | _Istream::skipws); |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2801 | _UInt __t[_Rp+1]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2802 | for (size_t __i = 0; __i < _Rp+1; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2803 | __is >> __t[__i]; |
| 2804 | if (!__is.fail()) |
| 2805 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2806 | for (size_t __i = 0; __i < _Rp; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2807 | __x.__x_[__i] = __t[__i]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2808 | __x.__c_ = __t[_Rp]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2809 | __x.__i_ = 0; |
| 2810 | } |
| 2811 | return __is; |
| 2812 | } |
| 2813 | |
| 2814 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; |
| 2815 | typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; |
| 2816 | |
| 2817 | // discard_block_engine |
| 2818 | |
| 2819 | template<class _Engine, size_t __p, size_t __r> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2820 | class _LIBCPP_TEMPLATE_VIS discard_block_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2821 | { |
| 2822 | _Engine __e_; |
| 2823 | int __n_; |
| 2824 | |
| 2825 | static_assert( 0 < __r, "discard_block_engine invalid parameters"); |
| 2826 | static_assert(__r <= __p, "discard_block_engine invalid parameters"); |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 2827 | static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2828 | public: |
| 2829 | // types |
| 2830 | typedef typename _Engine::result_type result_type; |
| 2831 | |
| 2832 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2833 | static _LIBCPP_CONSTEXPR const size_t block_size = __p; |
| 2834 | static _LIBCPP_CONSTEXPR const size_t used_block = __r; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2835 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2836 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2837 | static const result_type _Min = _Engine::_Min; |
| 2838 | static const result_type _Max = _Engine::_Max; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2839 | #else |
| 2840 | static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); |
| 2841 | static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); |
| 2842 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2843 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2844 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2845 | static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2846 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2847 | static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2848 | |
| 2849 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2850 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2851 | discard_block_engine() : __n_(0) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2852 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2853 | explicit discard_block_engine(const _Engine& __e) |
| 2854 | : __e_(__e), __n_(0) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2855 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2857 | explicit discard_block_engine(_Engine&& __e) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2858 | : __e_(_VSTD::move(__e)), __n_(0) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2859 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2860 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2861 | explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2862 | template<class _Sseq> |
| 2863 | _LIBCPP_INLINE_VISIBILITY |
| 2864 | explicit discard_block_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2865 | typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2866 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2867 | : __e_(__q), __n_(0) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2868 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2869 | void seed() {__e_.seed(); __n_ = 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2870 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2871 | void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2872 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2873 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2874 | typename enable_if |
| 2875 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2876 | __is_seed_sequence<_Sseq, discard_block_engine>::value, |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2877 | void |
| 2878 | >::type |
| 2879 | seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2880 | |
| 2881 | // generating functions |
| 2882 | result_type operator()(); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2884 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2885 | |
| 2886 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2887 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 2888 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2889 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2890 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2891 | friend |
| 2892 | bool |
| 2893 | operator==( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2894 | const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2895 | const discard_block_engine<_Eng, _Pp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2896 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2897 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2898 | friend |
| 2899 | bool |
| 2900 | operator!=( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2901 | const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2902 | const discard_block_engine<_Eng, _Pp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2903 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2904 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2905 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2906 | friend |
| 2907 | basic_ostream<_CharT, _Traits>& |
| 2908 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2909 | const discard_block_engine<_Eng, _Pp, _Rp>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2910 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2911 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2912 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2913 | friend |
| 2914 | basic_istream<_CharT, _Traits>& |
| 2915 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2916 | discard_block_engine<_Eng, _Pp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2917 | }; |
| 2918 | |
| 2919 | template<class _Engine, size_t __p, size_t __r> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2920 | _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; |
| 2921 | |
| 2922 | template<class _Engine, size_t __p, size_t __r> |
| 2923 | _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; |
| 2924 | |
| 2925 | template<class _Engine, size_t __p, size_t __r> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2926 | typename discard_block_engine<_Engine, __p, __r>::result_type |
| 2927 | discard_block_engine<_Engine, __p, __r>::operator()() |
| 2928 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 2929 | if (__n_ >= static_cast<int>(__r)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2930 | { |
| 2931 | __e_.discard(__p - __r); |
| 2932 | __n_ = 0; |
| 2933 | } |
| 2934 | ++__n_; |
| 2935 | return __e_(); |
| 2936 | } |
| 2937 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2938 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2939 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2940 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2941 | operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2942 | const discard_block_engine<_Eng, _Pp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2943 | { |
| 2944 | return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; |
| 2945 | } |
| 2946 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2947 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2948 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2949 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2950 | operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2951 | const discard_block_engine<_Eng, _Pp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2952 | { |
| 2953 | return !(__x == __y); |
| 2954 | } |
| 2955 | |
| 2956 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2957 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2958 | basic_ostream<_CharT, _Traits>& |
| 2959 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2960 | const discard_block_engine<_Eng, _Pp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2961 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2962 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 2963 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2964 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2965 | _CharT __sp = __os.widen(' '); |
| 2966 | __os.fill(__sp); |
| 2967 | return __os << __x.__e_ << __sp << __x.__n_; |
| 2968 | } |
| 2969 | |
| 2970 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2971 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2972 | basic_istream<_CharT, _Traits>& |
| 2973 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2974 | discard_block_engine<_Eng, _Pp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2975 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2976 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 2977 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2978 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2979 | _Eng __e; |
| 2980 | int __n; |
| 2981 | __is >> __e >> __n; |
| 2982 | if (!__is.fail()) |
| 2983 | { |
| 2984 | __x.__e_ = __e; |
| 2985 | __x.__n_ = __n; |
| 2986 | } |
| 2987 | return __is; |
| 2988 | } |
| 2989 | |
| 2990 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; |
| 2991 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; |
| 2992 | |
| 2993 | // independent_bits_engine |
| 2994 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2995 | template<class _Engine, size_t __w, class _UIntType> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2996 | class _LIBCPP_TEMPLATE_VIS independent_bits_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2997 | { |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2998 | template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2999 | class __get_n |
| 3000 | { |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3001 | static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3002 | static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); |
| 3003 | static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3004 | static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3005 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3006 | 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] | 3007 | }; |
| 3008 | public: |
| 3009 | // types |
| 3010 | typedef _UIntType result_type; |
| 3011 | |
| 3012 | private: |
| 3013 | _Engine __e_; |
| 3014 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3015 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3016 | static_assert( 0 < __w, "independent_bits_engine invalid parameters"); |
| 3017 | static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); |
| 3018 | |
| 3019 | typedef typename _Engine::result_type _Engine_result_type; |
| 3020 | typedef typename conditional |
| 3021 | < |
| 3022 | sizeof(_Engine_result_type) <= sizeof(result_type), |
| 3023 | result_type, |
| 3024 | _Engine_result_type |
| 3025 | >::type _Working_result_type; |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3026 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3027 | static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3028 | + _Working_result_type(1); |
| 3029 | #else |
| 3030 | static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() |
| 3031 | + _Working_result_type(1); |
| 3032 | #endif |
| 3033 | static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; |
| 3034 | static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; |
| 3035 | static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; |
| 3036 | static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; |
| 3037 | static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; |
| 3038 | static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; |
| 3039 | static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : |
| 3040 | (_Rp >> __w0) << __w0; |
| 3041 | static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : |
| 3042 | (_Rp >> (__w0+1)) << (__w0+1); |
| 3043 | static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3044 | _Engine_result_type(~0) >> (_EDt - __w0) : |
| 3045 | _Engine_result_type(0); |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3046 | static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3047 | _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : |
| 3048 | _Engine_result_type(~0); |
| 3049 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3050 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 3051 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 3052 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3053 | static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); |
| 3054 | |
| 3055 | // engine characteristics |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3056 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3057 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3058 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3059 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3060 | |
| 3061 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3062 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3063 | independent_bits_engine() {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3064 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3065 | explicit independent_bits_engine(const _Engine& __e) |
| 3066 | : __e_(__e) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3067 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3068 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3069 | explicit independent_bits_engine(_Engine&& __e) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3070 | : __e_(_VSTD::move(__e)) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3071 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3072 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3073 | explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3074 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3075 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3076 | explicit independent_bits_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3077 | typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3078 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3079 | : __e_(__q) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3080 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3081 | void seed() {__e_.seed();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3082 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3083 | void seed(result_type __sd) {__e_.seed(__sd);} |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3084 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3085 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3086 | typename enable_if |
| 3087 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3088 | __is_seed_sequence<_Sseq, independent_bits_engine>::value, |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3089 | void |
| 3090 | >::type |
| 3091 | seed(_Sseq& __q) {__e_.seed(__q);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3092 | |
| 3093 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3094 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3095 | result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3096 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3097 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 3098 | |
| 3099 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3100 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3101 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3102 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3103 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3104 | friend |
| 3105 | bool |
| 3106 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3107 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3108 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3109 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3110 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3111 | friend |
| 3112 | bool |
| 3113 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3114 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3115 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3116 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3117 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3118 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3119 | friend |
| 3120 | basic_ostream<_CharT, _Traits>& |
| 3121 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3122 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3123 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3124 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3125 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3126 | friend |
| 3127 | basic_istream<_CharT, _Traits>& |
| 3128 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3129 | independent_bits_engine<_Eng, _Wp, _UInt>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3130 | |
| 3131 | private: |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3132 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | fe77858 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3133 | result_type __eval(false_type); |
| 3134 | result_type __eval(true_type); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3135 | |
| 3136 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3138 | static |
| 3139 | typename enable_if |
| 3140 | < |
| 3141 | __count < _Dt, |
| 3142 | result_type |
| 3143 | >::type |
| 3144 | __lshift(result_type __x) {return __x << __count;} |
| 3145 | |
| 3146 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3147 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3148 | static |
| 3149 | typename enable_if |
| 3150 | < |
| 3151 | (__count >= _Dt), |
| 3152 | result_type |
| 3153 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3154 | __lshift(result_type) {return result_type(0);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3155 | }; |
| 3156 | |
| 3157 | template<class _Engine, size_t __w, class _UIntType> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3158 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3159 | _UIntType |
Marshall Clow | fe77858 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3160 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3161 | { |
| 3162 | return static_cast<result_type>(__e_() & __mask0); |
| 3163 | } |
| 3164 | |
| 3165 | template<class _Engine, size_t __w, class _UIntType> |
| 3166 | _UIntType |
Marshall Clow | fe77858 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3167 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3168 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3169 | result_type _Sp = 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3170 | for (size_t __k = 0; __k < __n0; ++__k) |
| 3171 | { |
| 3172 | _Engine_result_type __u; |
| 3173 | do |
| 3174 | { |
| 3175 | __u = __e_() - _Engine::min(); |
| 3176 | } while (__u >= __y0); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3177 | _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3178 | } |
| 3179 | for (size_t __k = __n0; __k < __n; ++__k) |
| 3180 | { |
| 3181 | _Engine_result_type __u; |
| 3182 | do |
| 3183 | { |
| 3184 | __u = __e_() - _Engine::min(); |
| 3185 | } while (__u >= __y1); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3186 | _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3187 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3188 | return _Sp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3189 | } |
| 3190 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3191 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3192 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3193 | bool |
| 3194 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3195 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3196 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3197 | { |
| 3198 | return __x.base() == __y.base(); |
| 3199 | } |
| 3200 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3201 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3202 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3203 | bool |
| 3204 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3205 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3206 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3207 | { |
| 3208 | return !(__x == __y); |
| 3209 | } |
| 3210 | |
| 3211 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3212 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3213 | basic_ostream<_CharT, _Traits>& |
| 3214 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3215 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3216 | { |
| 3217 | return __os << __x.base(); |
| 3218 | } |
| 3219 | |
| 3220 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3221 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3222 | basic_istream<_CharT, _Traits>& |
| 3223 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3224 | independent_bits_engine<_Eng, _Wp, _UInt>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3225 | { |
| 3226 | _Eng __e; |
| 3227 | __is >> __e; |
| 3228 | if (!__is.fail()) |
| 3229 | __x.__e_ = __e; |
| 3230 | return __is; |
| 3231 | } |
| 3232 | |
| 3233 | // shuffle_order_engine |
| 3234 | |
| 3235 | template <uint64_t _Xp, uint64_t _Yp> |
| 3236 | struct __ugcd |
| 3237 | { |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3238 | static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3239 | }; |
| 3240 | |
| 3241 | template <uint64_t _Xp> |
| 3242 | struct __ugcd<_Xp, 0> |
| 3243 | { |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3244 | static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3245 | }; |
| 3246 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3247 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3248 | class __uratio |
| 3249 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3250 | static_assert(_Dp != 0, "__uratio divide by 0"); |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3251 | static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3252 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3253 | static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; |
| 3254 | static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3255 | |
| 3256 | typedef __uratio<num, den> type; |
| 3257 | }; |
| 3258 | |
| 3259 | template<class _Engine, size_t __k> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3260 | class _LIBCPP_TEMPLATE_VIS shuffle_order_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3261 | { |
| 3262 | static_assert(0 < __k, "shuffle_order_engine invalid parameters"); |
| 3263 | public: |
| 3264 | // types |
| 3265 | typedef typename _Engine::result_type result_type; |
| 3266 | |
| 3267 | private: |
| 3268 | _Engine __e_; |
| 3269 | result_type _V_[__k]; |
| 3270 | result_type _Y_; |
| 3271 | |
| 3272 | public: |
| 3273 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3274 | static _LIBCPP_CONSTEXPR const size_t table_size = __k; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3275 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3276 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3277 | static const result_type _Min = _Engine::_Min; |
| 3278 | static const result_type _Max = _Engine::_Max; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3279 | #else |
| 3280 | static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); |
| 3281 | static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); |
| 3282 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3283 | static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3284 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3285 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3286 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3287 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3288 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3289 | static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3290 | |
| 3291 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3292 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3293 | shuffle_order_engine() {__init();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3294 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3295 | explicit shuffle_order_engine(const _Engine& __e) |
| 3296 | : __e_(__e) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3297 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3298 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3299 | explicit shuffle_order_engine(_Engine&& __e) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3300 | : __e_(_VSTD::move(__e)) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3301 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3302 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3303 | explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3304 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3306 | explicit shuffle_order_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3307 | typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3308 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3309 | : __e_(__q) {__init();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3310 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3311 | void seed() {__e_.seed(); __init();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3312 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3313 | void seed(result_type __sd) {__e_.seed(__sd); __init();} |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3314 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3316 | typename enable_if |
| 3317 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3318 | __is_seed_sequence<_Sseq, shuffle_order_engine>::value, |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3319 | void |
| 3320 | >::type |
| 3321 | seed(_Sseq& __q) {__e_.seed(__q); __init();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3322 | |
| 3323 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3325 | result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3326 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3327 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 3328 | |
| 3329 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3330 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3331 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3332 | |
| 3333 | private: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3334 | template<class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3335 | friend |
| 3336 | bool |
| 3337 | operator==( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3338 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3339 | const shuffle_order_engine<_Eng, _Kp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3340 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3341 | template<class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3342 | friend |
| 3343 | bool |
| 3344 | operator!=( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3345 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3346 | const shuffle_order_engine<_Eng, _Kp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3347 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3348 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3349 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3350 | friend |
| 3351 | basic_ostream<_CharT, _Traits>& |
| 3352 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3353 | const shuffle_order_engine<_Eng, _Kp>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3354 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3355 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3356 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3357 | friend |
| 3358 | basic_istream<_CharT, _Traits>& |
| 3359 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3360 | shuffle_order_engine<_Eng, _Kp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3361 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3362 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3363 | void __init() |
| 3364 | { |
| 3365 | for (size_t __i = 0; __i < __k; ++__i) |
| 3366 | _V_[__i] = __e_(); |
| 3367 | _Y_ = __e_(); |
| 3368 | } |
| 3369 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3370 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3371 | result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3372 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3373 | result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3374 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3375 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3376 | result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3377 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3378 | result_type __eval2(true_type) {return __evalf<__k, 0>();} |
| 3379 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3380 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3381 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3382 | typename enable_if |
| 3383 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3384 | (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3385 | result_type |
| 3386 | >::type |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3387 | __eval(__uratio<_Np, _Dp>) |
| 3388 | {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3389 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3390 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3391 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3392 | typename enable_if |
| 3393 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3394 | __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3395 | result_type |
| 3396 | >::type |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3397 | __eval(__uratio<_Np, _Dp>) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3398 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3399 | const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min) |
| 3400 | / __uratio<_Np, _Dp>::den); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3401 | _Y_ = _V_[__j]; |
| 3402 | _V_[__j] = __e_(); |
| 3403 | return _Y_; |
| 3404 | } |
| 3405 | |
| 3406 | template <uint64_t __n, uint64_t __d> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3407 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3408 | result_type __evalf() |
| 3409 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3410 | const double _Fp = __d == 0 ? |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3411 | __n / (2. * 0x8000000000000000ull) : |
| 3412 | __n / (double)__d; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3413 | const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3414 | _Y_ = _V_[__j]; |
| 3415 | _V_[__j] = __e_(); |
| 3416 | return _Y_; |
| 3417 | } |
| 3418 | }; |
| 3419 | |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3420 | template<class _Engine, size_t __k> |
| 3421 | _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; |
| 3422 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3423 | template<class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3424 | bool |
| 3425 | operator==( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3426 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3427 | const shuffle_order_engine<_Eng, _Kp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3428 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3429 | 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] | 3430 | __x.__e_ == __y.__e_; |
| 3431 | } |
| 3432 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3433 | template<class _Eng, size_t _Kp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3434 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3435 | bool |
| 3436 | operator!=( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3437 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3438 | const shuffle_order_engine<_Eng, _Kp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3439 | { |
| 3440 | return !(__x == __y); |
| 3441 | } |
| 3442 | |
| 3443 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3444 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3445 | basic_ostream<_CharT, _Traits>& |
| 3446 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3447 | const shuffle_order_engine<_Eng, _Kp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3448 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3449 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 3450 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 3451 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3452 | _CharT __sp = __os.widen(' '); |
| 3453 | __os.fill(__sp); |
| 3454 | __os << __x.__e_ << __sp << __x._V_[0]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3455 | for (size_t __i = 1; __i < _Kp; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3456 | __os << __sp << __x._V_[__i]; |
| 3457 | return __os << __sp << __x._Y_; |
| 3458 | } |
| 3459 | |
| 3460 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3461 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3462 | basic_istream<_CharT, _Traits>& |
| 3463 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3464 | shuffle_order_engine<_Eng, _Kp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3465 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3466 | typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3467 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 3468 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3469 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3470 | _Eng __e; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3471 | result_type _Vp[_Kp+1]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3472 | __is >> __e; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3473 | for (size_t __i = 0; __i < _Kp+1; ++__i) |
| 3474 | __is >> _Vp[__i]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3475 | if (!__is.fail()) |
| 3476 | { |
| 3477 | __x.__e_ = __e; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3478 | for (size_t __i = 0; __i < _Kp; ++__i) |
| 3479 | __x._V_[__i] = _Vp[__i]; |
| 3480 | __x._Y_ = _Vp[_Kp]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3481 | } |
| 3482 | return __is; |
| 3483 | } |
| 3484 | |
| 3485 | typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; |
| 3486 | |
| 3487 | // random_device |
| 3488 | |
Louis Dionne | 3777e68 | 2020-10-15 10:32:09 -0400 | [diff] [blame] | 3489 | #if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE) |
| 3490 | |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 3491 | class _LIBCPP_TYPE_VIS random_device |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3492 | { |
Ed Schouten | dcf3740 | 2015-03-10 07:46:06 +0000 | [diff] [blame] | 3493 | #ifdef _LIBCPP_USING_DEV_RANDOM |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3494 | int __f_; |
Ed Schouten | dcf3740 | 2015-03-10 07:46:06 +0000 | [diff] [blame] | 3495 | #endif // defined(_LIBCPP_USING_DEV_RANDOM) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3496 | public: |
| 3497 | // types |
| 3498 | typedef unsigned result_type; |
| 3499 | |
| 3500 | // generator characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3501 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 3502 | static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3503 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3504 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 664183b | 2012-04-02 00:40:41 +0000 | [diff] [blame] | 3505 | static _LIBCPP_CONSTEXPR result_type min() { return _Min;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3506 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 664183b | 2012-04-02 00:40:41 +0000 | [diff] [blame] | 3507 | static _LIBCPP_CONSTEXPR result_type max() { return _Max;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3508 | |
| 3509 | // constructors |
| 3510 | explicit random_device(const string& __token = "/dev/urandom"); |
| 3511 | ~random_device(); |
| 3512 | |
| 3513 | // generating functions |
| 3514 | result_type operator()(); |
| 3515 | |
| 3516 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3517 | double entropy() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3518 | |
| 3519 | private: |
| 3520 | // no copy functions |
| 3521 | random_device(const random_device&); // = delete; |
| 3522 | random_device& operator=(const random_device&); // = delete; |
| 3523 | }; |
| 3524 | |
Louis Dionne | 3777e68 | 2020-10-15 10:32:09 -0400 | [diff] [blame] | 3525 | #endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE |
| 3526 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3527 | // seed_seq |
| 3528 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3529 | class _LIBCPP_TEMPLATE_VIS seed_seq |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3530 | { |
| 3531 | public: |
| 3532 | // types |
| 3533 | typedef uint32_t result_type; |
| 3534 | |
| 3535 | private: |
| 3536 | vector<result_type> __v_; |
| 3537 | |
| 3538 | template<class _InputIterator> |
| 3539 | void init(_InputIterator __first, _InputIterator __last); |
| 3540 | public: |
| 3541 | // constructors |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3542 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4b6b809 | 2013-10-23 05:56:47 +0000 | [diff] [blame] | 3543 | seed_seq() _NOEXCEPT {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3544 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3545 | template<class _Tp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3546 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3547 | seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3548 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3549 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3550 | template<class _InputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3551 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3552 | seed_seq(_InputIterator __first, _InputIterator __last) |
| 3553 | {init(__first, __last);} |
| 3554 | |
| 3555 | // generating functions |
| 3556 | template<class _RandomAccessIterator> |
| 3557 | void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); |
| 3558 | |
| 3559 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3560 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4b6b809 | 2013-10-23 05:56:47 +0000 | [diff] [blame] | 3561 | size_t size() const _NOEXCEPT {return __v_.size();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3562 | template<class _OutputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3563 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3564 | void param(_OutputIterator __dest) const |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3565 | {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3566 | |
| 3567 | private: |
| 3568 | // no copy functions |
| 3569 | seed_seq(const seed_seq&); // = delete; |
| 3570 | void operator=(const seed_seq&); // = delete; |
| 3571 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3572 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3573 | static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3574 | }; |
| 3575 | |
| 3576 | template<class _InputIterator> |
| 3577 | void |
| 3578 | seed_seq::init(_InputIterator __first, _InputIterator __last) |
| 3579 | { |
| 3580 | for (_InputIterator __s = __first; __s != __last; ++__s) |
| 3581 | __v_.push_back(*__s & 0xFFFFFFFF); |
| 3582 | } |
| 3583 | |
| 3584 | template<class _RandomAccessIterator> |
| 3585 | void |
| 3586 | seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) |
| 3587 | { |
| 3588 | if (__first != __last) |
| 3589 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3590 | _VSTD::fill(__first, __last, 0x8b8b8b8b); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3591 | const size_t __n = static_cast<size_t>(__last - __first); |
| 3592 | const size_t __s = __v_.size(); |
| 3593 | const size_t __t = (__n >= 623) ? 11 |
| 3594 | : (__n >= 68) ? 7 |
| 3595 | : (__n >= 39) ? 5 |
| 3596 | : (__n >= 7) ? 3 |
| 3597 | : (__n - 1) / 2; |
| 3598 | const size_t __p = (__n - __t) / 2; |
| 3599 | const size_t __q = __p + __t; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3600 | const size_t __m = _VSTD::max(__s + 1, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3601 | // __k = 0; |
| 3602 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3603 | result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3604 | ^ __first[__n - 1]); |
| 3605 | __first[__p] += __r; |
| 3606 | __r += __s; |
| 3607 | __first[__q] += __r; |
| 3608 | __first[0] = __r; |
| 3609 | } |
| 3610 | for (size_t __k = 1; __k <= __s; ++__k) |
| 3611 | { |
| 3612 | const size_t __kmodn = __k % __n; |
| 3613 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3614 | result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3615 | ^ __first[(__k - 1) % __n]); |
| 3616 | __first[__kpmodn] += __r; |
| 3617 | __r += __kmodn + __v_[__k-1]; |
| 3618 | __first[(__k + __q) % __n] += __r; |
| 3619 | __first[__kmodn] = __r; |
| 3620 | } |
| 3621 | for (size_t __k = __s + 1; __k < __m; ++__k) |
| 3622 | { |
| 3623 | const size_t __kmodn = __k % __n; |
| 3624 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3625 | result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3626 | ^ __first[(__k - 1) % __n]); |
| 3627 | __first[__kpmodn] += __r; |
| 3628 | __r += __kmodn; |
| 3629 | __first[(__k + __q) % __n] += __r; |
| 3630 | __first[__kmodn] = __r; |
| 3631 | } |
| 3632 | for (size_t __k = __m; __k < __m + __n; ++__k) |
| 3633 | { |
| 3634 | const size_t __kmodn = __k % __n; |
| 3635 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3636 | result_type __r = 1566083941 * _Tp(__first[__kmodn] + |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3637 | __first[__kpmodn] + |
| 3638 | __first[(__k - 1) % __n]); |
| 3639 | __first[__kpmodn] ^= __r; |
| 3640 | __r -= __kmodn; |
| 3641 | __first[(__k + __q) % __n] ^= __r; |
| 3642 | __first[__kmodn] = __r; |
| 3643 | } |
| 3644 | } |
| 3645 | } |
| 3646 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3647 | // generate_canonical |
| 3648 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3649 | template<class _RealType, size_t __bits, class _URNG> |
| 3650 | _RealType |
| 3651 | generate_canonical(_URNG& __g) |
| 3652 | { |
| 3653 | const size_t _Dt = numeric_limits<_RealType>::digits; |
| 3654 | const size_t __b = _Dt < __bits ? _Dt : __bits; |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3655 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3656 | 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] | 3657 | #else |
| 3658 | const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; |
| 3659 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3660 | const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); |
Louis Dionne | 2422bdb | 2019-08-20 15:39:20 +0000 | [diff] [blame] | 3661 | const _RealType _Rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3662 | _RealType __base = _Rp; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3663 | _RealType _Sp = __g() - _URNG::min(); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3664 | for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3665 | _Sp += (__g() - _URNG::min()) * __base; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3666 | return _Sp / __base; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3667 | } |
| 3668 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3669 | // uniform_int_distribution |
| 3670 | |
Howard Hinnant | 578ac0f | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 3671 | // in <algorithm> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3672 | |
| 3673 | template <class _CharT, class _Traits, class _IT> |
| 3674 | basic_ostream<_CharT, _Traits>& |
| 3675 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 3676 | const uniform_int_distribution<_IT>& __x) |
| 3677 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3678 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 3679 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 3680 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3681 | _CharT __sp = __os.widen(' '); |
| 3682 | __os.fill(__sp); |
| 3683 | return __os << __x.a() << __sp << __x.b(); |
| 3684 | } |
| 3685 | |
| 3686 | template <class _CharT, class _Traits, class _IT> |
| 3687 | basic_istream<_CharT, _Traits>& |
| 3688 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 3689 | uniform_int_distribution<_IT>& __x) |
| 3690 | { |
| 3691 | typedef uniform_int_distribution<_IT> _Eng; |
| 3692 | typedef typename _Eng::result_type result_type; |
| 3693 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3694 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 3695 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3696 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3697 | result_type __a; |
| 3698 | result_type __b; |
| 3699 | __is >> __a >> __b; |
| 3700 | if (!__is.fail()) |
| 3701 | __x.param(param_type(__a, __b)); |
| 3702 | return __is; |
| 3703 | } |
| 3704 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3705 | // uniform_real_distribution |
| 3706 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3707 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3708 | class _LIBCPP_TEMPLATE_VIS uniform_real_distribution |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3709 | { |
| 3710 | public: |
| 3711 | // types |
| 3712 | typedef _RealType result_type; |
| 3713 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3714 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3715 | { |
| 3716 | result_type __a_; |
| 3717 | result_type __b_; |
| 3718 | public: |
| 3719 | typedef uniform_real_distribution distribution_type; |
| 3720 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3721 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3722 | explicit param_type(result_type __a = 0, |
| 3723 | result_type __b = 1) |
| 3724 | : __a_(__a), __b_(__b) {} |
| 3725 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3726 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3727 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3728 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3729 | result_type b() const {return __b_;} |
| 3730 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3731 | friend _LIBCPP_INLINE_VISIBILITY |
| 3732 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3733 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3734 | friend _LIBCPP_INLINE_VISIBILITY |
| 3735 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3736 | {return !(__x == __y);} |
| 3737 | }; |
| 3738 | |
| 3739 | private: |
| 3740 | param_type __p_; |
| 3741 | |
| 3742 | public: |
| 3743 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3744 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3745 | explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) |
| 3746 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3747 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3748 | explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3749 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3750 | void reset() {} |
| 3751 | |
| 3752 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3753 | template<class _URNG> |
| 3754 | _LIBCPP_INLINE_VISIBILITY |
| 3755 | result_type operator()(_URNG& __g) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3756 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3757 | 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] | 3758 | |
| 3759 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3760 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3761 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3762 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3763 | result_type b() const {return __p_.b();} |
| 3764 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3765 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3766 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3767 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3768 | void param(const param_type& __p) {__p_ = __p;} |
| 3769 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3770 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3771 | result_type min() const {return a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3772 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3773 | result_type max() const {return b();} |
| 3774 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3775 | friend _LIBCPP_INLINE_VISIBILITY |
| 3776 | bool operator==(const uniform_real_distribution& __x, |
| 3777 | const uniform_real_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3778 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3779 | friend _LIBCPP_INLINE_VISIBILITY |
| 3780 | bool operator!=(const uniform_real_distribution& __x, |
| 3781 | const uniform_real_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3782 | {return !(__x == __y);} |
| 3783 | }; |
| 3784 | |
| 3785 | template<class _RealType> |
| 3786 | template<class _URNG> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3787 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3788 | typename uniform_real_distribution<_RealType>::result_type |
| 3789 | uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 3790 | { |
| 3791 | return (__p.b() - __p.a()) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3792 | * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3793 | + __p.a(); |
| 3794 | } |
| 3795 | |
| 3796 | template <class _CharT, class _Traits, class _RT> |
| 3797 | basic_ostream<_CharT, _Traits>& |
| 3798 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 3799 | const uniform_real_distribution<_RT>& __x) |
| 3800 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3801 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 3802 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 3803 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 3804 | _OStream::scientific); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3805 | _CharT __sp = __os.widen(' '); |
| 3806 | __os.fill(__sp); |
| 3807 | return __os << __x.a() << __sp << __x.b(); |
| 3808 | } |
| 3809 | |
| 3810 | template <class _CharT, class _Traits, class _RT> |
| 3811 | basic_istream<_CharT, _Traits>& |
| 3812 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 3813 | uniform_real_distribution<_RT>& __x) |
| 3814 | { |
| 3815 | typedef uniform_real_distribution<_RT> _Eng; |
| 3816 | typedef typename _Eng::result_type result_type; |
| 3817 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3818 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 3819 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3820 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3821 | result_type __a; |
| 3822 | result_type __b; |
| 3823 | __is >> __a >> __b; |
| 3824 | if (!__is.fail()) |
| 3825 | __x.param(param_type(__a, __b)); |
| 3826 | return __is; |
| 3827 | } |
| 3828 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3829 | // bernoulli_distribution |
| 3830 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3831 | class _LIBCPP_TEMPLATE_VIS bernoulli_distribution |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3832 | { |
| 3833 | public: |
| 3834 | // types |
| 3835 | typedef bool result_type; |
| 3836 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3837 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3838 | { |
| 3839 | double __p_; |
| 3840 | public: |
| 3841 | typedef bernoulli_distribution distribution_type; |
| 3842 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3843 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3844 | explicit param_type(double __p = 0.5) : __p_(__p) {} |
| 3845 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3846 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3847 | double p() const {return __p_;} |
| 3848 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3849 | friend _LIBCPP_INLINE_VISIBILITY |
| 3850 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3851 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3852 | friend _LIBCPP_INLINE_VISIBILITY |
| 3853 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3854 | {return !(__x == __y);} |
| 3855 | }; |
| 3856 | |
| 3857 | private: |
| 3858 | param_type __p_; |
| 3859 | |
| 3860 | public: |
| 3861 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3862 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3863 | explicit bernoulli_distribution(double __p = 0.5) |
| 3864 | : __p_(param_type(__p)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3865 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3866 | explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3867 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3868 | void reset() {} |
| 3869 | |
| 3870 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3871 | template<class _URNG> |
| 3872 | _LIBCPP_INLINE_VISIBILITY |
| 3873 | result_type operator()(_URNG& __g) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3874 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3875 | 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] | 3876 | |
| 3877 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3878 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3879 | double p() const {return __p_.p();} |
| 3880 | |
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 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3884 | void param(const param_type& __p) {__p_ = __p;} |
| 3885 | |
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 min() const {return false;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3888 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3889 | result_type max() const {return true;} |
| 3890 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3891 | friend _LIBCPP_INLINE_VISIBILITY |
| 3892 | bool operator==(const bernoulli_distribution& __x, |
| 3893 | const bernoulli_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3894 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3895 | friend _LIBCPP_INLINE_VISIBILITY |
| 3896 | bool operator!=(const bernoulli_distribution& __x, |
| 3897 | const bernoulli_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3898 | {return !(__x == __y);} |
| 3899 | }; |
| 3900 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3901 | template<class _URNG> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3902 | inline |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3903 | bernoulli_distribution::result_type |
| 3904 | bernoulli_distribution::operator()(_URNG& __g, const param_type& __p) |
| 3905 | { |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 3906 | uniform_real_distribution<double> __gen; |
| 3907 | return __gen(__g) < __p.p(); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3908 | } |
| 3909 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3910 | template <class _CharT, class _Traits> |
| 3911 | basic_ostream<_CharT, _Traits>& |
| 3912 | operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) |
| 3913 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3914 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 3915 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 3916 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 3917 | _OStream::scientific); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3918 | _CharT __sp = __os.widen(' '); |
| 3919 | __os.fill(__sp); |
| 3920 | return __os << __x.p(); |
| 3921 | } |
| 3922 | |
| 3923 | template <class _CharT, class _Traits> |
| 3924 | basic_istream<_CharT, _Traits>& |
| 3925 | operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) |
| 3926 | { |
| 3927 | typedef bernoulli_distribution _Eng; |
| 3928 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3929 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 3930 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3931 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3932 | double __p; |
| 3933 | __is >> __p; |
| 3934 | if (!__is.fail()) |
| 3935 | __x.param(param_type(__p)); |
| 3936 | return __is; |
| 3937 | } |
| 3938 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3939 | // binomial_distribution |
| 3940 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3941 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3942 | class _LIBCPP_TEMPLATE_VIS binomial_distribution |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3943 | { |
| 3944 | public: |
| 3945 | // types |
| 3946 | typedef _IntType result_type; |
| 3947 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3948 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3949 | { |
| 3950 | result_type __t_; |
| 3951 | double __p_; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3952 | double __pr_; |
| 3953 | double __odds_ratio_; |
| 3954 | result_type __r0_; |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3955 | public: |
| 3956 | typedef binomial_distribution distribution_type; |
| 3957 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3958 | explicit param_type(result_type __t = 1, double __p = 0.5); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3959 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3960 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3961 | result_type t() const {return __t_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3962 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3963 | double p() const {return __p_;} |
| 3964 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3965 | friend _LIBCPP_INLINE_VISIBILITY |
| 3966 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3967 | {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3968 | friend _LIBCPP_INLINE_VISIBILITY |
| 3969 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3970 | {return !(__x == __y);} |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3971 | |
| 3972 | friend class binomial_distribution; |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3973 | }; |
| 3974 | |
| 3975 | private: |
| 3976 | param_type __p_; |
| 3977 | |
| 3978 | public: |
| 3979 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3980 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3981 | explicit binomial_distribution(result_type __t = 1, double __p = 0.5) |
| 3982 | : __p_(param_type(__t, __p)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3983 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3984 | explicit binomial_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3985 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3986 | void reset() {} |
| 3987 | |
| 3988 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3989 | template<class _URNG> |
| 3990 | _LIBCPP_INLINE_VISIBILITY |
| 3991 | result_type operator()(_URNG& __g) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3992 | {return (*this)(__g, __p_);} |
| 3993 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 3994 | |
| 3995 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3996 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3997 | result_type t() const {return __p_.t();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3998 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +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 | 53f28fa | 2010-05-11 23:26:59 +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 | 53f28fa | 2010-05-11 23:26:59 +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 | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4007 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4008 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4009 | result_type max() const {return t();} |
| 4010 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4011 | friend _LIBCPP_INLINE_VISIBILITY |
| 4012 | bool operator==(const binomial_distribution& __x, |
| 4013 | const binomial_distribution& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +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 binomial_distribution& __x, |
| 4017 | const binomial_distribution& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4018 | {return !(__x == __y);} |
| 4019 | }; |
| 4020 | |
Eric Fiselier | 651ca6e | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4021 | #ifndef _LIBCPP_MSVCRT |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4022 | extern "C" double lgamma_r(double, int *); |
Eric Fiselier | 651ca6e | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4023 | #endif |
| 4024 | |
| 4025 | inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { |
| 4026 | #if defined(_LIBCPP_MSVCRT) |
| 4027 | return lgamma(__d); |
| 4028 | #else |
| 4029 | int __sign; |
| 4030 | return lgamma_r(__d, &__sign); |
| 4031 | #endif |
| 4032 | } |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4033 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4034 | template<class _IntType> |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4035 | 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] | 4036 | : __t_(__t), __p_(__p) |
| 4037 | { |
| 4038 | if (0 < __p_ && __p_ < 1) |
| 4039 | { |
| 4040 | __r0_ = static_cast<result_type>((__t_ + 1) * __p_); |
Eric Fiselier | 651ca6e | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4041 | __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - |
| 4042 | __libcpp_lgamma(__r0_ + 1.) - |
| 4043 | __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4044 | (__t_ - __r0_) * _VSTD::log(1 - __p_)); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4045 | __odds_ratio_ = __p_ / (1 - __p_); |
| 4046 | } |
| 4047 | } |
| 4048 | |
Marshall Clow | f97a84f | 2014-09-17 18:33:58 +0000 | [diff] [blame] | 4049 | // Reference: Kemp, C.D. (1986). `A modal method for generating binomial |
| 4050 | // variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4051 | template<class _IntType> |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4052 | template<class _URNG> |
| 4053 | _IntType |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4054 | binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4055 | { |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4056 | if (__pr.__t_ == 0 || __pr.__p_ == 0) |
| 4057 | return 0; |
| 4058 | if (__pr.__p_ == 1) |
| 4059 | return __pr.__t_; |
| 4060 | uniform_real_distribution<double> __gen; |
| 4061 | double __u = __gen(__g) - __pr.__pr_; |
| 4062 | if (__u < 0) |
| 4063 | return __pr.__r0_; |
| 4064 | double __pu = __pr.__pr_; |
| 4065 | double __pd = __pu; |
| 4066 | result_type __ru = __pr.__r0_; |
| 4067 | result_type __rd = __ru; |
| 4068 | while (true) |
| 4069 | { |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4070 | bool __break = true; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4071 | if (__rd >= 1) |
| 4072 | { |
| 4073 | __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); |
| 4074 | __u -= __pd; |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4075 | __break = false; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4076 | if (__u < 0) |
| 4077 | return __rd - 1; |
| 4078 | } |
Marshall Clow | f97a84f | 2014-09-17 18:33:58 +0000 | [diff] [blame] | 4079 | if ( __rd != 0 ) |
| 4080 | --__rd; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4081 | ++__ru; |
| 4082 | if (__ru <= __pr.__t_) |
| 4083 | { |
| 4084 | __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; |
| 4085 | __u -= __pu; |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4086 | __break = false; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4087 | if (__u < 0) |
| 4088 | return __ru; |
| 4089 | } |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4090 | if (__break) |
| 4091 | return 0; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4092 | } |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4093 | } |
| 4094 | |
| 4095 | template <class _CharT, class _Traits, class _IntType> |
| 4096 | basic_ostream<_CharT, _Traits>& |
| 4097 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4098 | const binomial_distribution<_IntType>& __x) |
| 4099 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4100 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4101 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4102 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4103 | _OStream::scientific); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4104 | _CharT __sp = __os.widen(' '); |
| 4105 | __os.fill(__sp); |
| 4106 | return __os << __x.t() << __sp << __x.p(); |
| 4107 | } |
| 4108 | |
| 4109 | template <class _CharT, class _Traits, class _IntType> |
| 4110 | basic_istream<_CharT, _Traits>& |
| 4111 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4112 | binomial_distribution<_IntType>& __x) |
| 4113 | { |
| 4114 | typedef binomial_distribution<_IntType> _Eng; |
| 4115 | typedef typename _Eng::result_type result_type; |
| 4116 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4117 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4118 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4119 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4120 | result_type __t; |
| 4121 | double __p; |
| 4122 | __is >> __t >> __p; |
| 4123 | if (!__is.fail()) |
| 4124 | __x.param(param_type(__t, __p)); |
| 4125 | return __is; |
| 4126 | } |
| 4127 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4128 | // exponential_distribution |
| 4129 | |
| 4130 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4131 | class _LIBCPP_TEMPLATE_VIS exponential_distribution |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4132 | { |
| 4133 | public: |
| 4134 | // types |
| 4135 | typedef _RealType result_type; |
| 4136 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4137 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4138 | { |
| 4139 | result_type __lambda_; |
| 4140 | public: |
| 4141 | typedef exponential_distribution distribution_type; |
| 4142 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4143 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4144 | explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} |
| 4145 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4146 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4147 | result_type lambda() const {return __lambda_;} |
| 4148 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4149 | friend _LIBCPP_INLINE_VISIBILITY |
| 4150 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4151 | {return __x.__lambda_ == __y.__lambda_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4152 | friend _LIBCPP_INLINE_VISIBILITY |
| 4153 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4154 | {return !(__x == __y);} |
| 4155 | }; |
| 4156 | |
| 4157 | private: |
| 4158 | param_type __p_; |
| 4159 | |
| 4160 | public: |
| 4161 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4162 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4163 | explicit exponential_distribution(result_type __lambda = 1) |
| 4164 | : __p_(param_type(__lambda)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4165 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4166 | explicit exponential_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4167 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4168 | void reset() {} |
| 4169 | |
| 4170 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4171 | template<class _URNG> |
| 4172 | _LIBCPP_INLINE_VISIBILITY |
| 4173 | result_type operator()(_URNG& __g) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4174 | {return (*this)(__g, __p_);} |
| 4175 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4176 | |
| 4177 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4178 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4179 | result_type lambda() const {return __p_.lambda();} |
| 4180 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4181 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4182 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4183 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4184 | void param(const param_type& __p) {__p_ = __p;} |
| 4185 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4186 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4187 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4188 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 021f990 | 2010-05-16 17:56:20 +0000 | [diff] [blame] | 4189 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4190 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4191 | friend _LIBCPP_INLINE_VISIBILITY |
| 4192 | bool operator==(const exponential_distribution& __x, |
| 4193 | const exponential_distribution& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4194 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4195 | friend _LIBCPP_INLINE_VISIBILITY |
| 4196 | bool operator!=(const exponential_distribution& __x, |
| 4197 | const exponential_distribution& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4198 | {return !(__x == __y);} |
| 4199 | }; |
| 4200 | |
| 4201 | template <class _RealType> |
| 4202 | template<class _URNG> |
| 4203 | _RealType |
| 4204 | exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4205 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4206 | return -_VSTD::log |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4207 | ( |
| 4208 | result_type(1) - |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4209 | _VSTD::generate_canonical<result_type, |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4210 | numeric_limits<result_type>::digits>(__g) |
| 4211 | ) |
| 4212 | / __p.lambda(); |
| 4213 | } |
| 4214 | |
| 4215 | template <class _CharT, class _Traits, class _RealType> |
| 4216 | basic_ostream<_CharT, _Traits>& |
| 4217 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4218 | const exponential_distribution<_RealType>& __x) |
| 4219 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4220 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4221 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4222 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4223 | _OStream::scientific); |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4224 | return __os << __x.lambda(); |
| 4225 | } |
| 4226 | |
| 4227 | template <class _CharT, class _Traits, class _RealType> |
| 4228 | basic_istream<_CharT, _Traits>& |
| 4229 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4230 | exponential_distribution<_RealType>& __x) |
| 4231 | { |
| 4232 | typedef exponential_distribution<_RealType> _Eng; |
| 4233 | typedef typename _Eng::result_type result_type; |
| 4234 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4235 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4236 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4237 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4238 | result_type __lambda; |
| 4239 | __is >> __lambda; |
| 4240 | if (!__is.fail()) |
| 4241 | __x.param(param_type(__lambda)); |
| 4242 | return __is; |
| 4243 | } |
| 4244 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4245 | // normal_distribution |
| 4246 | |
| 4247 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4248 | class _LIBCPP_TEMPLATE_VIS normal_distribution |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4249 | { |
| 4250 | public: |
| 4251 | // types |
| 4252 | typedef _RealType result_type; |
| 4253 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4254 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4255 | { |
| 4256 | result_type __mean_; |
| 4257 | result_type __stddev_; |
| 4258 | public: |
| 4259 | typedef normal_distribution distribution_type; |
| 4260 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4261 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4262 | explicit param_type(result_type __mean = 0, result_type __stddev = 1) |
| 4263 | : __mean_(__mean), __stddev_(__stddev) {} |
| 4264 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4265 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4266 | result_type mean() const {return __mean_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4267 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4268 | result_type stddev() const {return __stddev_;} |
| 4269 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4270 | friend _LIBCPP_INLINE_VISIBILITY |
| 4271 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4272 | {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4273 | friend _LIBCPP_INLINE_VISIBILITY |
| 4274 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4275 | {return !(__x == __y);} |
| 4276 | }; |
| 4277 | |
| 4278 | private: |
| 4279 | param_type __p_; |
| 4280 | result_type _V_; |
| 4281 | bool _V_hot_; |
| 4282 | |
| 4283 | public: |
| 4284 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4285 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4286 | explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) |
| 4287 | : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4288 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4289 | explicit normal_distribution(const param_type& __p) |
| 4290 | : __p_(__p), _V_hot_(false) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4291 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4292 | void reset() {_V_hot_ = false;} |
| 4293 | |
| 4294 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4295 | template<class _URNG> |
| 4296 | _LIBCPP_INLINE_VISIBILITY |
| 4297 | result_type operator()(_URNG& __g) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4298 | {return (*this)(__g, __p_);} |
| 4299 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4300 | |
| 4301 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4302 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4303 | result_type mean() const {return __p_.mean();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4304 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4305 | result_type stddev() const {return __p_.stddev();} |
| 4306 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4307 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4308 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4309 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4310 | void param(const param_type& __p) {__p_ = __p;} |
| 4311 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4312 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4313 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4314 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4315 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4316 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4317 | friend _LIBCPP_INLINE_VISIBILITY |
| 4318 | bool operator==(const normal_distribution& __x, |
| 4319 | const normal_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4320 | {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && |
| 4321 | (!__x._V_hot_ || __x._V_ == __y._V_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4322 | friend _LIBCPP_INLINE_VISIBILITY |
| 4323 | bool operator!=(const normal_distribution& __x, |
| 4324 | const normal_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4325 | {return !(__x == __y);} |
| 4326 | |
| 4327 | template <class _CharT, class _Traits, class _RT> |
| 4328 | friend |
| 4329 | basic_ostream<_CharT, _Traits>& |
| 4330 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4331 | const normal_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4332 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4333 | template <class _CharT, class _Traits, class _RT> |
| 4334 | friend |
| 4335 | basic_istream<_CharT, _Traits>& |
| 4336 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4337 | normal_distribution<_RT>& __x); |
| 4338 | }; |
| 4339 | |
| 4340 | template <class _RealType> |
| 4341 | template<class _URNG> |
| 4342 | _RealType |
| 4343 | normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4344 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4345 | result_type _Up; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4346 | if (_V_hot_) |
| 4347 | { |
| 4348 | _V_hot_ = false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4349 | _Up = _V_; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4350 | } |
| 4351 | else |
| 4352 | { |
| 4353 | uniform_real_distribution<result_type> _Uni(-1, 1); |
| 4354 | result_type __u; |
| 4355 | result_type __v; |
| 4356 | result_type __s; |
| 4357 | do |
| 4358 | { |
| 4359 | __u = _Uni(__g); |
| 4360 | __v = _Uni(__g); |
| 4361 | __s = __u * __u + __v * __v; |
| 4362 | } while (__s > 1 || __s == 0); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4363 | result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); |
| 4364 | _V_ = __v * _Fp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4365 | _V_hot_ = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4366 | _Up = __u * _Fp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4367 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4368 | return _Up * __p.stddev() + __p.mean(); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
| 4371 | template <class _CharT, class _Traits, class _RT> |
| 4372 | basic_ostream<_CharT, _Traits>& |
| 4373 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4374 | const normal_distribution<_RT>& __x) |
| 4375 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4376 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4377 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4378 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4379 | _OStream::scientific); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4380 | _CharT __sp = __os.widen(' '); |
| 4381 | __os.fill(__sp); |
| 4382 | __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; |
| 4383 | if (__x._V_hot_) |
| 4384 | __os << __sp << __x._V_; |
| 4385 | return __os; |
| 4386 | } |
| 4387 | |
| 4388 | template <class _CharT, class _Traits, class _RT> |
| 4389 | basic_istream<_CharT, _Traits>& |
| 4390 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4391 | normal_distribution<_RT>& __x) |
| 4392 | { |
| 4393 | typedef normal_distribution<_RT> _Eng; |
| 4394 | typedef typename _Eng::result_type result_type; |
| 4395 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4396 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4397 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4398 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4399 | result_type __mean; |
| 4400 | result_type __stddev; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4401 | result_type _Vp = 0; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4402 | bool _V_hot = false; |
| 4403 | __is >> __mean >> __stddev >> _V_hot; |
| 4404 | if (_V_hot) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4405 | __is >> _Vp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4406 | if (!__is.fail()) |
| 4407 | { |
| 4408 | __x.param(param_type(__mean, __stddev)); |
| 4409 | __x._V_hot_ = _V_hot; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4410 | __x._V_ = _Vp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4411 | } |
| 4412 | return __is; |
| 4413 | } |
| 4414 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4415 | // lognormal_distribution |
| 4416 | |
| 4417 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4418 | class _LIBCPP_TEMPLATE_VIS lognormal_distribution |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4419 | { |
| 4420 | public: |
| 4421 | // types |
| 4422 | typedef _RealType result_type; |
| 4423 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4424 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4425 | { |
| 4426 | normal_distribution<result_type> __nd_; |
| 4427 | public: |
| 4428 | typedef lognormal_distribution distribution_type; |
| 4429 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4430 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4431 | explicit param_type(result_type __m = 0, result_type __s = 1) |
| 4432 | : __nd_(__m, __s) {} |
| 4433 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4434 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4435 | result_type m() const {return __nd_.mean();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4436 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4437 | result_type s() const {return __nd_.stddev();} |
| 4438 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4439 | friend _LIBCPP_INLINE_VISIBILITY |
| 4440 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4441 | {return __x.__nd_ == __y.__nd_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4442 | friend _LIBCPP_INLINE_VISIBILITY |
| 4443 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4444 | {return !(__x == __y);} |
| 4445 | friend class lognormal_distribution; |
| 4446 | |
| 4447 | template <class _CharT, class _Traits, class _RT> |
| 4448 | friend |
| 4449 | basic_ostream<_CharT, _Traits>& |
| 4450 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4451 | const lognormal_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4452 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4453 | template <class _CharT, class _Traits, class _RT> |
| 4454 | friend |
| 4455 | basic_istream<_CharT, _Traits>& |
| 4456 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4457 | lognormal_distribution<_RT>& __x); |
| 4458 | }; |
| 4459 | |
| 4460 | private: |
| 4461 | param_type __p_; |
| 4462 | |
| 4463 | public: |
| 4464 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4465 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4466 | explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) |
| 4467 | : __p_(param_type(__m, __s)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4468 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4469 | explicit lognormal_distribution(const param_type& __p) |
| 4470 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4471 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4472 | void reset() {__p_.__nd_.reset();} |
| 4473 | |
| 4474 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4475 | template<class _URNG> |
| 4476 | _LIBCPP_INLINE_VISIBILITY |
| 4477 | result_type operator()(_URNG& __g) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4478 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4479 | template<class _URNG> |
| 4480 | _LIBCPP_INLINE_VISIBILITY |
| 4481 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4482 | {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4483 | |
| 4484 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4485 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4486 | result_type m() const {return __p_.m();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4487 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4488 | result_type s() const {return __p_.s();} |
| 4489 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4490 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4491 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4492 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 4493 | void param(const param_type& __p) {__p_ = __p;} |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4494 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4495 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4496 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4497 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4498 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4499 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4500 | friend _LIBCPP_INLINE_VISIBILITY |
| 4501 | bool operator==(const lognormal_distribution& __x, |
| 4502 | const lognormal_distribution& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4503 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4504 | friend _LIBCPP_INLINE_VISIBILITY |
| 4505 | bool operator!=(const lognormal_distribution& __x, |
| 4506 | const lognormal_distribution& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4507 | {return !(__x == __y);} |
| 4508 | |
| 4509 | template <class _CharT, class _Traits, class _RT> |
| 4510 | friend |
| 4511 | basic_ostream<_CharT, _Traits>& |
| 4512 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4513 | const lognormal_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4514 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4515 | template <class _CharT, class _Traits, class _RT> |
| 4516 | friend |
| 4517 | basic_istream<_CharT, _Traits>& |
| 4518 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4519 | lognormal_distribution<_RT>& __x); |
| 4520 | }; |
| 4521 | |
| 4522 | template <class _CharT, class _Traits, class _RT> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4523 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4524 | basic_ostream<_CharT, _Traits>& |
| 4525 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4526 | const lognormal_distribution<_RT>& __x) |
| 4527 | { |
| 4528 | return __os << __x.__p_.__nd_; |
| 4529 | } |
| 4530 | |
| 4531 | template <class _CharT, class _Traits, class _RT> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4532 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4533 | basic_istream<_CharT, _Traits>& |
| 4534 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4535 | lognormal_distribution<_RT>& __x) |
| 4536 | { |
| 4537 | return __is >> __x.__p_.__nd_; |
| 4538 | } |
| 4539 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4540 | // poisson_distribution |
| 4541 | |
| 4542 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4543 | class _LIBCPP_TEMPLATE_VIS poisson_distribution |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4544 | { |
| 4545 | public: |
| 4546 | // types |
| 4547 | typedef _IntType result_type; |
| 4548 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4549 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4550 | { |
| 4551 | double __mean_; |
| 4552 | double __s_; |
| 4553 | double __d_; |
| 4554 | double __l_; |
| 4555 | double __omega_; |
| 4556 | double __c0_; |
| 4557 | double __c1_; |
| 4558 | double __c2_; |
| 4559 | double __c3_; |
| 4560 | double __c_; |
| 4561 | |
| 4562 | public: |
| 4563 | typedef poisson_distribution distribution_type; |
| 4564 | |
| 4565 | explicit param_type(double __mean = 1.0); |
| 4566 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4567 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4568 | double mean() const {return __mean_;} |
| 4569 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4570 | friend _LIBCPP_INLINE_VISIBILITY |
| 4571 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4572 | {return __x.__mean_ == __y.__mean_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4573 | friend _LIBCPP_INLINE_VISIBILITY |
| 4574 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4575 | {return !(__x == __y);} |
| 4576 | |
| 4577 | friend class poisson_distribution; |
| 4578 | }; |
| 4579 | |
| 4580 | private: |
| 4581 | param_type __p_; |
| 4582 | |
| 4583 | public: |
| 4584 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4585 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4586 | explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4587 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4588 | explicit poisson_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4589 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4590 | void reset() {} |
| 4591 | |
| 4592 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4593 | template<class _URNG> |
| 4594 | _LIBCPP_INLINE_VISIBILITY |
| 4595 | result_type operator()(_URNG& __g) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4596 | {return (*this)(__g, __p_);} |
| 4597 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4598 | |
| 4599 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4600 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4601 | double mean() const {return __p_.mean();} |
| 4602 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4603 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4604 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4605 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4606 | void param(const param_type& __p) {__p_ = __p;} |
| 4607 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4608 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4609 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4610 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4611 | result_type max() const {return numeric_limits<result_type>::max();} |
| 4612 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4613 | friend _LIBCPP_INLINE_VISIBILITY |
| 4614 | bool operator==(const poisson_distribution& __x, |
| 4615 | const poisson_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4616 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4617 | friend _LIBCPP_INLINE_VISIBILITY |
| 4618 | bool operator!=(const poisson_distribution& __x, |
| 4619 | const poisson_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4620 | {return !(__x == __y);} |
| 4621 | }; |
| 4622 | |
| 4623 | template<class _IntType> |
| 4624 | poisson_distribution<_IntType>::param_type::param_type(double __mean) |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4625 | // According to the standard `inf` is a valid input, but it causes the |
| 4626 | // distribution to hang, so we replace it with the maximum representable |
| 4627 | // mean. |
| 4628 | : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4629 | { |
| 4630 | if (__mean_ < 10) |
| 4631 | { |
| 4632 | __s_ = 0; |
| 4633 | __d_ = 0; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4634 | __l_ = _VSTD::exp(-__mean_); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4635 | __omega_ = 0; |
| 4636 | __c3_ = 0; |
| 4637 | __c2_ = 0; |
| 4638 | __c1_ = 0; |
| 4639 | __c0_ = 0; |
| 4640 | __c_ = 0; |
| 4641 | } |
| 4642 | else |
| 4643 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4644 | __s_ = _VSTD::sqrt(__mean_); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4645 | __d_ = 6 * __mean_ * __mean_; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4646 | __l_ = std::trunc(__mean_ - 1.1484); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4647 | __omega_ = .3989423 / __s_; |
| 4648 | double __b1_ = .4166667E-1 / __mean_; |
| 4649 | double __b2_ = .3 * __b1_ * __b1_; |
| 4650 | __c3_ = .1428571 * __b1_ * __b2_; |
| 4651 | __c2_ = __b2_ - 15. * __c3_; |
| 4652 | __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; |
| 4653 | __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; |
| 4654 | __c_ = .1069 / __mean_; |
| 4655 | } |
| 4656 | } |
| 4657 | |
| 4658 | template <class _IntType> |
| 4659 | template<class _URNG> |
| 4660 | _IntType |
| 4661 | poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) |
| 4662 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4663 | double __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4664 | uniform_real_distribution<double> __urd; |
Howard Hinnant | a5fb7ac | 2011-04-14 15:59:22 +0000 | [diff] [blame] | 4665 | if (__pr.__mean_ < 10) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4666 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4667 | __tx = 0; |
| 4668 | for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4669 | __p *= __urd(__urng); |
| 4670 | } |
| 4671 | else |
| 4672 | { |
| 4673 | double __difmuk; |
| 4674 | double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); |
| 4675 | double __u; |
| 4676 | if (__g > 0) |
| 4677 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4678 | __tx = std::trunc(__g); |
| 4679 | if (__tx >= __pr.__l_) |
| 4680 | return std::__clamp_to_integral<result_type>(__tx); |
| 4681 | __difmuk = __pr.__mean_ - __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4682 | __u = __urd(__urng); |
| 4683 | if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4684 | return std::__clamp_to_integral<result_type>(__tx); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4685 | } |
| 4686 | exponential_distribution<double> __edist; |
| 4687 | for (bool __using_exp_dist = false; true; __using_exp_dist = true) |
| 4688 | { |
| 4689 | double __e; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4690 | if (__using_exp_dist || __g <= 0) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4691 | { |
| 4692 | double __t; |
| 4693 | do |
| 4694 | { |
| 4695 | __e = __edist(__urng); |
| 4696 | __u = __urd(__urng); |
| 4697 | __u += __u - 1; |
| 4698 | __t = 1.8 + (__u < 0 ? -__e : __e); |
| 4699 | } while (__t <= -.6744); |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4700 | __tx = std::trunc(__pr.__mean_ + __pr.__s_ * __t); |
| 4701 | __difmuk = __pr.__mean_ - __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4702 | __using_exp_dist = true; |
| 4703 | } |
| 4704 | double __px; |
| 4705 | double __py; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4706 | if (__tx < 10 && __tx >= 0) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4707 | { |
Marshall Clow | c7e36e8 | 2018-01-16 14:54:36 +0000 | [diff] [blame] | 4708 | const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4709 | 40320, 362880}; |
| 4710 | __px = -__pr.__mean_; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4711 | __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)]; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4712 | } |
| 4713 | else |
| 4714 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4715 | double __del = .8333333E-1 / __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4716 | __del -= 4.8 * __del * __del * __del; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4717 | double __v = __difmuk / __tx; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4718 | if (_VSTD::abs(__v) > 0.25) |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4719 | __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4720 | else |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4721 | __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) * |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4722 | __v + .1421878) * __v + -.1661269) * __v + .2000118) * |
| 4723 | __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4724 | __py = .3989423 / _VSTD::sqrt(__tx); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4725 | } |
| 4726 | double __r = (0.5 - __difmuk) / __pr.__s_; |
| 4727 | double __r2 = __r * __r; |
| 4728 | double __fx = -0.5 * __r2; |
| 4729 | double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * |
| 4730 | __r2 + __pr.__c1_) * __r2 + __pr.__c0_); |
| 4731 | if (__using_exp_dist) |
| 4732 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4733 | if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - |
| 4734 | __fy * _VSTD::exp(__fx + __e)) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4735 | break; |
| 4736 | } |
| 4737 | else |
| 4738 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4739 | if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4740 | break; |
| 4741 | } |
| 4742 | } |
| 4743 | } |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4744 | return std::__clamp_to_integral<result_type>(__tx); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | template <class _CharT, class _Traits, class _IntType> |
| 4748 | basic_ostream<_CharT, _Traits>& |
| 4749 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4750 | const poisson_distribution<_IntType>& __x) |
| 4751 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4752 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4753 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4754 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4755 | _OStream::scientific); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4756 | return __os << __x.mean(); |
| 4757 | } |
| 4758 | |
| 4759 | template <class _CharT, class _Traits, class _IntType> |
| 4760 | basic_istream<_CharT, _Traits>& |
| 4761 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4762 | poisson_distribution<_IntType>& __x) |
| 4763 | { |
| 4764 | typedef poisson_distribution<_IntType> _Eng; |
| 4765 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4766 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4767 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4768 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4769 | double __mean; |
| 4770 | __is >> __mean; |
| 4771 | if (!__is.fail()) |
| 4772 | __x.param(param_type(__mean)); |
| 4773 | return __is; |
| 4774 | } |
| 4775 | |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4776 | // weibull_distribution |
| 4777 | |
| 4778 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4779 | class _LIBCPP_TEMPLATE_VIS weibull_distribution |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4780 | { |
| 4781 | public: |
| 4782 | // types |
| 4783 | typedef _RealType result_type; |
| 4784 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4785 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4786 | { |
| 4787 | result_type __a_; |
| 4788 | result_type __b_; |
| 4789 | public: |
| 4790 | typedef weibull_distribution distribution_type; |
| 4791 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4793 | explicit param_type(result_type __a = 1, result_type __b = 1) |
| 4794 | : __a_(__a), __b_(__b) {} |
| 4795 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4796 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4797 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4799 | result_type b() const {return __b_;} |
| 4800 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4801 | friend _LIBCPP_INLINE_VISIBILITY |
| 4802 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4803 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4804 | friend _LIBCPP_INLINE_VISIBILITY |
| 4805 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4806 | {return !(__x == __y);} |
| 4807 | }; |
| 4808 | |
| 4809 | private: |
| 4810 | param_type __p_; |
| 4811 | |
| 4812 | public: |
| 4813 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4814 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4815 | explicit weibull_distribution(result_type __a = 1, result_type __b = 1) |
| 4816 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4817 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4818 | explicit weibull_distribution(const param_type& __p) |
| 4819 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4820 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4821 | void reset() {} |
| 4822 | |
| 4823 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4824 | template<class _URNG> |
| 4825 | _LIBCPP_INLINE_VISIBILITY |
| 4826 | result_type operator()(_URNG& __g) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4827 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4828 | template<class _URNG> |
| 4829 | _LIBCPP_INLINE_VISIBILITY |
| 4830 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4831 | {return __p.b() * |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4832 | _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4833 | |
| 4834 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4835 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4836 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4837 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4838 | result_type b() const {return __p_.b();} |
| 4839 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4840 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4841 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4842 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4843 | void param(const param_type& __p) {__p_ = __p;} |
| 4844 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4845 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4846 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4847 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4848 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4849 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4850 | friend _LIBCPP_INLINE_VISIBILITY |
| 4851 | bool operator==(const weibull_distribution& __x, |
| 4852 | const weibull_distribution& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4853 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4854 | friend _LIBCPP_INLINE_VISIBILITY |
| 4855 | bool operator!=(const weibull_distribution& __x, |
| 4856 | const weibull_distribution& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4857 | {return !(__x == __y);} |
| 4858 | }; |
| 4859 | |
| 4860 | template <class _CharT, class _Traits, class _RT> |
| 4861 | basic_ostream<_CharT, _Traits>& |
| 4862 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4863 | const weibull_distribution<_RT>& __x) |
| 4864 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4865 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4866 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4867 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4868 | _OStream::scientific); |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4869 | _CharT __sp = __os.widen(' '); |
| 4870 | __os.fill(__sp); |
| 4871 | __os << __x.a() << __sp << __x.b(); |
| 4872 | return __os; |
| 4873 | } |
| 4874 | |
| 4875 | template <class _CharT, class _Traits, class _RT> |
| 4876 | basic_istream<_CharT, _Traits>& |
| 4877 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4878 | weibull_distribution<_RT>& __x) |
| 4879 | { |
| 4880 | typedef weibull_distribution<_RT> _Eng; |
| 4881 | typedef typename _Eng::result_type result_type; |
| 4882 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4883 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4884 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4885 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4886 | result_type __a; |
| 4887 | result_type __b; |
| 4888 | __is >> __a >> __b; |
| 4889 | if (!__is.fail()) |
| 4890 | __x.param(param_type(__a, __b)); |
| 4891 | return __is; |
| 4892 | } |
| 4893 | |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4894 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4895 | class _LIBCPP_TEMPLATE_VIS extreme_value_distribution |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4896 | { |
| 4897 | public: |
| 4898 | // types |
| 4899 | typedef _RealType result_type; |
| 4900 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4901 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4902 | { |
| 4903 | result_type __a_; |
| 4904 | result_type __b_; |
| 4905 | public: |
| 4906 | typedef extreme_value_distribution distribution_type; |
| 4907 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4908 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4909 | explicit param_type(result_type __a = 0, result_type __b = 1) |
| 4910 | : __a_(__a), __b_(__b) {} |
| 4911 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4912 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4913 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4914 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4915 | result_type b() const {return __b_;} |
| 4916 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4917 | friend _LIBCPP_INLINE_VISIBILITY |
| 4918 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4919 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4920 | friend _LIBCPP_INLINE_VISIBILITY |
| 4921 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4922 | {return !(__x == __y);} |
| 4923 | }; |
| 4924 | |
| 4925 | private: |
| 4926 | param_type __p_; |
| 4927 | |
| 4928 | public: |
| 4929 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4930 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4931 | explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) |
| 4932 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4933 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4934 | explicit extreme_value_distribution(const param_type& __p) |
| 4935 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4936 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4937 | void reset() {} |
| 4938 | |
| 4939 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4940 | template<class _URNG> |
| 4941 | _LIBCPP_INLINE_VISIBILITY |
| 4942 | result_type operator()(_URNG& __g) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4943 | {return (*this)(__g, __p_);} |
| 4944 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4945 | |
| 4946 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4947 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4948 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4949 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4950 | result_type b() const {return __p_.b();} |
| 4951 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4952 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4953 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4954 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4955 | void param(const param_type& __p) {__p_ = __p;} |
| 4956 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4957 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4958 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4959 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4960 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4961 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4962 | friend _LIBCPP_INLINE_VISIBILITY |
| 4963 | bool operator==(const extreme_value_distribution& __x, |
| 4964 | const extreme_value_distribution& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4965 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4966 | friend _LIBCPP_INLINE_VISIBILITY |
| 4967 | bool operator!=(const extreme_value_distribution& __x, |
| 4968 | const extreme_value_distribution& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4969 | {return !(__x == __y);} |
| 4970 | }; |
| 4971 | |
| 4972 | template<class _RealType> |
| 4973 | template<class _URNG> |
| 4974 | _RealType |
| 4975 | extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4976 | { |
| 4977 | return __p.a() - __p.b() * |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4978 | _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | template <class _CharT, class _Traits, class _RT> |
| 4982 | basic_ostream<_CharT, _Traits>& |
| 4983 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4984 | const extreme_value_distribution<_RT>& __x) |
| 4985 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4986 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 4987 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4988 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4989 | _OStream::scientific); |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4990 | _CharT __sp = __os.widen(' '); |
| 4991 | __os.fill(__sp); |
| 4992 | __os << __x.a() << __sp << __x.b(); |
| 4993 | return __os; |
| 4994 | } |
| 4995 | |
| 4996 | template <class _CharT, class _Traits, class _RT> |
| 4997 | basic_istream<_CharT, _Traits>& |
| 4998 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4999 | extreme_value_distribution<_RT>& __x) |
| 5000 | { |
| 5001 | typedef extreme_value_distribution<_RT> _Eng; |
| 5002 | typedef typename _Eng::result_type result_type; |
| 5003 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5004 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5005 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5006 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5007 | result_type __a; |
| 5008 | result_type __b; |
| 5009 | __is >> __a >> __b; |
| 5010 | if (!__is.fail()) |
| 5011 | __x.param(param_type(__a, __b)); |
| 5012 | return __is; |
| 5013 | } |
| 5014 | |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5015 | // gamma_distribution |
| 5016 | |
| 5017 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5018 | class _LIBCPP_TEMPLATE_VIS gamma_distribution |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5019 | { |
| 5020 | public: |
| 5021 | // types |
| 5022 | typedef _RealType result_type; |
| 5023 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5024 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5025 | { |
| 5026 | result_type __alpha_; |
| 5027 | result_type __beta_; |
| 5028 | public: |
| 5029 | typedef gamma_distribution distribution_type; |
| 5030 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5031 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5032 | explicit param_type(result_type __alpha = 1, result_type __beta = 1) |
| 5033 | : __alpha_(__alpha), __beta_(__beta) {} |
| 5034 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5035 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5036 | result_type alpha() const {return __alpha_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5037 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5038 | result_type beta() const {return __beta_;} |
| 5039 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5040 | friend _LIBCPP_INLINE_VISIBILITY |
| 5041 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5042 | {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5043 | friend _LIBCPP_INLINE_VISIBILITY |
| 5044 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5045 | {return !(__x == __y);} |
| 5046 | }; |
| 5047 | |
| 5048 | private: |
| 5049 | param_type __p_; |
| 5050 | |
| 5051 | public: |
| 5052 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5053 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5054 | explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) |
| 5055 | : __p_(param_type(__alpha, __beta)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5056 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5057 | explicit gamma_distribution(const param_type& __p) |
| 5058 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5059 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5060 | void reset() {} |
| 5061 | |
| 5062 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5063 | template<class _URNG> |
| 5064 | _LIBCPP_INLINE_VISIBILITY |
| 5065 | result_type operator()(_URNG& __g) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5066 | {return (*this)(__g, __p_);} |
| 5067 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5068 | |
| 5069 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5070 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5071 | result_type alpha() const {return __p_.alpha();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5072 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5073 | result_type beta() const {return __p_.beta();} |
| 5074 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5075 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5076 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5077 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5078 | void param(const param_type& __p) {__p_ = __p;} |
| 5079 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5080 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5081 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5082 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5083 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5084 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5085 | friend _LIBCPP_INLINE_VISIBILITY |
| 5086 | bool operator==(const gamma_distribution& __x, |
| 5087 | const gamma_distribution& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5088 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5089 | friend _LIBCPP_INLINE_VISIBILITY |
| 5090 | bool operator!=(const gamma_distribution& __x, |
| 5091 | const gamma_distribution& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5092 | {return !(__x == __y);} |
| 5093 | }; |
| 5094 | |
| 5095 | template <class _RealType> |
| 5096 | template<class _URNG> |
| 5097 | _RealType |
| 5098 | gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5099 | { |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5100 | result_type __a = __p.alpha(); |
| 5101 | uniform_real_distribution<result_type> __gen(0, 1); |
| 5102 | exponential_distribution<result_type> __egen; |
| 5103 | result_type __x; |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5104 | if (__a == 1) |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5105 | __x = __egen(__g); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5106 | else if (__a > 1) |
| 5107 | { |
| 5108 | const result_type __b = __a - 1; |
| 5109 | const result_type __c = 3 * __a - result_type(0.75); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5110 | while (true) |
| 5111 | { |
| 5112 | const result_type __u = __gen(__g); |
| 5113 | const result_type __v = __gen(__g); |
| 5114 | const result_type __w = __u * (1 - __u); |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5115 | if (__w != 0) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5116 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5117 | const result_type __y = _VSTD::sqrt(__c / __w) * |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5118 | (__u - result_type(0.5)); |
| 5119 | __x = __b + __y; |
| 5120 | if (__x >= 0) |
| 5121 | { |
| 5122 | const result_type __z = 64 * __w * __w * __w * __v * __v; |
| 5123 | if (__z <= 1 - 2 * __y * __y / __x) |
| 5124 | break; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5125 | if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5126 | break; |
| 5127 | } |
| 5128 | } |
| 5129 | } |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5130 | } |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5131 | else // __a < 1 |
| 5132 | { |
| 5133 | while (true) |
| 5134 | { |
| 5135 | const result_type __u = __gen(__g); |
| 5136 | const result_type __es = __egen(__g); |
| 5137 | if (__u <= 1 - __a) |
| 5138 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5139 | __x = _VSTD::pow(__u, 1 / __a); |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5140 | if (__x <= __es) |
| 5141 | break; |
| 5142 | } |
| 5143 | else |
| 5144 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5145 | const result_type __e = -_VSTD::log((1-__u)/__a); |
| 5146 | __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5147 | if (__x <= __e + __es) |
| 5148 | break; |
| 5149 | } |
| 5150 | } |
| 5151 | } |
| 5152 | return __x * __p.beta(); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5153 | } |
| 5154 | |
| 5155 | template <class _CharT, class _Traits, class _RT> |
| 5156 | basic_ostream<_CharT, _Traits>& |
| 5157 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5158 | const gamma_distribution<_RT>& __x) |
| 5159 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5160 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5161 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5162 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5163 | _OStream::scientific); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5164 | _CharT __sp = __os.widen(' '); |
| 5165 | __os.fill(__sp); |
| 5166 | __os << __x.alpha() << __sp << __x.beta(); |
| 5167 | return __os; |
| 5168 | } |
| 5169 | |
| 5170 | template <class _CharT, class _Traits, class _RT> |
| 5171 | basic_istream<_CharT, _Traits>& |
| 5172 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5173 | gamma_distribution<_RT>& __x) |
| 5174 | { |
| 5175 | typedef gamma_distribution<_RT> _Eng; |
| 5176 | typedef typename _Eng::result_type result_type; |
| 5177 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5178 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5179 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5180 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5181 | result_type __alpha; |
| 5182 | result_type __beta; |
| 5183 | __is >> __alpha >> __beta; |
| 5184 | if (!__is.fail()) |
| 5185 | __x.param(param_type(__alpha, __beta)); |
| 5186 | return __is; |
| 5187 | } |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 5188 | |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5189 | // negative_binomial_distribution |
| 5190 | |
| 5191 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5192 | class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5193 | { |
| 5194 | public: |
| 5195 | // types |
| 5196 | typedef _IntType result_type; |
| 5197 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5198 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5199 | { |
| 5200 | result_type __k_; |
| 5201 | double __p_; |
| 5202 | public: |
| 5203 | typedef negative_binomial_distribution distribution_type; |
| 5204 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5205 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5206 | explicit param_type(result_type __k = 1, double __p = 0.5) |
| 5207 | : __k_(__k), __p_(__p) {} |
| 5208 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5209 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5210 | result_type k() const {return __k_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5211 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5212 | double p() const {return __p_;} |
| 5213 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5214 | friend _LIBCPP_INLINE_VISIBILITY |
| 5215 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5216 | {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5217 | friend _LIBCPP_INLINE_VISIBILITY |
| 5218 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5219 | {return !(__x == __y);} |
| 5220 | }; |
| 5221 | |
| 5222 | private: |
| 5223 | param_type __p_; |
| 5224 | |
| 5225 | public: |
| 5226 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5227 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5228 | explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) |
| 5229 | : __p_(__k, __p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5230 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5231 | explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5232 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5233 | void reset() {} |
| 5234 | |
| 5235 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5236 | template<class _URNG> |
| 5237 | _LIBCPP_INLINE_VISIBILITY |
| 5238 | result_type operator()(_URNG& __g) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5239 | {return (*this)(__g, __p_);} |
| 5240 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5241 | |
| 5242 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5243 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5244 | result_type k() const {return __p_.k();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5245 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5246 | double p() const {return __p_.p();} |
| 5247 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5248 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5249 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5250 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5251 | void param(const param_type& __p) {__p_ = __p;} |
| 5252 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5253 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5254 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5255 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5256 | result_type max() const {return numeric_limits<result_type>::max();} |
| 5257 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5258 | friend _LIBCPP_INLINE_VISIBILITY |
| 5259 | bool operator==(const negative_binomial_distribution& __x, |
| 5260 | const negative_binomial_distribution& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5261 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5262 | friend _LIBCPP_INLINE_VISIBILITY |
| 5263 | bool operator!=(const negative_binomial_distribution& __x, |
| 5264 | const negative_binomial_distribution& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5265 | {return !(__x == __y);} |
| 5266 | }; |
| 5267 | |
| 5268 | template <class _IntType> |
| 5269 | template<class _URNG> |
| 5270 | _IntType |
| 5271 | negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) |
| 5272 | { |
| 5273 | result_type __k = __pr.k(); |
| 5274 | double __p = __pr.p(); |
| 5275 | if (__k <= 21 * __p) |
| 5276 | { |
| 5277 | bernoulli_distribution __gen(__p); |
| 5278 | result_type __f = 0; |
| 5279 | result_type __s = 0; |
| 5280 | while (__s < __k) |
| 5281 | { |
| 5282 | if (__gen(__urng)) |
| 5283 | ++__s; |
| 5284 | else |
| 5285 | ++__f; |
| 5286 | } |
| 5287 | return __f; |
| 5288 | } |
| 5289 | return poisson_distribution<result_type>(gamma_distribution<double> |
| 5290 | (__k, (1-__p)/__p)(__urng))(__urng); |
| 5291 | } |
| 5292 | |
| 5293 | template <class _CharT, class _Traits, class _IntType> |
| 5294 | basic_ostream<_CharT, _Traits>& |
| 5295 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5296 | const negative_binomial_distribution<_IntType>& __x) |
| 5297 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5298 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5299 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5300 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5301 | _OStream::scientific); |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5302 | _CharT __sp = __os.widen(' '); |
| 5303 | __os.fill(__sp); |
| 5304 | return __os << __x.k() << __sp << __x.p(); |
| 5305 | } |
| 5306 | |
| 5307 | template <class _CharT, class _Traits, class _IntType> |
| 5308 | basic_istream<_CharT, _Traits>& |
| 5309 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5310 | negative_binomial_distribution<_IntType>& __x) |
| 5311 | { |
| 5312 | typedef negative_binomial_distribution<_IntType> _Eng; |
| 5313 | typedef typename _Eng::result_type result_type; |
| 5314 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5315 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5316 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5317 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5318 | result_type __k; |
| 5319 | double __p; |
| 5320 | __is >> __k >> __p; |
| 5321 | if (!__is.fail()) |
| 5322 | __x.param(param_type(__k, __p)); |
| 5323 | return __is; |
| 5324 | } |
| 5325 | |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5326 | // geometric_distribution |
| 5327 | |
| 5328 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5329 | class _LIBCPP_TEMPLATE_VIS geometric_distribution |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5330 | { |
| 5331 | public: |
| 5332 | // types |
| 5333 | typedef _IntType result_type; |
| 5334 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5335 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5336 | { |
| 5337 | double __p_; |
| 5338 | public: |
| 5339 | typedef geometric_distribution distribution_type; |
| 5340 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5341 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5342 | explicit param_type(double __p = 0.5) : __p_(__p) {} |
| 5343 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5344 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5345 | double p() const {return __p_;} |
| 5346 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5347 | friend _LIBCPP_INLINE_VISIBILITY |
| 5348 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5349 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5350 | friend _LIBCPP_INLINE_VISIBILITY |
| 5351 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5352 | {return !(__x == __y);} |
| 5353 | }; |
| 5354 | |
| 5355 | private: |
| 5356 | param_type __p_; |
| 5357 | |
| 5358 | public: |
| 5359 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5360 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5361 | explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5362 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5363 | explicit geometric_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5364 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5365 | void reset() {} |
| 5366 | |
| 5367 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5368 | template<class _URNG> |
| 5369 | _LIBCPP_INLINE_VISIBILITY |
| 5370 | result_type operator()(_URNG& __g) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5371 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5372 | template<class _URNG> |
| 5373 | _LIBCPP_INLINE_VISIBILITY |
| 5374 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5375 | {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} |
| 5376 | |
| 5377 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5378 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5379 | double p() const {return __p_.p();} |
| 5380 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5381 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5382 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5383 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5384 | void param(const param_type& __p) {__p_ = __p;} |
| 5385 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5386 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5387 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5388 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5389 | result_type max() const {return numeric_limits<result_type>::max();} |
| 5390 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5391 | friend _LIBCPP_INLINE_VISIBILITY |
| 5392 | bool operator==(const geometric_distribution& __x, |
| 5393 | const geometric_distribution& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5394 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5395 | friend _LIBCPP_INLINE_VISIBILITY |
| 5396 | bool operator!=(const geometric_distribution& __x, |
| 5397 | const geometric_distribution& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5398 | {return !(__x == __y);} |
| 5399 | }; |
| 5400 | |
| 5401 | template <class _CharT, class _Traits, class _IntType> |
| 5402 | basic_ostream<_CharT, _Traits>& |
| 5403 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5404 | const geometric_distribution<_IntType>& __x) |
| 5405 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5406 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5407 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5408 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5409 | _OStream::scientific); |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5410 | return __os << __x.p(); |
| 5411 | } |
| 5412 | |
| 5413 | template <class _CharT, class _Traits, class _IntType> |
| 5414 | basic_istream<_CharT, _Traits>& |
| 5415 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5416 | geometric_distribution<_IntType>& __x) |
| 5417 | { |
| 5418 | typedef geometric_distribution<_IntType> _Eng; |
| 5419 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5420 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5421 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5422 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5423 | double __p; |
| 5424 | __is >> __p; |
| 5425 | if (!__is.fail()) |
| 5426 | __x.param(param_type(__p)); |
| 5427 | return __is; |
| 5428 | } |
| 5429 | |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5430 | // chi_squared_distribution |
| 5431 | |
| 5432 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5433 | class _LIBCPP_TEMPLATE_VIS chi_squared_distribution |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5434 | { |
| 5435 | public: |
| 5436 | // types |
| 5437 | typedef _RealType result_type; |
| 5438 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5439 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5440 | { |
| 5441 | result_type __n_; |
| 5442 | public: |
| 5443 | typedef chi_squared_distribution distribution_type; |
| 5444 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5445 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5446 | explicit param_type(result_type __n = 1) : __n_(__n) {} |
| 5447 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5449 | result_type n() const {return __n_;} |
| 5450 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5451 | friend _LIBCPP_INLINE_VISIBILITY |
| 5452 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5453 | {return __x.__n_ == __y.__n_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5454 | friend _LIBCPP_INLINE_VISIBILITY |
| 5455 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5456 | {return !(__x == __y);} |
| 5457 | }; |
| 5458 | |
| 5459 | private: |
| 5460 | param_type __p_; |
| 5461 | |
| 5462 | public: |
| 5463 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5464 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5465 | explicit chi_squared_distribution(result_type __n = 1) |
| 5466 | : __p_(param_type(__n)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5467 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5468 | explicit chi_squared_distribution(const param_type& __p) |
| 5469 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5470 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5471 | void reset() {} |
| 5472 | |
| 5473 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5474 | template<class _URNG> |
| 5475 | _LIBCPP_INLINE_VISIBILITY |
| 5476 | result_type operator()(_URNG& __g) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5477 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5478 | template<class _URNG> |
| 5479 | _LIBCPP_INLINE_VISIBILITY |
| 5480 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5481 | {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} |
| 5482 | |
| 5483 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5484 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5485 | result_type n() const {return __p_.n();} |
| 5486 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5487 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5488 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5489 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5490 | void param(const param_type& __p) {__p_ = __p;} |
| 5491 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5492 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5493 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5494 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5495 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5496 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5497 | friend _LIBCPP_INLINE_VISIBILITY |
| 5498 | bool operator==(const chi_squared_distribution& __x, |
| 5499 | const chi_squared_distribution& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5500 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5501 | friend _LIBCPP_INLINE_VISIBILITY |
| 5502 | bool operator!=(const chi_squared_distribution& __x, |
| 5503 | const chi_squared_distribution& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5504 | {return !(__x == __y);} |
| 5505 | }; |
| 5506 | |
| 5507 | template <class _CharT, class _Traits, class _RT> |
| 5508 | basic_ostream<_CharT, _Traits>& |
| 5509 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5510 | const chi_squared_distribution<_RT>& __x) |
| 5511 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5512 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5513 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5514 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5515 | _OStream::scientific); |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5516 | __os << __x.n(); |
| 5517 | return __os; |
| 5518 | } |
| 5519 | |
| 5520 | template <class _CharT, class _Traits, class _RT> |
| 5521 | basic_istream<_CharT, _Traits>& |
| 5522 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5523 | chi_squared_distribution<_RT>& __x) |
| 5524 | { |
| 5525 | typedef chi_squared_distribution<_RT> _Eng; |
| 5526 | typedef typename _Eng::result_type result_type; |
| 5527 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5528 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5529 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5530 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5531 | result_type __n; |
| 5532 | __is >> __n; |
| 5533 | if (!__is.fail()) |
| 5534 | __x.param(param_type(__n)); |
| 5535 | return __is; |
| 5536 | } |
| 5537 | |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5538 | // cauchy_distribution |
| 5539 | |
| 5540 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5541 | class _LIBCPP_TEMPLATE_VIS cauchy_distribution |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5542 | { |
| 5543 | public: |
| 5544 | // types |
| 5545 | typedef _RealType result_type; |
| 5546 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5547 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5548 | { |
| 5549 | result_type __a_; |
| 5550 | result_type __b_; |
| 5551 | public: |
| 5552 | typedef cauchy_distribution distribution_type; |
| 5553 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5554 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5555 | explicit param_type(result_type __a = 0, result_type __b = 1) |
| 5556 | : __a_(__a), __b_(__b) {} |
| 5557 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5558 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5559 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5560 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5561 | result_type b() const {return __b_;} |
| 5562 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5563 | friend _LIBCPP_INLINE_VISIBILITY |
| 5564 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5565 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5566 | friend _LIBCPP_INLINE_VISIBILITY |
| 5567 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5568 | {return !(__x == __y);} |
| 5569 | }; |
| 5570 | |
| 5571 | private: |
| 5572 | param_type __p_; |
| 5573 | |
| 5574 | public: |
| 5575 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5577 | explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) |
| 5578 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5579 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5580 | explicit cauchy_distribution(const param_type& __p) |
| 5581 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5582 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5583 | void reset() {} |
| 5584 | |
| 5585 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5586 | template<class _URNG> |
| 5587 | _LIBCPP_INLINE_VISIBILITY |
| 5588 | result_type operator()(_URNG& __g) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5589 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5590 | 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] | 5591 | |
| 5592 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5593 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5594 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5595 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5596 | result_type b() const {return __p_.b();} |
| 5597 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5598 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5599 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5600 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5601 | void param(const param_type& __p) {__p_ = __p;} |
| 5602 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5603 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5604 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5605 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5606 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5607 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5608 | friend _LIBCPP_INLINE_VISIBILITY |
| 5609 | bool operator==(const cauchy_distribution& __x, |
| 5610 | const cauchy_distribution& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5611 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5612 | friend _LIBCPP_INLINE_VISIBILITY |
| 5613 | bool operator!=(const cauchy_distribution& __x, |
| 5614 | const cauchy_distribution& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5615 | {return !(__x == __y);} |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5616 | }; |
| 5617 | |
| 5618 | template <class _RealType> |
| 5619 | template<class _URNG> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5620 | inline |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5621 | _RealType |
| 5622 | cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5623 | { |
| 5624 | uniform_real_distribution<result_type> __gen; |
| 5625 | // 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] | 5626 | return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5627 | } |
| 5628 | |
| 5629 | template <class _CharT, class _Traits, class _RT> |
| 5630 | basic_ostream<_CharT, _Traits>& |
| 5631 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5632 | const cauchy_distribution<_RT>& __x) |
| 5633 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5634 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5635 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5636 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5637 | _OStream::scientific); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5638 | _CharT __sp = __os.widen(' '); |
| 5639 | __os.fill(__sp); |
| 5640 | __os << __x.a() << __sp << __x.b(); |
| 5641 | return __os; |
| 5642 | } |
| 5643 | |
| 5644 | template <class _CharT, class _Traits, class _RT> |
| 5645 | basic_istream<_CharT, _Traits>& |
| 5646 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5647 | cauchy_distribution<_RT>& __x) |
| 5648 | { |
| 5649 | typedef cauchy_distribution<_RT> _Eng; |
| 5650 | typedef typename _Eng::result_type result_type; |
| 5651 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5652 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5653 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5654 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5655 | result_type __a; |
| 5656 | result_type __b; |
| 5657 | __is >> __a >> __b; |
| 5658 | if (!__is.fail()) |
| 5659 | __x.param(param_type(__a, __b)); |
| 5660 | return __is; |
| 5661 | } |
| 5662 | |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5663 | // fisher_f_distribution |
| 5664 | |
| 5665 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5666 | class _LIBCPP_TEMPLATE_VIS fisher_f_distribution |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5667 | { |
| 5668 | public: |
| 5669 | // types |
| 5670 | typedef _RealType result_type; |
| 5671 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5672 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5673 | { |
| 5674 | result_type __m_; |
| 5675 | result_type __n_; |
| 5676 | public: |
| 5677 | typedef fisher_f_distribution distribution_type; |
| 5678 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5679 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5680 | explicit param_type(result_type __m = 1, result_type __n = 1) |
| 5681 | : __m_(__m), __n_(__n) {} |
| 5682 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5683 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5684 | result_type m() const {return __m_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5685 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5686 | result_type n() const {return __n_;} |
| 5687 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5688 | friend _LIBCPP_INLINE_VISIBILITY |
| 5689 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5690 | {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5691 | friend _LIBCPP_INLINE_VISIBILITY |
| 5692 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5693 | {return !(__x == __y);} |
| 5694 | }; |
| 5695 | |
| 5696 | private: |
| 5697 | param_type __p_; |
| 5698 | |
| 5699 | public: |
| 5700 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5701 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5702 | explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) |
| 5703 | : __p_(param_type(__m, __n)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5704 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5705 | explicit fisher_f_distribution(const param_type& __p) |
| 5706 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5707 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5708 | void reset() {} |
| 5709 | |
| 5710 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5711 | template<class _URNG> |
| 5712 | _LIBCPP_INLINE_VISIBILITY |
| 5713 | result_type operator()(_URNG& __g) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5714 | {return (*this)(__g, __p_);} |
| 5715 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5716 | |
| 5717 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5718 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5719 | result_type m() const {return __p_.m();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5720 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5721 | result_type n() const {return __p_.n();} |
| 5722 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5723 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5724 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5725 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5726 | void param(const param_type& __p) {__p_ = __p;} |
| 5727 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5728 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5729 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5730 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5731 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5732 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5733 | friend _LIBCPP_INLINE_VISIBILITY |
| 5734 | bool operator==(const fisher_f_distribution& __x, |
| 5735 | const fisher_f_distribution& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5736 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5737 | friend _LIBCPP_INLINE_VISIBILITY |
| 5738 | bool operator!=(const fisher_f_distribution& __x, |
| 5739 | const fisher_f_distribution& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5740 | {return !(__x == __y);} |
| 5741 | }; |
| 5742 | |
| 5743 | template <class _RealType> |
| 5744 | template<class _URNG> |
| 5745 | _RealType |
| 5746 | fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5747 | { |
| 5748 | gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); |
| 5749 | gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); |
| 5750 | return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); |
| 5751 | } |
| 5752 | |
| 5753 | template <class _CharT, class _Traits, class _RT> |
| 5754 | basic_ostream<_CharT, _Traits>& |
| 5755 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5756 | const fisher_f_distribution<_RT>& __x) |
| 5757 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5758 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5759 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5760 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5761 | _OStream::scientific); |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5762 | _CharT __sp = __os.widen(' '); |
| 5763 | __os.fill(__sp); |
| 5764 | __os << __x.m() << __sp << __x.n(); |
| 5765 | return __os; |
| 5766 | } |
| 5767 | |
| 5768 | template <class _CharT, class _Traits, class _RT> |
| 5769 | basic_istream<_CharT, _Traits>& |
| 5770 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5771 | fisher_f_distribution<_RT>& __x) |
| 5772 | { |
| 5773 | typedef fisher_f_distribution<_RT> _Eng; |
| 5774 | typedef typename _Eng::result_type result_type; |
| 5775 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5776 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5777 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5778 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5779 | result_type __m; |
| 5780 | result_type __n; |
| 5781 | __is >> __m >> __n; |
| 5782 | if (!__is.fail()) |
| 5783 | __x.param(param_type(__m, __n)); |
| 5784 | return __is; |
| 5785 | } |
| 5786 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5787 | // student_t_distribution |
| 5788 | |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5789 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5790 | class _LIBCPP_TEMPLATE_VIS student_t_distribution |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5791 | { |
| 5792 | public: |
| 5793 | // types |
| 5794 | typedef _RealType result_type; |
| 5795 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5796 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5797 | { |
| 5798 | result_type __n_; |
| 5799 | public: |
| 5800 | typedef student_t_distribution distribution_type; |
| 5801 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5803 | explicit param_type(result_type __n = 1) : __n_(__n) {} |
| 5804 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5805 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5806 | result_type n() const {return __n_;} |
| 5807 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5808 | friend _LIBCPP_INLINE_VISIBILITY |
| 5809 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5810 | {return __x.__n_ == __y.__n_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5811 | friend _LIBCPP_INLINE_VISIBILITY |
| 5812 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5813 | {return !(__x == __y);} |
| 5814 | }; |
| 5815 | |
| 5816 | private: |
| 5817 | param_type __p_; |
| 5818 | normal_distribution<result_type> __nd_; |
| 5819 | |
| 5820 | public: |
| 5821 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5822 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5823 | explicit student_t_distribution(result_type __n = 1) |
| 5824 | : __p_(param_type(__n)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5825 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5826 | explicit student_t_distribution(const param_type& __p) |
| 5827 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5828 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5829 | void reset() {__nd_.reset();} |
| 5830 | |
| 5831 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5832 | template<class _URNG> |
| 5833 | _LIBCPP_INLINE_VISIBILITY |
| 5834 | result_type operator()(_URNG& __g) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5835 | {return (*this)(__g, __p_);} |
| 5836 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5837 | |
| 5838 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5839 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5840 | result_type n() const {return __p_.n();} |
| 5841 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5842 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5843 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5844 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5845 | void param(const param_type& __p) {__p_ = __p;} |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5846 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5847 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5848 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5849 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5850 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 5851 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5852 | friend _LIBCPP_INLINE_VISIBILITY |
| 5853 | bool operator==(const student_t_distribution& __x, |
| 5854 | const student_t_distribution& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5855 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5856 | friend _LIBCPP_INLINE_VISIBILITY |
| 5857 | bool operator!=(const student_t_distribution& __x, |
| 5858 | const student_t_distribution& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5859 | {return !(__x == __y);} |
| 5860 | }; |
| 5861 | |
| 5862 | template <class _RealType> |
| 5863 | template<class _URNG> |
| 5864 | _RealType |
| 5865 | student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5866 | { |
| 5867 | gamma_distribution<result_type> __gd(__p.n() * .5, 2); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5868 | return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5869 | } |
| 5870 | |
| 5871 | template <class _CharT, class _Traits, class _RT> |
| 5872 | basic_ostream<_CharT, _Traits>& |
| 5873 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5874 | const student_t_distribution<_RT>& __x) |
| 5875 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5876 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5877 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5878 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5879 | _OStream::scientific); |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5880 | __os << __x.n(); |
| 5881 | return __os; |
| 5882 | } |
| 5883 | |
| 5884 | template <class _CharT, class _Traits, class _RT> |
| 5885 | basic_istream<_CharT, _Traits>& |
| 5886 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5887 | student_t_distribution<_RT>& __x) |
| 5888 | { |
| 5889 | typedef student_t_distribution<_RT> _Eng; |
| 5890 | typedef typename _Eng::result_type result_type; |
| 5891 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5892 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 5893 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5894 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5895 | result_type __n; |
| 5896 | __is >> __n; |
| 5897 | if (!__is.fail()) |
| 5898 | __x.param(param_type(__n)); |
| 5899 | return __is; |
| 5900 | } |
| 5901 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5902 | // discrete_distribution |
| 5903 | |
| 5904 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5905 | class _LIBCPP_TEMPLATE_VIS discrete_distribution |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5906 | { |
| 5907 | public: |
| 5908 | // types |
| 5909 | typedef _IntType result_type; |
| 5910 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5911 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5912 | { |
| 5913 | vector<double> __p_; |
| 5914 | public: |
| 5915 | typedef discrete_distribution distribution_type; |
| 5916 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5917 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5918 | param_type() {} |
| 5919 | template<class _InputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5920 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5921 | param_type(_InputIterator __f, _InputIterator __l) |
| 5922 | : __p_(__f, __l) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5923 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5924 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5925 | param_type(initializer_list<double> __wl) |
| 5926 | : __p_(__wl.begin(), __wl.end()) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5927 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5928 | template<class _UnaryOperation> |
| 5929 | param_type(size_t __nw, double __xmin, double __xmax, |
| 5930 | _UnaryOperation __fw); |
| 5931 | |
| 5932 | vector<double> probabilities() const; |
| 5933 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5934 | friend _LIBCPP_INLINE_VISIBILITY |
| 5935 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5936 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5937 | friend _LIBCPP_INLINE_VISIBILITY |
| 5938 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5939 | {return !(__x == __y);} |
| 5940 | |
| 5941 | private: |
| 5942 | void __init(); |
| 5943 | |
| 5944 | friend class discrete_distribution; |
| 5945 | |
| 5946 | template <class _CharT, class _Traits, class _IT> |
| 5947 | friend |
| 5948 | basic_ostream<_CharT, _Traits>& |
| 5949 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5950 | const discrete_distribution<_IT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5951 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5952 | template <class _CharT, class _Traits, class _IT> |
| 5953 | friend |
| 5954 | basic_istream<_CharT, _Traits>& |
| 5955 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5956 | discrete_distribution<_IT>& __x); |
| 5957 | }; |
| 5958 | |
| 5959 | private: |
| 5960 | param_type __p_; |
| 5961 | |
| 5962 | public: |
| 5963 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5964 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5965 | discrete_distribution() {} |
| 5966 | template<class _InputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5967 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5968 | discrete_distribution(_InputIterator __f, _InputIterator __l) |
| 5969 | : __p_(__f, __l) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5970 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5971 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5972 | discrete_distribution(initializer_list<double> __wl) |
| 5973 | : __p_(__wl) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5974 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5975 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5976 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5977 | discrete_distribution(size_t __nw, double __xmin, double __xmax, |
| 5978 | _UnaryOperation __fw) |
| 5979 | : __p_(__nw, __xmin, __xmax, __fw) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5980 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 5981 | explicit discrete_distribution(const param_type& __p) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5982 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5983 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5984 | void reset() {} |
| 5985 | |
| 5986 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5987 | template<class _URNG> |
| 5988 | _LIBCPP_INLINE_VISIBILITY |
| 5989 | result_type operator()(_URNG& __g) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5990 | {return (*this)(__g, __p_);} |
| 5991 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5992 | |
| 5993 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5994 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5995 | vector<double> probabilities() const {return __p_.probabilities();} |
| 5996 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5997 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5998 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5999 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6000 | void param(const param_type& __p) {__p_ = __p;} |
| 6001 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6002 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6003 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6004 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6005 | result_type max() const {return __p_.__p_.size();} |
| 6006 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6007 | friend _LIBCPP_INLINE_VISIBILITY |
| 6008 | bool operator==(const discrete_distribution& __x, |
| 6009 | const discrete_distribution& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6010 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6011 | friend _LIBCPP_INLINE_VISIBILITY |
| 6012 | bool operator!=(const discrete_distribution& __x, |
| 6013 | const discrete_distribution& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6014 | {return !(__x == __y);} |
| 6015 | |
| 6016 | template <class _CharT, class _Traits, class _IT> |
| 6017 | friend |
| 6018 | basic_ostream<_CharT, _Traits>& |
| 6019 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6020 | const discrete_distribution<_IT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6021 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6022 | template <class _CharT, class _Traits, class _IT> |
| 6023 | friend |
| 6024 | basic_istream<_CharT, _Traits>& |
| 6025 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6026 | discrete_distribution<_IT>& __x); |
| 6027 | }; |
| 6028 | |
| 6029 | template<class _IntType> |
| 6030 | template<class _UnaryOperation> |
| 6031 | discrete_distribution<_IntType>::param_type::param_type(size_t __nw, |
| 6032 | double __xmin, |
| 6033 | double __xmax, |
| 6034 | _UnaryOperation __fw) |
| 6035 | { |
| 6036 | if (__nw > 1) |
| 6037 | { |
| 6038 | __p_.reserve(__nw - 1); |
| 6039 | double __d = (__xmax - __xmin) / __nw; |
| 6040 | double __d2 = __d / 2; |
| 6041 | for (size_t __k = 0; __k < __nw; ++__k) |
| 6042 | __p_.push_back(__fw(__xmin + __k * __d + __d2)); |
| 6043 | __init(); |
| 6044 | } |
| 6045 | } |
| 6046 | |
| 6047 | template<class _IntType> |
| 6048 | void |
| 6049 | discrete_distribution<_IntType>::param_type::__init() |
| 6050 | { |
| 6051 | if (!__p_.empty()) |
| 6052 | { |
| 6053 | if (__p_.size() > 1) |
| 6054 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6055 | double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); |
| 6056 | for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6057 | __i < __e; ++__i) |
| 6058 | *__i /= __s; |
| 6059 | vector<double> __t(__p_.size() - 1); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6060 | _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6061 | swap(__p_, __t); |
| 6062 | } |
| 6063 | else |
| 6064 | { |
| 6065 | __p_.clear(); |
| 6066 | __p_.shrink_to_fit(); |
| 6067 | } |
| 6068 | } |
| 6069 | } |
| 6070 | |
| 6071 | template<class _IntType> |
| 6072 | vector<double> |
| 6073 | discrete_distribution<_IntType>::param_type::probabilities() const |
| 6074 | { |
| 6075 | size_t __n = __p_.size(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6076 | _VSTD::vector<double> __p(__n+1); |
| 6077 | _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6078 | if (__n > 0) |
| 6079 | __p[__n] = 1 - __p_[__n-1]; |
| 6080 | else |
| 6081 | __p[0] = 1; |
| 6082 | return __p; |
| 6083 | } |
| 6084 | |
| 6085 | template<class _IntType> |
| 6086 | template<class _URNG> |
| 6087 | _IntType |
| 6088 | discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) |
| 6089 | { |
| 6090 | uniform_real_distribution<double> __gen; |
| 6091 | return static_cast<_IntType>( |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6092 | _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6093 | __p.__p_.begin()); |
| 6094 | } |
| 6095 | |
| 6096 | template <class _CharT, class _Traits, class _IT> |
| 6097 | basic_ostream<_CharT, _Traits>& |
| 6098 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6099 | const discrete_distribution<_IT>& __x) |
| 6100 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6101 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 6102 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6103 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6104 | _OStream::scientific); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6105 | _CharT __sp = __os.widen(' '); |
| 6106 | __os.fill(__sp); |
| 6107 | size_t __n = __x.__p_.__p_.size(); |
| 6108 | __os << __n; |
| 6109 | for (size_t __i = 0; __i < __n; ++__i) |
| 6110 | __os << __sp << __x.__p_.__p_[__i]; |
| 6111 | return __os; |
| 6112 | } |
| 6113 | |
| 6114 | template <class _CharT, class _Traits, class _IT> |
| 6115 | basic_istream<_CharT, _Traits>& |
| 6116 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6117 | discrete_distribution<_IT>& __x) |
| 6118 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6119 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 6120 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6121 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6122 | size_t __n; |
| 6123 | __is >> __n; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6124 | vector<double> __p(__n); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6125 | for (size_t __i = 0; __i < __n; ++__i) |
| 6126 | __is >> __p[__i]; |
| 6127 | if (!__is.fail()) |
| 6128 | swap(__x.__p_.__p_, __p); |
| 6129 | return __is; |
| 6130 | } |
| 6131 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6132 | // piecewise_constant_distribution |
| 6133 | |
| 6134 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6135 | class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6136 | { |
| 6137 | public: |
| 6138 | // types |
| 6139 | typedef _RealType result_type; |
| 6140 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6141 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6142 | { |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6143 | vector<result_type> __b_; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6144 | vector<result_type> __densities_; |
| 6145 | vector<result_type> __areas_; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6146 | public: |
| 6147 | typedef piecewise_constant_distribution distribution_type; |
| 6148 | |
| 6149 | param_type(); |
| 6150 | template<class _InputIteratorB, class _InputIteratorW> |
| 6151 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, |
| 6152 | _InputIteratorW __fW); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6153 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6154 | template<class _UnaryOperation> |
| 6155 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6156 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6157 | template<class _UnaryOperation> |
| 6158 | param_type(size_t __nw, result_type __xmin, result_type __xmax, |
| 6159 | _UnaryOperation __fw); |
Eric Fiselier | b9f37ca | 2019-12-12 20:48:11 -0500 | [diff] [blame] | 6160 | param_type(param_type const&) = default; |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6161 | param_type & operator=(const param_type& __rhs); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6162 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6163 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6164 | vector<result_type> intervals() const {return __b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6165 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6166 | vector<result_type> densities() const {return __densities_;} |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6167 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6168 | friend _LIBCPP_INLINE_VISIBILITY |
| 6169 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6170 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6171 | friend _LIBCPP_INLINE_VISIBILITY |
| 6172 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6173 | {return !(__x == __y);} |
| 6174 | |
| 6175 | private: |
| 6176 | void __init(); |
| 6177 | |
| 6178 | friend class piecewise_constant_distribution; |
| 6179 | |
| 6180 | template <class _CharT, class _Traits, class _RT> |
| 6181 | friend |
| 6182 | basic_ostream<_CharT, _Traits>& |
| 6183 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6184 | const piecewise_constant_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6185 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6186 | template <class _CharT, class _Traits, class _RT> |
| 6187 | friend |
| 6188 | basic_istream<_CharT, _Traits>& |
| 6189 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6190 | piecewise_constant_distribution<_RT>& __x); |
| 6191 | }; |
| 6192 | |
| 6193 | private: |
| 6194 | param_type __p_; |
| 6195 | |
| 6196 | public: |
| 6197 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6198 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6199 | piecewise_constant_distribution() {} |
| 6200 | template<class _InputIteratorB, class _InputIteratorW> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6201 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6202 | piecewise_constant_distribution(_InputIteratorB __fB, |
| 6203 | _InputIteratorB __lB, |
| 6204 | _InputIteratorW __fW) |
| 6205 | : __p_(__fB, __lB, __fW) {} |
| 6206 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6207 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6208 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6209 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6210 | piecewise_constant_distribution(initializer_list<result_type> __bl, |
| 6211 | _UnaryOperation __fw) |
| 6212 | : __p_(__bl, __fw) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6213 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6214 | |
| 6215 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6216 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6217 | piecewise_constant_distribution(size_t __nw, result_type __xmin, |
| 6218 | result_type __xmax, _UnaryOperation __fw) |
| 6219 | : __p_(__nw, __xmin, __xmax, __fw) {} |
| 6220 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6221 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6222 | explicit piecewise_constant_distribution(const param_type& __p) |
| 6223 | : __p_(__p) {} |
| 6224 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6225 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6226 | void reset() {} |
| 6227 | |
| 6228 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6229 | template<class _URNG> |
| 6230 | _LIBCPP_INLINE_VISIBILITY |
| 6231 | result_type operator()(_URNG& __g) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6232 | {return (*this)(__g, __p_);} |
| 6233 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6234 | |
| 6235 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6236 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6237 | vector<result_type> intervals() const {return __p_.intervals();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6238 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6239 | vector<result_type> densities() const {return __p_.densities();} |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6240 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6241 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6242 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6243 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6244 | void param(const param_type& __p) {__p_ = __p;} |
| 6245 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6246 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6247 | result_type min() const {return __p_.__b_.front();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6248 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6249 | result_type max() const {return __p_.__b_.back();} |
| 6250 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6251 | friend _LIBCPP_INLINE_VISIBILITY |
| 6252 | bool operator==(const piecewise_constant_distribution& __x, |
| 6253 | const piecewise_constant_distribution& __y) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6254 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6255 | friend _LIBCPP_INLINE_VISIBILITY |
| 6256 | bool operator!=(const piecewise_constant_distribution& __x, |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6257 | const piecewise_constant_distribution& __y) |
| 6258 | {return !(__x == __y);} |
| 6259 | |
| 6260 | template <class _CharT, class _Traits, class _RT> |
| 6261 | friend |
| 6262 | basic_ostream<_CharT, _Traits>& |
| 6263 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6264 | const piecewise_constant_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6265 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6266 | template <class _CharT, class _Traits, class _RT> |
| 6267 | friend |
| 6268 | basic_istream<_CharT, _Traits>& |
| 6269 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6270 | piecewise_constant_distribution<_RT>& __x); |
| 6271 | }; |
| 6272 | |
| 6273 | template<class _RealType> |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6274 | typename piecewise_constant_distribution<_RealType>::param_type & |
| 6275 | piecewise_constant_distribution<_RealType>::param_type::operator= |
| 6276 | (const param_type& __rhs) |
| 6277 | { |
| 6278 | // These can throw |
| 6279 | __b_.reserve (__rhs.__b_.size ()); |
| 6280 | __densities_.reserve(__rhs.__densities_.size()); |
| 6281 | __areas_.reserve (__rhs.__areas_.size()); |
| 6282 | |
| 6283 | // These can not throw |
| 6284 | __b_ = __rhs.__b_; |
| 6285 | __densities_ = __rhs.__densities_; |
| 6286 | __areas_ = __rhs.__areas_; |
| 6287 | return *this; |
| 6288 | } |
| 6289 | |
| 6290 | template<class _RealType> |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6291 | void |
| 6292 | piecewise_constant_distribution<_RealType>::param_type::__init() |
| 6293 | { |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6294 | // __densities_ contains non-normalized areas |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6295 | result_type __total_area = _VSTD::accumulate(__densities_.begin(), |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6296 | __densities_.end(), |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6297 | result_type()); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6298 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
| 6299 | __densities_[__i] /= __total_area; |
| 6300 | // __densities_ contains normalized areas |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6301 | __areas_.assign(__densities_.size(), result_type()); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6302 | _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6303 | __areas_.begin() + 1); |
| 6304 | // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] |
| 6305 | __densities_.back() = 1 - __areas_.back(); // correct round off error |
| 6306 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
| 6307 | __densities_[__i] /= (__b_[__i+1] - __b_[__i]); |
| 6308 | // __densities_ now contains __densities_ |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6309 | } |
| 6310 | |
| 6311 | template<class _RealType> |
| 6312 | piecewise_constant_distribution<_RealType>::param_type::param_type() |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6313 | : __b_(2), |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6314 | __densities_(1, 1.0), |
| 6315 | __areas_(1, 0.0) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6316 | { |
| 6317 | __b_[1] = 1; |
| 6318 | } |
| 6319 | |
| 6320 | template<class _RealType> |
| 6321 | template<class _InputIteratorB, class _InputIteratorW> |
| 6322 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6323 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) |
| 6324 | : __b_(__fB, __lB) |
| 6325 | { |
| 6326 | if (__b_.size() < 2) |
| 6327 | { |
| 6328 | __b_.resize(2); |
| 6329 | __b_[0] = 0; |
| 6330 | __b_[1] = 1; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6331 | __densities_.assign(1, 1.0); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6332 | __areas_.assign(1, 0.0); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6333 | } |
| 6334 | else |
| 6335 | { |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6336 | __densities_.reserve(__b_.size() - 1); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6337 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6338 | __densities_.push_back(*__fW); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6339 | __init(); |
| 6340 | } |
| 6341 | } |
| 6342 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6343 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6344 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6345 | template<class _RealType> |
| 6346 | template<class _UnaryOperation> |
| 6347 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6348 | initializer_list<result_type> __bl, _UnaryOperation __fw) |
| 6349 | : __b_(__bl.begin(), __bl.end()) |
| 6350 | { |
| 6351 | if (__b_.size() < 2) |
| 6352 | { |
| 6353 | __b_.resize(2); |
| 6354 | __b_[0] = 0; |
| 6355 | __b_[1] = 1; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6356 | __densities_.assign(1, 1.0); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6357 | __areas_.assign(1, 0.0); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6358 | } |
| 6359 | else |
| 6360 | { |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6361 | __densities_.reserve(__b_.size() - 1); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6362 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6363 | __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6364 | __init(); |
| 6365 | } |
| 6366 | } |
| 6367 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6368 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6369 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6370 | template<class _RealType> |
| 6371 | template<class _UnaryOperation> |
| 6372 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6373 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) |
| 6374 | : __b_(__nw == 0 ? 2 : __nw + 1) |
| 6375 | { |
| 6376 | size_t __n = __b_.size() - 1; |
| 6377 | result_type __d = (__xmax - __xmin) / __n; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6378 | __densities_.reserve(__n); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6379 | for (size_t __i = 0; __i < __n; ++__i) |
| 6380 | { |
| 6381 | __b_[__i] = __xmin + __i * __d; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6382 | __densities_.push_back(__fw(__b_[__i] + __d*.5)); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6383 | } |
| 6384 | __b_[__n] = __xmax; |
| 6385 | __init(); |
| 6386 | } |
| 6387 | |
| 6388 | template<class _RealType> |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6389 | template<class _URNG> |
| 6390 | _RealType |
| 6391 | piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 6392 | { |
| 6393 | typedef uniform_real_distribution<result_type> _Gen; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6394 | result_type __u = _Gen()(__g); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6395 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6396 | __u) - __p.__areas_.begin() - 1; |
| 6397 | return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6398 | } |
| 6399 | |
| 6400 | template <class _CharT, class _Traits, class _RT> |
| 6401 | basic_ostream<_CharT, _Traits>& |
| 6402 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6403 | const piecewise_constant_distribution<_RT>& __x) |
| 6404 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6405 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 6406 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6407 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6408 | _OStream::scientific); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6409 | _CharT __sp = __os.widen(' '); |
| 6410 | __os.fill(__sp); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6411 | size_t __n = __x.__p_.__b_.size(); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6412 | __os << __n; |
| 6413 | for (size_t __i = 0; __i < __n; ++__i) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6414 | __os << __sp << __x.__p_.__b_[__i]; |
| 6415 | __n = __x.__p_.__densities_.size(); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6416 | __os << __sp << __n; |
| 6417 | for (size_t __i = 0; __i < __n; ++__i) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6418 | __os << __sp << __x.__p_.__densities_[__i]; |
| 6419 | __n = __x.__p_.__areas_.size(); |
| 6420 | __os << __sp << __n; |
| 6421 | for (size_t __i = 0; __i < __n; ++__i) |
| 6422 | __os << __sp << __x.__p_.__areas_[__i]; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6423 | return __os; |
| 6424 | } |
| 6425 | |
| 6426 | template <class _CharT, class _Traits, class _RT> |
| 6427 | basic_istream<_CharT, _Traits>& |
| 6428 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6429 | piecewise_constant_distribution<_RT>& __x) |
| 6430 | { |
| 6431 | typedef piecewise_constant_distribution<_RT> _Eng; |
| 6432 | typedef typename _Eng::result_type result_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6433 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 6434 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6435 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6436 | size_t __n; |
| 6437 | __is >> __n; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6438 | vector<result_type> __b(__n); |
| 6439 | for (size_t __i = 0; __i < __n; ++__i) |
| 6440 | __is >> __b[__i]; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6441 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6442 | vector<result_type> __densities(__n); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6443 | for (size_t __i = 0; __i < __n; ++__i) |
| 6444 | __is >> __densities[__i]; |
| 6445 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6446 | vector<result_type> __areas(__n); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6447 | for (size_t __i = 0; __i < __n; ++__i) |
| 6448 | __is >> __areas[__i]; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6449 | if (!__is.fail()) |
| 6450 | { |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6451 | swap(__x.__p_.__b_, __b); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6452 | swap(__x.__p_.__densities_, __densities); |
| 6453 | swap(__x.__p_.__areas_, __areas); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6454 | } |
| 6455 | return __is; |
| 6456 | } |
| 6457 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6458 | // piecewise_linear_distribution |
| 6459 | |
| 6460 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6461 | class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6462 | { |
| 6463 | public: |
| 6464 | // types |
| 6465 | typedef _RealType result_type; |
| 6466 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6467 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6468 | { |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6469 | vector<result_type> __b_; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6470 | vector<result_type> __densities_; |
| 6471 | vector<result_type> __areas_; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6472 | public: |
| 6473 | typedef piecewise_linear_distribution distribution_type; |
| 6474 | |
| 6475 | param_type(); |
| 6476 | template<class _InputIteratorB, class _InputIteratorW> |
| 6477 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, |
| 6478 | _InputIteratorW __fW); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6479 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6480 | template<class _UnaryOperation> |
| 6481 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6482 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6483 | template<class _UnaryOperation> |
| 6484 | param_type(size_t __nw, result_type __xmin, result_type __xmax, |
| 6485 | _UnaryOperation __fw); |
Eric Fiselier | b9f37ca | 2019-12-12 20:48:11 -0500 | [diff] [blame] | 6486 | param_type(param_type const&) = default; |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6487 | param_type & operator=(const param_type& __rhs); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6488 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6489 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6490 | vector<result_type> intervals() const {return __b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6491 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6492 | vector<result_type> densities() const {return __densities_;} |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6493 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6494 | friend _LIBCPP_INLINE_VISIBILITY |
| 6495 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6496 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6497 | friend _LIBCPP_INLINE_VISIBILITY |
| 6498 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6499 | {return !(__x == __y);} |
| 6500 | |
| 6501 | private: |
| 6502 | void __init(); |
| 6503 | |
| 6504 | friend class piecewise_linear_distribution; |
| 6505 | |
| 6506 | template <class _CharT, class _Traits, class _RT> |
| 6507 | friend |
| 6508 | basic_ostream<_CharT, _Traits>& |
| 6509 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6510 | const piecewise_linear_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6511 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6512 | template <class _CharT, class _Traits, class _RT> |
| 6513 | friend |
| 6514 | basic_istream<_CharT, _Traits>& |
| 6515 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6516 | piecewise_linear_distribution<_RT>& __x); |
| 6517 | }; |
| 6518 | |
| 6519 | private: |
| 6520 | param_type __p_; |
| 6521 | |
| 6522 | public: |
| 6523 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6524 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6525 | piecewise_linear_distribution() {} |
| 6526 | template<class _InputIteratorB, class _InputIteratorW> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6528 | piecewise_linear_distribution(_InputIteratorB __fB, |
| 6529 | _InputIteratorB __lB, |
| 6530 | _InputIteratorW __fW) |
| 6531 | : __p_(__fB, __lB, __fW) {} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6532 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6533 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6534 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6535 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6536 | piecewise_linear_distribution(initializer_list<result_type> __bl, |
| 6537 | _UnaryOperation __fw) |
| 6538 | : __p_(__bl, __fw) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6539 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6540 | |
| 6541 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6543 | piecewise_linear_distribution(size_t __nw, result_type __xmin, |
| 6544 | result_type __xmax, _UnaryOperation __fw) |
| 6545 | : __p_(__nw, __xmin, __xmax, __fw) {} |
| 6546 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6547 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6548 | explicit piecewise_linear_distribution(const param_type& __p) |
| 6549 | : __p_(__p) {} |
| 6550 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6551 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6552 | void reset() {} |
| 6553 | |
| 6554 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6555 | template<class _URNG> |
| 6556 | _LIBCPP_INLINE_VISIBILITY |
| 6557 | result_type operator()(_URNG& __g) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6558 | {return (*this)(__g, __p_);} |
| 6559 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6560 | |
| 6561 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6562 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6563 | vector<result_type> intervals() const {return __p_.intervals();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6564 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6565 | vector<result_type> densities() const {return __p_.densities();} |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6566 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6567 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6568 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6569 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6570 | void param(const param_type& __p) {__p_ = __p;} |
| 6571 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6572 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6573 | result_type min() const {return __p_.__b_.front();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6575 | result_type max() const {return __p_.__b_.back();} |
| 6576 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6577 | friend _LIBCPP_INLINE_VISIBILITY |
| 6578 | bool operator==(const piecewise_linear_distribution& __x, |
| 6579 | const piecewise_linear_distribution& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6580 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6581 | friend _LIBCPP_INLINE_VISIBILITY |
| 6582 | bool operator!=(const piecewise_linear_distribution& __x, |
| 6583 | const piecewise_linear_distribution& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6584 | {return !(__x == __y);} |
| 6585 | |
| 6586 | template <class _CharT, class _Traits, class _RT> |
| 6587 | friend |
| 6588 | basic_ostream<_CharT, _Traits>& |
| 6589 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6590 | const piecewise_linear_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6591 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6592 | template <class _CharT, class _Traits, class _RT> |
| 6593 | friend |
| 6594 | basic_istream<_CharT, _Traits>& |
| 6595 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6596 | piecewise_linear_distribution<_RT>& __x); |
| 6597 | }; |
| 6598 | |
| 6599 | template<class _RealType> |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6600 | typename piecewise_linear_distribution<_RealType>::param_type & |
| 6601 | piecewise_linear_distribution<_RealType>::param_type::operator= |
| 6602 | (const param_type& __rhs) |
| 6603 | { |
| 6604 | // These can throw |
| 6605 | __b_.reserve (__rhs.__b_.size ()); |
| 6606 | __densities_.reserve(__rhs.__densities_.size()); |
| 6607 | __areas_.reserve (__rhs.__areas_.size()); |
| 6608 | |
| 6609 | // These can not throw |
| 6610 | __b_ = __rhs.__b_; |
| 6611 | __densities_ = __rhs.__densities_; |
| 6612 | __areas_ = __rhs.__areas_; |
| 6613 | return *this; |
| 6614 | } |
| 6615 | |
| 6616 | |
| 6617 | template<class _RealType> |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6618 | void |
| 6619 | piecewise_linear_distribution<_RealType>::param_type::__init() |
| 6620 | { |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6621 | __areas_.assign(__densities_.size() - 1, result_type()); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6622 | result_type _Sp = 0; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6623 | for (size_t __i = 0; __i < __areas_.size(); ++__i) |
| 6624 | { |
| 6625 | __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * |
| 6626 | (__b_[__i+1] - __b_[__i]) * .5; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6627 | _Sp += __areas_[__i]; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6628 | } |
| 6629 | for (size_t __i = __areas_.size(); __i > 1;) |
| 6630 | { |
| 6631 | --__i; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6632 | __areas_[__i] = __areas_[__i-1] / _Sp; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6633 | } |
| 6634 | __areas_[0] = 0; |
| 6635 | for (size_t __i = 1; __i < __areas_.size(); ++__i) |
| 6636 | __areas_[__i] += __areas_[__i-1]; |
| 6637 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6638 | __densities_[__i] /= _Sp; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6639 | } |
| 6640 | |
| 6641 | template<class _RealType> |
| 6642 | piecewise_linear_distribution<_RealType>::param_type::param_type() |
| 6643 | : __b_(2), |
| 6644 | __densities_(2, 1.0), |
| 6645 | __areas_(1, 0.0) |
| 6646 | { |
| 6647 | __b_[1] = 1; |
| 6648 | } |
| 6649 | |
| 6650 | template<class _RealType> |
| 6651 | template<class _InputIteratorB, class _InputIteratorW> |
| 6652 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6653 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) |
| 6654 | : __b_(__fB, __lB) |
| 6655 | { |
| 6656 | if (__b_.size() < 2) |
| 6657 | { |
| 6658 | __b_.resize(2); |
| 6659 | __b_[0] = 0; |
| 6660 | __b_[1] = 1; |
| 6661 | __densities_.assign(2, 1.0); |
| 6662 | __areas_.assign(1, 0.0); |
| 6663 | } |
| 6664 | else |
| 6665 | { |
| 6666 | __densities_.reserve(__b_.size()); |
| 6667 | for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) |
| 6668 | __densities_.push_back(*__fW); |
| 6669 | __init(); |
| 6670 | } |
| 6671 | } |
| 6672 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6673 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6674 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6675 | template<class _RealType> |
| 6676 | template<class _UnaryOperation> |
| 6677 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6678 | initializer_list<result_type> __bl, _UnaryOperation __fw) |
| 6679 | : __b_(__bl.begin(), __bl.end()) |
| 6680 | { |
| 6681 | if (__b_.size() < 2) |
| 6682 | { |
| 6683 | __b_.resize(2); |
| 6684 | __b_[0] = 0; |
| 6685 | __b_[1] = 1; |
| 6686 | __densities_.assign(2, 1.0); |
| 6687 | __areas_.assign(1, 0.0); |
| 6688 | } |
| 6689 | else |
| 6690 | { |
| 6691 | __densities_.reserve(__b_.size()); |
| 6692 | for (size_t __i = 0; __i < __b_.size(); ++__i) |
| 6693 | __densities_.push_back(__fw(__b_[__i])); |
| 6694 | __init(); |
| 6695 | } |
| 6696 | } |
| 6697 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6698 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6699 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6700 | template<class _RealType> |
| 6701 | template<class _UnaryOperation> |
| 6702 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6703 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) |
| 6704 | : __b_(__nw == 0 ? 2 : __nw + 1) |
| 6705 | { |
| 6706 | size_t __n = __b_.size() - 1; |
| 6707 | result_type __d = (__xmax - __xmin) / __n; |
| 6708 | __densities_.reserve(__b_.size()); |
| 6709 | for (size_t __i = 0; __i < __n; ++__i) |
| 6710 | { |
| 6711 | __b_[__i] = __xmin + __i * __d; |
| 6712 | __densities_.push_back(__fw(__b_[__i])); |
| 6713 | } |
| 6714 | __b_[__n] = __xmax; |
| 6715 | __densities_.push_back(__fw(__b_[__n])); |
| 6716 | __init(); |
| 6717 | } |
| 6718 | |
| 6719 | template<class _RealType> |
| 6720 | template<class _URNG> |
| 6721 | _RealType |
| 6722 | piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 6723 | { |
| 6724 | typedef uniform_real_distribution<result_type> _Gen; |
| 6725 | result_type __u = _Gen()(__g); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6726 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6727 | __u) - __p.__areas_.begin() - 1; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6728 | __u -= __p.__areas_[__k]; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6729 | const result_type __dk = __p.__densities_[__k]; |
| 6730 | const result_type __dk1 = __p.__densities_[__k+1]; |
| 6731 | const result_type __deltad = __dk1 - __dk; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6732 | const result_type __bk = __p.__b_[__k]; |
| 6733 | if (__deltad == 0) |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6734 | return __u / __dk + __bk; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6735 | const result_type __bk1 = __p.__b_[__k+1]; |
| 6736 | const result_type __deltab = __bk1 - __bk; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6737 | return (__bk * __dk1 - __bk1 * __dk + |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6738 | _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6739 | __deltad; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6740 | } |
| 6741 | |
| 6742 | template <class _CharT, class _Traits, class _RT> |
| 6743 | basic_ostream<_CharT, _Traits>& |
| 6744 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6745 | const piecewise_linear_distribution<_RT>& __x) |
| 6746 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6747 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 6748 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6749 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6750 | _OStream::scientific); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6751 | _CharT __sp = __os.widen(' '); |
| 6752 | __os.fill(__sp); |
| 6753 | size_t __n = __x.__p_.__b_.size(); |
| 6754 | __os << __n; |
| 6755 | for (size_t __i = 0; __i < __n; ++__i) |
| 6756 | __os << __sp << __x.__p_.__b_[__i]; |
| 6757 | __n = __x.__p_.__densities_.size(); |
| 6758 | __os << __sp << __n; |
| 6759 | for (size_t __i = 0; __i < __n; ++__i) |
| 6760 | __os << __sp << __x.__p_.__densities_[__i]; |
| 6761 | __n = __x.__p_.__areas_.size(); |
| 6762 | __os << __sp << __n; |
| 6763 | for (size_t __i = 0; __i < __n; ++__i) |
| 6764 | __os << __sp << __x.__p_.__areas_[__i]; |
| 6765 | return __os; |
| 6766 | } |
| 6767 | |
| 6768 | template <class _CharT, class _Traits, class _RT> |
| 6769 | basic_istream<_CharT, _Traits>& |
| 6770 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6771 | piecewise_linear_distribution<_RT>& __x) |
| 6772 | { |
| 6773 | typedef piecewise_linear_distribution<_RT> _Eng; |
| 6774 | typedef typename _Eng::result_type result_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6775 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame^] | 6776 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6777 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6778 | size_t __n; |
| 6779 | __is >> __n; |
| 6780 | vector<result_type> __b(__n); |
| 6781 | for (size_t __i = 0; __i < __n; ++__i) |
| 6782 | __is >> __b[__i]; |
| 6783 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6784 | vector<result_type> __densities(__n); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6785 | for (size_t __i = 0; __i < __n; ++__i) |
| 6786 | __is >> __densities[__i]; |
| 6787 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6788 | vector<result_type> __areas(__n); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6789 | for (size_t __i = 0; __i < __n; ++__i) |
| 6790 | __is >> __areas[__i]; |
| 6791 | if (!__is.fail()) |
| 6792 | { |
| 6793 | swap(__x.__p_.__b_, __b); |
| 6794 | swap(__x.__p_.__densities_, __densities); |
| 6795 | swap(__x.__p_.__areas_, __areas); |
| 6796 | } |
| 6797 | return __is; |
| 6798 | } |
| 6799 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6800 | _LIBCPP_END_NAMESPACE_STD |
| 6801 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 6802 | _LIBCPP_POP_MACROS |
| 6803 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6804 | #endif // _LIBCPP_RANDOM |