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, |
zoecarver | 68c3702 | 2020-11-10 18:23:22 -0800 | [diff] [blame] | 1671 | bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a), |
| 1672 | bool _OverflowOK = ((__m|__m-1) > __m), // m = 2^n |
| 1673 | bool _SchrageOK = (__a != 0 && __m != 0 && __m % __a <= __m / __a)> // r <= q |
| 1674 | struct __lce_alg_picker |
| 1675 | { |
| 1676 | static_assert(__a != 0 || __m != 0 || !_MightOverflow || _OverflowOK || _SchrageOK, |
| 1677 | "The current values of a, c, and m cannot generate a number " |
| 1678 | "within bounds of linear_congruential_engine."); |
| 1679 | |
| 1680 | static _LIBCPP_CONSTEXPR const bool __use_schrage = _MightOverflow && |
| 1681 | !_OverflowOK && |
| 1682 | _SchrageOK; |
| 1683 | }; |
| 1684 | |
| 1685 | template <unsigned long long __a, unsigned long long __c, |
| 1686 | unsigned long long __m, unsigned long long _Mp, |
| 1687 | bool _UseSchrage = __lce_alg_picker<__a, __c, __m, _Mp>::__use_schrage> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1688 | struct __lce_ta; |
| 1689 | |
| 1690 | // 64 |
| 1691 | |
| 1692 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> |
| 1693 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> |
| 1694 | { |
| 1695 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1696 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1697 | static result_type next(result_type __x) |
| 1698 | { |
| 1699 | // Schrage's algorithm |
| 1700 | const result_type __q = __m / __a; |
| 1701 | const result_type __r = __m % __a; |
| 1702 | const result_type __t0 = __a * (__x % __q); |
| 1703 | const result_type __t1 = __r * (__x / __q); |
| 1704 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1705 | __x += __c - (__x >= __m - __c) * __m; |
| 1706 | return __x; |
| 1707 | } |
| 1708 | }; |
| 1709 | |
| 1710 | template <unsigned long long __a, unsigned long long __m> |
| 1711 | struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> |
| 1712 | { |
| 1713 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1714 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1715 | static result_type next(result_type __x) |
| 1716 | { |
| 1717 | // Schrage's algorithm |
| 1718 | const result_type __q = __m / __a; |
| 1719 | const result_type __r = __m % __a; |
| 1720 | const result_type __t0 = __a * (__x % __q); |
| 1721 | const result_type __t1 = __r * (__x / __q); |
| 1722 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1723 | return __x; |
| 1724 | } |
| 1725 | }; |
| 1726 | |
| 1727 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> |
| 1728 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> |
| 1729 | { |
| 1730 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1731 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1732 | static result_type next(result_type __x) |
| 1733 | { |
| 1734 | return (__a * __x + __c) % __m; |
| 1735 | } |
| 1736 | }; |
| 1737 | |
| 1738 | template <unsigned long long __a, unsigned long long __c> |
| 1739 | struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> |
| 1740 | { |
| 1741 | typedef unsigned long long result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1742 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1743 | static result_type next(result_type __x) |
| 1744 | { |
| 1745 | return __a * __x + __c; |
| 1746 | } |
| 1747 | }; |
| 1748 | |
| 1749 | // 32 |
| 1750 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1751 | template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> |
| 1752 | struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1753 | { |
| 1754 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1755 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1756 | static result_type next(result_type __x) |
| 1757 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1758 | const result_type __a = static_cast<result_type>(_Ap); |
| 1759 | const result_type __c = static_cast<result_type>(_Cp); |
| 1760 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1761 | // Schrage's algorithm |
| 1762 | const result_type __q = __m / __a; |
| 1763 | const result_type __r = __m % __a; |
| 1764 | const result_type __t0 = __a * (__x % __q); |
| 1765 | const result_type __t1 = __r * (__x / __q); |
| 1766 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1767 | __x += __c - (__x >= __m - __c) * __m; |
| 1768 | return __x; |
| 1769 | } |
| 1770 | }; |
| 1771 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1772 | template <unsigned long long _Ap, unsigned long long _Mp> |
| 1773 | struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1774 | { |
| 1775 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1776 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1777 | static result_type next(result_type __x) |
| 1778 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1779 | const result_type __a = static_cast<result_type>(_Ap); |
| 1780 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1781 | // Schrage's algorithm |
| 1782 | const result_type __q = __m / __a; |
| 1783 | const result_type __r = __m % __a; |
| 1784 | const result_type __t0 = __a * (__x % __q); |
| 1785 | const result_type __t1 = __r * (__x / __q); |
| 1786 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1787 | return __x; |
| 1788 | } |
| 1789 | }; |
| 1790 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1791 | template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> |
| 1792 | struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1793 | { |
| 1794 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1795 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1796 | static result_type next(result_type __x) |
| 1797 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1798 | const result_type __a = static_cast<result_type>(_Ap); |
| 1799 | const result_type __c = static_cast<result_type>(_Cp); |
| 1800 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1801 | return (__a * __x + __c) % __m; |
| 1802 | } |
| 1803 | }; |
| 1804 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1805 | template <unsigned long long _Ap, unsigned long long _Cp> |
| 1806 | struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1807 | { |
| 1808 | typedef unsigned result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1809 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1810 | static result_type next(result_type __x) |
| 1811 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1812 | const result_type __a = static_cast<result_type>(_Ap); |
| 1813 | const result_type __c = static_cast<result_type>(_Cp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1814 | return __a * __x + __c; |
| 1815 | } |
| 1816 | }; |
| 1817 | |
| 1818 | // 16 |
| 1819 | |
| 1820 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> |
| 1821 | struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> |
| 1822 | { |
| 1823 | typedef unsigned short result_type; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1824 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1825 | static result_type next(result_type __x) |
| 1826 | { |
| 1827 | return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); |
| 1828 | } |
| 1829 | }; |
| 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 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1835 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1836 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | basic_ostream<_CharT, _Traits>& |
| 1838 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1839 | const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1840 | |
| 1841 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1842 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1843 | basic_istream<_CharT, _Traits>& |
| 1844 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1845 | linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1846 | |
| 1847 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1848 | class _LIBCPP_TEMPLATE_VIS linear_congruential_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1849 | { |
| 1850 | public: |
| 1851 | // types |
| 1852 | typedef _UIntType result_type; |
| 1853 | |
Howard Hinnant | a741b24 | 2013-05-21 21:19:35 +0000 | [diff] [blame] | 1854 | private: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1855 | result_type __x_; |
| 1856 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1857 | static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1858 | |
| 1859 | static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); |
| 1860 | static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); |
zoecarver | 68c3702 | 2020-11-10 18:23:22 -0800 | [diff] [blame] | 1861 | static_assert(_VSTD::is_unsigned<_UIntType>::value, "_UIntType must be unsigned type"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1862 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1863 | static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; |
| 1864 | static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); |
| 1866 | |
| 1867 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1868 | static _LIBCPP_CONSTEXPR const result_type multiplier = __a; |
| 1869 | static _LIBCPP_CONSTEXPR const result_type increment = __c; |
| 1870 | static _LIBCPP_CONSTEXPR const result_type modulus = __m; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1871 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1872 | static _LIBCPP_CONSTEXPR result_type min() {return _Min;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1873 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1874 | static _LIBCPP_CONSTEXPR result_type max() {return _Max;} |
| 1875 | static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1876 | |
| 1877 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1878 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1879 | explicit linear_congruential_engine(result_type __s = default_seed) |
| 1880 | {seed(__s);} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1881 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1882 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1883 | explicit linear_congruential_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1884 | 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] | 1885 | {seed(__q);} |
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 | void seed(result_type __s = default_seed) |
| 1888 | {seed(integral_constant<bool, __m == 0>(), |
| 1889 | integral_constant<bool, __c == 0>(), __s);} |
| 1890 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1891 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1892 | typename enable_if |
| 1893 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1894 | __is_seed_sequence<_Sseq, linear_congruential_engine>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1895 | void |
| 1896 | >::type |
| 1897 | seed(_Sseq& __q) |
| 1898 | {__seed(__q, integral_constant<unsigned, |
| 1899 | 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 |
Howard Hinnant | a0c4f7c | 2013-05-21 21:05:12 +0000 | [diff] [blame] | 1900 | : (__m > 0x100000000ull))>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1901 | |
| 1902 | // generating functions |
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 | result_type operator()() |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1905 | {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] | 1906 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1907 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 1908 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1909 | friend _LIBCPP_INLINE_VISIBILITY |
| 1910 | bool operator==(const linear_congruential_engine& __x, |
| 1911 | const linear_congruential_engine& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1912 | {return __x.__x_ == __y.__x_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1913 | friend _LIBCPP_INLINE_VISIBILITY |
| 1914 | bool operator!=(const linear_congruential_engine& __x, |
| 1915 | const linear_congruential_engine& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1916 | {return !(__x == __y);} |
| 1917 | |
| 1918 | private: |
| 1919 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1920 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1921 | 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] | 1922 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1923 | void seed(true_type, false_type, result_type __s) {__x_ = __s;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1924 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1925 | void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? |
| 1926 | 1 : __s % __m;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1927 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1928 | void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} |
| 1929 | |
| 1930 | template<class _Sseq> |
| 1931 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 1932 | template<class _Sseq> |
| 1933 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 1934 | |
| 1935 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1936 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1937 | friend |
| 1938 | basic_ostream<_CharT, _Traits>& |
| 1939 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1940 | const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1941 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1942 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1943 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1944 | friend |
| 1945 | basic_istream<_CharT, _Traits>& |
| 1946 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1947 | linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1948 | }; |
| 1949 | |
| 1950 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 1951 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1952 | linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; |
| 1953 | |
| 1954 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1955 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1956 | linear_congruential_engine<_UIntType, __a, __c, __m>::increment; |
| 1957 | |
| 1958 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1959 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1960 | linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; |
| 1961 | |
| 1962 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1963 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1964 | linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; |
| 1965 | |
| 1966 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1967 | template<class _Sseq> |
| 1968 | void |
| 1969 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, |
| 1970 | integral_constant<unsigned, 1>) |
| 1971 | { |
| 1972 | const unsigned __k = 1; |
| 1973 | uint32_t __ar[__k+3]; |
| 1974 | __q.generate(__ar, __ar + __k + 3); |
| 1975 | result_type __s = static_cast<result_type>(__ar[3] % __m); |
| 1976 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; |
| 1977 | } |
| 1978 | |
| 1979 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1980 | template<class _Sseq> |
| 1981 | void |
| 1982 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, |
| 1983 | integral_constant<unsigned, 2>) |
| 1984 | { |
| 1985 | const unsigned __k = 2; |
| 1986 | uint32_t __ar[__k+3]; |
| 1987 | __q.generate(__ar, __ar + __k + 3); |
| 1988 | result_type __s = static_cast<result_type>((__ar[3] + |
Howard Hinnant | a0c4f7c | 2013-05-21 21:05:12 +0000 | [diff] [blame] | 1989 | ((uint64_t)__ar[4] << 32)) % __m); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1990 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; |
| 1991 | } |
| 1992 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1993 | template <class _CharT, class _Traits, |
| 1994 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1995 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1996 | basic_ostream<_CharT, _Traits>& |
| 1997 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 1998 | const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) |
| 1999 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2000 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2001 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2002 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2003 | __os.fill(__os.widen(' ')); |
| 2004 | return __os << __x.__x_; |
| 2005 | } |
| 2006 | |
| 2007 | template <class _CharT, class _Traits, |
| 2008 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 2009 | basic_istream<_CharT, _Traits>& |
| 2010 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 2011 | linear_congruential_engine<_UIntType, __a, __c, __m>& __x) |
| 2012 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2013 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2014 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2015 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2016 | _UIntType __t; |
| 2017 | __is >> __t; |
| 2018 | if (!__is.fail()) |
| 2019 | __x.__x_ = __t; |
| 2020 | return __is; |
| 2021 | } |
| 2022 | |
| 2023 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> |
| 2024 | minstd_rand0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2025 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> |
| 2026 | minstd_rand; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 2027 | typedef minstd_rand default_random_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2028 | // mersenne_twister_engine |
| 2029 | |
| 2030 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2031 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2032 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2033 | class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2034 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2035 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2036 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2037 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2038 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2039 | 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] | 2040 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2041 | 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] | 2042 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2043 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2044 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2045 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2046 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 2047 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2048 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2049 | 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] | 2050 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2051 | 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] | 2052 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2053 | |
| 2054 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2055 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2056 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2057 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2058 | basic_ostream<_CharT, _Traits>& |
| 2059 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2060 | 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] | 2061 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2062 | |
| 2063 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2064 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2065 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2066 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2067 | basic_istream<_CharT, _Traits>& |
| 2068 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2069 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2070 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2071 | |
| 2072 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2073 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2074 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2075 | class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2076 | { |
| 2077 | public: |
| 2078 | // types |
| 2079 | typedef _UIntType result_type; |
| 2080 | |
| 2081 | private: |
| 2082 | result_type __x_[__n]; |
| 2083 | size_t __i_; |
| 2084 | |
| 2085 | static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); |
| 2086 | static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2087 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2088 | static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); |
| 2089 | static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); |
| 2090 | static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); |
| 2091 | static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); |
| 2092 | static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); |
| 2093 | static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); |
| 2094 | static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); |
| 2095 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2096 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 2097 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 2098 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2099 | static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); |
| 2100 | static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2101 | static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2102 | static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2103 | static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2104 | static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2105 | |
| 2106 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2107 | static _LIBCPP_CONSTEXPR const size_t word_size = __w; |
| 2108 | static _LIBCPP_CONSTEXPR const size_t state_size = __n; |
| 2109 | static _LIBCPP_CONSTEXPR const size_t shift_size = __m; |
| 2110 | static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; |
| 2111 | static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; |
| 2112 | static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; |
| 2113 | static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; |
| 2114 | static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; |
| 2115 | static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; |
| 2116 | static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; |
| 2117 | static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; |
| 2118 | static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; |
| 2119 | static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2120 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2121 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2122 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2123 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
| 2124 | static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2125 | |
| 2126 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2127 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2128 | explicit mersenne_twister_engine(result_type __sd = default_seed) |
| 2129 | {seed(__sd);} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2130 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2131 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2132 | explicit mersenne_twister_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2133 | 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] | 2134 | {seed(__q);} |
| 2135 | void seed(result_type __sd = default_seed); |
| 2136 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2138 | typename enable_if |
| 2139 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2140 | __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2141 | void |
| 2142 | >::type |
| 2143 | seed(_Sseq& __q) |
| 2144 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2145 | |
| 2146 | // generating functions |
| 2147 | result_type operator()(); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2148 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2149 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2150 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2151 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2152 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2153 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2154 | friend |
| 2155 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2156 | 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] | 2157 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2158 | 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] | 2159 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2160 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2161 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2162 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2163 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2164 | friend |
| 2165 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2166 | 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] | 2167 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2168 | 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] | 2169 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2170 | |
| 2171 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2172 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2173 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2174 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2175 | friend |
| 2176 | basic_ostream<_CharT, _Traits>& |
| 2177 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2178 | 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] | 2179 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2180 | |
| 2181 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2182 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2183 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2184 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2185 | friend |
| 2186 | basic_istream<_CharT, _Traits>& |
| 2187 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2188 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2189 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2190 | private: |
| 2191 | |
| 2192 | template<class _Sseq> |
| 2193 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 2194 | template<class _Sseq> |
| 2195 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 2196 | |
| 2197 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2198 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2199 | static |
| 2200 | typename enable_if |
| 2201 | < |
| 2202 | __count < __w, |
| 2203 | result_type |
| 2204 | >::type |
| 2205 | __lshift(result_type __x) {return (__x << __count) & _Max;} |
| 2206 | |
| 2207 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2208 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2209 | static |
| 2210 | typename enable_if |
| 2211 | < |
| 2212 | (__count >= __w), |
| 2213 | result_type |
| 2214 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2215 | __lshift(result_type) {return result_type(0);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2216 | |
| 2217 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2218 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2219 | static |
| 2220 | typename enable_if |
| 2221 | < |
| 2222 | __count < _Dt, |
| 2223 | result_type |
| 2224 | >::type |
| 2225 | __rshift(result_type __x) {return __x >> __count;} |
| 2226 | |
| 2227 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2228 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2229 | static |
| 2230 | typename enable_if |
| 2231 | < |
| 2232 | (__count >= _Dt), |
| 2233 | result_type |
| 2234 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2235 | __rshift(result_type) {return result_type(0);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2236 | }; |
| 2237 | |
| 2238 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2239 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2240 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2241 | _LIBCPP_CONSTEXPR const size_t |
| 2242 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; |
| 2243 | |
| 2244 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2245 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2246 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2247 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2248 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; |
| 2249 | |
| 2250 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2251 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2252 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2253 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2254 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; |
| 2255 | |
| 2256 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2257 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2258 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2259 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2260 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; |
| 2261 | |
| 2262 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2263 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2264 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2265 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2266 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; |
| 2267 | |
| 2268 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2269 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2270 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2271 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2272 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; |
| 2273 | |
| 2274 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2275 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2276 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2277 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2278 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; |
| 2279 | |
| 2280 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2281 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2282 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2283 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2284 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; |
| 2285 | |
| 2286 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2287 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2288 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2289 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2290 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; |
| 2291 | |
| 2292 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2293 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2294 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2295 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2296 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; |
| 2297 | |
| 2298 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2299 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2300 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2301 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2302 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; |
| 2303 | |
| 2304 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2305 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2306 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 2307 | _LIBCPP_CONSTEXPR const size_t |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2308 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; |
| 2309 | |
| 2310 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2311 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2312 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2313 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2314 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; |
| 2315 | |
| 2316 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2317 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2318 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2319 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2320 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; |
| 2321 | |
| 2322 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2323 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2324 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2325 | void |
| 2326 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2327 | __t, __c, __l, __f>::seed(result_type __sd) |
Marshall Clow | c189463 | 2017-09-11 18:10:33 +0000 | [diff] [blame] | 2328 | _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2329 | { // __w >= 2 |
| 2330 | __x_[0] = __sd & _Max; |
| 2331 | for (size_t __i = 1; __i < __n; ++__i) |
| 2332 | __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; |
| 2333 | __i_ = 0; |
| 2334 | } |
| 2335 | |
| 2336 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2337 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2338 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2339 | template<class _Sseq> |
| 2340 | void |
| 2341 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2342 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) |
| 2343 | { |
| 2344 | const unsigned __k = 1; |
| 2345 | uint32_t __ar[__n * __k]; |
| 2346 | __q.generate(__ar, __ar + __n * __k); |
| 2347 | for (size_t __i = 0; __i < __n; ++__i) |
| 2348 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); |
| 2349 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2350 | (result_type(1) << __r) - result_type(1); |
| 2351 | __i_ = 0; |
| 2352 | if ((__x_[0] & ~__mask) == 0) |
| 2353 | { |
| 2354 | for (size_t __i = 1; __i < __n; ++__i) |
| 2355 | if (__x_[__i] != 0) |
| 2356 | return; |
Hubert Tong | ca5b776 | 2018-08-16 23:56:54 +0000 | [diff] [blame] | 2357 | __x_[0] = result_type(1) << (__w - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2362 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2363 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2364 | template<class _Sseq> |
| 2365 | void |
| 2366 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2367 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) |
| 2368 | { |
| 2369 | const unsigned __k = 2; |
| 2370 | uint32_t __ar[__n * __k]; |
| 2371 | __q.generate(__ar, __ar + __n * __k); |
| 2372 | for (size_t __i = 0; __i < __n; ++__i) |
| 2373 | __x_[__i] = static_cast<result_type>( |
| 2374 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); |
| 2375 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2376 | (result_type(1) << __r) - result_type(1); |
| 2377 | __i_ = 0; |
| 2378 | if ((__x_[0] & ~__mask) == 0) |
| 2379 | { |
| 2380 | for (size_t __i = 1; __i < __n; ++__i) |
| 2381 | if (__x_[__i] != 0) |
| 2382 | return; |
Hubert Tong | ca5b776 | 2018-08-16 23:56:54 +0000 | [diff] [blame] | 2383 | __x_[0] = result_type(1) << (__w - 1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2388 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2389 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2390 | _UIntType |
| 2391 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2392 | __t, __c, __l, __f>::operator()() |
| 2393 | { |
| 2394 | const size_t __j = (__i_ + 1) % __n; |
| 2395 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2396 | (result_type(1) << __r) - result_type(1); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2397 | const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2398 | const size_t __k = (__i_ + __m) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2399 | __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2400 | result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); |
| 2401 | __i_ = __j; |
| 2402 | __z ^= __lshift<__s>(__z) & __b; |
| 2403 | __z ^= __lshift<__t>(__z) & __c; |
| 2404 | return __z ^ __rshift<__l>(__z); |
| 2405 | } |
| 2406 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2407 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2408 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2409 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2410 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2411 | 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] | 2412 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2413 | 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] | 2414 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2415 | { |
| 2416 | if (__x.__i_ == __y.__i_) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2417 | return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2418 | if (__x.__i_ == 0 || __y.__i_ == 0) |
| 2419 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2420 | size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2421 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2422 | __y.__x_ + __y.__i_)) |
| 2423 | return false; |
| 2424 | if (__x.__i_ == 0) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2425 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); |
| 2426 | return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2427 | } |
| 2428 | if (__x.__i_ < __y.__i_) |
| 2429 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2430 | size_t __j = _Np - __y.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2431 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2432 | __y.__x_ + __y.__i_)) |
| 2433 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2434 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2435 | __y.__x_)) |
| 2436 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2437 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2438 | __y.__x_ + (_Np - (__x.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2439 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2440 | size_t __j = _Np - __x.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2441 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2442 | __x.__x_ + __x.__i_)) |
| 2443 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2444 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2445 | __x.__x_)) |
| 2446 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2447 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2448 | __x.__x_ + (_Np - (__y.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2449 | } |
| 2450 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2451 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2452 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2453 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2454 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2455 | bool |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2456 | 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] | 2457 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2458 | 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] | 2459 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2460 | { |
| 2461 | return !(__x == __y); |
| 2462 | } |
| 2463 | |
| 2464 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2465 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2466 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2467 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2468 | basic_ostream<_CharT, _Traits>& |
| 2469 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2470 | 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] | 2471 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2472 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2473 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2474 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2475 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2476 | _CharT __sp = __os.widen(' '); |
| 2477 | __os.fill(__sp); |
| 2478 | __os << __x.__x_[__x.__i_]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2479 | for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2480 | __os << __sp << __x.__x_[__j]; |
| 2481 | for (size_t __j = 0; __j < __x.__i_; ++__j) |
| 2482 | __os << __sp << __x.__x_[__j]; |
| 2483 | return __os; |
| 2484 | } |
| 2485 | |
| 2486 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2487 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2488 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2489 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2490 | basic_istream<_CharT, _Traits>& |
| 2491 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2492 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2493 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2494 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2495 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2496 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2497 | __is.flags(_Istream::dec | _Istream::skipws); |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2498 | _UInt __t[_Np]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2499 | for (size_t __i = 0; __i < _Np; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2500 | __is >> __t[__i]; |
| 2501 | if (!__is.fail()) |
| 2502 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2503 | for (size_t __i = 0; __i < _Np; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2504 | __x.__x_[__i] = __t[__i]; |
| 2505 | __x.__i_ = 0; |
| 2506 | } |
| 2507 | return __is; |
| 2508 | } |
| 2509 | |
| 2510 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, |
| 2511 | 0x9908b0df, 11, 0xffffffff, |
| 2512 | 7, 0x9d2c5680, |
| 2513 | 15, 0xefc60000, |
| 2514 | 18, 1812433253> mt19937; |
| 2515 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, |
| 2516 | 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, |
| 2517 | 17, 0x71d67fffeda60000ULL, |
| 2518 | 37, 0xfff7eee000000000ULL, |
| 2519 | 43, 6364136223846793005ULL> mt19937_64; |
| 2520 | |
| 2521 | // subtract_with_carry_engine |
| 2522 | |
| 2523 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2524 | class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2525 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2526 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2527 | bool |
| 2528 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2529 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2530 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2531 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2532 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | a54386e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 2533 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2534 | bool |
| 2535 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2536 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2537 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2538 | |
| 2539 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2540 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2541 | basic_ostream<_CharT, _Traits>& |
| 2542 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2543 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2544 | |
| 2545 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2546 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2547 | basic_istream<_CharT, _Traits>& |
| 2548 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2549 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2550 | |
| 2551 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2552 | class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2553 | { |
| 2554 | public: |
| 2555 | // types |
| 2556 | typedef _UIntType result_type; |
| 2557 | |
| 2558 | private: |
| 2559 | result_type __x_[__r]; |
| 2560 | result_type __c_; |
| 2561 | size_t __i_; |
| 2562 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2563 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2564 | static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); |
| 2565 | static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); |
| 2566 | static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); |
| 2567 | static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); |
| 2568 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2569 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 2570 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 2571 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2572 | static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); |
| 2573 | |
| 2574 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2575 | static _LIBCPP_CONSTEXPR const size_t word_size = __w; |
| 2576 | static _LIBCPP_CONSTEXPR const size_t short_lag = __s; |
| 2577 | static _LIBCPP_CONSTEXPR const size_t long_lag = __r; |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2579 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2581 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
| 2582 | static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2583 | |
| 2584 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2585 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2586 | explicit subtract_with_carry_engine(result_type __sd = default_seed) |
| 2587 | {seed(__sd);} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2588 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2589 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2590 | explicit subtract_with_carry_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2591 | 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] | 2592 | {seed(__q);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2593 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2594 | void seed(result_type __sd = default_seed) |
| 2595 | {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2596 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2597 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2598 | typename enable_if |
| 2599 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2600 | __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2601 | void |
| 2602 | >::type |
| 2603 | seed(_Sseq& __q) |
| 2604 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2605 | |
| 2606 | // generating functions |
| 2607 | result_type operator()(); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2608 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2609 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2610 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2611 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2612 | friend |
| 2613 | bool |
| 2614 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2615 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2616 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2617 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2618 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2619 | friend |
| 2620 | bool |
| 2621 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2622 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2623 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2624 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2625 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2626 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2627 | friend |
| 2628 | basic_ostream<_CharT, _Traits>& |
| 2629 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2630 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2631 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2632 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2633 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2634 | friend |
| 2635 | basic_istream<_CharT, _Traits>& |
| 2636 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2637 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2638 | |
| 2639 | private: |
| 2640 | |
| 2641 | void seed(result_type __sd, integral_constant<unsigned, 1>); |
| 2642 | void seed(result_type __sd, integral_constant<unsigned, 2>); |
| 2643 | template<class _Sseq> |
| 2644 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 2645 | template<class _Sseq> |
| 2646 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 2647 | }; |
| 2648 | |
| 2649 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2650 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; |
| 2651 | |
| 2652 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2653 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; |
| 2654 | |
| 2655 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2656 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; |
| 2657 | |
| 2658 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2659 | _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type |
| 2660 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; |
| 2661 | |
| 2662 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2663 | void |
| 2664 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, |
| 2665 | integral_constant<unsigned, 1>) |
| 2666 | { |
| 2667 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> |
| 2668 | __e(__sd == 0u ? default_seed : __sd); |
| 2669 | for (size_t __i = 0; __i < __r; ++__i) |
| 2670 | __x_[__i] = static_cast<result_type>(__e() & _Max); |
| 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 | void |
| 2677 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, |
| 2678 | integral_constant<unsigned, 2>) |
| 2679 | { |
| 2680 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> |
| 2681 | __e(__sd == 0u ? default_seed : __sd); |
| 2682 | for (size_t __i = 0; __i < __r; ++__i) |
Howard Hinnant | 93072c1 | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2683 | { |
| 2684 | result_type __e0 = __e(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2685 | __x_[__i] = static_cast<result_type>( |
Howard Hinnant | 93072c1 | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2686 | (__e0 + ((uint64_t)__e() << 32)) & _Max); |
| 2687 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2688 | __c_ = __x_[__r-1] == 0; |
| 2689 | __i_ = 0; |
| 2690 | } |
| 2691 | |
| 2692 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2693 | template<class _Sseq> |
| 2694 | void |
| 2695 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, |
| 2696 | integral_constant<unsigned, 1>) |
| 2697 | { |
| 2698 | const unsigned __k = 1; |
| 2699 | uint32_t __ar[__r * __k]; |
| 2700 | __q.generate(__ar, __ar + __r * __k); |
| 2701 | for (size_t __i = 0; __i < __r; ++__i) |
| 2702 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); |
| 2703 | __c_ = __x_[__r-1] == 0; |
| 2704 | __i_ = 0; |
| 2705 | } |
| 2706 | |
| 2707 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2708 | template<class _Sseq> |
| 2709 | void |
| 2710 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, |
| 2711 | integral_constant<unsigned, 2>) |
| 2712 | { |
| 2713 | const unsigned __k = 2; |
| 2714 | uint32_t __ar[__r * __k]; |
| 2715 | __q.generate(__ar, __ar + __r * __k); |
| 2716 | for (size_t __i = 0; __i < __r; ++__i) |
| 2717 | __x_[__i] = static_cast<result_type>( |
| 2718 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); |
| 2719 | __c_ = __x_[__r-1] == 0; |
| 2720 | __i_ = 0; |
| 2721 | } |
| 2722 | |
| 2723 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2724 | _UIntType |
| 2725 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() |
| 2726 | { |
| 2727 | const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; |
| 2728 | result_type& __xr = __x_[__i_]; |
| 2729 | result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; |
| 2730 | __xr = (__xs - __xr - __c_) & _Max; |
| 2731 | __c_ = __new_c; |
| 2732 | __i_ = (__i_ + 1) % __r; |
| 2733 | return __xr; |
| 2734 | } |
| 2735 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2736 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2737 | bool |
| 2738 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2739 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2740 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2741 | { |
| 2742 | if (__x.__c_ != __y.__c_) |
| 2743 | return false; |
| 2744 | if (__x.__i_ == __y.__i_) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2745 | return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2746 | if (__x.__i_ == 0 || __y.__i_ == 0) |
| 2747 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2748 | size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2749 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2750 | __y.__x_ + __y.__i_)) |
| 2751 | return false; |
| 2752 | if (__x.__i_ == 0) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2753 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); |
| 2754 | return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2755 | } |
| 2756 | if (__x.__i_ < __y.__i_) |
| 2757 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2758 | size_t __j = _Rp - __y.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2759 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2760 | __y.__x_ + __y.__i_)) |
| 2761 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2762 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2763 | __y.__x_)) |
| 2764 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2765 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2766 | __y.__x_ + (_Rp - (__x.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2767 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2768 | size_t __j = _Rp - __x.__i_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2769 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2770 | __x.__x_ + __x.__i_)) |
| 2771 | return false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2772 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2773 | __x.__x_)) |
| 2774 | return false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2775 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2776 | __x.__x_ + (_Rp - (__y.__i_ + __j))); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2779 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2780 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2781 | bool |
| 2782 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2783 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2784 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2785 | { |
| 2786 | return !(__x == __y); |
| 2787 | } |
| 2788 | |
| 2789 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2790 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2791 | basic_ostream<_CharT, _Traits>& |
| 2792 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2793 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2794 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2795 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2796 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2797 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2798 | _CharT __sp = __os.widen(' '); |
| 2799 | __os.fill(__sp); |
| 2800 | __os << __x.__x_[__x.__i_]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2801 | for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2802 | __os << __sp << __x.__x_[__j]; |
| 2803 | for (size_t __j = 0; __j < __x.__i_; ++__j) |
| 2804 | __os << __sp << __x.__x_[__j]; |
| 2805 | __os << __sp << __x.__c_; |
| 2806 | return __os; |
| 2807 | } |
| 2808 | |
| 2809 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2810 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2811 | basic_istream<_CharT, _Traits>& |
| 2812 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2813 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2814 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2815 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2816 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2817 | __is.flags(_Istream::dec | _Istream::skipws); |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2818 | _UInt __t[_Rp+1]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2819 | for (size_t __i = 0; __i < _Rp+1; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2820 | __is >> __t[__i]; |
| 2821 | if (!__is.fail()) |
| 2822 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2823 | for (size_t __i = 0; __i < _Rp; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2824 | __x.__x_[__i] = __t[__i]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2825 | __x.__c_ = __t[_Rp]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2826 | __x.__i_ = 0; |
| 2827 | } |
| 2828 | return __is; |
| 2829 | } |
| 2830 | |
| 2831 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; |
| 2832 | typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; |
| 2833 | |
| 2834 | // discard_block_engine |
| 2835 | |
| 2836 | template<class _Engine, size_t __p, size_t __r> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2837 | class _LIBCPP_TEMPLATE_VIS discard_block_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2838 | { |
| 2839 | _Engine __e_; |
| 2840 | int __n_; |
| 2841 | |
| 2842 | static_assert( 0 < __r, "discard_block_engine invalid parameters"); |
| 2843 | static_assert(__r <= __p, "discard_block_engine invalid parameters"); |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 2844 | static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2845 | public: |
| 2846 | // types |
| 2847 | typedef typename _Engine::result_type result_type; |
| 2848 | |
| 2849 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2850 | static _LIBCPP_CONSTEXPR const size_t block_size = __p; |
| 2851 | static _LIBCPP_CONSTEXPR const size_t used_block = __r; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2852 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2853 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2854 | static const result_type _Min = _Engine::_Min; |
| 2855 | static const result_type _Max = _Engine::_Max; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2856 | #else |
| 2857 | static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); |
| 2858 | static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); |
| 2859 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2860 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2861 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2862 | static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2863 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2864 | static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2865 | |
| 2866 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2867 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2868 | discard_block_engine() : __n_(0) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2869 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2870 | explicit discard_block_engine(const _Engine& __e) |
| 2871 | : __e_(__e), __n_(0) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2872 | #ifndef _LIBCPP_CXX03_LANG |
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 | explicit discard_block_engine(_Engine&& __e) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2875 | : __e_(_VSTD::move(__e)), __n_(0) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2876 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2877 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2878 | explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2879 | template<class _Sseq> |
| 2880 | _LIBCPP_INLINE_VISIBILITY |
| 2881 | explicit discard_block_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2882 | typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2883 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2884 | : __e_(__q), __n_(0) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2885 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2886 | void seed() {__e_.seed(); __n_ = 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2887 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2888 | void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2889 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2890 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2891 | typename enable_if |
| 2892 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2893 | __is_seed_sequence<_Sseq, discard_block_engine>::value, |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2894 | void |
| 2895 | >::type |
| 2896 | seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2897 | |
| 2898 | // generating functions |
| 2899 | result_type operator()(); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2900 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2901 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2902 | |
| 2903 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2904 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 2905 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2906 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2907 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2908 | friend |
| 2909 | bool |
| 2910 | operator==( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2911 | const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2912 | const discard_block_engine<_Eng, _Pp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2913 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2914 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2915 | friend |
| 2916 | bool |
| 2917 | operator!=( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2918 | const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2919 | const discard_block_engine<_Eng, _Pp, _Rp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2920 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2921 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2922 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2923 | friend |
| 2924 | basic_ostream<_CharT, _Traits>& |
| 2925 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2926 | const discard_block_engine<_Eng, _Pp, _Rp>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2927 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2928 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2929 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2930 | friend |
| 2931 | basic_istream<_CharT, _Traits>& |
| 2932 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2933 | discard_block_engine<_Eng, _Pp, _Rp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2934 | }; |
| 2935 | |
| 2936 | template<class _Engine, size_t __p, size_t __r> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2937 | _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; |
| 2938 | |
| 2939 | template<class _Engine, size_t __p, size_t __r> |
| 2940 | _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; |
| 2941 | |
| 2942 | template<class _Engine, size_t __p, size_t __r> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2943 | typename discard_block_engine<_Engine, __p, __r>::result_type |
| 2944 | discard_block_engine<_Engine, __p, __r>::operator()() |
| 2945 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 2946 | if (__n_ >= static_cast<int>(__r)) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2947 | { |
| 2948 | __e_.discard(__p - __r); |
| 2949 | __n_ = 0; |
| 2950 | } |
| 2951 | ++__n_; |
| 2952 | return __e_(); |
| 2953 | } |
| 2954 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2955 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2956 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2957 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2958 | operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2959 | const discard_block_engine<_Eng, _Pp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2960 | { |
| 2961 | return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; |
| 2962 | } |
| 2963 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2964 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2965 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2966 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2967 | operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2968 | const discard_block_engine<_Eng, _Pp, _Rp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2969 | { |
| 2970 | return !(__x == __y); |
| 2971 | } |
| 2972 | |
| 2973 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2974 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2975 | basic_ostream<_CharT, _Traits>& |
| 2976 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2977 | const discard_block_engine<_Eng, _Pp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2978 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2979 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2980 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 2981 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2982 | _CharT __sp = __os.widen(' '); |
| 2983 | __os.fill(__sp); |
| 2984 | return __os << __x.__e_ << __sp << __x.__n_; |
| 2985 | } |
| 2986 | |
| 2987 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2988 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2989 | basic_istream<_CharT, _Traits>& |
| 2990 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2991 | discard_block_engine<_Eng, _Pp, _Rp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2992 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2993 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 2994 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 2995 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2996 | _Eng __e; |
| 2997 | int __n; |
| 2998 | __is >> __e >> __n; |
| 2999 | if (!__is.fail()) |
| 3000 | { |
| 3001 | __x.__e_ = __e; |
| 3002 | __x.__n_ = __n; |
| 3003 | } |
| 3004 | return __is; |
| 3005 | } |
| 3006 | |
| 3007 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; |
| 3008 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; |
| 3009 | |
| 3010 | // independent_bits_engine |
| 3011 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3012 | template<class _Engine, size_t __w, class _UIntType> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3013 | class _LIBCPP_TEMPLATE_VIS independent_bits_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3014 | { |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3015 | template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3016 | class __get_n |
| 3017 | { |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3018 | static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3019 | static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); |
| 3020 | static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3021 | static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3022 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3023 | 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] | 3024 | }; |
| 3025 | public: |
| 3026 | // types |
| 3027 | typedef _UIntType result_type; |
| 3028 | |
| 3029 | private: |
| 3030 | _Engine __e_; |
| 3031 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3032 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3033 | static_assert( 0 < __w, "independent_bits_engine invalid parameters"); |
| 3034 | static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); |
| 3035 | |
| 3036 | typedef typename _Engine::result_type _Engine_result_type; |
| 3037 | typedef typename conditional |
| 3038 | < |
| 3039 | sizeof(_Engine_result_type) <= sizeof(result_type), |
| 3040 | result_type, |
| 3041 | _Engine_result_type |
| 3042 | >::type _Working_result_type; |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3043 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3044 | static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3045 | + _Working_result_type(1); |
| 3046 | #else |
| 3047 | static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() |
| 3048 | + _Working_result_type(1); |
| 3049 | #endif |
| 3050 | static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; |
| 3051 | static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; |
| 3052 | static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; |
| 3053 | static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; |
| 3054 | static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; |
| 3055 | static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; |
| 3056 | static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : |
| 3057 | (_Rp >> __w0) << __w0; |
| 3058 | static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : |
| 3059 | (_Rp >> (__w0+1)) << (__w0+1); |
| 3060 | static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3061 | _Engine_result_type(~0) >> (_EDt - __w0) : |
| 3062 | _Engine_result_type(0); |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3063 | static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3064 | _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : |
| 3065 | _Engine_result_type(~0); |
| 3066 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3067 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 3068 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 3069 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3070 | static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); |
| 3071 | |
| 3072 | // engine characteristics |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3073 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3074 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3075 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3076 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3077 | |
| 3078 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3079 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3080 | independent_bits_engine() {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3081 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3082 | explicit independent_bits_engine(const _Engine& __e) |
| 3083 | : __e_(__e) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3084 | #ifndef _LIBCPP_CXX03_LANG |
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 | explicit independent_bits_engine(_Engine&& __e) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3087 | : __e_(_VSTD::move(__e)) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3088 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3089 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3090 | explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3091 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3092 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3093 | explicit independent_bits_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3094 | typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3095 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3096 | : __e_(__q) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3097 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3098 | void seed() {__e_.seed();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3099 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3100 | void seed(result_type __sd) {__e_.seed(__sd);} |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3101 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3102 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3103 | typename enable_if |
| 3104 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3105 | __is_seed_sequence<_Sseq, independent_bits_engine>::value, |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3106 | void |
| 3107 | >::type |
| 3108 | seed(_Sseq& __q) {__e_.seed(__q);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3109 | |
| 3110 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3111 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3112 | result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3113 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3114 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 3115 | |
| 3116 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3117 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3118 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3119 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3120 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3121 | friend |
| 3122 | bool |
| 3123 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3124 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3125 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3126 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3127 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3128 | friend |
| 3129 | bool |
| 3130 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3131 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3132 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3133 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3134 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3135 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3136 | friend |
| 3137 | basic_ostream<_CharT, _Traits>& |
| 3138 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3139 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3140 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3141 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3142 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3143 | friend |
| 3144 | basic_istream<_CharT, _Traits>& |
| 3145 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3146 | independent_bits_engine<_Eng, _Wp, _UInt>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3147 | |
| 3148 | private: |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3149 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | fe77858 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3150 | result_type __eval(false_type); |
| 3151 | result_type __eval(true_type); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3152 | |
| 3153 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3154 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3155 | static |
| 3156 | typename enable_if |
| 3157 | < |
| 3158 | __count < _Dt, |
| 3159 | result_type |
| 3160 | >::type |
| 3161 | __lshift(result_type __x) {return __x << __count;} |
| 3162 | |
| 3163 | template <size_t __count> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3164 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3165 | static |
| 3166 | typename enable_if |
| 3167 | < |
| 3168 | (__count >= _Dt), |
| 3169 | result_type |
| 3170 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3171 | __lshift(result_type) {return result_type(0);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3172 | }; |
| 3173 | |
| 3174 | template<class _Engine, size_t __w, class _UIntType> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3175 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3176 | _UIntType |
Marshall Clow | fe77858 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3177 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3178 | { |
| 3179 | return static_cast<result_type>(__e_() & __mask0); |
| 3180 | } |
| 3181 | |
| 3182 | template<class _Engine, size_t __w, class _UIntType> |
| 3183 | _UIntType |
Marshall Clow | fe77858 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3184 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3185 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3186 | result_type _Sp = 0; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3187 | for (size_t __k = 0; __k < __n0; ++__k) |
| 3188 | { |
| 3189 | _Engine_result_type __u; |
| 3190 | do |
| 3191 | { |
| 3192 | __u = __e_() - _Engine::min(); |
| 3193 | } while (__u >= __y0); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3194 | _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3195 | } |
| 3196 | for (size_t __k = __n0; __k < __n; ++__k) |
| 3197 | { |
| 3198 | _Engine_result_type __u; |
| 3199 | do |
| 3200 | { |
| 3201 | __u = __e_() - _Engine::min(); |
| 3202 | } while (__u >= __y1); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3203 | _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3204 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3205 | return _Sp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3206 | } |
| 3207 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3208 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3209 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3210 | bool |
| 3211 | operator==( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3212 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3213 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3214 | { |
| 3215 | return __x.base() == __y.base(); |
| 3216 | } |
| 3217 | |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3218 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3219 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3220 | bool |
| 3221 | operator!=( |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3222 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3223 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3224 | { |
| 3225 | return !(__x == __y); |
| 3226 | } |
| 3227 | |
| 3228 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3229 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3230 | basic_ostream<_CharT, _Traits>& |
| 3231 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3232 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3233 | { |
| 3234 | return __os << __x.base(); |
| 3235 | } |
| 3236 | |
| 3237 | template <class _CharT, class _Traits, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3238 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3239 | basic_istream<_CharT, _Traits>& |
| 3240 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | 4638fca | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3241 | independent_bits_engine<_Eng, _Wp, _UInt>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3242 | { |
| 3243 | _Eng __e; |
| 3244 | __is >> __e; |
| 3245 | if (!__is.fail()) |
| 3246 | __x.__e_ = __e; |
| 3247 | return __is; |
| 3248 | } |
| 3249 | |
| 3250 | // shuffle_order_engine |
| 3251 | |
| 3252 | template <uint64_t _Xp, uint64_t _Yp> |
| 3253 | struct __ugcd |
| 3254 | { |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3255 | static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3256 | }; |
| 3257 | |
| 3258 | template <uint64_t _Xp> |
| 3259 | struct __ugcd<_Xp, 0> |
| 3260 | { |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3261 | static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3262 | }; |
| 3263 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3264 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3265 | class __uratio |
| 3266 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3267 | static_assert(_Dp != 0, "__uratio divide by 0"); |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3268 | static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3269 | public: |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3270 | static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; |
| 3271 | static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3272 | |
| 3273 | typedef __uratio<num, den> type; |
| 3274 | }; |
| 3275 | |
| 3276 | template<class _Engine, size_t __k> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3277 | class _LIBCPP_TEMPLATE_VIS shuffle_order_engine |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3278 | { |
| 3279 | static_assert(0 < __k, "shuffle_order_engine invalid parameters"); |
| 3280 | public: |
| 3281 | // types |
| 3282 | typedef typename _Engine::result_type result_type; |
| 3283 | |
| 3284 | private: |
| 3285 | _Engine __e_; |
| 3286 | result_type _V_[__k]; |
| 3287 | result_type _Y_; |
| 3288 | |
| 3289 | public: |
| 3290 | // engine characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3291 | static _LIBCPP_CONSTEXPR const size_t table_size = __k; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3292 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3293 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3294 | static const result_type _Min = _Engine::_Min; |
| 3295 | static const result_type _Max = _Engine::_Max; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3296 | #else |
| 3297 | static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); |
| 3298 | static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); |
| 3299 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3300 | static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3301 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3302 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3303 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3304 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3305 | |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3306 | static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3307 | |
| 3308 | // constructors and seeding functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3309 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3310 | shuffle_order_engine() {__init();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3311 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3312 | explicit shuffle_order_engine(const _Engine& __e) |
| 3313 | : __e_(__e) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3314 | #ifndef _LIBCPP_CXX03_LANG |
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 | explicit shuffle_order_engine(_Engine&& __e) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3317 | : __e_(_VSTD::move(__e)) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3318 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3319 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3320 | explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3321 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3322 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3323 | explicit shuffle_order_engine(_Sseq& __q, |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3324 | typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3325 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3326 | : __e_(__q) {__init();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3327 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3328 | void seed() {__e_.seed(); __init();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3329 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3330 | void seed(result_type __sd) {__e_.seed(__sd); __init();} |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3331 | template<class _Sseq> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3332 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3333 | typename enable_if |
| 3334 | < |
Howard Hinnant | c8c7399 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3335 | __is_seed_sequence<_Sseq, shuffle_order_engine>::value, |
Howard Hinnant | 6047d5b | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3336 | void |
| 3337 | >::type |
| 3338 | seed(_Sseq& __q) {__e_.seed(__q); __init();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3339 | |
| 3340 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3341 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3342 | result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3343 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3344 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 3345 | |
| 3346 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3347 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3348 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3349 | |
| 3350 | private: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3351 | template<class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3352 | friend |
| 3353 | bool |
| 3354 | operator==( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3355 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3356 | const shuffle_order_engine<_Eng, _Kp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3357 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3358 | template<class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3359 | friend |
| 3360 | bool |
| 3361 | operator!=( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3362 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3363 | const shuffle_order_engine<_Eng, _Kp>& __y); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3364 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3365 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3366 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3367 | friend |
| 3368 | basic_ostream<_CharT, _Traits>& |
| 3369 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3370 | const shuffle_order_engine<_Eng, _Kp>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3371 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3372 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3373 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3374 | friend |
| 3375 | basic_istream<_CharT, _Traits>& |
| 3376 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3377 | shuffle_order_engine<_Eng, _Kp>& __x); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3378 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3379 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3380 | void __init() |
| 3381 | { |
| 3382 | for (size_t __i = 0; __i < __k; ++__i) |
| 3383 | _V_[__i] = __e_(); |
| 3384 | _Y_ = __e_(); |
| 3385 | } |
| 3386 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3387 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3388 | result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3389 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3390 | result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3391 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3392 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3393 | result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3394 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3395 | result_type __eval2(true_type) {return __evalf<__k, 0>();} |
| 3396 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3397 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3398 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3399 | typename enable_if |
| 3400 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3401 | (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3402 | result_type |
| 3403 | >::type |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3404 | __eval(__uratio<_Np, _Dp>) |
| 3405 | {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3406 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3407 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3408 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3409 | typename enable_if |
| 3410 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3411 | __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3412 | result_type |
| 3413 | >::type |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3414 | __eval(__uratio<_Np, _Dp>) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3415 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3416 | const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min) |
| 3417 | / __uratio<_Np, _Dp>::den); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3418 | _Y_ = _V_[__j]; |
| 3419 | _V_[__j] = __e_(); |
| 3420 | return _Y_; |
| 3421 | } |
| 3422 | |
| 3423 | template <uint64_t __n, uint64_t __d> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3424 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3425 | result_type __evalf() |
| 3426 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3427 | const double _Fp = __d == 0 ? |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3428 | __n / (2. * 0x8000000000000000ull) : |
| 3429 | __n / (double)__d; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3430 | const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3431 | _Y_ = _V_[__j]; |
| 3432 | _V_[__j] = __e_(); |
| 3433 | return _Y_; |
| 3434 | } |
| 3435 | }; |
| 3436 | |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3437 | template<class _Engine, size_t __k> |
| 3438 | _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; |
| 3439 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3440 | template<class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3441 | bool |
| 3442 | operator==( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3443 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3444 | const shuffle_order_engine<_Eng, _Kp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3445 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3446 | 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] | 3447 | __x.__e_ == __y.__e_; |
| 3448 | } |
| 3449 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3450 | template<class _Eng, size_t _Kp> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3451 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3452 | bool |
| 3453 | operator!=( |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3454 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3455 | const shuffle_order_engine<_Eng, _Kp>& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3456 | { |
| 3457 | return !(__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_ostream<_CharT, _Traits>& |
| 3463 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3464 | const shuffle_order_engine<_Eng, _Kp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3465 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3466 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3467 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 3468 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3469 | _CharT __sp = __os.widen(' '); |
| 3470 | __os.fill(__sp); |
| 3471 | __os << __x.__e_ << __sp << __x._V_[0]; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3472 | for (size_t __i = 1; __i < _Kp; ++__i) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3473 | __os << __sp << __x._V_[__i]; |
| 3474 | return __os << __sp << __x._Y_; |
| 3475 | } |
| 3476 | |
| 3477 | template <class _CharT, class _Traits, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3478 | class _Eng, size_t _Kp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3479 | basic_istream<_CharT, _Traits>& |
| 3480 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3481 | shuffle_order_engine<_Eng, _Kp>& __x) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3482 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3483 | typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3484 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3485 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3486 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3487 | _Eng __e; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3488 | result_type _Vp[_Kp+1]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3489 | __is >> __e; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3490 | for (size_t __i = 0; __i < _Kp+1; ++__i) |
| 3491 | __is >> _Vp[__i]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3492 | if (!__is.fail()) |
| 3493 | { |
| 3494 | __x.__e_ = __e; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3495 | for (size_t __i = 0; __i < _Kp; ++__i) |
| 3496 | __x._V_[__i] = _Vp[__i]; |
| 3497 | __x._Y_ = _Vp[_Kp]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3498 | } |
| 3499 | return __is; |
| 3500 | } |
| 3501 | |
| 3502 | typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; |
| 3503 | |
| 3504 | // random_device |
| 3505 | |
Louis Dionne | 3777e68 | 2020-10-15 10:32:09 -0400 | [diff] [blame] | 3506 | #if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE) |
| 3507 | |
Howard Hinnant | 8331b76 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 3508 | class _LIBCPP_TYPE_VIS random_device |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3509 | { |
Ed Schouten | dcf3740 | 2015-03-10 07:46:06 +0000 | [diff] [blame] | 3510 | #ifdef _LIBCPP_USING_DEV_RANDOM |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3511 | int __f_; |
Ed Schouten | dcf3740 | 2015-03-10 07:46:06 +0000 | [diff] [blame] | 3512 | #endif // defined(_LIBCPP_USING_DEV_RANDOM) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3513 | public: |
| 3514 | // types |
| 3515 | typedef unsigned result_type; |
| 3516 | |
| 3517 | // generator characteristics |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3518 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 3519 | static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3520 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3521 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 664183b | 2012-04-02 00:40:41 +0000 | [diff] [blame] | 3522 | static _LIBCPP_CONSTEXPR result_type min() { return _Min;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3523 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 664183b | 2012-04-02 00:40:41 +0000 | [diff] [blame] | 3524 | static _LIBCPP_CONSTEXPR result_type max() { return _Max;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3525 | |
| 3526 | // constructors |
| 3527 | explicit random_device(const string& __token = "/dev/urandom"); |
| 3528 | ~random_device(); |
| 3529 | |
| 3530 | // generating functions |
| 3531 | result_type operator()(); |
| 3532 | |
| 3533 | // property functions |
Howard Hinnant | 6f926b1 | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3534 | double entropy() const _NOEXCEPT; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3535 | |
| 3536 | private: |
| 3537 | // no copy functions |
| 3538 | random_device(const random_device&); // = delete; |
| 3539 | random_device& operator=(const random_device&); // = delete; |
| 3540 | }; |
| 3541 | |
Louis Dionne | 3777e68 | 2020-10-15 10:32:09 -0400 | [diff] [blame] | 3542 | #endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE |
| 3543 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3544 | // seed_seq |
| 3545 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3546 | class _LIBCPP_TEMPLATE_VIS seed_seq |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3547 | { |
| 3548 | public: |
| 3549 | // types |
| 3550 | typedef uint32_t result_type; |
| 3551 | |
| 3552 | private: |
| 3553 | vector<result_type> __v_; |
| 3554 | |
| 3555 | template<class _InputIterator> |
| 3556 | void init(_InputIterator __first, _InputIterator __last); |
| 3557 | public: |
| 3558 | // constructors |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3559 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4b6b809 | 2013-10-23 05:56:47 +0000 | [diff] [blame] | 3560 | seed_seq() _NOEXCEPT {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3561 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3562 | template<class _Tp> |
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 | seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3565 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3566 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3567 | template<class _InputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3568 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3569 | seed_seq(_InputIterator __first, _InputIterator __last) |
| 3570 | {init(__first, __last);} |
| 3571 | |
| 3572 | // generating functions |
| 3573 | template<class _RandomAccessIterator> |
| 3574 | void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); |
| 3575 | |
| 3576 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3577 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 4b6b809 | 2013-10-23 05:56:47 +0000 | [diff] [blame] | 3578 | size_t size() const _NOEXCEPT {return __v_.size();} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3579 | template<class _OutputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3581 | void param(_OutputIterator __dest) const |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3582 | {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3583 | |
| 3584 | private: |
| 3585 | // no copy functions |
| 3586 | seed_seq(const seed_seq&); // = delete; |
| 3587 | void operator=(const seed_seq&); // = delete; |
| 3588 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3589 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3590 | static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3591 | }; |
| 3592 | |
| 3593 | template<class _InputIterator> |
| 3594 | void |
| 3595 | seed_seq::init(_InputIterator __first, _InputIterator __last) |
| 3596 | { |
| 3597 | for (_InputIterator __s = __first; __s != __last; ++__s) |
| 3598 | __v_.push_back(*__s & 0xFFFFFFFF); |
| 3599 | } |
| 3600 | |
| 3601 | template<class _RandomAccessIterator> |
| 3602 | void |
| 3603 | seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) |
| 3604 | { |
| 3605 | if (__first != __last) |
| 3606 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3607 | _VSTD::fill(__first, __last, 0x8b8b8b8b); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3608 | const size_t __n = static_cast<size_t>(__last - __first); |
| 3609 | const size_t __s = __v_.size(); |
| 3610 | const size_t __t = (__n >= 623) ? 11 |
| 3611 | : (__n >= 68) ? 7 |
| 3612 | : (__n >= 39) ? 5 |
| 3613 | : (__n >= 7) ? 3 |
| 3614 | : (__n - 1) / 2; |
| 3615 | const size_t __p = (__n - __t) / 2; |
| 3616 | const size_t __q = __p + __t; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3617 | const size_t __m = _VSTD::max(__s + 1, __n); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3618 | // __k = 0; |
| 3619 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3620 | result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3621 | ^ __first[__n - 1]); |
| 3622 | __first[__p] += __r; |
| 3623 | __r += __s; |
| 3624 | __first[__q] += __r; |
| 3625 | __first[0] = __r; |
| 3626 | } |
| 3627 | for (size_t __k = 1; __k <= __s; ++__k) |
| 3628 | { |
| 3629 | const size_t __kmodn = __k % __n; |
| 3630 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3631 | result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3632 | ^ __first[(__k - 1) % __n]); |
| 3633 | __first[__kpmodn] += __r; |
| 3634 | __r += __kmodn + __v_[__k-1]; |
| 3635 | __first[(__k + __q) % __n] += __r; |
| 3636 | __first[__kmodn] = __r; |
| 3637 | } |
| 3638 | for (size_t __k = __s + 1; __k < __m; ++__k) |
| 3639 | { |
| 3640 | const size_t __kmodn = __k % __n; |
| 3641 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3642 | result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3643 | ^ __first[(__k - 1) % __n]); |
| 3644 | __first[__kpmodn] += __r; |
| 3645 | __r += __kmodn; |
| 3646 | __first[(__k + __q) % __n] += __r; |
| 3647 | __first[__kmodn] = __r; |
| 3648 | } |
| 3649 | for (size_t __k = __m; __k < __m + __n; ++__k) |
| 3650 | { |
| 3651 | const size_t __kmodn = __k % __n; |
| 3652 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3653 | result_type __r = 1566083941 * _Tp(__first[__kmodn] + |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3654 | __first[__kpmodn] + |
| 3655 | __first[(__k - 1) % __n]); |
| 3656 | __first[__kpmodn] ^= __r; |
| 3657 | __r -= __kmodn; |
| 3658 | __first[(__k + __q) % __n] ^= __r; |
| 3659 | __first[__kmodn] = __r; |
| 3660 | } |
| 3661 | } |
| 3662 | } |
| 3663 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3664 | // generate_canonical |
| 3665 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3666 | template<class _RealType, size_t __bits, class _URNG> |
| 3667 | _RealType |
| 3668 | generate_canonical(_URNG& __g) |
| 3669 | { |
| 3670 | const size_t _Dt = numeric_limits<_RealType>::digits; |
| 3671 | const size_t __b = _Dt < __bits ? _Dt : __bits; |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3672 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3673 | 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] | 3674 | #else |
| 3675 | const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; |
| 3676 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3677 | const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); |
Louis Dionne | 2422bdb | 2019-08-20 15:39:20 +0000 | [diff] [blame] | 3678 | const _RealType _Rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3679 | _RealType __base = _Rp; |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3680 | _RealType _Sp = __g() - _URNG::min(); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3681 | for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) |
Howard Hinnant | 5a64685 | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3682 | _Sp += (__g() - _URNG::min()) * __base; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3683 | return _Sp / __base; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3684 | } |
| 3685 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3686 | // uniform_int_distribution |
| 3687 | |
Howard Hinnant | 578ac0f | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 3688 | // in <algorithm> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3689 | |
| 3690 | template <class _CharT, class _Traits, class _IT> |
| 3691 | basic_ostream<_CharT, _Traits>& |
| 3692 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 3693 | const uniform_int_distribution<_IT>& __x) |
| 3694 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3695 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3696 | typedef basic_ostream<_CharT, _Traits> _Ostream; |
| 3697 | __os.flags(_Ostream::dec | _Ostream::left); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3698 | _CharT __sp = __os.widen(' '); |
| 3699 | __os.fill(__sp); |
| 3700 | return __os << __x.a() << __sp << __x.b(); |
| 3701 | } |
| 3702 | |
| 3703 | template <class _CharT, class _Traits, class _IT> |
| 3704 | basic_istream<_CharT, _Traits>& |
| 3705 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 3706 | uniform_int_distribution<_IT>& __x) |
| 3707 | { |
| 3708 | typedef uniform_int_distribution<_IT> _Eng; |
| 3709 | typedef typename _Eng::result_type result_type; |
| 3710 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3711 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3712 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3713 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3714 | result_type __a; |
| 3715 | result_type __b; |
| 3716 | __is >> __a >> __b; |
| 3717 | if (!__is.fail()) |
| 3718 | __x.param(param_type(__a, __b)); |
| 3719 | return __is; |
| 3720 | } |
| 3721 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3722 | // uniform_real_distribution |
| 3723 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3724 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3725 | class _LIBCPP_TEMPLATE_VIS uniform_real_distribution |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3726 | { |
| 3727 | public: |
| 3728 | // types |
| 3729 | typedef _RealType result_type; |
| 3730 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3731 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3732 | { |
| 3733 | result_type __a_; |
| 3734 | result_type __b_; |
| 3735 | public: |
| 3736 | typedef uniform_real_distribution distribution_type; |
| 3737 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3738 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3739 | explicit param_type(result_type __a = 0, |
| 3740 | result_type __b = 1) |
| 3741 | : __a_(__a), __b_(__b) {} |
| 3742 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3743 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3744 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3745 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3746 | result_type b() const {return __b_;} |
| 3747 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3748 | friend _LIBCPP_INLINE_VISIBILITY |
| 3749 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3750 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3751 | friend _LIBCPP_INLINE_VISIBILITY |
| 3752 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3753 | {return !(__x == __y);} |
| 3754 | }; |
| 3755 | |
| 3756 | private: |
| 3757 | param_type __p_; |
| 3758 | |
| 3759 | public: |
| 3760 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3761 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3762 | explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) |
| 3763 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3764 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3765 | explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3766 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3767 | void reset() {} |
| 3768 | |
| 3769 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3770 | template<class _URNG> |
| 3771 | _LIBCPP_INLINE_VISIBILITY |
| 3772 | result_type operator()(_URNG& __g) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3773 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3774 | 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] | 3775 | |
| 3776 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3777 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3778 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3779 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3780 | result_type b() const {return __p_.b();} |
| 3781 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3782 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3783 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3784 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3785 | void param(const param_type& __p) {__p_ = __p;} |
| 3786 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3787 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3788 | result_type min() const {return a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3789 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3790 | result_type max() const {return b();} |
| 3791 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3792 | friend _LIBCPP_INLINE_VISIBILITY |
| 3793 | bool operator==(const uniform_real_distribution& __x, |
| 3794 | const uniform_real_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3795 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3796 | friend _LIBCPP_INLINE_VISIBILITY |
| 3797 | bool operator!=(const uniform_real_distribution& __x, |
| 3798 | const uniform_real_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3799 | {return !(__x == __y);} |
| 3800 | }; |
| 3801 | |
| 3802 | template<class _RealType> |
| 3803 | template<class _URNG> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3804 | inline |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3805 | typename uniform_real_distribution<_RealType>::result_type |
| 3806 | uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 3807 | { |
| 3808 | return (__p.b() - __p.a()) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3809 | * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3810 | + __p.a(); |
| 3811 | } |
| 3812 | |
| 3813 | template <class _CharT, class _Traits, class _RT> |
| 3814 | basic_ostream<_CharT, _Traits>& |
| 3815 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 3816 | const uniform_real_distribution<_RT>& __x) |
| 3817 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3818 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3819 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 3820 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 3821 | _OStream::scientific); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3822 | _CharT __sp = __os.widen(' '); |
| 3823 | __os.fill(__sp); |
| 3824 | return __os << __x.a() << __sp << __x.b(); |
| 3825 | } |
| 3826 | |
| 3827 | template <class _CharT, class _Traits, class _RT> |
| 3828 | basic_istream<_CharT, _Traits>& |
| 3829 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 3830 | uniform_real_distribution<_RT>& __x) |
| 3831 | { |
| 3832 | typedef uniform_real_distribution<_RT> _Eng; |
| 3833 | typedef typename _Eng::result_type result_type; |
| 3834 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3835 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3836 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3837 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3838 | result_type __a; |
| 3839 | result_type __b; |
| 3840 | __is >> __a >> __b; |
| 3841 | if (!__is.fail()) |
| 3842 | __x.param(param_type(__a, __b)); |
| 3843 | return __is; |
| 3844 | } |
| 3845 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3846 | // bernoulli_distribution |
| 3847 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3848 | class _LIBCPP_TEMPLATE_VIS bernoulli_distribution |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3849 | { |
| 3850 | public: |
| 3851 | // types |
| 3852 | typedef bool result_type; |
| 3853 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3854 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3855 | { |
| 3856 | double __p_; |
| 3857 | public: |
| 3858 | typedef bernoulli_distribution distribution_type; |
| 3859 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3860 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3861 | explicit param_type(double __p = 0.5) : __p_(__p) {} |
| 3862 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3863 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3864 | double p() const {return __p_;} |
| 3865 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3866 | friend _LIBCPP_INLINE_VISIBILITY |
| 3867 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3868 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3869 | friend _LIBCPP_INLINE_VISIBILITY |
| 3870 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3871 | {return !(__x == __y);} |
| 3872 | }; |
| 3873 | |
| 3874 | private: |
| 3875 | param_type __p_; |
| 3876 | |
| 3877 | public: |
| 3878 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3879 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3880 | explicit bernoulli_distribution(double __p = 0.5) |
| 3881 | : __p_(param_type(__p)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3882 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3883 | explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3884 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3885 | void reset() {} |
| 3886 | |
| 3887 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3888 | template<class _URNG> |
| 3889 | _LIBCPP_INLINE_VISIBILITY |
| 3890 | result_type operator()(_URNG& __g) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3891 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3892 | 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] | 3893 | |
| 3894 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3895 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3896 | double p() const {return __p_.p();} |
| 3897 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3898 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3899 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3900 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3901 | void param(const param_type& __p) {__p_ = __p;} |
| 3902 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3903 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3904 | result_type min() const {return false;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3905 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3906 | result_type max() const {return true;} |
| 3907 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3908 | friend _LIBCPP_INLINE_VISIBILITY |
| 3909 | bool operator==(const bernoulli_distribution& __x, |
| 3910 | const bernoulli_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3911 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3912 | friend _LIBCPP_INLINE_VISIBILITY |
| 3913 | bool operator!=(const bernoulli_distribution& __x, |
| 3914 | const bernoulli_distribution& __y) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3915 | {return !(__x == __y);} |
| 3916 | }; |
| 3917 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3918 | template<class _URNG> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3919 | inline |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3920 | bernoulli_distribution::result_type |
| 3921 | bernoulli_distribution::operator()(_URNG& __g, const param_type& __p) |
| 3922 | { |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 3923 | uniform_real_distribution<double> __gen; |
| 3924 | return __gen(__g) < __p.p(); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3925 | } |
| 3926 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3927 | template <class _CharT, class _Traits> |
| 3928 | basic_ostream<_CharT, _Traits>& |
| 3929 | operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) |
| 3930 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3931 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3932 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 3933 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 3934 | _OStream::scientific); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3935 | _CharT __sp = __os.widen(' '); |
| 3936 | __os.fill(__sp); |
| 3937 | return __os << __x.p(); |
| 3938 | } |
| 3939 | |
| 3940 | template <class _CharT, class _Traits> |
| 3941 | basic_istream<_CharT, _Traits>& |
| 3942 | operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) |
| 3943 | { |
| 3944 | typedef bernoulli_distribution _Eng; |
| 3945 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3946 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 3947 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 3948 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3949 | double __p; |
| 3950 | __is >> __p; |
| 3951 | if (!__is.fail()) |
| 3952 | __x.param(param_type(__p)); |
| 3953 | return __is; |
| 3954 | } |
| 3955 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3956 | // binomial_distribution |
| 3957 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3958 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3959 | class _LIBCPP_TEMPLATE_VIS binomial_distribution |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3960 | { |
| 3961 | public: |
| 3962 | // types |
| 3963 | typedef _IntType result_type; |
| 3964 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3965 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3966 | { |
| 3967 | result_type __t_; |
| 3968 | double __p_; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3969 | double __pr_; |
| 3970 | double __odds_ratio_; |
| 3971 | result_type __r0_; |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3972 | public: |
| 3973 | typedef binomial_distribution distribution_type; |
| 3974 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3975 | explicit param_type(result_type __t = 1, double __p = 0.5); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3976 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3977 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3978 | result_type t() const {return __t_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3979 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3980 | double p() const {return __p_;} |
| 3981 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3982 | friend _LIBCPP_INLINE_VISIBILITY |
| 3983 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3984 | {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3985 | friend _LIBCPP_INLINE_VISIBILITY |
| 3986 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3987 | {return !(__x == __y);} |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3988 | |
| 3989 | friend class binomial_distribution; |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3990 | }; |
| 3991 | |
| 3992 | private: |
| 3993 | param_type __p_; |
| 3994 | |
| 3995 | public: |
| 3996 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3997 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3998 | explicit binomial_distribution(result_type __t = 1, double __p = 0.5) |
| 3999 | : __p_(param_type(__t, __p)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4000 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4001 | explicit binomial_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4002 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4003 | void reset() {} |
| 4004 | |
| 4005 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4006 | template<class _URNG> |
| 4007 | _LIBCPP_INLINE_VISIBILITY |
| 4008 | result_type operator()(_URNG& __g) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4009 | {return (*this)(__g, __p_);} |
| 4010 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4011 | |
| 4012 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4013 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4014 | result_type t() const {return __p_.t();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4015 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4016 | double p() const {return __p_.p();} |
| 4017 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4018 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4019 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4020 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4021 | void param(const param_type& __p) {__p_ = __p;} |
| 4022 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4023 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4024 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4025 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4026 | result_type max() const {return t();} |
| 4027 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4028 | friend _LIBCPP_INLINE_VISIBILITY |
| 4029 | bool operator==(const binomial_distribution& __x, |
| 4030 | const binomial_distribution& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4031 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4032 | friend _LIBCPP_INLINE_VISIBILITY |
| 4033 | bool operator!=(const binomial_distribution& __x, |
| 4034 | const binomial_distribution& __y) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4035 | {return !(__x == __y);} |
| 4036 | }; |
| 4037 | |
Martin Storsjö | 408cee7 | 2020-12-01 13:37:16 +0200 | [diff] [blame^] | 4038 | #ifndef _LIBCPP_MSVCRT_LIKE |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4039 | extern "C" double lgamma_r(double, int *); |
Eric Fiselier | 651ca6e | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4040 | #endif |
| 4041 | |
| 4042 | inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { |
Martin Storsjö | 408cee7 | 2020-12-01 13:37:16 +0200 | [diff] [blame^] | 4043 | #if defined(_LIBCPP_MSVCRT_LIKE) |
Eric Fiselier | 651ca6e | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4044 | return lgamma(__d); |
| 4045 | #else |
| 4046 | int __sign; |
| 4047 | return lgamma_r(__d, &__sign); |
| 4048 | #endif |
| 4049 | } |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4050 | |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4051 | template<class _IntType> |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4052 | 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] | 4053 | : __t_(__t), __p_(__p) |
| 4054 | { |
| 4055 | if (0 < __p_ && __p_ < 1) |
| 4056 | { |
| 4057 | __r0_ = static_cast<result_type>((__t_ + 1) * __p_); |
Eric Fiselier | 651ca6e | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4058 | __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - |
| 4059 | __libcpp_lgamma(__r0_ + 1.) - |
| 4060 | __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + |
Marshall Clow | 7db2857 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4061 | (__t_ - __r0_) * _VSTD::log(1 - __p_)); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4062 | __odds_ratio_ = __p_ / (1 - __p_); |
| 4063 | } |
| 4064 | } |
| 4065 | |
Marshall Clow | f97a84f | 2014-09-17 18:33:58 +0000 | [diff] [blame] | 4066 | // Reference: Kemp, C.D. (1986). `A modal method for generating binomial |
| 4067 | // variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4068 | template<class _IntType> |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4069 | template<class _URNG> |
| 4070 | _IntType |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4071 | binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4072 | { |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4073 | if (__pr.__t_ == 0 || __pr.__p_ == 0) |
| 4074 | return 0; |
| 4075 | if (__pr.__p_ == 1) |
| 4076 | return __pr.__t_; |
| 4077 | uniform_real_distribution<double> __gen; |
| 4078 | double __u = __gen(__g) - __pr.__pr_; |
| 4079 | if (__u < 0) |
| 4080 | return __pr.__r0_; |
| 4081 | double __pu = __pr.__pr_; |
| 4082 | double __pd = __pu; |
| 4083 | result_type __ru = __pr.__r0_; |
| 4084 | result_type __rd = __ru; |
| 4085 | while (true) |
| 4086 | { |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4087 | bool __break = true; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4088 | if (__rd >= 1) |
| 4089 | { |
| 4090 | __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); |
| 4091 | __u -= __pd; |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4092 | __break = false; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4093 | if (__u < 0) |
| 4094 | return __rd - 1; |
| 4095 | } |
Marshall Clow | f97a84f | 2014-09-17 18:33:58 +0000 | [diff] [blame] | 4096 | if ( __rd != 0 ) |
| 4097 | --__rd; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4098 | ++__ru; |
| 4099 | if (__ru <= __pr.__t_) |
| 4100 | { |
| 4101 | __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; |
| 4102 | __u -= __pu; |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4103 | __break = false; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4104 | if (__u < 0) |
| 4105 | return __ru; |
| 4106 | } |
Atmn Patel | da0b1b6 | 2020-03-17 15:52:36 -0400 | [diff] [blame] | 4107 | if (__break) |
| 4108 | return 0; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4109 | } |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4110 | } |
| 4111 | |
| 4112 | template <class _CharT, class _Traits, class _IntType> |
| 4113 | basic_ostream<_CharT, _Traits>& |
| 4114 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4115 | const binomial_distribution<_IntType>& __x) |
| 4116 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4117 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4118 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4119 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4120 | _OStream::scientific); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4121 | _CharT __sp = __os.widen(' '); |
| 4122 | __os.fill(__sp); |
| 4123 | return __os << __x.t() << __sp << __x.p(); |
| 4124 | } |
| 4125 | |
| 4126 | template <class _CharT, class _Traits, class _IntType> |
| 4127 | basic_istream<_CharT, _Traits>& |
| 4128 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4129 | binomial_distribution<_IntType>& __x) |
| 4130 | { |
| 4131 | typedef binomial_distribution<_IntType> _Eng; |
| 4132 | typedef typename _Eng::result_type result_type; |
| 4133 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4134 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4135 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4136 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 53f28fa | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4137 | result_type __t; |
| 4138 | double __p; |
| 4139 | __is >> __t >> __p; |
| 4140 | if (!__is.fail()) |
| 4141 | __x.param(param_type(__t, __p)); |
| 4142 | return __is; |
| 4143 | } |
| 4144 | |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4145 | // exponential_distribution |
| 4146 | |
| 4147 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4148 | class _LIBCPP_TEMPLATE_VIS exponential_distribution |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4149 | { |
| 4150 | public: |
| 4151 | // types |
| 4152 | typedef _RealType result_type; |
| 4153 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4154 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4155 | { |
| 4156 | result_type __lambda_; |
| 4157 | public: |
| 4158 | typedef exponential_distribution distribution_type; |
| 4159 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4160 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4161 | explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} |
| 4162 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4163 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4164 | result_type lambda() const {return __lambda_;} |
| 4165 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4166 | friend _LIBCPP_INLINE_VISIBILITY |
| 4167 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4168 | {return __x.__lambda_ == __y.__lambda_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4169 | friend _LIBCPP_INLINE_VISIBILITY |
| 4170 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4171 | {return !(__x == __y);} |
| 4172 | }; |
| 4173 | |
| 4174 | private: |
| 4175 | param_type __p_; |
| 4176 | |
| 4177 | public: |
| 4178 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4179 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4180 | explicit exponential_distribution(result_type __lambda = 1) |
| 4181 | : __p_(param_type(__lambda)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4182 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4183 | explicit exponential_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4184 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4185 | void reset() {} |
| 4186 | |
| 4187 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4188 | template<class _URNG> |
| 4189 | _LIBCPP_INLINE_VISIBILITY |
| 4190 | result_type operator()(_URNG& __g) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4191 | {return (*this)(__g, __p_);} |
| 4192 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4193 | |
| 4194 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4195 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4196 | result_type lambda() const {return __p_.lambda();} |
| 4197 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4198 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4199 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4200 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4201 | void param(const param_type& __p) {__p_ = __p;} |
| 4202 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4203 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4204 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4205 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 021f990 | 2010-05-16 17:56:20 +0000 | [diff] [blame] | 4206 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4207 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4208 | friend _LIBCPP_INLINE_VISIBILITY |
| 4209 | bool operator==(const exponential_distribution& __x, |
| 4210 | const exponential_distribution& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4211 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4212 | friend _LIBCPP_INLINE_VISIBILITY |
| 4213 | bool operator!=(const exponential_distribution& __x, |
| 4214 | const exponential_distribution& __y) |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4215 | {return !(__x == __y);} |
| 4216 | }; |
| 4217 | |
| 4218 | template <class _RealType> |
| 4219 | template<class _URNG> |
| 4220 | _RealType |
| 4221 | exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4222 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4223 | return -_VSTD::log |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4224 | ( |
| 4225 | result_type(1) - |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4226 | _VSTD::generate_canonical<result_type, |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4227 | numeric_limits<result_type>::digits>(__g) |
| 4228 | ) |
| 4229 | / __p.lambda(); |
| 4230 | } |
| 4231 | |
| 4232 | template <class _CharT, class _Traits, class _RealType> |
| 4233 | basic_ostream<_CharT, _Traits>& |
| 4234 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4235 | const exponential_distribution<_RealType>& __x) |
| 4236 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4237 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4238 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4239 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4240 | _OStream::scientific); |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4241 | return __os << __x.lambda(); |
| 4242 | } |
| 4243 | |
| 4244 | template <class _CharT, class _Traits, class _RealType> |
| 4245 | basic_istream<_CharT, _Traits>& |
| 4246 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4247 | exponential_distribution<_RealType>& __x) |
| 4248 | { |
| 4249 | typedef exponential_distribution<_RealType> _Eng; |
| 4250 | typedef typename _Eng::result_type result_type; |
| 4251 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4252 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4253 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4254 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | d31dfb5 | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4255 | result_type __lambda; |
| 4256 | __is >> __lambda; |
| 4257 | if (!__is.fail()) |
| 4258 | __x.param(param_type(__lambda)); |
| 4259 | return __is; |
| 4260 | } |
| 4261 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4262 | // normal_distribution |
| 4263 | |
| 4264 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4265 | class _LIBCPP_TEMPLATE_VIS normal_distribution |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4266 | { |
| 4267 | public: |
| 4268 | // types |
| 4269 | typedef _RealType result_type; |
| 4270 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4271 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4272 | { |
| 4273 | result_type __mean_; |
| 4274 | result_type __stddev_; |
| 4275 | public: |
| 4276 | typedef normal_distribution distribution_type; |
| 4277 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4278 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4279 | explicit param_type(result_type __mean = 0, result_type __stddev = 1) |
| 4280 | : __mean_(__mean), __stddev_(__stddev) {} |
| 4281 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4282 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4283 | result_type mean() const {return __mean_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4284 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4285 | result_type stddev() const {return __stddev_;} |
| 4286 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4287 | friend _LIBCPP_INLINE_VISIBILITY |
| 4288 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4289 | {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4290 | friend _LIBCPP_INLINE_VISIBILITY |
| 4291 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4292 | {return !(__x == __y);} |
| 4293 | }; |
| 4294 | |
| 4295 | private: |
| 4296 | param_type __p_; |
| 4297 | result_type _V_; |
| 4298 | bool _V_hot_; |
| 4299 | |
| 4300 | public: |
| 4301 | // constructors and reset 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 | explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) |
| 4304 | : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4306 | explicit normal_distribution(const param_type& __p) |
| 4307 | : __p_(__p), _V_hot_(false) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4308 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4309 | void reset() {_V_hot_ = false;} |
| 4310 | |
| 4311 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4312 | template<class _URNG> |
| 4313 | _LIBCPP_INLINE_VISIBILITY |
| 4314 | result_type operator()(_URNG& __g) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4315 | {return (*this)(__g, __p_);} |
| 4316 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4317 | |
| 4318 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4319 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4320 | result_type mean() const {return __p_.mean();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4321 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4322 | result_type stddev() const {return __p_.stddev();} |
| 4323 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4325 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4326 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4327 | void param(const param_type& __p) {__p_ = __p;} |
| 4328 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4329 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4330 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4331 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4332 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4333 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4334 | friend _LIBCPP_INLINE_VISIBILITY |
| 4335 | bool operator==(const normal_distribution& __x, |
| 4336 | const normal_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4337 | {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && |
| 4338 | (!__x._V_hot_ || __x._V_ == __y._V_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4339 | friend _LIBCPP_INLINE_VISIBILITY |
| 4340 | bool operator!=(const normal_distribution& __x, |
| 4341 | const normal_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4342 | {return !(__x == __y);} |
| 4343 | |
| 4344 | template <class _CharT, class _Traits, class _RT> |
| 4345 | friend |
| 4346 | basic_ostream<_CharT, _Traits>& |
| 4347 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4348 | const normal_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4349 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4350 | template <class _CharT, class _Traits, class _RT> |
| 4351 | friend |
| 4352 | basic_istream<_CharT, _Traits>& |
| 4353 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4354 | normal_distribution<_RT>& __x); |
| 4355 | }; |
| 4356 | |
| 4357 | template <class _RealType> |
| 4358 | template<class _URNG> |
| 4359 | _RealType |
| 4360 | normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4361 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4362 | result_type _Up; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4363 | if (_V_hot_) |
| 4364 | { |
| 4365 | _V_hot_ = false; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4366 | _Up = _V_; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4367 | } |
| 4368 | else |
| 4369 | { |
| 4370 | uniform_real_distribution<result_type> _Uni(-1, 1); |
| 4371 | result_type __u; |
| 4372 | result_type __v; |
| 4373 | result_type __s; |
| 4374 | do |
| 4375 | { |
| 4376 | __u = _Uni(__g); |
| 4377 | __v = _Uni(__g); |
| 4378 | __s = __u * __u + __v * __v; |
| 4379 | } while (__s > 1 || __s == 0); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4380 | result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); |
| 4381 | _V_ = __v * _Fp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4382 | _V_hot_ = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4383 | _Up = __u * _Fp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4384 | } |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4385 | return _Up * __p.stddev() + __p.mean(); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | template <class _CharT, class _Traits, class _RT> |
| 4389 | basic_ostream<_CharT, _Traits>& |
| 4390 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4391 | const normal_distribution<_RT>& __x) |
| 4392 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4393 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4394 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4395 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4396 | _OStream::scientific); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4397 | _CharT __sp = __os.widen(' '); |
| 4398 | __os.fill(__sp); |
| 4399 | __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; |
| 4400 | if (__x._V_hot_) |
| 4401 | __os << __sp << __x._V_; |
| 4402 | return __os; |
| 4403 | } |
| 4404 | |
| 4405 | template <class _CharT, class _Traits, class _RT> |
| 4406 | basic_istream<_CharT, _Traits>& |
| 4407 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4408 | normal_distribution<_RT>& __x) |
| 4409 | { |
| 4410 | typedef normal_distribution<_RT> _Eng; |
| 4411 | typedef typename _Eng::result_type result_type; |
| 4412 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4413 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4414 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4415 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4416 | result_type __mean; |
| 4417 | result_type __stddev; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4418 | result_type _Vp = 0; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4419 | bool _V_hot = false; |
| 4420 | __is >> __mean >> __stddev >> _V_hot; |
| 4421 | if (_V_hot) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4422 | __is >> _Vp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4423 | if (!__is.fail()) |
| 4424 | { |
| 4425 | __x.param(param_type(__mean, __stddev)); |
| 4426 | __x._V_hot_ = _V_hot; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4427 | __x._V_ = _Vp; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4428 | } |
| 4429 | return __is; |
| 4430 | } |
| 4431 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4432 | // lognormal_distribution |
| 4433 | |
| 4434 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4435 | class _LIBCPP_TEMPLATE_VIS lognormal_distribution |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4436 | { |
| 4437 | public: |
| 4438 | // types |
| 4439 | typedef _RealType result_type; |
| 4440 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4441 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4442 | { |
| 4443 | normal_distribution<result_type> __nd_; |
| 4444 | public: |
| 4445 | typedef lognormal_distribution distribution_type; |
| 4446 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4447 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4448 | explicit param_type(result_type __m = 0, result_type __s = 1) |
| 4449 | : __nd_(__m, __s) {} |
| 4450 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4451 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4452 | result_type m() const {return __nd_.mean();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4453 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4454 | result_type s() const {return __nd_.stddev();} |
| 4455 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4456 | friend _LIBCPP_INLINE_VISIBILITY |
| 4457 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4458 | {return __x.__nd_ == __y.__nd_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4459 | friend _LIBCPP_INLINE_VISIBILITY |
| 4460 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4461 | {return !(__x == __y);} |
| 4462 | friend class lognormal_distribution; |
| 4463 | |
| 4464 | template <class _CharT, class _Traits, class _RT> |
| 4465 | friend |
| 4466 | basic_ostream<_CharT, _Traits>& |
| 4467 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4468 | const lognormal_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4469 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4470 | template <class _CharT, class _Traits, class _RT> |
| 4471 | friend |
| 4472 | basic_istream<_CharT, _Traits>& |
| 4473 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4474 | lognormal_distribution<_RT>& __x); |
| 4475 | }; |
| 4476 | |
| 4477 | private: |
| 4478 | param_type __p_; |
| 4479 | |
| 4480 | public: |
| 4481 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4482 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4483 | explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) |
| 4484 | : __p_(param_type(__m, __s)) {} |
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 | explicit lognormal_distribution(const param_type& __p) |
| 4487 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4488 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4489 | void reset() {__p_.__nd_.reset();} |
| 4490 | |
| 4491 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4492 | template<class _URNG> |
| 4493 | _LIBCPP_INLINE_VISIBILITY |
| 4494 | result_type operator()(_URNG& __g) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4495 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4496 | template<class _URNG> |
| 4497 | _LIBCPP_INLINE_VISIBILITY |
| 4498 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4499 | {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4500 | |
| 4501 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4502 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4503 | result_type m() const {return __p_.m();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4504 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4505 | result_type s() const {return __p_.s();} |
| 4506 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4507 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4508 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4509 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 4510 | void param(const param_type& __p) {__p_ = __p;} |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4511 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4512 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4513 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4515 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4516 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4517 | friend _LIBCPP_INLINE_VISIBILITY |
| 4518 | bool operator==(const lognormal_distribution& __x, |
| 4519 | const lognormal_distribution& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4520 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4521 | friend _LIBCPP_INLINE_VISIBILITY |
| 4522 | bool operator!=(const lognormal_distribution& __x, |
| 4523 | const lognormal_distribution& __y) |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4524 | {return !(__x == __y);} |
| 4525 | |
| 4526 | template <class _CharT, class _Traits, class _RT> |
| 4527 | friend |
| 4528 | basic_ostream<_CharT, _Traits>& |
| 4529 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4530 | const lognormal_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4531 | |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4532 | template <class _CharT, class _Traits, class _RT> |
| 4533 | friend |
| 4534 | basic_istream<_CharT, _Traits>& |
| 4535 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4536 | lognormal_distribution<_RT>& __x); |
| 4537 | }; |
| 4538 | |
| 4539 | template <class _CharT, class _Traits, class _RT> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4540 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4541 | basic_ostream<_CharT, _Traits>& |
| 4542 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4543 | const lognormal_distribution<_RT>& __x) |
| 4544 | { |
| 4545 | return __os << __x.__p_.__nd_; |
| 4546 | } |
| 4547 | |
| 4548 | template <class _CharT, class _Traits, class _RT> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4549 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df3bed6 | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4550 | basic_istream<_CharT, _Traits>& |
| 4551 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4552 | lognormal_distribution<_RT>& __x) |
| 4553 | { |
| 4554 | return __is >> __x.__p_.__nd_; |
| 4555 | } |
| 4556 | |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4557 | // poisson_distribution |
| 4558 | |
| 4559 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4560 | class _LIBCPP_TEMPLATE_VIS poisson_distribution |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4561 | { |
| 4562 | public: |
| 4563 | // types |
| 4564 | typedef _IntType result_type; |
| 4565 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4566 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4567 | { |
| 4568 | double __mean_; |
| 4569 | double __s_; |
| 4570 | double __d_; |
| 4571 | double __l_; |
| 4572 | double __omega_; |
| 4573 | double __c0_; |
| 4574 | double __c1_; |
| 4575 | double __c2_; |
| 4576 | double __c3_; |
| 4577 | double __c_; |
| 4578 | |
| 4579 | public: |
| 4580 | typedef poisson_distribution distribution_type; |
| 4581 | |
| 4582 | explicit param_type(double __mean = 1.0); |
| 4583 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4584 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4585 | double mean() const {return __mean_;} |
| 4586 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4587 | friend _LIBCPP_INLINE_VISIBILITY |
| 4588 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4589 | {return __x.__mean_ == __y.__mean_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4590 | friend _LIBCPP_INLINE_VISIBILITY |
| 4591 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4592 | {return !(__x == __y);} |
| 4593 | |
| 4594 | friend class poisson_distribution; |
| 4595 | }; |
| 4596 | |
| 4597 | private: |
| 4598 | param_type __p_; |
| 4599 | |
| 4600 | public: |
| 4601 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4602 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4603 | explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4604 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4605 | explicit poisson_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4606 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4607 | void reset() {} |
| 4608 | |
| 4609 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4610 | template<class _URNG> |
| 4611 | _LIBCPP_INLINE_VISIBILITY |
| 4612 | result_type operator()(_URNG& __g) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4613 | {return (*this)(__g, __p_);} |
| 4614 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4615 | |
| 4616 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4618 | double mean() const {return __p_.mean();} |
| 4619 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4620 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4621 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4622 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4623 | void param(const param_type& __p) {__p_ = __p;} |
| 4624 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4625 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4626 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4627 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4628 | result_type max() const {return numeric_limits<result_type>::max();} |
| 4629 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4630 | friend _LIBCPP_INLINE_VISIBILITY |
| 4631 | bool operator==(const poisson_distribution& __x, |
| 4632 | const poisson_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4633 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4634 | friend _LIBCPP_INLINE_VISIBILITY |
| 4635 | bool operator!=(const poisson_distribution& __x, |
| 4636 | const poisson_distribution& __y) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4637 | {return !(__x == __y);} |
| 4638 | }; |
| 4639 | |
| 4640 | template<class _IntType> |
| 4641 | poisson_distribution<_IntType>::param_type::param_type(double __mean) |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4642 | // According to the standard `inf` is a valid input, but it causes the |
| 4643 | // distribution to hang, so we replace it with the maximum representable |
| 4644 | // mean. |
| 4645 | : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4646 | { |
| 4647 | if (__mean_ < 10) |
| 4648 | { |
| 4649 | __s_ = 0; |
| 4650 | __d_ = 0; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4651 | __l_ = _VSTD::exp(-__mean_); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4652 | __omega_ = 0; |
| 4653 | __c3_ = 0; |
| 4654 | __c2_ = 0; |
| 4655 | __c1_ = 0; |
| 4656 | __c0_ = 0; |
| 4657 | __c_ = 0; |
| 4658 | } |
| 4659 | else |
| 4660 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4661 | __s_ = _VSTD::sqrt(__mean_); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4662 | __d_ = 6 * __mean_ * __mean_; |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4663 | __l_ = _VSTD::trunc(__mean_ - 1.1484); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4664 | __omega_ = .3989423 / __s_; |
| 4665 | double __b1_ = .4166667E-1 / __mean_; |
| 4666 | double __b2_ = .3 * __b1_ * __b1_; |
| 4667 | __c3_ = .1428571 * __b1_ * __b2_; |
| 4668 | __c2_ = __b2_ - 15. * __c3_; |
| 4669 | __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; |
| 4670 | __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; |
| 4671 | __c_ = .1069 / __mean_; |
| 4672 | } |
| 4673 | } |
| 4674 | |
| 4675 | template <class _IntType> |
| 4676 | template<class _URNG> |
| 4677 | _IntType |
| 4678 | poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) |
| 4679 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4680 | double __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4681 | uniform_real_distribution<double> __urd; |
Howard Hinnant | a5fb7ac | 2011-04-14 15:59:22 +0000 | [diff] [blame] | 4682 | if (__pr.__mean_ < 10) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4683 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4684 | __tx = 0; |
| 4685 | for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4686 | __p *= __urd(__urng); |
| 4687 | } |
| 4688 | else |
| 4689 | { |
| 4690 | double __difmuk; |
| 4691 | double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); |
| 4692 | double __u; |
| 4693 | if (__g > 0) |
| 4694 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4695 | __tx = _VSTD::trunc(__g); |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4696 | if (__tx >= __pr.__l_) |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4697 | return _VSTD::__clamp_to_integral<result_type>(__tx); |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4698 | __difmuk = __pr.__mean_ - __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4699 | __u = __urd(__urng); |
| 4700 | if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4701 | return _VSTD::__clamp_to_integral<result_type>(__tx); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4702 | } |
| 4703 | exponential_distribution<double> __edist; |
| 4704 | for (bool __using_exp_dist = false; true; __using_exp_dist = true) |
| 4705 | { |
| 4706 | double __e; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4707 | if (__using_exp_dist || __g <= 0) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4708 | { |
| 4709 | double __t; |
| 4710 | do |
| 4711 | { |
| 4712 | __e = __edist(__urng); |
| 4713 | __u = __urd(__urng); |
| 4714 | __u += __u - 1; |
| 4715 | __t = 1.8 + (__u < 0 ? -__e : __e); |
| 4716 | } while (__t <= -.6744); |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4717 | __tx = _VSTD::trunc(__pr.__mean_ + __pr.__s_ * __t); |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4718 | __difmuk = __pr.__mean_ - __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4719 | __using_exp_dist = true; |
| 4720 | } |
| 4721 | double __px; |
| 4722 | double __py; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4723 | if (__tx < 10 && __tx >= 0) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4724 | { |
Marshall Clow | c7e36e8 | 2018-01-16 14:54:36 +0000 | [diff] [blame] | 4725 | const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4726 | 40320, 362880}; |
| 4727 | __px = -__pr.__mean_; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4728 | __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)]; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4729 | } |
| 4730 | else |
| 4731 | { |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4732 | double __del = .8333333E-1 / __tx; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4733 | __del -= 4.8 * __del * __del * __del; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4734 | double __v = __difmuk / __tx; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4735 | if (_VSTD::abs(__v) > 0.25) |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4736 | __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del; |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4737 | else |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4738 | __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) * |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4739 | __v + .1421878) * __v + -.1661269) * __v + .2000118) * |
| 4740 | __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; |
Louis Dionne | 7d19d1c | 2019-11-07 12:06:14 +0000 | [diff] [blame] | 4741 | __py = .3989423 / _VSTD::sqrt(__tx); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4742 | } |
| 4743 | double __r = (0.5 - __difmuk) / __pr.__s_; |
| 4744 | double __r2 = __r * __r; |
| 4745 | double __fx = -0.5 * __r2; |
| 4746 | double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * |
| 4747 | __r2 + __pr.__c1_) * __r2 + __pr.__c0_); |
| 4748 | if (__using_exp_dist) |
| 4749 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4750 | if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - |
| 4751 | __fy * _VSTD::exp(__fx + __e)) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4752 | break; |
| 4753 | } |
| 4754 | else |
| 4755 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4756 | if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4757 | break; |
| 4758 | } |
| 4759 | } |
| 4760 | } |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4761 | return _VSTD::__clamp_to_integral<result_type>(__tx); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4762 | } |
| 4763 | |
| 4764 | template <class _CharT, class _Traits, class _IntType> |
| 4765 | basic_ostream<_CharT, _Traits>& |
| 4766 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4767 | const poisson_distribution<_IntType>& __x) |
| 4768 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4769 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4770 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4771 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4772 | _OStream::scientific); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4773 | return __os << __x.mean(); |
| 4774 | } |
| 4775 | |
| 4776 | template <class _CharT, class _Traits, class _IntType> |
| 4777 | basic_istream<_CharT, _Traits>& |
| 4778 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4779 | poisson_distribution<_IntType>& __x) |
| 4780 | { |
| 4781 | typedef poisson_distribution<_IntType> _Eng; |
| 4782 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4783 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4784 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4785 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 7631035 | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4786 | double __mean; |
| 4787 | __is >> __mean; |
| 4788 | if (!__is.fail()) |
| 4789 | __x.param(param_type(__mean)); |
| 4790 | return __is; |
| 4791 | } |
| 4792 | |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4793 | // weibull_distribution |
| 4794 | |
| 4795 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4796 | class _LIBCPP_TEMPLATE_VIS weibull_distribution |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4797 | { |
| 4798 | public: |
| 4799 | // types |
| 4800 | typedef _RealType result_type; |
| 4801 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4802 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4803 | { |
| 4804 | result_type __a_; |
| 4805 | result_type __b_; |
| 4806 | public: |
| 4807 | typedef weibull_distribution distribution_type; |
| 4808 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4809 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4810 | explicit param_type(result_type __a = 1, result_type __b = 1) |
| 4811 | : __a_(__a), __b_(__b) {} |
| 4812 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4813 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4814 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4815 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4816 | result_type b() const {return __b_;} |
| 4817 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4818 | friend _LIBCPP_INLINE_VISIBILITY |
| 4819 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4820 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4821 | friend _LIBCPP_INLINE_VISIBILITY |
| 4822 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4823 | {return !(__x == __y);} |
| 4824 | }; |
| 4825 | |
| 4826 | private: |
| 4827 | param_type __p_; |
| 4828 | |
| 4829 | public: |
| 4830 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4831 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4832 | explicit weibull_distribution(result_type __a = 1, result_type __b = 1) |
| 4833 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4834 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4835 | explicit weibull_distribution(const param_type& __p) |
| 4836 | : __p_(__p) {} |
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 | void reset() {} |
| 4839 | |
| 4840 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4841 | template<class _URNG> |
| 4842 | _LIBCPP_INLINE_VISIBILITY |
| 4843 | result_type operator()(_URNG& __g) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4844 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4845 | template<class _URNG> |
| 4846 | _LIBCPP_INLINE_VISIBILITY |
| 4847 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4848 | {return __p.b() * |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4849 | _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4850 | |
| 4851 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4852 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4853 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4854 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4855 | result_type b() const {return __p_.b();} |
| 4856 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4857 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4858 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4859 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4860 | void param(const param_type& __p) {__p_ = __p;} |
| 4861 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4862 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4863 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4864 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4865 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4866 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4867 | friend _LIBCPP_INLINE_VISIBILITY |
| 4868 | bool operator==(const weibull_distribution& __x, |
| 4869 | const weibull_distribution& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4870 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4871 | friend _LIBCPP_INLINE_VISIBILITY |
| 4872 | bool operator!=(const weibull_distribution& __x, |
| 4873 | const weibull_distribution& __y) |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4874 | {return !(__x == __y);} |
| 4875 | }; |
| 4876 | |
| 4877 | template <class _CharT, class _Traits, class _RT> |
| 4878 | basic_ostream<_CharT, _Traits>& |
| 4879 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4880 | const weibull_distribution<_RT>& __x) |
| 4881 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4882 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4883 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 4884 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 4885 | _OStream::scientific); |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4886 | _CharT __sp = __os.widen(' '); |
| 4887 | __os.fill(__sp); |
| 4888 | __os << __x.a() << __sp << __x.b(); |
| 4889 | return __os; |
| 4890 | } |
| 4891 | |
| 4892 | template <class _CharT, class _Traits, class _RT> |
| 4893 | basic_istream<_CharT, _Traits>& |
| 4894 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4895 | weibull_distribution<_RT>& __x) |
| 4896 | { |
| 4897 | typedef weibull_distribution<_RT> _Eng; |
| 4898 | typedef typename _Eng::result_type result_type; |
| 4899 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4900 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 4901 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 4902 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | db6b97b | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4903 | result_type __a; |
| 4904 | result_type __b; |
| 4905 | __is >> __a >> __b; |
| 4906 | if (!__is.fail()) |
| 4907 | __x.param(param_type(__a, __b)); |
| 4908 | return __is; |
| 4909 | } |
| 4910 | |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4911 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4912 | class _LIBCPP_TEMPLATE_VIS extreme_value_distribution |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4913 | { |
| 4914 | public: |
| 4915 | // types |
| 4916 | typedef _RealType result_type; |
| 4917 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4918 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4919 | { |
| 4920 | result_type __a_; |
| 4921 | result_type __b_; |
| 4922 | public: |
| 4923 | typedef extreme_value_distribution distribution_type; |
| 4924 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4925 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4926 | explicit param_type(result_type __a = 0, result_type __b = 1) |
| 4927 | : __a_(__a), __b_(__b) {} |
| 4928 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4929 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4930 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4931 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4932 | result_type b() const {return __b_;} |
| 4933 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4934 | friend _LIBCPP_INLINE_VISIBILITY |
| 4935 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4936 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4937 | friend _LIBCPP_INLINE_VISIBILITY |
| 4938 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4939 | {return !(__x == __y);} |
| 4940 | }; |
| 4941 | |
| 4942 | private: |
| 4943 | param_type __p_; |
| 4944 | |
| 4945 | public: |
| 4946 | // constructor and reset 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 | explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) |
| 4949 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4950 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4951 | explicit extreme_value_distribution(const param_type& __p) |
| 4952 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4953 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4954 | void reset() {} |
| 4955 | |
| 4956 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4957 | template<class _URNG> |
| 4958 | _LIBCPP_INLINE_VISIBILITY |
| 4959 | result_type operator()(_URNG& __g) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4960 | {return (*this)(__g, __p_);} |
| 4961 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4962 | |
| 4963 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4964 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4965 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4966 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4967 | result_type b() const {return __p_.b();} |
| 4968 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4969 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4970 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4971 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4972 | void param(const param_type& __p) {__p_ = __p;} |
| 4973 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4974 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4975 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4976 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4977 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4978 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4979 | friend _LIBCPP_INLINE_VISIBILITY |
| 4980 | bool operator==(const extreme_value_distribution& __x, |
| 4981 | const extreme_value_distribution& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4982 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4983 | friend _LIBCPP_INLINE_VISIBILITY |
| 4984 | bool operator!=(const extreme_value_distribution& __x, |
| 4985 | const extreme_value_distribution& __y) |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4986 | {return !(__x == __y);} |
| 4987 | }; |
| 4988 | |
| 4989 | template<class _RealType> |
| 4990 | template<class _URNG> |
| 4991 | _RealType |
| 4992 | extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4993 | { |
| 4994 | return __p.a() - __p.b() * |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4995 | _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | template <class _CharT, class _Traits, class _RT> |
| 4999 | basic_ostream<_CharT, _Traits>& |
| 5000 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5001 | const extreme_value_distribution<_RT>& __x) |
| 5002 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5003 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5004 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5005 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5006 | _OStream::scientific); |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5007 | _CharT __sp = __os.widen(' '); |
| 5008 | __os.fill(__sp); |
| 5009 | __os << __x.a() << __sp << __x.b(); |
| 5010 | return __os; |
| 5011 | } |
| 5012 | |
| 5013 | template <class _CharT, class _Traits, class _RT> |
| 5014 | basic_istream<_CharT, _Traits>& |
| 5015 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5016 | extreme_value_distribution<_RT>& __x) |
| 5017 | { |
| 5018 | typedef extreme_value_distribution<_RT> _Eng; |
| 5019 | typedef typename _Eng::result_type result_type; |
| 5020 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5021 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5022 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5023 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 8e4ddf4 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 5024 | result_type __a; |
| 5025 | result_type __b; |
| 5026 | __is >> __a >> __b; |
| 5027 | if (!__is.fail()) |
| 5028 | __x.param(param_type(__a, __b)); |
| 5029 | return __is; |
| 5030 | } |
| 5031 | |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5032 | // gamma_distribution |
| 5033 | |
| 5034 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5035 | class _LIBCPP_TEMPLATE_VIS gamma_distribution |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5036 | { |
| 5037 | public: |
| 5038 | // types |
| 5039 | typedef _RealType result_type; |
| 5040 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5041 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5042 | { |
| 5043 | result_type __alpha_; |
| 5044 | result_type __beta_; |
| 5045 | public: |
| 5046 | typedef gamma_distribution distribution_type; |
| 5047 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5048 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5049 | explicit param_type(result_type __alpha = 1, result_type __beta = 1) |
| 5050 | : __alpha_(__alpha), __beta_(__beta) {} |
| 5051 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5052 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5053 | result_type alpha() const {return __alpha_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5054 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5055 | result_type beta() const {return __beta_;} |
| 5056 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5057 | friend _LIBCPP_INLINE_VISIBILITY |
| 5058 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5059 | {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5060 | friend _LIBCPP_INLINE_VISIBILITY |
| 5061 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5062 | {return !(__x == __y);} |
| 5063 | }; |
| 5064 | |
| 5065 | private: |
| 5066 | param_type __p_; |
| 5067 | |
| 5068 | public: |
| 5069 | // constructors and reset 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 | explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) |
| 5072 | : __p_(param_type(__alpha, __beta)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5073 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5074 | explicit gamma_distribution(const param_type& __p) |
| 5075 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5076 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5077 | void reset() {} |
| 5078 | |
| 5079 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5080 | template<class _URNG> |
| 5081 | _LIBCPP_INLINE_VISIBILITY |
| 5082 | result_type operator()(_URNG& __g) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5083 | {return (*this)(__g, __p_);} |
| 5084 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5085 | |
| 5086 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5087 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5088 | result_type alpha() const {return __p_.alpha();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5089 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5090 | result_type beta() const {return __p_.beta();} |
| 5091 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5092 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5093 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5094 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5095 | void param(const param_type& __p) {__p_ = __p;} |
| 5096 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5097 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5098 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5099 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5100 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5101 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5102 | friend _LIBCPP_INLINE_VISIBILITY |
| 5103 | bool operator==(const gamma_distribution& __x, |
| 5104 | const gamma_distribution& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5105 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5106 | friend _LIBCPP_INLINE_VISIBILITY |
| 5107 | bool operator!=(const gamma_distribution& __x, |
| 5108 | const gamma_distribution& __y) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5109 | {return !(__x == __y);} |
| 5110 | }; |
| 5111 | |
| 5112 | template <class _RealType> |
| 5113 | template<class _URNG> |
| 5114 | _RealType |
| 5115 | gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5116 | { |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5117 | result_type __a = __p.alpha(); |
| 5118 | uniform_real_distribution<result_type> __gen(0, 1); |
| 5119 | exponential_distribution<result_type> __egen; |
| 5120 | result_type __x; |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5121 | if (__a == 1) |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5122 | __x = __egen(__g); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5123 | else if (__a > 1) |
| 5124 | { |
| 5125 | const result_type __b = __a - 1; |
| 5126 | const result_type __c = 3 * __a - result_type(0.75); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5127 | while (true) |
| 5128 | { |
| 5129 | const result_type __u = __gen(__g); |
| 5130 | const result_type __v = __gen(__g); |
| 5131 | const result_type __w = __u * (1 - __u); |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5132 | if (__w != 0) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5133 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5134 | const result_type __y = _VSTD::sqrt(__c / __w) * |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5135 | (__u - result_type(0.5)); |
| 5136 | __x = __b + __y; |
| 5137 | if (__x >= 0) |
| 5138 | { |
| 5139 | const result_type __z = 64 * __w * __w * __w * __v * __v; |
| 5140 | if (__z <= 1 - 2 * __y * __y / __x) |
| 5141 | break; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5142 | if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5143 | break; |
| 5144 | } |
| 5145 | } |
| 5146 | } |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5147 | } |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5148 | else // __a < 1 |
| 5149 | { |
| 5150 | while (true) |
| 5151 | { |
| 5152 | const result_type __u = __gen(__g); |
| 5153 | const result_type __es = __egen(__g); |
| 5154 | if (__u <= 1 - __a) |
| 5155 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5156 | __x = _VSTD::pow(__u, 1 / __a); |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5157 | if (__x <= __es) |
| 5158 | break; |
| 5159 | } |
| 5160 | else |
| 5161 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5162 | const result_type __e = -_VSTD::log((1-__u)/__a); |
| 5163 | __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); |
Howard Hinnant | 71c6b0b | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5164 | if (__x <= __e + __es) |
| 5165 | break; |
| 5166 | } |
| 5167 | } |
| 5168 | } |
| 5169 | return __x * __p.beta(); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5170 | } |
| 5171 | |
| 5172 | template <class _CharT, class _Traits, class _RT> |
| 5173 | basic_ostream<_CharT, _Traits>& |
| 5174 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5175 | const gamma_distribution<_RT>& __x) |
| 5176 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5177 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5178 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5179 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5180 | _OStream::scientific); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5181 | _CharT __sp = __os.widen(' '); |
| 5182 | __os.fill(__sp); |
| 5183 | __os << __x.alpha() << __sp << __x.beta(); |
| 5184 | return __os; |
| 5185 | } |
| 5186 | |
| 5187 | template <class _CharT, class _Traits, class _RT> |
| 5188 | basic_istream<_CharT, _Traits>& |
| 5189 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5190 | gamma_distribution<_RT>& __x) |
| 5191 | { |
| 5192 | typedef gamma_distribution<_RT> _Eng; |
| 5193 | typedef typename _Eng::result_type result_type; |
| 5194 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5195 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5196 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5197 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | bb6d202 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5198 | result_type __alpha; |
| 5199 | result_type __beta; |
| 5200 | __is >> __alpha >> __beta; |
| 5201 | if (!__is.fail()) |
| 5202 | __x.param(param_type(__alpha, __beta)); |
| 5203 | return __is; |
| 5204 | } |
Howard Hinnant | 0b95bc9 | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 5205 | |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5206 | // negative_binomial_distribution |
| 5207 | |
| 5208 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5209 | class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5210 | { |
| 5211 | public: |
| 5212 | // types |
| 5213 | typedef _IntType result_type; |
| 5214 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5215 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5216 | { |
| 5217 | result_type __k_; |
| 5218 | double __p_; |
| 5219 | public: |
| 5220 | typedef negative_binomial_distribution distribution_type; |
| 5221 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5222 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5223 | explicit param_type(result_type __k = 1, double __p = 0.5) |
| 5224 | : __k_(__k), __p_(__p) {} |
| 5225 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5226 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5227 | result_type k() const {return __k_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5228 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5229 | double p() const {return __p_;} |
| 5230 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5231 | friend _LIBCPP_INLINE_VISIBILITY |
| 5232 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5233 | {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5234 | friend _LIBCPP_INLINE_VISIBILITY |
| 5235 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5236 | {return !(__x == __y);} |
| 5237 | }; |
| 5238 | |
| 5239 | private: |
| 5240 | param_type __p_; |
| 5241 | |
| 5242 | public: |
| 5243 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5244 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5245 | explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) |
| 5246 | : __p_(__k, __p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5247 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5248 | explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5249 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5250 | void reset() {} |
| 5251 | |
| 5252 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5253 | template<class _URNG> |
| 5254 | _LIBCPP_INLINE_VISIBILITY |
| 5255 | result_type operator()(_URNG& __g) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5256 | {return (*this)(__g, __p_);} |
| 5257 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5258 | |
| 5259 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5260 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5261 | result_type k() const {return __p_.k();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5262 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5263 | double p() const {return __p_.p();} |
| 5264 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5265 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5266 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5267 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5268 | void param(const param_type& __p) {__p_ = __p;} |
| 5269 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5270 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5271 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5272 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5273 | result_type max() const {return numeric_limits<result_type>::max();} |
| 5274 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5275 | friend _LIBCPP_INLINE_VISIBILITY |
| 5276 | bool operator==(const negative_binomial_distribution& __x, |
| 5277 | const negative_binomial_distribution& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5278 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5279 | friend _LIBCPP_INLINE_VISIBILITY |
| 5280 | bool operator!=(const negative_binomial_distribution& __x, |
| 5281 | const negative_binomial_distribution& __y) |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5282 | {return !(__x == __y);} |
| 5283 | }; |
| 5284 | |
| 5285 | template <class _IntType> |
| 5286 | template<class _URNG> |
| 5287 | _IntType |
| 5288 | negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) |
| 5289 | { |
| 5290 | result_type __k = __pr.k(); |
| 5291 | double __p = __pr.p(); |
| 5292 | if (__k <= 21 * __p) |
| 5293 | { |
| 5294 | bernoulli_distribution __gen(__p); |
| 5295 | result_type __f = 0; |
| 5296 | result_type __s = 0; |
| 5297 | while (__s < __k) |
| 5298 | { |
| 5299 | if (__gen(__urng)) |
| 5300 | ++__s; |
| 5301 | else |
| 5302 | ++__f; |
| 5303 | } |
| 5304 | return __f; |
| 5305 | } |
| 5306 | return poisson_distribution<result_type>(gamma_distribution<double> |
| 5307 | (__k, (1-__p)/__p)(__urng))(__urng); |
| 5308 | } |
| 5309 | |
| 5310 | template <class _CharT, class _Traits, class _IntType> |
| 5311 | basic_ostream<_CharT, _Traits>& |
| 5312 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5313 | const negative_binomial_distribution<_IntType>& __x) |
| 5314 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5315 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5316 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5317 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5318 | _OStream::scientific); |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5319 | _CharT __sp = __os.widen(' '); |
| 5320 | __os.fill(__sp); |
| 5321 | return __os << __x.k() << __sp << __x.p(); |
| 5322 | } |
| 5323 | |
| 5324 | template <class _CharT, class _Traits, class _IntType> |
| 5325 | basic_istream<_CharT, _Traits>& |
| 5326 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5327 | negative_binomial_distribution<_IntType>& __x) |
| 5328 | { |
| 5329 | typedef negative_binomial_distribution<_IntType> _Eng; |
| 5330 | typedef typename _Eng::result_type result_type; |
| 5331 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5332 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5333 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5334 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 0f43ce6 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5335 | result_type __k; |
| 5336 | double __p; |
| 5337 | __is >> __k >> __p; |
| 5338 | if (!__is.fail()) |
| 5339 | __x.param(param_type(__k, __p)); |
| 5340 | return __is; |
| 5341 | } |
| 5342 | |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5343 | // geometric_distribution |
| 5344 | |
| 5345 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5346 | class _LIBCPP_TEMPLATE_VIS geometric_distribution |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5347 | { |
| 5348 | public: |
| 5349 | // types |
| 5350 | typedef _IntType result_type; |
| 5351 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5352 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5353 | { |
| 5354 | double __p_; |
| 5355 | public: |
| 5356 | typedef geometric_distribution distribution_type; |
| 5357 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5358 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5359 | explicit param_type(double __p = 0.5) : __p_(__p) {} |
| 5360 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5361 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5362 | double p() const {return __p_;} |
| 5363 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5364 | friend _LIBCPP_INLINE_VISIBILITY |
| 5365 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5366 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5367 | friend _LIBCPP_INLINE_VISIBILITY |
| 5368 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5369 | {return !(__x == __y);} |
| 5370 | }; |
| 5371 | |
| 5372 | private: |
| 5373 | param_type __p_; |
| 5374 | |
| 5375 | public: |
| 5376 | // constructors and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5377 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5378 | explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5379 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5380 | explicit geometric_distribution(const param_type& __p) : __p_(__p) {} |
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 | void reset() {} |
| 5383 | |
| 5384 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5385 | template<class _URNG> |
| 5386 | _LIBCPP_INLINE_VISIBILITY |
| 5387 | result_type operator()(_URNG& __g) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5388 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5389 | template<class _URNG> |
| 5390 | _LIBCPP_INLINE_VISIBILITY |
| 5391 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5392 | {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} |
| 5393 | |
| 5394 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5395 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5396 | double p() const {return __p_.p();} |
| 5397 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5398 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5399 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5400 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5401 | void param(const param_type& __p) {__p_ = __p;} |
| 5402 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5403 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5404 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5405 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5406 | result_type max() const {return numeric_limits<result_type>::max();} |
| 5407 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5408 | friend _LIBCPP_INLINE_VISIBILITY |
| 5409 | bool operator==(const geometric_distribution& __x, |
| 5410 | const geometric_distribution& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5411 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5412 | friend _LIBCPP_INLINE_VISIBILITY |
| 5413 | bool operator!=(const geometric_distribution& __x, |
| 5414 | const geometric_distribution& __y) |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5415 | {return !(__x == __y);} |
| 5416 | }; |
| 5417 | |
| 5418 | template <class _CharT, class _Traits, class _IntType> |
| 5419 | basic_ostream<_CharT, _Traits>& |
| 5420 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5421 | const geometric_distribution<_IntType>& __x) |
| 5422 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5423 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5424 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5425 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5426 | _OStream::scientific); |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5427 | return __os << __x.p(); |
| 5428 | } |
| 5429 | |
| 5430 | template <class _CharT, class _Traits, class _IntType> |
| 5431 | basic_istream<_CharT, _Traits>& |
| 5432 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5433 | geometric_distribution<_IntType>& __x) |
| 5434 | { |
| 5435 | typedef geometric_distribution<_IntType> _Eng; |
| 5436 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5437 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5438 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5439 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 28beb16 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5440 | double __p; |
| 5441 | __is >> __p; |
| 5442 | if (!__is.fail()) |
| 5443 | __x.param(param_type(__p)); |
| 5444 | return __is; |
| 5445 | } |
| 5446 | |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5447 | // chi_squared_distribution |
| 5448 | |
| 5449 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5450 | class _LIBCPP_TEMPLATE_VIS chi_squared_distribution |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5451 | { |
| 5452 | public: |
| 5453 | // types |
| 5454 | typedef _RealType result_type; |
| 5455 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5456 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5457 | { |
| 5458 | result_type __n_; |
| 5459 | public: |
| 5460 | typedef chi_squared_distribution distribution_type; |
| 5461 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5462 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5463 | explicit param_type(result_type __n = 1) : __n_(__n) {} |
| 5464 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5465 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5466 | result_type n() const {return __n_;} |
| 5467 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5468 | friend _LIBCPP_INLINE_VISIBILITY |
| 5469 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5470 | {return __x.__n_ == __y.__n_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5471 | friend _LIBCPP_INLINE_VISIBILITY |
| 5472 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5473 | {return !(__x == __y);} |
| 5474 | }; |
| 5475 | |
| 5476 | private: |
| 5477 | param_type __p_; |
| 5478 | |
| 5479 | public: |
| 5480 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5481 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5482 | explicit chi_squared_distribution(result_type __n = 1) |
| 5483 | : __p_(param_type(__n)) {} |
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 | explicit chi_squared_distribution(const param_type& __p) |
| 5486 | : __p_(__p) {} |
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 | void reset() {} |
| 5489 | |
| 5490 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5491 | template<class _URNG> |
| 5492 | _LIBCPP_INLINE_VISIBILITY |
| 5493 | result_type operator()(_URNG& __g) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5494 | {return (*this)(__g, __p_);} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5495 | template<class _URNG> |
| 5496 | _LIBCPP_INLINE_VISIBILITY |
| 5497 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5498 | {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} |
| 5499 | |
| 5500 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5501 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5502 | result_type n() const {return __p_.n();} |
| 5503 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5504 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5505 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5506 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5507 | void param(const param_type& __p) {__p_ = __p;} |
| 5508 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5509 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5510 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5511 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5512 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5513 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5514 | friend _LIBCPP_INLINE_VISIBILITY |
| 5515 | bool operator==(const chi_squared_distribution& __x, |
| 5516 | const chi_squared_distribution& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5517 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5518 | friend _LIBCPP_INLINE_VISIBILITY |
| 5519 | bool operator!=(const chi_squared_distribution& __x, |
| 5520 | const chi_squared_distribution& __y) |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5521 | {return !(__x == __y);} |
| 5522 | }; |
| 5523 | |
| 5524 | template <class _CharT, class _Traits, class _RT> |
| 5525 | basic_ostream<_CharT, _Traits>& |
| 5526 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5527 | const chi_squared_distribution<_RT>& __x) |
| 5528 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5529 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5530 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5531 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5532 | _OStream::scientific); |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5533 | __os << __x.n(); |
| 5534 | return __os; |
| 5535 | } |
| 5536 | |
| 5537 | template <class _CharT, class _Traits, class _RT> |
| 5538 | basic_istream<_CharT, _Traits>& |
| 5539 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5540 | chi_squared_distribution<_RT>& __x) |
| 5541 | { |
| 5542 | typedef chi_squared_distribution<_RT> _Eng; |
| 5543 | typedef typename _Eng::result_type result_type; |
| 5544 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5545 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5546 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5547 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 252ebf0 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5548 | result_type __n; |
| 5549 | __is >> __n; |
| 5550 | if (!__is.fail()) |
| 5551 | __x.param(param_type(__n)); |
| 5552 | return __is; |
| 5553 | } |
| 5554 | |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5555 | // cauchy_distribution |
| 5556 | |
| 5557 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5558 | class _LIBCPP_TEMPLATE_VIS cauchy_distribution |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5559 | { |
| 5560 | public: |
| 5561 | // types |
| 5562 | typedef _RealType result_type; |
| 5563 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5564 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5565 | { |
| 5566 | result_type __a_; |
| 5567 | result_type __b_; |
| 5568 | public: |
| 5569 | typedef cauchy_distribution distribution_type; |
| 5570 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5571 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5572 | explicit param_type(result_type __a = 0, result_type __b = 1) |
| 5573 | : __a_(__a), __b_(__b) {} |
| 5574 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5575 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5576 | result_type a() const {return __a_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5577 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5578 | result_type b() const {return __b_;} |
| 5579 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5580 | friend _LIBCPP_INLINE_VISIBILITY |
| 5581 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5582 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5583 | friend _LIBCPP_INLINE_VISIBILITY |
| 5584 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5585 | {return !(__x == __y);} |
| 5586 | }; |
| 5587 | |
| 5588 | private: |
| 5589 | param_type __p_; |
| 5590 | |
| 5591 | public: |
| 5592 | // constructor and reset 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 | explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) |
| 5595 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5596 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5597 | explicit cauchy_distribution(const param_type& __p) |
| 5598 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5599 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5600 | void reset() {} |
| 5601 | |
| 5602 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5603 | template<class _URNG> |
| 5604 | _LIBCPP_INLINE_VISIBILITY |
| 5605 | result_type operator()(_URNG& __g) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5606 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5607 | 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] | 5608 | |
| 5609 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5610 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5611 | result_type a() const {return __p_.a();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5612 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5613 | result_type b() const {return __p_.b();} |
| 5614 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5615 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5616 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5618 | void param(const param_type& __p) {__p_ = __p;} |
| 5619 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5620 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5621 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5622 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5623 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5624 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5625 | friend _LIBCPP_INLINE_VISIBILITY |
| 5626 | bool operator==(const cauchy_distribution& __x, |
| 5627 | const cauchy_distribution& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5628 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5629 | friend _LIBCPP_INLINE_VISIBILITY |
| 5630 | bool operator!=(const cauchy_distribution& __x, |
| 5631 | const cauchy_distribution& __y) |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5632 | {return !(__x == __y);} |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5633 | }; |
| 5634 | |
| 5635 | template <class _RealType> |
| 5636 | template<class _URNG> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5637 | inline |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5638 | _RealType |
| 5639 | cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5640 | { |
| 5641 | uniform_real_distribution<result_type> __gen; |
| 5642 | // 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] | 5643 | return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | template <class _CharT, class _Traits, class _RT> |
| 5647 | basic_ostream<_CharT, _Traits>& |
| 5648 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5649 | const cauchy_distribution<_RT>& __x) |
| 5650 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5651 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5652 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5653 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5654 | _OStream::scientific); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5655 | _CharT __sp = __os.widen(' '); |
| 5656 | __os.fill(__sp); |
| 5657 | __os << __x.a() << __sp << __x.b(); |
| 5658 | return __os; |
| 5659 | } |
| 5660 | |
| 5661 | template <class _CharT, class _Traits, class _RT> |
| 5662 | basic_istream<_CharT, _Traits>& |
| 5663 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5664 | cauchy_distribution<_RT>& __x) |
| 5665 | { |
| 5666 | typedef cauchy_distribution<_RT> _Eng; |
| 5667 | typedef typename _Eng::result_type result_type; |
| 5668 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5669 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5670 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5671 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | f329256 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5672 | result_type __a; |
| 5673 | result_type __b; |
| 5674 | __is >> __a >> __b; |
| 5675 | if (!__is.fail()) |
| 5676 | __x.param(param_type(__a, __b)); |
| 5677 | return __is; |
| 5678 | } |
| 5679 | |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5680 | // fisher_f_distribution |
| 5681 | |
| 5682 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5683 | class _LIBCPP_TEMPLATE_VIS fisher_f_distribution |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5684 | { |
| 5685 | public: |
| 5686 | // types |
| 5687 | typedef _RealType result_type; |
| 5688 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5689 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5690 | { |
| 5691 | result_type __m_; |
| 5692 | result_type __n_; |
| 5693 | public: |
| 5694 | typedef fisher_f_distribution distribution_type; |
| 5695 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5696 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5697 | explicit param_type(result_type __m = 1, result_type __n = 1) |
| 5698 | : __m_(__m), __n_(__n) {} |
| 5699 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5700 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5701 | result_type m() const {return __m_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5702 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5703 | result_type n() const {return __n_;} |
| 5704 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5705 | friend _LIBCPP_INLINE_VISIBILITY |
| 5706 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5707 | {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5708 | friend _LIBCPP_INLINE_VISIBILITY |
| 5709 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5710 | {return !(__x == __y);} |
| 5711 | }; |
| 5712 | |
| 5713 | private: |
| 5714 | param_type __p_; |
| 5715 | |
| 5716 | public: |
| 5717 | // constructor and reset 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 | explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) |
| 5720 | : __p_(param_type(__m, __n)) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5721 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5722 | explicit fisher_f_distribution(const param_type& __p) |
| 5723 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5724 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5725 | void reset() {} |
| 5726 | |
| 5727 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5728 | template<class _URNG> |
| 5729 | _LIBCPP_INLINE_VISIBILITY |
| 5730 | result_type operator()(_URNG& __g) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5731 | {return (*this)(__g, __p_);} |
| 5732 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5733 | |
| 5734 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5735 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5736 | result_type m() const {return __p_.m();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5737 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5738 | result_type n() const {return __p_.n();} |
| 5739 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5740 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5741 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5742 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5743 | void param(const param_type& __p) {__p_ = __p;} |
| 5744 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5745 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5746 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5747 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5748 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5749 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5750 | friend _LIBCPP_INLINE_VISIBILITY |
| 5751 | bool operator==(const fisher_f_distribution& __x, |
| 5752 | const fisher_f_distribution& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5753 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5754 | friend _LIBCPP_INLINE_VISIBILITY |
| 5755 | bool operator!=(const fisher_f_distribution& __x, |
| 5756 | const fisher_f_distribution& __y) |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5757 | {return !(__x == __y);} |
| 5758 | }; |
| 5759 | |
| 5760 | template <class _RealType> |
| 5761 | template<class _URNG> |
| 5762 | _RealType |
| 5763 | fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5764 | { |
| 5765 | gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); |
| 5766 | gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); |
| 5767 | return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); |
| 5768 | } |
| 5769 | |
| 5770 | template <class _CharT, class _Traits, class _RT> |
| 5771 | basic_ostream<_CharT, _Traits>& |
| 5772 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5773 | const fisher_f_distribution<_RT>& __x) |
| 5774 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5775 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5776 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5777 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5778 | _OStream::scientific); |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5779 | _CharT __sp = __os.widen(' '); |
| 5780 | __os.fill(__sp); |
| 5781 | __os << __x.m() << __sp << __x.n(); |
| 5782 | return __os; |
| 5783 | } |
| 5784 | |
| 5785 | template <class _CharT, class _Traits, class _RT> |
| 5786 | basic_istream<_CharT, _Traits>& |
| 5787 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5788 | fisher_f_distribution<_RT>& __x) |
| 5789 | { |
| 5790 | typedef fisher_f_distribution<_RT> _Eng; |
| 5791 | typedef typename _Eng::result_type result_type; |
| 5792 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5793 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5794 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5795 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | f39463b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5796 | result_type __m; |
| 5797 | result_type __n; |
| 5798 | __is >> __m >> __n; |
| 5799 | if (!__is.fail()) |
| 5800 | __x.param(param_type(__m, __n)); |
| 5801 | return __is; |
| 5802 | } |
| 5803 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5804 | // student_t_distribution |
| 5805 | |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5806 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5807 | class _LIBCPP_TEMPLATE_VIS student_t_distribution |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5808 | { |
| 5809 | public: |
| 5810 | // types |
| 5811 | typedef _RealType result_type; |
| 5812 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5813 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5814 | { |
| 5815 | result_type __n_; |
| 5816 | public: |
| 5817 | typedef student_t_distribution distribution_type; |
| 5818 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5819 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5820 | explicit param_type(result_type __n = 1) : __n_(__n) {} |
| 5821 | |
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 | result_type n() const {return __n_;} |
| 5824 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5825 | friend _LIBCPP_INLINE_VISIBILITY |
| 5826 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5827 | {return __x.__n_ == __y.__n_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5828 | friend _LIBCPP_INLINE_VISIBILITY |
| 5829 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5830 | {return !(__x == __y);} |
| 5831 | }; |
| 5832 | |
| 5833 | private: |
| 5834 | param_type __p_; |
| 5835 | normal_distribution<result_type> __nd_; |
| 5836 | |
| 5837 | public: |
| 5838 | // constructor and reset 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 | explicit student_t_distribution(result_type __n = 1) |
| 5841 | : __p_(param_type(__n)) {} |
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 | explicit student_t_distribution(const param_type& __p) |
| 5844 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5845 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5846 | void reset() {__nd_.reset();} |
| 5847 | |
| 5848 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5849 | template<class _URNG> |
| 5850 | _LIBCPP_INLINE_VISIBILITY |
| 5851 | result_type operator()(_URNG& __g) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5852 | {return (*this)(__g, __p_);} |
| 5853 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5854 | |
| 5855 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5857 | result_type n() const {return __p_.n();} |
| 5858 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5859 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5860 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5861 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5862 | void param(const param_type& __p) {__p_ = __p;} |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5863 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5864 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5865 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5866 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5867 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 5868 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5869 | friend _LIBCPP_INLINE_VISIBILITY |
| 5870 | bool operator==(const student_t_distribution& __x, |
| 5871 | const student_t_distribution& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5872 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5873 | friend _LIBCPP_INLINE_VISIBILITY |
| 5874 | bool operator!=(const student_t_distribution& __x, |
| 5875 | const student_t_distribution& __y) |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5876 | {return !(__x == __y);} |
| 5877 | }; |
| 5878 | |
| 5879 | template <class _RealType> |
| 5880 | template<class _URNG> |
| 5881 | _RealType |
| 5882 | student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5883 | { |
| 5884 | gamma_distribution<result_type> __gd(__p.n() * .5, 2); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5885 | return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5886 | } |
| 5887 | |
| 5888 | template <class _CharT, class _Traits, class _RT> |
| 5889 | basic_ostream<_CharT, _Traits>& |
| 5890 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5891 | const student_t_distribution<_RT>& __x) |
| 5892 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5893 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5894 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 5895 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 5896 | _OStream::scientific); |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5897 | __os << __x.n(); |
| 5898 | return __os; |
| 5899 | } |
| 5900 | |
| 5901 | template <class _CharT, class _Traits, class _RT> |
| 5902 | basic_istream<_CharT, _Traits>& |
| 5903 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5904 | student_t_distribution<_RT>& __x) |
| 5905 | { |
| 5906 | typedef student_t_distribution<_RT> _Eng; |
| 5907 | typedef typename _Eng::result_type result_type; |
| 5908 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5909 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 5910 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 5911 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 20c5088 | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5912 | result_type __n; |
| 5913 | __is >> __n; |
| 5914 | if (!__is.fail()) |
| 5915 | __x.param(param_type(__n)); |
| 5916 | return __is; |
| 5917 | } |
| 5918 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5919 | // discrete_distribution |
| 5920 | |
| 5921 | template<class _IntType = int> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5922 | class _LIBCPP_TEMPLATE_VIS discrete_distribution |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5923 | { |
| 5924 | public: |
| 5925 | // types |
| 5926 | typedef _IntType result_type; |
| 5927 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5928 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5929 | { |
| 5930 | vector<double> __p_; |
| 5931 | public: |
| 5932 | typedef discrete_distribution distribution_type; |
| 5933 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5934 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5935 | param_type() {} |
| 5936 | template<class _InputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5937 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5938 | param_type(_InputIterator __f, _InputIterator __l) |
| 5939 | : __p_(__f, __l) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5940 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5941 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5942 | param_type(initializer_list<double> __wl) |
| 5943 | : __p_(__wl.begin(), __wl.end()) {__init();} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5944 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5945 | template<class _UnaryOperation> |
| 5946 | param_type(size_t __nw, double __xmin, double __xmax, |
| 5947 | _UnaryOperation __fw); |
| 5948 | |
| 5949 | vector<double> probabilities() const; |
| 5950 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5951 | friend _LIBCPP_INLINE_VISIBILITY |
| 5952 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5953 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5954 | friend _LIBCPP_INLINE_VISIBILITY |
| 5955 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5956 | {return !(__x == __y);} |
| 5957 | |
| 5958 | private: |
| 5959 | void __init(); |
| 5960 | |
| 5961 | friend class discrete_distribution; |
| 5962 | |
| 5963 | template <class _CharT, class _Traits, class _IT> |
| 5964 | friend |
| 5965 | basic_ostream<_CharT, _Traits>& |
| 5966 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5967 | const discrete_distribution<_IT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5968 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5969 | template <class _CharT, class _Traits, class _IT> |
| 5970 | friend |
| 5971 | basic_istream<_CharT, _Traits>& |
| 5972 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5973 | discrete_distribution<_IT>& __x); |
| 5974 | }; |
| 5975 | |
| 5976 | private: |
| 5977 | param_type __p_; |
| 5978 | |
| 5979 | public: |
| 5980 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5981 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5982 | discrete_distribution() {} |
| 5983 | template<class _InputIterator> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5984 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5985 | discrete_distribution(_InputIterator __f, _InputIterator __l) |
| 5986 | : __p_(__f, __l) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5987 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5988 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5989 | discrete_distribution(initializer_list<double> __wl) |
| 5990 | : __p_(__wl) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5991 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5992 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5993 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5994 | discrete_distribution(size_t __nw, double __xmin, double __xmax, |
| 5995 | _UnaryOperation __fw) |
| 5996 | : __p_(__nw, __xmin, __xmax, __fw) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5997 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ea38295 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 5998 | explicit discrete_distribution(const param_type& __p) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5999 | : __p_(__p) {} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6000 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6001 | void reset() {} |
| 6002 | |
| 6003 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6004 | template<class _URNG> |
| 6005 | _LIBCPP_INLINE_VISIBILITY |
| 6006 | result_type operator()(_URNG& __g) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6007 | {return (*this)(__g, __p_);} |
| 6008 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6009 | |
| 6010 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6011 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6012 | vector<double> probabilities() const {return __p_.probabilities();} |
| 6013 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6014 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6015 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6016 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6017 | void param(const param_type& __p) {__p_ = __p;} |
| 6018 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6019 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6020 | result_type min() const {return 0;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6021 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6022 | result_type max() const {return __p_.__p_.size();} |
| 6023 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6024 | friend _LIBCPP_INLINE_VISIBILITY |
| 6025 | bool operator==(const discrete_distribution& __x, |
| 6026 | const discrete_distribution& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6027 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6028 | friend _LIBCPP_INLINE_VISIBILITY |
| 6029 | bool operator!=(const discrete_distribution& __x, |
| 6030 | const discrete_distribution& __y) |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6031 | {return !(__x == __y);} |
| 6032 | |
| 6033 | template <class _CharT, class _Traits, class _IT> |
| 6034 | friend |
| 6035 | basic_ostream<_CharT, _Traits>& |
| 6036 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6037 | const discrete_distribution<_IT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6038 | |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6039 | template <class _CharT, class _Traits, class _IT> |
| 6040 | friend |
| 6041 | basic_istream<_CharT, _Traits>& |
| 6042 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6043 | discrete_distribution<_IT>& __x); |
| 6044 | }; |
| 6045 | |
| 6046 | template<class _IntType> |
| 6047 | template<class _UnaryOperation> |
| 6048 | discrete_distribution<_IntType>::param_type::param_type(size_t __nw, |
| 6049 | double __xmin, |
| 6050 | double __xmax, |
| 6051 | _UnaryOperation __fw) |
| 6052 | { |
| 6053 | if (__nw > 1) |
| 6054 | { |
| 6055 | __p_.reserve(__nw - 1); |
| 6056 | double __d = (__xmax - __xmin) / __nw; |
| 6057 | double __d2 = __d / 2; |
| 6058 | for (size_t __k = 0; __k < __nw; ++__k) |
| 6059 | __p_.push_back(__fw(__xmin + __k * __d + __d2)); |
| 6060 | __init(); |
| 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | template<class _IntType> |
| 6065 | void |
| 6066 | discrete_distribution<_IntType>::param_type::__init() |
| 6067 | { |
| 6068 | if (!__p_.empty()) |
| 6069 | { |
| 6070 | if (__p_.size() > 1) |
| 6071 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6072 | double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); |
| 6073 | for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6074 | __i < __e; ++__i) |
| 6075 | *__i /= __s; |
| 6076 | vector<double> __t(__p_.size() - 1); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6077 | _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6078 | swap(__p_, __t); |
| 6079 | } |
| 6080 | else |
| 6081 | { |
| 6082 | __p_.clear(); |
| 6083 | __p_.shrink_to_fit(); |
| 6084 | } |
| 6085 | } |
| 6086 | } |
| 6087 | |
| 6088 | template<class _IntType> |
| 6089 | vector<double> |
| 6090 | discrete_distribution<_IntType>::param_type::probabilities() const |
| 6091 | { |
| 6092 | size_t __n = __p_.size(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6093 | _VSTD::vector<double> __p(__n+1); |
| 6094 | _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6095 | if (__n > 0) |
| 6096 | __p[__n] = 1 - __p_[__n-1]; |
| 6097 | else |
| 6098 | __p[0] = 1; |
| 6099 | return __p; |
| 6100 | } |
| 6101 | |
| 6102 | template<class _IntType> |
| 6103 | template<class _URNG> |
| 6104 | _IntType |
| 6105 | discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) |
| 6106 | { |
| 6107 | uniform_real_distribution<double> __gen; |
| 6108 | return static_cast<_IntType>( |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6109 | _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6110 | __p.__p_.begin()); |
| 6111 | } |
| 6112 | |
| 6113 | template <class _CharT, class _Traits, class _IT> |
| 6114 | basic_ostream<_CharT, _Traits>& |
| 6115 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6116 | const discrete_distribution<_IT>& __x) |
| 6117 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6118 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6119 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6120 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6121 | _OStream::scientific); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6122 | _CharT __sp = __os.widen(' '); |
| 6123 | __os.fill(__sp); |
| 6124 | size_t __n = __x.__p_.__p_.size(); |
| 6125 | __os << __n; |
| 6126 | for (size_t __i = 0; __i < __n; ++__i) |
| 6127 | __os << __sp << __x.__p_.__p_[__i]; |
| 6128 | return __os; |
| 6129 | } |
| 6130 | |
| 6131 | template <class _CharT, class _Traits, class _IT> |
| 6132 | basic_istream<_CharT, _Traits>& |
| 6133 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6134 | discrete_distribution<_IT>& __x) |
| 6135 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6136 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6137 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6138 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6139 | size_t __n; |
| 6140 | __is >> __n; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6141 | vector<double> __p(__n); |
Howard Hinnant | 7fdb18d | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6142 | for (size_t __i = 0; __i < __n; ++__i) |
| 6143 | __is >> __p[__i]; |
| 6144 | if (!__is.fail()) |
| 6145 | swap(__x.__p_.__p_, __p); |
| 6146 | return __is; |
| 6147 | } |
| 6148 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6149 | // piecewise_constant_distribution |
| 6150 | |
| 6151 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6152 | class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6153 | { |
| 6154 | public: |
| 6155 | // types |
| 6156 | typedef _RealType result_type; |
| 6157 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6158 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6159 | { |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6160 | vector<result_type> __b_; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6161 | vector<result_type> __densities_; |
| 6162 | vector<result_type> __areas_; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6163 | public: |
| 6164 | typedef piecewise_constant_distribution distribution_type; |
| 6165 | |
| 6166 | param_type(); |
| 6167 | template<class _InputIteratorB, class _InputIteratorW> |
| 6168 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, |
| 6169 | _InputIteratorW __fW); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6170 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6171 | template<class _UnaryOperation> |
| 6172 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6173 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6174 | template<class _UnaryOperation> |
| 6175 | param_type(size_t __nw, result_type __xmin, result_type __xmax, |
| 6176 | _UnaryOperation __fw); |
Eric Fiselier | b9f37ca | 2019-12-12 20:48:11 -0500 | [diff] [blame] | 6177 | param_type(param_type const&) = default; |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6178 | param_type & operator=(const param_type& __rhs); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6179 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6180 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6181 | vector<result_type> intervals() const {return __b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6182 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6183 | vector<result_type> densities() const {return __densities_;} |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6184 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6185 | friend _LIBCPP_INLINE_VISIBILITY |
| 6186 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6187 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6188 | friend _LIBCPP_INLINE_VISIBILITY |
| 6189 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6190 | {return !(__x == __y);} |
| 6191 | |
| 6192 | private: |
| 6193 | void __init(); |
| 6194 | |
| 6195 | friend class piecewise_constant_distribution; |
| 6196 | |
| 6197 | template <class _CharT, class _Traits, class _RT> |
| 6198 | friend |
| 6199 | basic_ostream<_CharT, _Traits>& |
| 6200 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6201 | const piecewise_constant_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6202 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6203 | template <class _CharT, class _Traits, class _RT> |
| 6204 | friend |
| 6205 | basic_istream<_CharT, _Traits>& |
| 6206 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6207 | piecewise_constant_distribution<_RT>& __x); |
| 6208 | }; |
| 6209 | |
| 6210 | private: |
| 6211 | param_type __p_; |
| 6212 | |
| 6213 | public: |
| 6214 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6215 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6216 | piecewise_constant_distribution() {} |
| 6217 | template<class _InputIteratorB, class _InputIteratorW> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6218 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6219 | piecewise_constant_distribution(_InputIteratorB __fB, |
| 6220 | _InputIteratorB __lB, |
| 6221 | _InputIteratorW __fW) |
| 6222 | : __p_(__fB, __lB, __fW) {} |
| 6223 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6224 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6225 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6226 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6227 | piecewise_constant_distribution(initializer_list<result_type> __bl, |
| 6228 | _UnaryOperation __fw) |
| 6229 | : __p_(__bl, __fw) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6230 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6231 | |
| 6232 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6233 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6234 | piecewise_constant_distribution(size_t __nw, result_type __xmin, |
| 6235 | result_type __xmax, _UnaryOperation __fw) |
| 6236 | : __p_(__nw, __xmin, __xmax, __fw) {} |
| 6237 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6238 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6239 | explicit piecewise_constant_distribution(const param_type& __p) |
| 6240 | : __p_(__p) {} |
| 6241 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6242 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6243 | void reset() {} |
| 6244 | |
| 6245 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6246 | template<class _URNG> |
| 6247 | _LIBCPP_INLINE_VISIBILITY |
| 6248 | result_type operator()(_URNG& __g) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6249 | {return (*this)(__g, __p_);} |
| 6250 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6251 | |
| 6252 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6253 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6254 | vector<result_type> intervals() const {return __p_.intervals();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6255 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6256 | vector<result_type> densities() const {return __p_.densities();} |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6257 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6258 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6259 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6260 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6261 | void param(const param_type& __p) {__p_ = __p;} |
| 6262 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6263 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6264 | result_type min() const {return __p_.__b_.front();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6265 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6266 | result_type max() const {return __p_.__b_.back();} |
| 6267 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6268 | friend _LIBCPP_INLINE_VISIBILITY |
| 6269 | bool operator==(const piecewise_constant_distribution& __x, |
| 6270 | const piecewise_constant_distribution& __y) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6271 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6272 | friend _LIBCPP_INLINE_VISIBILITY |
| 6273 | bool operator!=(const piecewise_constant_distribution& __x, |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6274 | const piecewise_constant_distribution& __y) |
| 6275 | {return !(__x == __y);} |
| 6276 | |
| 6277 | template <class _CharT, class _Traits, class _RT> |
| 6278 | friend |
| 6279 | basic_ostream<_CharT, _Traits>& |
| 6280 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6281 | const piecewise_constant_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6282 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6283 | template <class _CharT, class _Traits, class _RT> |
| 6284 | friend |
| 6285 | basic_istream<_CharT, _Traits>& |
| 6286 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6287 | piecewise_constant_distribution<_RT>& __x); |
| 6288 | }; |
| 6289 | |
| 6290 | template<class _RealType> |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6291 | typename piecewise_constant_distribution<_RealType>::param_type & |
| 6292 | piecewise_constant_distribution<_RealType>::param_type::operator= |
| 6293 | (const param_type& __rhs) |
| 6294 | { |
| 6295 | // These can throw |
| 6296 | __b_.reserve (__rhs.__b_.size ()); |
| 6297 | __densities_.reserve(__rhs.__densities_.size()); |
| 6298 | __areas_.reserve (__rhs.__areas_.size()); |
| 6299 | |
| 6300 | // These can not throw |
| 6301 | __b_ = __rhs.__b_; |
| 6302 | __densities_ = __rhs.__densities_; |
| 6303 | __areas_ = __rhs.__areas_; |
| 6304 | return *this; |
| 6305 | } |
| 6306 | |
| 6307 | template<class _RealType> |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6308 | void |
| 6309 | piecewise_constant_distribution<_RealType>::param_type::__init() |
| 6310 | { |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6311 | // __densities_ contains non-normalized areas |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6312 | result_type __total_area = _VSTD::accumulate(__densities_.begin(), |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6313 | __densities_.end(), |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6314 | result_type()); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6315 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
| 6316 | __densities_[__i] /= __total_area; |
| 6317 | // __densities_ contains normalized areas |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6318 | __areas_.assign(__densities_.size(), result_type()); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6319 | _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6320 | __areas_.begin() + 1); |
| 6321 | // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] |
| 6322 | __densities_.back() = 1 - __areas_.back(); // correct round off error |
| 6323 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
| 6324 | __densities_[__i] /= (__b_[__i+1] - __b_[__i]); |
| 6325 | // __densities_ now contains __densities_ |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6326 | } |
| 6327 | |
| 6328 | template<class _RealType> |
| 6329 | piecewise_constant_distribution<_RealType>::param_type::param_type() |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6330 | : __b_(2), |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6331 | __densities_(1, 1.0), |
| 6332 | __areas_(1, 0.0) |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6333 | { |
| 6334 | __b_[1] = 1; |
| 6335 | } |
| 6336 | |
| 6337 | template<class _RealType> |
| 6338 | template<class _InputIteratorB, class _InputIteratorW> |
| 6339 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6340 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) |
| 6341 | : __b_(__fB, __lB) |
| 6342 | { |
| 6343 | if (__b_.size() < 2) |
| 6344 | { |
| 6345 | __b_.resize(2); |
| 6346 | __b_[0] = 0; |
| 6347 | __b_[1] = 1; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6348 | __densities_.assign(1, 1.0); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6349 | __areas_.assign(1, 0.0); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6350 | } |
| 6351 | else |
| 6352 | { |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6353 | __densities_.reserve(__b_.size() - 1); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6354 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6355 | __densities_.push_back(*__fW); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6356 | __init(); |
| 6357 | } |
| 6358 | } |
| 6359 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6360 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6361 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6362 | template<class _RealType> |
| 6363 | template<class _UnaryOperation> |
| 6364 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6365 | initializer_list<result_type> __bl, _UnaryOperation __fw) |
| 6366 | : __b_(__bl.begin(), __bl.end()) |
| 6367 | { |
| 6368 | if (__b_.size() < 2) |
| 6369 | { |
| 6370 | __b_.resize(2); |
| 6371 | __b_[0] = 0; |
| 6372 | __b_[1] = 1; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6373 | __densities_.assign(1, 1.0); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6374 | __areas_.assign(1, 0.0); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6375 | } |
| 6376 | else |
| 6377 | { |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6378 | __densities_.reserve(__b_.size() - 1); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6379 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6380 | __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6381 | __init(); |
| 6382 | } |
| 6383 | } |
| 6384 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6385 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6386 | |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6387 | template<class _RealType> |
| 6388 | template<class _UnaryOperation> |
| 6389 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6390 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) |
| 6391 | : __b_(__nw == 0 ? 2 : __nw + 1) |
| 6392 | { |
| 6393 | size_t __n = __b_.size() - 1; |
| 6394 | result_type __d = (__xmax - __xmin) / __n; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6395 | __densities_.reserve(__n); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6396 | for (size_t __i = 0; __i < __n; ++__i) |
| 6397 | { |
| 6398 | __b_[__i] = __xmin + __i * __d; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6399 | __densities_.push_back(__fw(__b_[__i] + __d*.5)); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6400 | } |
| 6401 | __b_[__n] = __xmax; |
| 6402 | __init(); |
| 6403 | } |
| 6404 | |
| 6405 | template<class _RealType> |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6406 | template<class _URNG> |
| 6407 | _RealType |
| 6408 | piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 6409 | { |
| 6410 | typedef uniform_real_distribution<result_type> _Gen; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6411 | result_type __u = _Gen()(__g); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6412 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6413 | __u) - __p.__areas_.begin() - 1; |
| 6414 | return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6415 | } |
| 6416 | |
| 6417 | template <class _CharT, class _Traits, class _RT> |
| 6418 | basic_ostream<_CharT, _Traits>& |
| 6419 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6420 | const piecewise_constant_distribution<_RT>& __x) |
| 6421 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6422 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6423 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6424 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6425 | _OStream::scientific); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6426 | _CharT __sp = __os.widen(' '); |
| 6427 | __os.fill(__sp); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6428 | size_t __n = __x.__p_.__b_.size(); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6429 | __os << __n; |
| 6430 | for (size_t __i = 0; __i < __n; ++__i) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6431 | __os << __sp << __x.__p_.__b_[__i]; |
| 6432 | __n = __x.__p_.__densities_.size(); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6433 | __os << __sp << __n; |
| 6434 | for (size_t __i = 0; __i < __n; ++__i) |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6435 | __os << __sp << __x.__p_.__densities_[__i]; |
| 6436 | __n = __x.__p_.__areas_.size(); |
| 6437 | __os << __sp << __n; |
| 6438 | for (size_t __i = 0; __i < __n; ++__i) |
| 6439 | __os << __sp << __x.__p_.__areas_[__i]; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6440 | return __os; |
| 6441 | } |
| 6442 | |
| 6443 | template <class _CharT, class _Traits, class _RT> |
| 6444 | basic_istream<_CharT, _Traits>& |
| 6445 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6446 | piecewise_constant_distribution<_RT>& __x) |
| 6447 | { |
| 6448 | typedef piecewise_constant_distribution<_RT> _Eng; |
| 6449 | typedef typename _Eng::result_type result_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6450 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6451 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6452 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6453 | size_t __n; |
| 6454 | __is >> __n; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6455 | vector<result_type> __b(__n); |
| 6456 | for (size_t __i = 0; __i < __n; ++__i) |
| 6457 | __is >> __b[__i]; |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6458 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6459 | vector<result_type> __densities(__n); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6460 | for (size_t __i = 0; __i < __n; ++__i) |
| 6461 | __is >> __densities[__i]; |
| 6462 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6463 | vector<result_type> __areas(__n); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6464 | for (size_t __i = 0; __i < __n; ++__i) |
| 6465 | __is >> __areas[__i]; |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6466 | if (!__is.fail()) |
| 6467 | { |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6468 | swap(__x.__p_.__b_, __b); |
Howard Hinnant | 35d83df | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6469 | swap(__x.__p_.__densities_, __densities); |
| 6470 | swap(__x.__p_.__areas_, __areas); |
Howard Hinnant | 481ba38 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6471 | } |
| 6472 | return __is; |
| 6473 | } |
| 6474 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6475 | // piecewise_linear_distribution |
| 6476 | |
| 6477 | template<class _RealType = double> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6478 | class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6479 | { |
| 6480 | public: |
| 6481 | // types |
| 6482 | typedef _RealType result_type; |
| 6483 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6484 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6485 | { |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6486 | vector<result_type> __b_; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6487 | vector<result_type> __densities_; |
| 6488 | vector<result_type> __areas_; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6489 | public: |
| 6490 | typedef piecewise_linear_distribution distribution_type; |
| 6491 | |
| 6492 | param_type(); |
| 6493 | template<class _InputIteratorB, class _InputIteratorW> |
| 6494 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, |
| 6495 | _InputIteratorW __fW); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6496 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6497 | template<class _UnaryOperation> |
| 6498 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6499 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6500 | template<class _UnaryOperation> |
| 6501 | param_type(size_t __nw, result_type __xmin, result_type __xmax, |
| 6502 | _UnaryOperation __fw); |
Eric Fiselier | b9f37ca | 2019-12-12 20:48:11 -0500 | [diff] [blame] | 6503 | param_type(param_type const&) = default; |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6504 | param_type & operator=(const param_type& __rhs); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6505 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6506 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6507 | vector<result_type> intervals() const {return __b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6508 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6509 | vector<result_type> densities() const {return __densities_;} |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6510 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6511 | friend _LIBCPP_INLINE_VISIBILITY |
| 6512 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6513 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6514 | friend _LIBCPP_INLINE_VISIBILITY |
| 6515 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6516 | {return !(__x == __y);} |
| 6517 | |
| 6518 | private: |
| 6519 | void __init(); |
| 6520 | |
| 6521 | friend class piecewise_linear_distribution; |
| 6522 | |
| 6523 | template <class _CharT, class _Traits, class _RT> |
| 6524 | friend |
| 6525 | basic_ostream<_CharT, _Traits>& |
| 6526 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6527 | const piecewise_linear_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6528 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6529 | template <class _CharT, class _Traits, class _RT> |
| 6530 | friend |
| 6531 | basic_istream<_CharT, _Traits>& |
| 6532 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6533 | piecewise_linear_distribution<_RT>& __x); |
| 6534 | }; |
| 6535 | |
| 6536 | private: |
| 6537 | param_type __p_; |
| 6538 | |
| 6539 | public: |
| 6540 | // constructor and reset functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6541 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6542 | piecewise_linear_distribution() {} |
| 6543 | template<class _InputIteratorB, class _InputIteratorW> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6544 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6545 | piecewise_linear_distribution(_InputIteratorB __fB, |
| 6546 | _InputIteratorB __lB, |
| 6547 | _InputIteratorW __fW) |
| 6548 | : __p_(__fB, __lB, __fW) {} |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6549 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6550 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6551 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6552 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6553 | piecewise_linear_distribution(initializer_list<result_type> __bl, |
| 6554 | _UnaryOperation __fw) |
| 6555 | : __p_(__bl, __fw) {} |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6556 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6557 | |
| 6558 | template<class _UnaryOperation> |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6559 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6560 | piecewise_linear_distribution(size_t __nw, result_type __xmin, |
| 6561 | result_type __xmax, _UnaryOperation __fw) |
| 6562 | : __p_(__nw, __xmin, __xmax, __fw) {} |
| 6563 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6564 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6565 | explicit piecewise_linear_distribution(const param_type& __p) |
| 6566 | : __p_(__p) {} |
| 6567 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6568 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6569 | void reset() {} |
| 6570 | |
| 6571 | // generating functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6572 | template<class _URNG> |
| 6573 | _LIBCPP_INLINE_VISIBILITY |
| 6574 | result_type operator()(_URNG& __g) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6575 | {return (*this)(__g, __p_);} |
| 6576 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6577 | |
| 6578 | // property functions |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6579 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6580 | vector<result_type> intervals() const {return __p_.intervals();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6581 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6582 | vector<result_type> densities() const {return __p_.densities();} |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6583 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6584 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6585 | param_type param() const {return __p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6586 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6587 | void param(const param_type& __p) {__p_ = __p;} |
| 6588 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6589 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6590 | result_type min() const {return __p_.__b_.front();} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6591 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6592 | result_type max() const {return __p_.__b_.back();} |
| 6593 | |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6594 | friend _LIBCPP_INLINE_VISIBILITY |
| 6595 | bool operator==(const piecewise_linear_distribution& __x, |
| 6596 | const piecewise_linear_distribution& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6597 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | f5f9999 | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6598 | friend _LIBCPP_INLINE_VISIBILITY |
| 6599 | bool operator!=(const piecewise_linear_distribution& __x, |
| 6600 | const piecewise_linear_distribution& __y) |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6601 | {return !(__x == __y);} |
| 6602 | |
| 6603 | template <class _CharT, class _Traits, class _RT> |
| 6604 | friend |
| 6605 | basic_ostream<_CharT, _Traits>& |
| 6606 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6607 | const piecewise_linear_distribution<_RT>& __x); |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6608 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6609 | template <class _CharT, class _Traits, class _RT> |
| 6610 | friend |
| 6611 | basic_istream<_CharT, _Traits>& |
| 6612 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6613 | piecewise_linear_distribution<_RT>& __x); |
| 6614 | }; |
| 6615 | |
| 6616 | template<class _RealType> |
Howard Hinnant | 71c410b | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6617 | typename piecewise_linear_distribution<_RealType>::param_type & |
| 6618 | piecewise_linear_distribution<_RealType>::param_type::operator= |
| 6619 | (const param_type& __rhs) |
| 6620 | { |
| 6621 | // These can throw |
| 6622 | __b_.reserve (__rhs.__b_.size ()); |
| 6623 | __densities_.reserve(__rhs.__densities_.size()); |
| 6624 | __areas_.reserve (__rhs.__areas_.size()); |
| 6625 | |
| 6626 | // These can not throw |
| 6627 | __b_ = __rhs.__b_; |
| 6628 | __densities_ = __rhs.__densities_; |
| 6629 | __areas_ = __rhs.__areas_; |
| 6630 | return *this; |
| 6631 | } |
| 6632 | |
| 6633 | |
| 6634 | template<class _RealType> |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6635 | void |
| 6636 | piecewise_linear_distribution<_RealType>::param_type::__init() |
| 6637 | { |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6638 | __areas_.assign(__densities_.size() - 1, result_type()); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6639 | result_type _Sp = 0; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6640 | for (size_t __i = 0; __i < __areas_.size(); ++__i) |
| 6641 | { |
| 6642 | __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * |
| 6643 | (__b_[__i+1] - __b_[__i]) * .5; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6644 | _Sp += __areas_[__i]; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6645 | } |
| 6646 | for (size_t __i = __areas_.size(); __i > 1;) |
| 6647 | { |
| 6648 | --__i; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6649 | __areas_[__i] = __areas_[__i-1] / _Sp; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6650 | } |
| 6651 | __areas_[0] = 0; |
| 6652 | for (size_t __i = 1; __i < __areas_.size(); ++__i) |
| 6653 | __areas_[__i] += __areas_[__i-1]; |
| 6654 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6655 | __densities_[__i] /= _Sp; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6656 | } |
| 6657 | |
| 6658 | template<class _RealType> |
| 6659 | piecewise_linear_distribution<_RealType>::param_type::param_type() |
| 6660 | : __b_(2), |
| 6661 | __densities_(2, 1.0), |
| 6662 | __areas_(1, 0.0) |
| 6663 | { |
| 6664 | __b_[1] = 1; |
| 6665 | } |
| 6666 | |
| 6667 | template<class _RealType> |
| 6668 | template<class _InputIteratorB, class _InputIteratorW> |
| 6669 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6670 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) |
| 6671 | : __b_(__fB, __lB) |
| 6672 | { |
| 6673 | if (__b_.size() < 2) |
| 6674 | { |
| 6675 | __b_.resize(2); |
| 6676 | __b_[0] = 0; |
| 6677 | __b_[1] = 1; |
| 6678 | __densities_.assign(2, 1.0); |
| 6679 | __areas_.assign(1, 0.0); |
| 6680 | } |
| 6681 | else |
| 6682 | { |
| 6683 | __densities_.reserve(__b_.size()); |
| 6684 | for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) |
| 6685 | __densities_.push_back(*__fW); |
| 6686 | __init(); |
| 6687 | } |
| 6688 | } |
| 6689 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6690 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6691 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6692 | template<class _RealType> |
| 6693 | template<class _UnaryOperation> |
| 6694 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6695 | initializer_list<result_type> __bl, _UnaryOperation __fw) |
| 6696 | : __b_(__bl.begin(), __bl.end()) |
| 6697 | { |
| 6698 | if (__b_.size() < 2) |
| 6699 | { |
| 6700 | __b_.resize(2); |
| 6701 | __b_[0] = 0; |
| 6702 | __b_[1] = 1; |
| 6703 | __densities_.assign(2, 1.0); |
| 6704 | __areas_.assign(1, 0.0); |
| 6705 | } |
| 6706 | else |
| 6707 | { |
| 6708 | __densities_.reserve(__b_.size()); |
| 6709 | for (size_t __i = 0; __i < __b_.size(); ++__i) |
| 6710 | __densities_.push_back(__fw(__b_[__i])); |
| 6711 | __init(); |
| 6712 | } |
| 6713 | } |
| 6714 | |
Eric Fiselier | 3b0b81f | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6715 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6716 | |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6717 | template<class _RealType> |
| 6718 | template<class _UnaryOperation> |
| 6719 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6720 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) |
| 6721 | : __b_(__nw == 0 ? 2 : __nw + 1) |
| 6722 | { |
| 6723 | size_t __n = __b_.size() - 1; |
| 6724 | result_type __d = (__xmax - __xmin) / __n; |
| 6725 | __densities_.reserve(__b_.size()); |
| 6726 | for (size_t __i = 0; __i < __n; ++__i) |
| 6727 | { |
| 6728 | __b_[__i] = __xmin + __i * __d; |
| 6729 | __densities_.push_back(__fw(__b_[__i])); |
| 6730 | } |
| 6731 | __b_[__n] = __xmax; |
| 6732 | __densities_.push_back(__fw(__b_[__n])); |
| 6733 | __init(); |
| 6734 | } |
| 6735 | |
| 6736 | template<class _RealType> |
| 6737 | template<class _URNG> |
| 6738 | _RealType |
| 6739 | piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 6740 | { |
| 6741 | typedef uniform_real_distribution<result_type> _Gen; |
| 6742 | result_type __u = _Gen()(__g); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6743 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6744 | __u) - __p.__areas_.begin() - 1; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6745 | __u -= __p.__areas_[__k]; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6746 | const result_type __dk = __p.__densities_[__k]; |
| 6747 | const result_type __dk1 = __p.__densities_[__k+1]; |
| 6748 | const result_type __deltad = __dk1 - __dk; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6749 | const result_type __bk = __p.__b_[__k]; |
| 6750 | if (__deltad == 0) |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6751 | return __u / __dk + __bk; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6752 | const result_type __bk1 = __p.__b_[__k+1]; |
| 6753 | const result_type __deltab = __bk1 - __bk; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6754 | return (__bk * __dk1 - __bk1 * __dk + |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6755 | _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6756 | __deltad; |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6757 | } |
| 6758 | |
| 6759 | template <class _CharT, class _Traits, class _RT> |
| 6760 | basic_ostream<_CharT, _Traits>& |
| 6761 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6762 | const piecewise_linear_distribution<_RT>& __x) |
| 6763 | { |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6764 | __save_flags<_CharT, _Traits> __lx(__os); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6765 | typedef basic_ostream<_CharT, _Traits> _OStream; |
| 6766 | __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | |
| 6767 | _OStream::scientific); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6768 | _CharT __sp = __os.widen(' '); |
| 6769 | __os.fill(__sp); |
| 6770 | size_t __n = __x.__p_.__b_.size(); |
| 6771 | __os << __n; |
| 6772 | for (size_t __i = 0; __i < __n; ++__i) |
| 6773 | __os << __sp << __x.__p_.__b_[__i]; |
| 6774 | __n = __x.__p_.__densities_.size(); |
| 6775 | __os << __sp << __n; |
| 6776 | for (size_t __i = 0; __i < __n; ++__i) |
| 6777 | __os << __sp << __x.__p_.__densities_[__i]; |
| 6778 | __n = __x.__p_.__areas_.size(); |
| 6779 | __os << __sp << __n; |
| 6780 | for (size_t __i = 0; __i < __n; ++__i) |
| 6781 | __os << __sp << __x.__p_.__areas_[__i]; |
| 6782 | return __os; |
| 6783 | } |
| 6784 | |
| 6785 | template <class _CharT, class _Traits, class _RT> |
| 6786 | basic_istream<_CharT, _Traits>& |
| 6787 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6788 | piecewise_linear_distribution<_RT>& __x) |
| 6789 | { |
| 6790 | typedef piecewise_linear_distribution<_RT> _Eng; |
| 6791 | typedef typename _Eng::result_type result_type; |
Howard Hinnant | 49e145e | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6792 | __save_flags<_CharT, _Traits> __lx(__is); |
Louis Dionne | 3df65ce | 2020-10-15 13:27:27 -0400 | [diff] [blame] | 6793 | typedef basic_istream<_CharT, _Traits> _Istream; |
| 6794 | __is.flags(_Istream::dec | _Istream::skipws); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6795 | size_t __n; |
| 6796 | __is >> __n; |
| 6797 | vector<result_type> __b(__n); |
| 6798 | for (size_t __i = 0; __i < __n; ++__i) |
| 6799 | __is >> __b[__i]; |
| 6800 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6801 | vector<result_type> __densities(__n); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6802 | for (size_t __i = 0; __i < __n; ++__i) |
| 6803 | __is >> __densities[__i]; |
| 6804 | __is >> __n; |
Howard Hinnant | 167159f | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6805 | vector<result_type> __areas(__n); |
Howard Hinnant | a001ef3 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6806 | for (size_t __i = 0; __i < __n; ++__i) |
| 6807 | __is >> __areas[__i]; |
| 6808 | if (!__is.fail()) |
| 6809 | { |
| 6810 | swap(__x.__p_.__b_, __b); |
| 6811 | swap(__x.__p_.__densities_, __densities); |
| 6812 | swap(__x.__p_.__areas_, __areas); |
| 6813 | } |
| 6814 | return __is; |
| 6815 | } |
| 6816 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6817 | _LIBCPP_END_NAMESPACE_STD |
| 6818 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 6819 | _LIBCPP_POP_MACROS |
| 6820 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6821 | #endif // _LIBCPP_RANDOM |