Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- random -----------------------------------===// |
| 3 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_RANDOM |
| 12 | #define _LIBCPP_RANDOM |
| 13 | |
| 14 | /* |
| 15 | random synopsis |
| 16 | |
| 17 | #include <initializer_list> |
| 18 | |
| 19 | namespace std |
| 20 | { |
| 21 | |
| 22 | // Engines |
| 23 | |
| 24 | template <class UIntType, UIntType a, UIntType c, UIntType m> |
| 25 | class linear_congruential_engine |
| 26 | { |
| 27 | public: |
| 28 | // types |
| 29 | typedef UIntType result_type; |
| 30 | |
| 31 | // engine characteristics |
| 32 | static constexpr result_type multiplier = a; |
| 33 | static constexpr result_type increment = c; |
| 34 | static constexpr result_type modulus = m; |
| 35 | static constexpr result_type min() { return c == 0u ? 1u: 0u;} |
| 36 | static constexpr result_type max() { return m - 1u;} |
| 37 | static constexpr result_type default_seed = 1u; |
| 38 | |
| 39 | // constructors and seeding functions |
| 40 | explicit linear_congruential_engine(result_type s = default_seed); |
| 41 | template<class Sseq> explicit linear_congruential_engine(Sseq& q); |
| 42 | void seed(result_type s = default_seed); |
| 43 | template<class Sseq> void seed(Sseq& q); |
| 44 | |
| 45 | // generating functions |
| 46 | result_type operator()(); |
| 47 | void discard(unsigned long long z); |
| 48 | }; |
| 49 | |
| 50 | template <class UIntType, UIntType a, UIntType c, UIntType m> |
| 51 | bool |
| 52 | operator==(const linear_congruential_engine<UIntType, a, c, m>& x, |
| 53 | const linear_congruential_engine<UIntType, a, c, m>& y); |
| 54 | |
| 55 | template <class UIntType, UIntType a, UIntType c, UIntType m> |
| 56 | bool |
| 57 | operator!=(const linear_congruential_engine<UIntType, a, c, m>& x, |
| 58 | const linear_congruential_engine<UIntType, a, c, m>& y); |
| 59 | |
| 60 | template <class charT, class traits, |
| 61 | class UIntType, UIntType a, UIntType c, UIntType m> |
| 62 | basic_ostream<charT, traits>& |
| 63 | operator<<(basic_ostream<charT, traits>& os, |
| 64 | const linear_congruential_engine<UIntType, a, c, m>& x); |
| 65 | |
| 66 | template <class charT, class traits, |
| 67 | class UIntType, UIntType a, UIntType c, UIntType m> |
| 68 | basic_istream<charT, traits>& |
| 69 | operator>>(basic_istream<charT, traits>& is, |
| 70 | linear_congruential_engine<UIntType, a, c, m>& x); |
| 71 | |
| 72 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 73 | UIntType a, size_t u, UIntType d, size_t s, |
| 74 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 75 | class mersenne_twister_engine |
| 76 | { |
| 77 | public: |
| 78 | // types |
| 79 | typedef UIntType result_type; |
| 80 | |
| 81 | // engine characteristics |
| 82 | static constexpr size_t word_size = w; |
| 83 | static constexpr size_t state_size = n; |
| 84 | static constexpr size_t shift_size = m; |
| 85 | static constexpr size_t mask_bits = r; |
| 86 | static constexpr result_type xor_mask = a; |
| 87 | static constexpr size_t tempering_u = u; |
| 88 | static constexpr result_type tempering_d = d; |
| 89 | static constexpr size_t tempering_s = s; |
| 90 | static constexpr result_type tempering_b = b; |
| 91 | static constexpr size_t tempering_t = t; |
| 92 | static constexpr result_type tempering_c = c; |
| 93 | static constexpr size_t tempering_l = l; |
| 94 | static constexpr result_type initialization_multiplier = f; |
| 95 | static constexpr result_type min () { return 0; } |
| 96 | static constexpr result_type max() { return 2^w - 1; } |
| 97 | static constexpr result_type default_seed = 5489u; |
| 98 | |
| 99 | // constructors and seeding functions |
| 100 | explicit mersenne_twister_engine(result_type value = default_seed); |
| 101 | template<class Sseq> explicit mersenne_twister_engine(Sseq& q); |
| 102 | void seed(result_type value = default_seed); |
| 103 | template<class Sseq> void seed(Sseq& q); |
| 104 | |
| 105 | // generating functions |
| 106 | result_type operator()(); |
| 107 | void discard(unsigned long long z); |
| 108 | }; |
| 109 | |
| 110 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 111 | UIntType a, size_t u, UIntType d, size_t s, |
| 112 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 113 | bool |
| 114 | operator==( |
| 115 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, |
| 116 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); |
| 117 | |
| 118 | template <class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 119 | UIntType a, size_t u, UIntType d, size_t s, |
| 120 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 121 | bool |
| 122 | operator!=( |
| 123 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x, |
| 124 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y); |
| 125 | |
| 126 | template <class charT, class traits, |
| 127 | class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 128 | UIntType a, size_t u, UIntType d, size_t s, |
| 129 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 130 | basic_ostream<charT, traits>& |
| 131 | operator<<(basic_ostream<charT, traits>& os, |
| 132 | const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); |
| 133 | |
| 134 | template <class charT, class traits, |
| 135 | class UIntType, size_t w, size_t n, size_t m, size_t r, |
| 136 | UIntType a, size_t u, UIntType d, size_t s, |
| 137 | UIntType b, size_t t, UIntType c, size_t l, UIntType f> |
| 138 | basic_istream<charT, traits>& |
| 139 | operator>>(basic_istream<charT, traits>& is, |
| 140 | mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x); |
| 141 | |
| 142 | template<class UIntType, size_t w, size_t s, size_t r> |
| 143 | class subtract_with_carry_engine |
| 144 | { |
| 145 | public: |
| 146 | // types |
| 147 | typedef UIntType result_type; |
| 148 | |
| 149 | // engine characteristics |
| 150 | static constexpr size_t word_size = w; |
| 151 | static constexpr size_t short_lag = s; |
| 152 | static constexpr size_t long_lag = r; |
| 153 | static constexpr result_type min() { return 0; } |
| 154 | static constexpr result_type max() { return m-1; } |
| 155 | static constexpr result_type default_seed = 19780503u; |
| 156 | |
| 157 | // constructors and seeding functions |
| 158 | explicit subtract_with_carry_engine(result_type value = default_seed); |
| 159 | template<class Sseq> explicit subtract_with_carry_engine(Sseq& q); |
| 160 | void seed(result_type value = default_seed); |
| 161 | template<class Sseq> void seed(Sseq& q); |
| 162 | |
| 163 | // generating functions |
| 164 | result_type operator()(); |
| 165 | void discard(unsigned long long z); |
| 166 | }; |
| 167 | |
| 168 | template<class UIntType, size_t w, size_t s, size_t r> |
| 169 | bool |
| 170 | operator==( |
| 171 | const subtract_with_carry_engine<UIntType, w, s, r>& x, |
| 172 | const subtract_with_carry_engine<UIntType, w, s, r>& y); |
| 173 | |
| 174 | template<class UIntType, size_t w, size_t s, size_t r> |
| 175 | bool |
| 176 | operator!=( |
| 177 | const subtract_with_carry_engine<UIntType, w, s, r>& x, |
| 178 | const subtract_with_carry_engine<UIntType, w, s, r>& y); |
| 179 | |
| 180 | template <class charT, class traits, |
| 181 | class UIntType, size_t w, size_t s, size_t r> |
| 182 | basic_ostream<charT, traits>& |
| 183 | operator<<(basic_ostream<charT, traits>& os, |
| 184 | const subtract_with_carry_engine<UIntType, w, s, r>& x); |
| 185 | |
| 186 | template <class charT, class traits, |
| 187 | class UIntType, size_t w, size_t s, size_t r> |
| 188 | basic_istream<charT, traits>& |
| 189 | operator>>(basic_istream<charT, traits>& is, |
| 190 | subtract_with_carry_engine<UIntType, w, s, r>& x); |
| 191 | |
| 192 | template<class Engine, size_t p, size_t r> |
| 193 | class discard_block_engine |
| 194 | { |
| 195 | public: |
| 196 | // types |
| 197 | typedef typename Engine::result_type result_type; |
| 198 | |
| 199 | // engine characteristics |
| 200 | static constexpr size_t block_size = p; |
| 201 | static constexpr size_t used_block = r; |
| 202 | static constexpr result_type min() { return Engine::min(); } |
| 203 | static constexpr result_type max() { return Engine::max(); } |
| 204 | |
| 205 | // constructors and seeding functions |
| 206 | discard_block_engine(); |
| 207 | explicit discard_block_engine(const Engine& e); |
| 208 | explicit discard_block_engine(Engine&& e); |
| 209 | explicit discard_block_engine(result_type s); |
| 210 | template<class Sseq> explicit discard_block_engine(Sseq& q); |
| 211 | void seed(); |
| 212 | void seed(result_type s); |
| 213 | template<class Sseq> void seed(Sseq& q); |
| 214 | |
| 215 | // generating functions |
| 216 | result_type operator()(); |
| 217 | void discard(unsigned long long z); |
| 218 | |
| 219 | // property functions |
Howard Hinnant | c83960a | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 220 | const Engine& base() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | template<class Engine, size_t p, size_t r> |
| 224 | bool |
| 225 | operator==( |
| 226 | const discard_block_engine<Engine, p, r>& x, |
| 227 | const discard_block_engine<Engine, p, r>& y); |
| 228 | |
| 229 | template<class Engine, size_t p, size_t r> |
| 230 | bool |
| 231 | operator!=( |
| 232 | const discard_block_engine<Engine, p, r>& x, |
| 233 | const discard_block_engine<Engine, p, r>& y); |
| 234 | |
| 235 | template <class charT, class traits, |
| 236 | class Engine, size_t p, size_t r> |
| 237 | basic_ostream<charT, traits>& |
| 238 | operator<<(basic_ostream<charT, traits>& os, |
| 239 | const discard_block_engine<Engine, p, r>& x); |
| 240 | |
| 241 | template <class charT, class traits, |
| 242 | class Engine, size_t p, size_t r> |
| 243 | basic_istream<charT, traits>& |
| 244 | operator>>(basic_istream<charT, traits>& is, |
| 245 | discard_block_engine<Engine, p, r>& x); |
| 246 | |
| 247 | template<class Engine, size_t w, class UIntType> |
| 248 | class independent_bits_engine |
| 249 | { |
| 250 | public: |
| 251 | // types |
| 252 | typedef UIntType result_type; |
| 253 | |
| 254 | // engine characteristics |
| 255 | static constexpr result_type min() { return 0; } |
| 256 | static constexpr result_type max() { return 2^w - 1; } |
| 257 | |
| 258 | // constructors and seeding functions |
| 259 | independent_bits_engine(); |
| 260 | explicit independent_bits_engine(const Engine& e); |
| 261 | explicit independent_bits_engine(Engine&& e); |
| 262 | explicit independent_bits_engine(result_type s); |
| 263 | template<class Sseq> explicit independent_bits_engine(Sseq& q); |
| 264 | void seed(); |
| 265 | void seed(result_type s); |
| 266 | template<class Sseq> void seed(Sseq& q); |
| 267 | |
| 268 | // generating functions |
| 269 | result_type operator()(); void discard(unsigned long long z); |
| 270 | |
| 271 | // property functions |
Howard Hinnant | c83960a | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 272 | const Engine& base() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | template<class Engine, size_t w, class UIntType> |
| 276 | bool |
| 277 | operator==( |
| 278 | const independent_bits_engine<Engine, w, UIntType>& x, |
| 279 | const independent_bits_engine<Engine, w, UIntType>& y); |
| 280 | |
| 281 | template<class Engine, size_t w, class UIntType> |
| 282 | bool |
| 283 | operator!=( |
| 284 | const independent_bits_engine<Engine, w, UIntType>& x, |
| 285 | const independent_bits_engine<Engine, w, UIntType>& y); |
| 286 | |
| 287 | template <class charT, class traits, |
| 288 | class Engine, size_t w, class UIntType> |
| 289 | basic_ostream<charT, traits>& |
| 290 | operator<<(basic_ostream<charT, traits>& os, |
| 291 | const independent_bits_engine<Engine, w, UIntType>& x); |
| 292 | |
| 293 | template <class charT, class traits, |
| 294 | class Engine, size_t w, class UIntType> |
| 295 | basic_istream<charT, traits>& |
| 296 | operator>>(basic_istream<charT, traits>& is, |
| 297 | independent_bits_engine<Engine, w, UIntType>& x); |
| 298 | |
| 299 | template<class Engine, size_t k> |
| 300 | class shuffle_order_engine |
| 301 | { |
| 302 | public: |
| 303 | // types |
| 304 | typedef typename Engine::result_type result_type; |
| 305 | |
| 306 | // engine characteristics |
| 307 | static constexpr size_t table_size = k; |
| 308 | static constexpr result_type min() { return Engine::min; } |
| 309 | static constexpr result_type max() { return Engine::max; } |
| 310 | |
| 311 | // constructors and seeding functions |
| 312 | shuffle_order_engine(); |
| 313 | explicit shuffle_order_engine(const Engine& e); |
| 314 | explicit shuffle_order_engine(Engine&& e); |
| 315 | explicit shuffle_order_engine(result_type s); |
| 316 | template<class Sseq> explicit shuffle_order_engine(Sseq& q); |
| 317 | void seed(); |
| 318 | void seed(result_type s); |
| 319 | template<class Sseq> void seed(Sseq& q); |
| 320 | |
| 321 | // generating functions |
| 322 | result_type operator()(); |
| 323 | void discard(unsigned long long z); |
| 324 | |
| 325 | // property functions |
Howard Hinnant | c83960a | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 326 | const Engine& base() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | template<class Engine, size_t k> |
| 330 | bool |
| 331 | operator==( |
| 332 | const shuffle_order_engine<Engine, k>& x, |
| 333 | const shuffle_order_engine<Engine, k>& y); |
| 334 | |
| 335 | template<class Engine, size_t k> |
| 336 | bool |
| 337 | operator!=( |
| 338 | const shuffle_order_engine<Engine, k>& x, |
| 339 | const shuffle_order_engine<Engine, k>& y); |
| 340 | |
| 341 | template <class charT, class traits, |
| 342 | class Engine, size_t k> |
| 343 | basic_ostream<charT, traits>& |
| 344 | operator<<(basic_ostream<charT, traits>& os, |
| 345 | const shuffle_order_engine<Engine, k>& x); |
| 346 | |
| 347 | template <class charT, class traits, |
| 348 | class Engine, size_t k> |
| 349 | basic_istream<charT, traits>& |
| 350 | operator>>(basic_istream<charT, traits>& is, |
| 351 | shuffle_order_engine<Engine, k>& x); |
| 352 | |
| 353 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> |
| 354 | minstd_rand0; |
| 355 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> |
| 356 | minstd_rand; |
| 357 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, |
| 358 | 0x9908b0df, |
| 359 | 11, 0xffffffff, |
| 360 | 7, 0x9d2c5680, |
| 361 | 15, 0xefc60000, |
| 362 | 18, 1812433253> mt19937; |
| 363 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, |
| 364 | 0xb5026f5aa96619e9, |
| 365 | 29, 0x5555555555555555, |
| 366 | 17, 0x71d67fffeda60000, |
| 367 | 37, 0xfff7eee000000000, |
| 368 | 43, 6364136223846793005> mt19937_64; |
| 369 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; |
| 370 | typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; |
| 371 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; |
| 372 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; |
| 373 | typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 374 | typedef minstd_rand default_random_engine; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 375 | |
| 376 | // Generators |
| 377 | |
| 378 | class random_device |
| 379 | { |
| 380 | public: |
| 381 | // types |
| 382 | typedef unsigned int result_type; |
| 383 | |
| 384 | // generator characteristics |
| 385 | static constexpr result_type min() { return numeric_limits<result_type>::min(); } |
| 386 | static constexpr result_type max() { return numeric_limits<result_type>::max(); } |
| 387 | |
| 388 | // constructors |
| 389 | explicit random_device(const string& token = "/dev/urandom"); |
| 390 | |
| 391 | // generating functions |
| 392 | result_type operator()(); |
| 393 | |
| 394 | // property functions |
Howard Hinnant | c83960a | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 395 | double entropy() const noexcept; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 396 | |
| 397 | // no copy functions |
| 398 | random_device(const random_device& ) = delete; |
| 399 | void operator=(const random_device& ) = delete; |
| 400 | }; |
| 401 | |
| 402 | // Utilities |
| 403 | |
| 404 | class seed_seq |
| 405 | { |
| 406 | public: |
| 407 | // types |
| 408 | typedef uint_least32_t result_type; |
| 409 | |
| 410 | // constructors |
| 411 | seed_seq(); |
| 412 | template<class T> |
| 413 | seed_seq(initializer_list<T> il); |
| 414 | template<class InputIterator> |
| 415 | seed_seq(InputIterator begin, InputIterator end); |
| 416 | |
| 417 | // generating functions |
| 418 | template<class RandomAccessIterator> |
| 419 | void generate(RandomAccessIterator begin, RandomAccessIterator end); |
| 420 | |
| 421 | // property functions |
| 422 | size_t size() const; |
| 423 | template<class OutputIterator> |
| 424 | void param(OutputIterator dest) const; |
| 425 | |
| 426 | // no copy functions |
| 427 | seed_seq(const seed_seq&) = delete; |
| 428 | void operator=(const seed_seq& ) = delete; |
| 429 | }; |
| 430 | |
| 431 | template<class RealType, size_t bits, class URNG> |
| 432 | RealType generate_canonical(URNG& g); |
| 433 | |
| 434 | // Distributions |
| 435 | |
| 436 | template<class IntType = int> |
| 437 | class uniform_int_distribution |
| 438 | { |
| 439 | public: |
| 440 | // types |
| 441 | typedef IntType result_type; |
| 442 | |
| 443 | class param_type |
| 444 | { |
| 445 | public: |
| 446 | typedef uniform_int_distribution distribution_type; |
| 447 | |
| 448 | explicit param_type(IntType a = 0, |
| 449 | IntType b = numeric_limits<IntType>::max()); |
| 450 | |
| 451 | result_type a() const; |
| 452 | result_type b() const; |
| 453 | |
| 454 | friend bool operator==(const param_type& x, const param_type& y); |
| 455 | friend bool operator!=(const param_type& x, const param_type& y); |
| 456 | }; |
| 457 | |
| 458 | // constructors and reset functions |
| 459 | explicit uniform_int_distribution(IntType a = 0, |
| 460 | IntType b = numeric_limits<IntType>::max()); |
| 461 | explicit uniform_int_distribution(const param_type& parm); |
| 462 | void reset(); |
| 463 | |
| 464 | // generating functions |
| 465 | template<class URNG> result_type operator()(URNG& g); |
| 466 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 467 | |
| 468 | // property functions |
| 469 | result_type a() const; |
| 470 | result_type b() const; |
| 471 | |
| 472 | param_type param() const; |
| 473 | void param(const param_type& parm); |
| 474 | |
| 475 | result_type min() const; |
| 476 | result_type max() const; |
| 477 | |
| 478 | friend bool operator==(const uniform_int_distribution& x, |
| 479 | const uniform_int_distribution& y); |
| 480 | friend bool operator!=(const uniform_int_distribution& x, |
| 481 | const uniform_int_distribution& y); |
| 482 | |
| 483 | template <class charT, class traits> |
| 484 | friend |
| 485 | basic_ostream<charT, traits>& |
| 486 | operator<<(basic_ostream<charT, traits>& os, |
| 487 | const uniform_int_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 488 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 489 | template <class charT, class traits> |
| 490 | friend |
| 491 | basic_istream<charT, traits>& |
| 492 | operator>>(basic_istream<charT, traits>& is, |
| 493 | uniform_int_distribution& x); |
| 494 | }; |
| 495 | |
| 496 | template<class RealType = double> |
| 497 | class uniform_real_distribution |
| 498 | { |
| 499 | public: |
| 500 | // types |
| 501 | typedef RealType result_type; |
| 502 | |
| 503 | class param_type |
| 504 | { |
| 505 | public: |
| 506 | typedef uniform_real_distribution distribution_type; |
| 507 | |
| 508 | explicit param_type(RealType a = 0, |
| 509 | RealType b = 1); |
| 510 | |
| 511 | result_type a() const; |
| 512 | result_type b() const; |
| 513 | |
| 514 | friend bool operator==(const param_type& x, const param_type& y); |
| 515 | friend bool operator!=(const param_type& x, const param_type& y); |
| 516 | }; |
| 517 | |
| 518 | // constructors and reset functions |
| 519 | explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0); |
| 520 | explicit uniform_real_distribution(const param_type& parm); |
| 521 | void reset(); |
| 522 | |
| 523 | // generating functions |
| 524 | template<class URNG> result_type operator()(URNG& g); |
| 525 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 526 | |
| 527 | // property functions |
| 528 | result_type a() const; |
| 529 | result_type b() const; |
| 530 | |
| 531 | param_type param() const; |
| 532 | void param(const param_type& parm); |
| 533 | |
| 534 | result_type min() const; |
| 535 | result_type max() const; |
| 536 | |
| 537 | friend bool operator==(const uniform_real_distribution& x, |
| 538 | const uniform_real_distribution& y); |
| 539 | friend bool operator!=(const uniform_real_distribution& x, |
| 540 | const uniform_real_distribution& y); |
| 541 | |
| 542 | template <class charT, class traits> |
| 543 | friend |
| 544 | basic_ostream<charT, traits>& |
| 545 | operator<<(basic_ostream<charT, traits>& os, |
| 546 | const uniform_real_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 547 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 548 | template <class charT, class traits> |
| 549 | friend |
| 550 | basic_istream<charT, traits>& |
| 551 | operator>>(basic_istream<charT, traits>& is, |
| 552 | uniform_real_distribution& x); |
| 553 | }; |
| 554 | |
| 555 | class bernoulli_distribution |
| 556 | { |
| 557 | public: |
| 558 | // types |
| 559 | typedef bool result_type; |
| 560 | |
| 561 | class param_type |
| 562 | { |
| 563 | public: |
| 564 | typedef bernoulli_distribution distribution_type; |
| 565 | |
| 566 | explicit param_type(double p = 0.5); |
| 567 | |
| 568 | double p() const; |
| 569 | |
| 570 | friend bool operator==(const param_type& x, const param_type& y); |
| 571 | friend bool operator!=(const param_type& x, const param_type& y); |
| 572 | }; |
| 573 | |
| 574 | // constructors and reset functions |
| 575 | explicit bernoulli_distribution(double p = 0.5); |
| 576 | explicit bernoulli_distribution(const param_type& parm); |
| 577 | void reset(); |
| 578 | |
| 579 | // generating functions |
| 580 | template<class URNG> result_type operator()(URNG& g); |
| 581 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 582 | |
| 583 | // property functions |
| 584 | double p() const; |
| 585 | |
| 586 | param_type param() const; |
| 587 | void param(const param_type& parm); |
| 588 | |
| 589 | result_type min() const; |
| 590 | result_type max() const; |
| 591 | |
| 592 | friend bool operator==(const bernoulli_distribution& x, |
| 593 | const bernoulli_distribution& y); |
| 594 | friend bool operator!=(const bernoulli_distribution& x, |
| 595 | const bernoulli_distribution& y); |
| 596 | |
| 597 | template <class charT, class traits> |
| 598 | friend |
| 599 | basic_ostream<charT, traits>& |
| 600 | operator<<(basic_ostream<charT, traits>& os, |
| 601 | const bernoulli_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 602 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 603 | template <class charT, class traits> |
| 604 | friend |
| 605 | basic_istream<charT, traits>& |
| 606 | operator>>(basic_istream<charT, traits>& is, |
| 607 | bernoulli_distribution& x); |
| 608 | }; |
| 609 | |
| 610 | template<class IntType = int> |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 611 | class binomial_distribution |
| 612 | { |
| 613 | public: |
| 614 | // types |
| 615 | typedef IntType result_type; |
| 616 | |
| 617 | class param_type |
| 618 | { |
| 619 | public: |
| 620 | typedef binomial_distribution distribution_type; |
| 621 | |
| 622 | explicit param_type(IntType t = 1, double p = 0.5); |
| 623 | |
| 624 | IntType t() const; |
| 625 | double p() const; |
| 626 | |
| 627 | friend bool operator==(const param_type& x, const param_type& y); |
| 628 | friend bool operator!=(const param_type& x, const param_type& y); |
| 629 | }; |
| 630 | |
| 631 | // constructors and reset functions |
| 632 | explicit binomial_distribution(IntType t = 1, double p = 0.5); |
| 633 | explicit binomial_distribution(const param_type& parm); |
| 634 | void reset(); |
| 635 | |
| 636 | // generating functions |
| 637 | template<class URNG> result_type operator()(URNG& g); |
| 638 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 639 | |
| 640 | // property functions |
| 641 | IntType t() const; |
| 642 | double p() const; |
| 643 | |
| 644 | param_type param() const; |
| 645 | void param(const param_type& parm); |
| 646 | |
| 647 | result_type min() const; |
| 648 | result_type max() const; |
| 649 | |
| 650 | friend bool operator==(const binomial_distribution& x, |
| 651 | const binomial_distribution& y); |
| 652 | friend bool operator!=(const binomial_distribution& x, |
| 653 | const binomial_distribution& y); |
| 654 | |
| 655 | template <class charT, class traits> |
| 656 | friend |
| 657 | basic_ostream<charT, traits>& |
| 658 | operator<<(basic_ostream<charT, traits>& os, |
| 659 | const binomial_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 660 | |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 661 | template <class charT, class traits> |
| 662 | friend |
| 663 | basic_istream<charT, traits>& |
| 664 | operator>>(basic_istream<charT, traits>& is, |
| 665 | binomial_distribution& x); |
| 666 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 667 | |
| 668 | template<class IntType = int> |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 669 | class geometric_distribution |
| 670 | { |
| 671 | public: |
| 672 | // types |
| 673 | typedef IntType result_type; |
| 674 | |
| 675 | class param_type |
| 676 | { |
| 677 | public: |
| 678 | typedef geometric_distribution distribution_type; |
| 679 | |
| 680 | explicit param_type(double p = 0.5); |
| 681 | |
| 682 | double p() const; |
| 683 | |
| 684 | friend bool operator==(const param_type& x, const param_type& y); |
| 685 | friend bool operator!=(const param_type& x, const param_type& y); |
| 686 | }; |
| 687 | |
| 688 | // constructors and reset functions |
| 689 | explicit geometric_distribution(double p = 0.5); |
| 690 | explicit geometric_distribution(const param_type& parm); |
| 691 | void reset(); |
| 692 | |
| 693 | // generating functions |
| 694 | template<class URNG> result_type operator()(URNG& g); |
| 695 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 696 | |
| 697 | // property functions |
| 698 | double p() const; |
| 699 | |
| 700 | param_type param() const; |
| 701 | void param(const param_type& parm); |
| 702 | |
| 703 | result_type min() const; |
| 704 | result_type max() const; |
| 705 | |
| 706 | friend bool operator==(const geometric_distribution& x, |
| 707 | const geometric_distribution& y); |
| 708 | friend bool operator!=(const geometric_distribution& x, |
| 709 | const geometric_distribution& y); |
| 710 | |
| 711 | template <class charT, class traits> |
| 712 | friend |
| 713 | basic_ostream<charT, traits>& |
| 714 | operator<<(basic_ostream<charT, traits>& os, |
| 715 | const geometric_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 716 | |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 717 | template <class charT, class traits> |
| 718 | friend |
| 719 | basic_istream<charT, traits>& |
| 720 | operator>>(basic_istream<charT, traits>& is, |
| 721 | geometric_distribution& x); |
| 722 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 723 | |
| 724 | template<class IntType = int> |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 725 | class negative_binomial_distribution |
| 726 | { |
| 727 | public: |
| 728 | // types |
| 729 | typedef IntType result_type; |
| 730 | |
| 731 | class param_type |
| 732 | { |
| 733 | public: |
| 734 | typedef negative_binomial_distribution distribution_type; |
| 735 | |
| 736 | explicit param_type(result_type k = 1, double p = 0.5); |
| 737 | |
| 738 | result_type k() const; |
| 739 | double p() const; |
| 740 | |
| 741 | friend bool operator==(const param_type& x, const param_type& y); |
| 742 | friend bool operator!=(const param_type& x, const param_type& y); |
| 743 | }; |
| 744 | |
| 745 | // constructor and reset functions |
| 746 | explicit negative_binomial_distribution(result_type k = 1, double p = 0.5); |
| 747 | explicit negative_binomial_distribution(const param_type& parm); |
| 748 | void reset(); |
| 749 | |
| 750 | // generating functions |
| 751 | template<class URNG> result_type operator()(URNG& g); |
| 752 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 753 | |
| 754 | // property functions |
| 755 | result_type k() const; |
| 756 | double p() const; |
| 757 | |
| 758 | param_type param() const; |
| 759 | void param(const param_type& parm); |
| 760 | |
| 761 | result_type min() const; |
| 762 | result_type max() const; |
| 763 | |
| 764 | friend bool operator==(const negative_binomial_distribution& x, |
| 765 | const negative_binomial_distribution& y); |
| 766 | friend bool operator!=(const negative_binomial_distribution& x, |
| 767 | const negative_binomial_distribution& y); |
| 768 | |
| 769 | template <class charT, class traits> |
| 770 | friend |
| 771 | basic_ostream<charT, traits>& |
| 772 | operator<<(basic_ostream<charT, traits>& os, |
| 773 | const negative_binomial_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 774 | |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 775 | template <class charT, class traits> |
| 776 | friend |
| 777 | basic_istream<charT, traits>& |
| 778 | operator>>(basic_istream<charT, traits>& is, |
| 779 | negative_binomial_distribution& x); |
| 780 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 781 | |
| 782 | template<class IntType = int> |
Howard Hinnant | 4ff556c | 2010-05-14 21:38:54 +0000 | [diff] [blame] | 783 | class poisson_distribution |
| 784 | { |
| 785 | public: |
| 786 | // types |
| 787 | typedef IntType result_type; |
| 788 | |
| 789 | class param_type |
| 790 | { |
| 791 | public: |
| 792 | typedef poisson_distribution distribution_type; |
| 793 | |
| 794 | explicit param_type(double mean = 1.0); |
| 795 | |
| 796 | double mean() const; |
| 797 | |
| 798 | friend bool operator==(const param_type& x, const param_type& y); |
| 799 | friend bool operator!=(const param_type& x, const param_type& y); |
| 800 | }; |
| 801 | |
| 802 | // constructors and reset functions |
| 803 | explicit poisson_distribution(double mean = 1.0); |
| 804 | explicit poisson_distribution(const param_type& parm); |
| 805 | void reset(); |
| 806 | |
| 807 | // generating functions |
| 808 | template<class URNG> result_type operator()(URNG& g); |
| 809 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 810 | |
| 811 | // property functions |
| 812 | double mean() const; |
| 813 | |
| 814 | param_type param() const; |
| 815 | void param(const param_type& parm); |
| 816 | |
| 817 | result_type min() const; |
| 818 | result_type max() const; |
| 819 | |
| 820 | friend bool operator==(const poisson_distribution& x, |
| 821 | const poisson_distribution& y); |
| 822 | friend bool operator!=(const poisson_distribution& x, |
| 823 | const poisson_distribution& y); |
| 824 | |
| 825 | template <class charT, class traits> |
| 826 | friend |
| 827 | basic_ostream<charT, traits>& |
| 828 | operator<<(basic_ostream<charT, traits>& os, |
| 829 | const poisson_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 830 | |
Howard Hinnant | 4ff556c | 2010-05-14 21:38:54 +0000 | [diff] [blame] | 831 | template <class charT, class traits> |
| 832 | friend |
| 833 | basic_istream<charT, traits>& |
| 834 | operator>>(basic_istream<charT, traits>& is, |
| 835 | poisson_distribution& x); |
| 836 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 837 | |
| 838 | template<class RealType = double> |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 839 | class exponential_distribution |
| 840 | { |
| 841 | public: |
| 842 | // types |
| 843 | typedef RealType result_type; |
| 844 | |
| 845 | class param_type |
| 846 | { |
| 847 | public: |
| 848 | typedef exponential_distribution distribution_type; |
| 849 | |
Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 850 | explicit param_type(result_type lambda = 1.0); |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 851 | |
Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 852 | result_type lambda() const; |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 853 | |
| 854 | friend bool operator==(const param_type& x, const param_type& y); |
| 855 | friend bool operator!=(const param_type& x, const param_type& y); |
| 856 | }; |
| 857 | |
| 858 | // constructors and reset functions |
Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 859 | explicit exponential_distribution(result_type lambda = 1.0); |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 860 | explicit exponential_distribution(const param_type& parm); |
| 861 | void reset(); |
| 862 | |
| 863 | // generating functions |
| 864 | template<class URNG> result_type operator()(URNG& g); |
| 865 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 866 | |
| 867 | // property functions |
Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 868 | result_type lambda() const; |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 869 | |
| 870 | param_type param() const; |
| 871 | void param(const param_type& parm); |
| 872 | |
| 873 | result_type min() const; |
| 874 | result_type max() const; |
| 875 | |
| 876 | friend bool operator==(const exponential_distribution& x, |
| 877 | const exponential_distribution& y); |
| 878 | friend bool operator!=(const exponential_distribution& x, |
| 879 | const exponential_distribution& y); |
| 880 | |
| 881 | template <class charT, class traits> |
| 882 | friend |
| 883 | basic_ostream<charT, traits>& |
| 884 | operator<<(basic_ostream<charT, traits>& os, |
| 885 | const exponential_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 886 | |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 887 | template <class charT, class traits> |
| 888 | friend |
| 889 | basic_istream<charT, traits>& |
| 890 | operator>>(basic_istream<charT, traits>& is, |
| 891 | exponential_distribution& x); |
| 892 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 893 | |
| 894 | template<class RealType = double> |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 895 | class gamma_distribution |
| 896 | { |
| 897 | public: |
| 898 | // types |
| 899 | typedef RealType result_type; |
| 900 | |
| 901 | class param_type |
| 902 | { |
| 903 | public: |
| 904 | typedef gamma_distribution distribution_type; |
| 905 | |
| 906 | explicit param_type(result_type alpha = 1, result_type beta = 1); |
| 907 | |
| 908 | result_type alpha() const; |
| 909 | result_type beta() const; |
| 910 | |
| 911 | friend bool operator==(const param_type& x, const param_type& y); |
| 912 | friend bool operator!=(const param_type& x, const param_type& y); |
| 913 | }; |
| 914 | |
| 915 | // constructors and reset functions |
| 916 | explicit gamma_distribution(result_type alpha = 1, result_type beta = 1); |
| 917 | explicit gamma_distribution(const param_type& parm); |
| 918 | void reset(); |
| 919 | |
| 920 | // generating functions |
| 921 | template<class URNG> result_type operator()(URNG& g); |
| 922 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 923 | |
| 924 | // property functions |
| 925 | result_type alpha() const; |
| 926 | result_type beta() const; |
| 927 | |
| 928 | param_type param() const; |
| 929 | void param(const param_type& parm); |
| 930 | |
| 931 | result_type min() const; |
| 932 | result_type max() const; |
| 933 | |
| 934 | friend bool operator==(const gamma_distribution& x, |
| 935 | const gamma_distribution& y); |
| 936 | friend bool operator!=(const gamma_distribution& x, |
| 937 | const gamma_distribution& y); |
| 938 | |
| 939 | template <class charT, class traits> |
| 940 | friend |
| 941 | basic_ostream<charT, traits>& |
| 942 | operator<<(basic_ostream<charT, traits>& os, |
| 943 | const gamma_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 944 | |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 945 | template <class charT, class traits> |
| 946 | friend |
| 947 | basic_istream<charT, traits>& |
| 948 | operator>>(basic_istream<charT, traits>& is, |
| 949 | gamma_distribution& x); |
| 950 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 951 | |
| 952 | template<class RealType = double> |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 953 | class weibull_distribution |
| 954 | { |
| 955 | public: |
| 956 | // types |
| 957 | typedef RealType result_type; |
| 958 | |
| 959 | class param_type |
| 960 | { |
| 961 | public: |
| 962 | typedef weibull_distribution distribution_type; |
| 963 | |
| 964 | explicit param_type(result_type alpha = 1, result_type beta = 1); |
| 965 | |
| 966 | result_type a() const; |
| 967 | result_type b() const; |
| 968 | |
| 969 | friend bool operator==(const param_type& x, const param_type& y); |
| 970 | friend bool operator!=(const param_type& x, const param_type& y); |
| 971 | }; |
| 972 | |
| 973 | // constructor and reset functions |
| 974 | explicit weibull_distribution(result_type a = 1, result_type b = 1); |
| 975 | explicit weibull_distribution(const param_type& parm); |
| 976 | void reset(); |
| 977 | |
| 978 | // generating functions |
| 979 | template<class URNG> result_type operator()(URNG& g); |
| 980 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 981 | |
| 982 | // property functions |
| 983 | result_type a() const; |
| 984 | result_type b() const; |
| 985 | |
| 986 | param_type param() const; |
| 987 | void param(const param_type& parm); |
| 988 | |
| 989 | result_type min() const; |
| 990 | result_type max() const; |
| 991 | |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 992 | friend bool operator==(const weibull_distribution& x, |
| 993 | const weibull_distribution& y); |
| 994 | friend bool operator!=(const weibull_distribution& x, |
| 995 | const weibull_distribution& y); |
| 996 | |
| 997 | template <class charT, class traits> |
| 998 | friend |
| 999 | basic_ostream<charT, traits>& |
| 1000 | operator<<(basic_ostream<charT, traits>& os, |
| 1001 | const weibull_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1002 | |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 1003 | template <class charT, class traits> |
| 1004 | friend |
| 1005 | basic_istream<charT, traits>& |
| 1006 | operator>>(basic_istream<charT, traits>& is, |
| 1007 | weibull_distribution& x); |
| 1008 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1009 | |
| 1010 | template<class RealType = double> |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 1011 | class extreme_value_distribution |
| 1012 | { |
| 1013 | public: |
| 1014 | // types |
| 1015 | typedef RealType result_type; |
| 1016 | |
| 1017 | class param_type |
| 1018 | { |
| 1019 | public: |
| 1020 | typedef extreme_value_distribution distribution_type; |
| 1021 | |
| 1022 | explicit param_type(result_type a = 0, result_type b = 1); |
| 1023 | |
| 1024 | result_type a() const; |
| 1025 | result_type b() const; |
| 1026 | |
| 1027 | friend bool operator==(const param_type& x, const param_type& y); |
| 1028 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1029 | }; |
| 1030 | |
| 1031 | // constructor and reset functions |
| 1032 | explicit extreme_value_distribution(result_type a = 0, result_type b = 1); |
| 1033 | explicit extreme_value_distribution(const param_type& parm); |
| 1034 | void reset(); |
| 1035 | |
| 1036 | // generating functions |
| 1037 | template<class URNG> result_type operator()(URNG& g); |
| 1038 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1039 | |
| 1040 | // property functions |
| 1041 | result_type a() const; |
| 1042 | result_type b() const; |
| 1043 | |
| 1044 | param_type param() const; |
| 1045 | void param(const param_type& parm); |
| 1046 | |
| 1047 | result_type min() const; |
| 1048 | result_type max() const; |
| 1049 | |
| 1050 | friend bool operator==(const extreme_value_distribution& x, |
| 1051 | const extreme_value_distribution& y); |
| 1052 | friend bool operator!=(const extreme_value_distribution& x, |
| 1053 | const extreme_value_distribution& y); |
| 1054 | |
| 1055 | template <class charT, class traits> |
| 1056 | friend |
| 1057 | basic_ostream<charT, traits>& |
| 1058 | operator<<(basic_ostream<charT, traits>& os, |
| 1059 | const extreme_value_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1060 | |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 1061 | template <class charT, class traits> |
| 1062 | friend |
| 1063 | basic_istream<charT, traits>& |
| 1064 | operator>>(basic_istream<charT, traits>& is, |
| 1065 | extreme_value_distribution& x); |
| 1066 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1067 | |
| 1068 | template<class RealType = double> |
Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 1069 | class normal_distribution |
| 1070 | { |
| 1071 | public: |
| 1072 | // types |
| 1073 | typedef RealType result_type; |
| 1074 | |
| 1075 | class param_type |
| 1076 | { |
| 1077 | public: |
| 1078 | typedef normal_distribution distribution_type; |
| 1079 | |
| 1080 | explicit param_type(result_type mean = 0, result_type stddev = 1); |
| 1081 | |
| 1082 | result_type mean() const; |
| 1083 | result_type stddev() const; |
| 1084 | |
| 1085 | friend bool operator==(const param_type& x, const param_type& y); |
| 1086 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1087 | }; |
| 1088 | |
| 1089 | // constructors and reset functions |
| 1090 | explicit normal_distribution(result_type mean = 0, result_type stddev = 1); |
| 1091 | explicit normal_distribution(const param_type& parm); |
| 1092 | void reset(); |
| 1093 | |
| 1094 | // generating functions |
| 1095 | template<class URNG> result_type operator()(URNG& g); |
| 1096 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1097 | |
| 1098 | // property functions |
| 1099 | result_type mean() const; |
| 1100 | result_type stddev() const; |
| 1101 | |
| 1102 | param_type param() const; |
| 1103 | void param(const param_type& parm); |
| 1104 | |
| 1105 | result_type min() const; |
| 1106 | result_type max() const; |
| 1107 | |
| 1108 | friend bool operator==(const normal_distribution& x, |
| 1109 | const normal_distribution& y); |
| 1110 | friend bool operator!=(const normal_distribution& x, |
| 1111 | const normal_distribution& y); |
| 1112 | |
| 1113 | template <class charT, class traits> |
| 1114 | friend |
| 1115 | basic_ostream<charT, traits>& |
| 1116 | operator<<(basic_ostream<charT, traits>& os, |
| 1117 | const normal_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1118 | |
Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 1119 | template <class charT, class traits> |
| 1120 | friend |
| 1121 | basic_istream<charT, traits>& |
| 1122 | operator>>(basic_istream<charT, traits>& is, |
| 1123 | normal_distribution& x); |
| 1124 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1125 | |
| 1126 | template<class RealType = double> |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 1127 | class lognormal_distribution |
| 1128 | { |
| 1129 | public: |
| 1130 | // types |
| 1131 | typedef RealType result_type; |
| 1132 | |
| 1133 | class param_type |
| 1134 | { |
| 1135 | public: |
| 1136 | typedef lognormal_distribution distribution_type; |
| 1137 | |
| 1138 | explicit param_type(result_type m = 0, result_type s = 1); |
| 1139 | |
| 1140 | result_type m() const; |
| 1141 | result_type s() const; |
| 1142 | |
| 1143 | friend bool operator==(const param_type& x, const param_type& y); |
| 1144 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1145 | }; |
| 1146 | |
| 1147 | // constructor and reset functions |
| 1148 | explicit lognormal_distribution(result_type m = 0, result_type s = 1); |
| 1149 | explicit lognormal_distribution(const param_type& parm); |
| 1150 | void reset(); |
| 1151 | |
| 1152 | // generating functions |
| 1153 | template<class URNG> result_type operator()(URNG& g); |
| 1154 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1155 | |
| 1156 | // property functions |
| 1157 | result_type m() const; |
| 1158 | result_type s() const; |
| 1159 | |
| 1160 | param_type param() const; |
| 1161 | void param(const param_type& parm); |
| 1162 | |
| 1163 | result_type min() const; |
| 1164 | result_type max() const; |
| 1165 | |
| 1166 | friend bool operator==(const lognormal_distribution& x, |
| 1167 | const lognormal_distribution& y); |
| 1168 | friend bool operator!=(const lognormal_distribution& x, |
| 1169 | const lognormal_distribution& y); |
| 1170 | |
| 1171 | template <class charT, class traits> |
| 1172 | friend |
| 1173 | basic_ostream<charT, traits>& |
| 1174 | operator<<(basic_ostream<charT, traits>& os, |
| 1175 | const lognormal_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1176 | |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 1177 | template <class charT, class traits> |
| 1178 | friend |
| 1179 | basic_istream<charT, traits>& |
| 1180 | operator>>(basic_istream<charT, traits>& is, |
| 1181 | lognormal_distribution& x); |
| 1182 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1183 | |
| 1184 | template<class RealType = double> |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1185 | class chi_squared_distribution |
| 1186 | { |
| 1187 | public: |
| 1188 | // types |
| 1189 | typedef RealType result_type; |
| 1190 | |
| 1191 | class param_type |
| 1192 | { |
| 1193 | public: |
| 1194 | typedef chi_squared_distribution distribution_type; |
| 1195 | |
| 1196 | explicit param_type(result_type n = 1); |
| 1197 | |
| 1198 | result_type n() const; |
| 1199 | |
| 1200 | friend bool operator==(const param_type& x, const param_type& y); |
| 1201 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1202 | }; |
| 1203 | |
| 1204 | // constructor and reset functions |
| 1205 | explicit chi_squared_distribution(result_type n = 1); |
| 1206 | explicit chi_squared_distribution(const param_type& parm); |
| 1207 | void reset(); |
| 1208 | |
| 1209 | // generating functions |
| 1210 | template<class URNG> result_type operator()(URNG& g); |
| 1211 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1212 | |
| 1213 | // property functions |
| 1214 | result_type n() const; |
| 1215 | |
| 1216 | param_type param() const; |
| 1217 | void param(const param_type& parm); |
| 1218 | |
| 1219 | result_type min() const; |
| 1220 | result_type max() const; |
| 1221 | |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1222 | friend bool operator==(const chi_squared_distribution& x, |
| 1223 | const chi_squared_distribution& y); |
| 1224 | friend bool operator!=(const chi_squared_distribution& x, |
| 1225 | const chi_squared_distribution& y); |
| 1226 | |
| 1227 | template <class charT, class traits> |
| 1228 | friend |
| 1229 | basic_ostream<charT, traits>& |
| 1230 | operator<<(basic_ostream<charT, traits>& os, |
| 1231 | const chi_squared_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1232 | |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 1233 | template <class charT, class traits> |
| 1234 | friend |
| 1235 | basic_istream<charT, traits>& |
| 1236 | operator>>(basic_istream<charT, traits>& is, |
| 1237 | chi_squared_distribution& x); |
| 1238 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1239 | |
| 1240 | template<class RealType = double> |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 1241 | class cauchy_distribution |
| 1242 | { |
| 1243 | public: |
| 1244 | // types |
| 1245 | typedef RealType result_type; |
| 1246 | |
| 1247 | class param_type |
| 1248 | { |
| 1249 | public: |
| 1250 | typedef cauchy_distribution distribution_type; |
| 1251 | |
| 1252 | explicit param_type(result_type a = 0, result_type b = 1); |
| 1253 | |
| 1254 | result_type a() const; |
| 1255 | result_type b() const; |
| 1256 | |
| 1257 | friend bool operator==(const param_type& x, const param_type& y); |
| 1258 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1259 | }; |
| 1260 | |
| 1261 | // constructor and reset functions |
| 1262 | explicit cauchy_distribution(result_type a = 0, result_type b = 1); |
| 1263 | explicit cauchy_distribution(const param_type& parm); |
| 1264 | void reset(); |
| 1265 | |
| 1266 | // generating functions |
| 1267 | template<class URNG> result_type operator()(URNG& g); |
| 1268 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1269 | |
| 1270 | // property functions |
| 1271 | result_type a() const; |
| 1272 | result_type b() const; |
| 1273 | |
| 1274 | param_type param() const; |
| 1275 | void param(const param_type& parm); |
| 1276 | |
| 1277 | result_type min() const; |
| 1278 | result_type max() const; |
| 1279 | |
| 1280 | friend bool operator==(const cauchy_distribution& x, |
| 1281 | const cauchy_distribution& y); |
| 1282 | friend bool operator!=(const cauchy_distribution& x, |
| 1283 | const cauchy_distribution& y); |
| 1284 | |
| 1285 | template <class charT, class traits> |
| 1286 | friend |
| 1287 | basic_ostream<charT, traits>& |
| 1288 | operator<<(basic_ostream<charT, traits>& os, |
| 1289 | const cauchy_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1290 | |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 1291 | template <class charT, class traits> |
| 1292 | friend |
| 1293 | basic_istream<charT, traits>& |
| 1294 | operator>>(basic_istream<charT, traits>& is, |
| 1295 | cauchy_distribution& x); |
| 1296 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1297 | |
| 1298 | template<class RealType = double> |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1299 | class fisher_f_distribution |
| 1300 | { |
| 1301 | public: |
| 1302 | // types |
| 1303 | typedef RealType result_type; |
| 1304 | |
| 1305 | class param_type |
| 1306 | { |
| 1307 | public: |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1308 | typedef fisher_f_distribution distribution_type; |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1309 | |
| 1310 | explicit param_type(result_type m = 1, result_type n = 1); |
| 1311 | |
| 1312 | result_type m() const; |
| 1313 | result_type n() const; |
| 1314 | |
| 1315 | friend bool operator==(const param_type& x, const param_type& y); |
| 1316 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1317 | }; |
| 1318 | |
| 1319 | // constructor and reset functions |
| 1320 | explicit fisher_f_distribution(result_type m = 1, result_type n = 1); |
| 1321 | explicit fisher_f_distribution(const param_type& parm); |
| 1322 | void reset(); |
| 1323 | |
| 1324 | // generating functions |
| 1325 | template<class URNG> result_type operator()(URNG& g); |
| 1326 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1327 | |
| 1328 | // property functions |
| 1329 | result_type m() const; |
| 1330 | result_type n() const; |
| 1331 | |
| 1332 | param_type param() const; |
| 1333 | void param(const param_type& parm); |
| 1334 | |
| 1335 | result_type min() const; |
| 1336 | result_type max() const; |
| 1337 | |
| 1338 | friend bool operator==(const fisher_f_distribution& x, |
| 1339 | const fisher_f_distribution& y); |
| 1340 | friend bool operator!=(const fisher_f_distribution& x, |
| 1341 | const fisher_f_distribution& y); |
| 1342 | |
| 1343 | template <class charT, class traits> |
| 1344 | friend |
| 1345 | basic_ostream<charT, traits>& |
| 1346 | operator<<(basic_ostream<charT, traits>& os, |
| 1347 | const fisher_f_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1348 | |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 1349 | template <class charT, class traits> |
| 1350 | friend |
| 1351 | basic_istream<charT, traits>& |
| 1352 | operator>>(basic_istream<charT, traits>& is, |
| 1353 | fisher_f_distribution& x); |
| 1354 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1355 | |
| 1356 | template<class RealType = double> |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1357 | class student_t_distribution |
| 1358 | { |
| 1359 | public: |
| 1360 | // types |
| 1361 | typedef RealType result_type; |
| 1362 | |
| 1363 | class param_type |
| 1364 | { |
| 1365 | public: |
| 1366 | typedef student_t_distribution distribution_type; |
| 1367 | |
| 1368 | explicit param_type(result_type n = 1); |
| 1369 | |
| 1370 | result_type n() const; |
| 1371 | |
| 1372 | friend bool operator==(const param_type& x, const param_type& y); |
| 1373 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1374 | }; |
| 1375 | |
| 1376 | // constructor and reset functions |
| 1377 | explicit student_t_distribution(result_type n = 1); |
| 1378 | explicit student_t_distribution(const param_type& parm); |
| 1379 | void reset(); |
| 1380 | |
| 1381 | // generating functions |
| 1382 | template<class URNG> result_type operator()(URNG& g); |
| 1383 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1384 | |
| 1385 | // property functions |
| 1386 | result_type n() const; |
| 1387 | |
| 1388 | param_type param() const; |
| 1389 | void param(const param_type& parm); |
| 1390 | |
| 1391 | result_type min() const; |
| 1392 | result_type max() const; |
| 1393 | |
| 1394 | friend bool operator==(const student_t_distribution& x, |
| 1395 | const student_t_distribution& y); |
| 1396 | friend bool operator!=(const student_t_distribution& x, |
| 1397 | const student_t_distribution& y); |
| 1398 | |
| 1399 | template <class charT, class traits> |
| 1400 | friend |
| 1401 | basic_ostream<charT, traits>& |
| 1402 | operator<<(basic_ostream<charT, traits>& os, |
| 1403 | const student_t_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1404 | |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 1405 | template <class charT, class traits> |
| 1406 | friend |
| 1407 | basic_istream<charT, traits>& |
| 1408 | operator>>(basic_istream<charT, traits>& is, |
| 1409 | student_t_distribution& x); |
| 1410 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1411 | |
| 1412 | template<class IntType = int> |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1413 | class discrete_distribution |
| 1414 | { |
| 1415 | public: |
| 1416 | // types |
| 1417 | typedef IntType result_type; |
| 1418 | |
| 1419 | class param_type |
| 1420 | { |
| 1421 | public: |
| 1422 | typedef discrete_distribution distribution_type; |
| 1423 | |
| 1424 | param_type(); |
| 1425 | template<class InputIterator> |
| 1426 | param_type(InputIterator firstW, InputIterator lastW); |
| 1427 | param_type(initializer_list<double> wl); |
| 1428 | template<class UnaryOperation> |
| 1429 | param_type(size_t nw, double xmin, double xmax, UnaryOperation fw); |
| 1430 | |
| 1431 | vector<double> probabilities() const; |
| 1432 | |
| 1433 | friend bool operator==(const param_type& x, const param_type& y); |
| 1434 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1435 | }; |
| 1436 | |
| 1437 | // constructor and reset functions |
| 1438 | discrete_distribution(); |
| 1439 | template<class InputIterator> |
| 1440 | discrete_distribution(InputIterator firstW, InputIterator lastW); |
| 1441 | discrete_distribution(initializer_list<double> wl); |
| 1442 | template<class UnaryOperation> |
| 1443 | discrete_distribution(size_t nw, double xmin, double xmax, |
| 1444 | UnaryOperation fw); |
| 1445 | explicit discrete_distribution(const param_type& parm); |
| 1446 | void reset(); |
| 1447 | |
| 1448 | // generating functions |
| 1449 | template<class URNG> result_type operator()(URNG& g); |
| 1450 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1451 | |
| 1452 | // property functions |
| 1453 | vector<double> probabilities() const; |
| 1454 | |
| 1455 | param_type param() const; |
| 1456 | void param(const param_type& parm); |
| 1457 | |
| 1458 | result_type min() const; |
| 1459 | result_type max() const; |
| 1460 | |
| 1461 | friend bool operator==(const discrete_distribution& x, |
| 1462 | const discrete_distribution& y); |
| 1463 | friend bool operator!=(const discrete_distribution& x, |
| 1464 | const discrete_distribution& y); |
| 1465 | |
| 1466 | template <class charT, class traits> |
| 1467 | friend |
| 1468 | basic_ostream<charT, traits>& |
| 1469 | operator<<(basic_ostream<charT, traits>& os, |
| 1470 | const discrete_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1471 | |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1472 | template <class charT, class traits> |
| 1473 | friend |
| 1474 | basic_istream<charT, traits>& |
| 1475 | operator>>(basic_istream<charT, traits>& is, |
| 1476 | discrete_distribution& x); |
| 1477 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1478 | |
| 1479 | template<class RealType = double> |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1480 | class piecewise_constant_distribution |
| 1481 | { |
| 1482 | // types |
| 1483 | typedef RealType result_type; |
| 1484 | |
| 1485 | class param_type |
| 1486 | { |
| 1487 | public: |
| 1488 | typedef piecewise_constant_distribution distribution_type; |
| 1489 | |
| 1490 | param_type(); |
| 1491 | template<class InputIteratorB, class InputIteratorW> |
| 1492 | param_type(InputIteratorB firstB, InputIteratorB lastB, |
| 1493 | InputIteratorW firstW); |
| 1494 | template<class UnaryOperation> |
| 1495 | param_type(initializer_list<result_type> bl, UnaryOperation fw); |
| 1496 | template<class UnaryOperation> |
| 1497 | param_type(size_t nw, result_type xmin, result_type xmax, |
| 1498 | UnaryOperation fw); |
| 1499 | |
| 1500 | vector<result_type> intervals() const; |
Howard Hinnant | 995676a | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1501 | vector<result_type> densities() const; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1502 | |
| 1503 | friend bool operator==(const param_type& x, const param_type& y); |
| 1504 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1505 | }; |
| 1506 | |
| 1507 | // constructor and reset functions |
| 1508 | piecewise_constant_distribution(); |
| 1509 | template<class InputIteratorB, class InputIteratorW> |
| 1510 | piecewise_constant_distribution(InputIteratorB firstB, |
| 1511 | InputIteratorB lastB, |
| 1512 | InputIteratorW firstW); |
| 1513 | template<class UnaryOperation> |
| 1514 | piecewise_constant_distribution(initializer_list<result_type> bl, |
| 1515 | UnaryOperation fw); |
| 1516 | template<class UnaryOperation> |
| 1517 | piecewise_constant_distribution(size_t nw, result_type xmin, |
| 1518 | result_type xmax, UnaryOperation fw); |
| 1519 | explicit piecewise_constant_distribution(const param_type& parm); |
| 1520 | void reset(); |
| 1521 | |
| 1522 | // generating functions |
| 1523 | template<class URNG> result_type operator()(URNG& g); |
| 1524 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1525 | |
| 1526 | // property functions |
| 1527 | vector<result_type> intervals() const; |
Howard Hinnant | 995676a | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1528 | vector<result_type> densities() const; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1529 | |
| 1530 | param_type param() const; |
| 1531 | void param(const param_type& parm); |
| 1532 | |
| 1533 | result_type min() const; |
| 1534 | result_type max() const; |
| 1535 | |
| 1536 | friend bool operator==(const piecewise_constant_distribution& x, |
| 1537 | const piecewise_constant_distribution& y); |
| 1538 | friend bool operator!=(const piecewise_constant_distribution& x, |
| 1539 | const piecewise_constant_distribution& y); |
| 1540 | |
| 1541 | template <class charT, class traits> |
| 1542 | friend |
| 1543 | basic_ostream<charT, traits>& |
| 1544 | operator<<(basic_ostream<charT, traits>& os, |
| 1545 | const piecewise_constant_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1546 | |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 1547 | template <class charT, class traits> |
| 1548 | friend |
| 1549 | basic_istream<charT, traits>& |
| 1550 | operator>>(basic_istream<charT, traits>& is, |
| 1551 | piecewise_constant_distribution& x); |
| 1552 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1553 | |
| 1554 | template<class RealType = double> |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1555 | class piecewise_linear_distribution |
| 1556 | { |
| 1557 | // types |
| 1558 | typedef RealType result_type; |
| 1559 | |
| 1560 | class param_type |
| 1561 | { |
| 1562 | public: |
| 1563 | typedef piecewise_linear_distribution distribution_type; |
| 1564 | |
| 1565 | param_type(); |
| 1566 | template<class InputIteratorB, class InputIteratorW> |
| 1567 | param_type(InputIteratorB firstB, InputIteratorB lastB, |
| 1568 | InputIteratorW firstW); |
| 1569 | template<class UnaryOperation> |
| 1570 | param_type(initializer_list<result_type> bl, UnaryOperation fw); |
| 1571 | template<class UnaryOperation> |
| 1572 | param_type(size_t nw, result_type xmin, result_type xmax, |
| 1573 | UnaryOperation fw); |
| 1574 | |
| 1575 | vector<result_type> intervals() const; |
Howard Hinnant | 995676a | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1576 | vector<result_type> densities() const; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1577 | |
| 1578 | friend bool operator==(const param_type& x, const param_type& y); |
| 1579 | friend bool operator!=(const param_type& x, const param_type& y); |
| 1580 | }; |
| 1581 | |
| 1582 | // constructor and reset functions |
| 1583 | piecewise_linear_distribution(); |
| 1584 | template<class InputIteratorB, class InputIteratorW> |
| 1585 | piecewise_linear_distribution(InputIteratorB firstB, |
| 1586 | InputIteratorB lastB, |
| 1587 | InputIteratorW firstW); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1588 | |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1589 | template<class UnaryOperation> |
| 1590 | piecewise_linear_distribution(initializer_list<result_type> bl, |
| 1591 | UnaryOperation fw); |
| 1592 | |
| 1593 | template<class UnaryOperation> |
| 1594 | piecewise_linear_distribution(size_t nw, result_type xmin, |
| 1595 | result_type xmax, UnaryOperation fw); |
| 1596 | |
| 1597 | explicit piecewise_linear_distribution(const param_type& parm); |
| 1598 | void reset(); |
| 1599 | |
| 1600 | // generating functions |
| 1601 | template<class URNG> result_type operator()(URNG& g); |
| 1602 | template<class URNG> result_type operator()(URNG& g, const param_type& parm); |
| 1603 | |
| 1604 | // property functions |
| 1605 | vector<result_type> intervals() const; |
Howard Hinnant | 995676a | 2010-11-18 17:34:48 +0000 | [diff] [blame] | 1606 | vector<result_type> densities() const; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1607 | |
| 1608 | param_type param() const; |
| 1609 | void param(const param_type& parm); |
| 1610 | |
| 1611 | result_type min() const; |
| 1612 | result_type max() const; |
| 1613 | |
| 1614 | friend bool operator==(const piecewise_linear_distribution& x, |
| 1615 | const piecewise_linear_distribution& y); |
| 1616 | friend bool operator!=(const piecewise_linear_distribution& x, |
| 1617 | const piecewise_linear_distribution& y); |
| 1618 | |
| 1619 | template <class charT, class traits> |
| 1620 | friend |
| 1621 | basic_ostream<charT, traits>& |
| 1622 | operator<<(basic_ostream<charT, traits>& os, |
| 1623 | const piecewise_linear_distribution& x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1624 | |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 1625 | template <class charT, class traits> |
| 1626 | friend |
| 1627 | basic_istream<charT, traits>& |
| 1628 | operator>>(basic_istream<charT, traits>& is, |
| 1629 | piecewise_linear_distribution& x); |
| 1630 | }; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1631 | |
| 1632 | } // std |
| 1633 | */ |
| 1634 | |
| 1635 | #include <__config> |
| 1636 | #include <cstddef> |
Eric Fiselier | f51d676 | 2015-01-23 22:22:36 +0000 | [diff] [blame] | 1637 | #include <cstdint> |
| 1638 | #include <cmath> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1639 | #include <type_traits> |
| 1640 | #include <initializer_list> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1641 | #include <limits> |
| 1642 | #include <algorithm> |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 1643 | #include <numeric> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1644 | #include <vector> |
| 1645 | #include <string> |
| 1646 | #include <istream> |
| 1647 | #include <ostream> |
| 1648 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 1649 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1650 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 1651 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1652 | |
Eric Fiselier | 018a3d5 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 1653 | _LIBCPP_PUSH_MACROS |
| 1654 | #include <__undef_macros> |
| 1655 | |
| 1656 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1657 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 1658 | |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1659 | // __is_seed_sequence |
| 1660 | |
| 1661 | template <class _Sseq, class _Engine> |
| 1662 | struct __is_seed_sequence |
| 1663 | { |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1664 | static _LIBCPP_CONSTEXPR const bool value = |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1665 | !is_convertible<_Sseq, typename _Engine::result_type>::value && |
| 1666 | !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; |
| 1667 | }; |
| 1668 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1669 | // linear_congruential_engine |
| 1670 | |
| 1671 | template <unsigned long long __a, unsigned long long __c, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1672 | unsigned long long __m, unsigned long long _Mp, |
| 1673 | bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a)> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1674 | struct __lce_ta; |
| 1675 | |
| 1676 | // 64 |
| 1677 | |
| 1678 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> |
| 1679 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> |
| 1680 | { |
| 1681 | typedef unsigned long long result_type; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1682 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1683 | static result_type next(result_type __x) |
| 1684 | { |
| 1685 | // Schrage's algorithm |
| 1686 | const result_type __q = __m / __a; |
| 1687 | const result_type __r = __m % __a; |
| 1688 | const result_type __t0 = __a * (__x % __q); |
| 1689 | const result_type __t1 = __r * (__x / __q); |
| 1690 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1691 | __x += __c - (__x >= __m - __c) * __m; |
| 1692 | return __x; |
| 1693 | } |
| 1694 | }; |
| 1695 | |
| 1696 | template <unsigned long long __a, unsigned long long __m> |
| 1697 | struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> |
| 1698 | { |
| 1699 | typedef unsigned long long result_type; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1700 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1701 | static result_type next(result_type __x) |
| 1702 | { |
| 1703 | // Schrage's algorithm |
| 1704 | const result_type __q = __m / __a; |
| 1705 | const result_type __r = __m % __a; |
| 1706 | const result_type __t0 = __a * (__x % __q); |
| 1707 | const result_type __t1 = __r * (__x / __q); |
| 1708 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1709 | return __x; |
| 1710 | } |
| 1711 | }; |
| 1712 | |
| 1713 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m> |
| 1714 | struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> |
| 1715 | { |
| 1716 | typedef unsigned long long result_type; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1717 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1718 | static result_type next(result_type __x) |
| 1719 | { |
| 1720 | return (__a * __x + __c) % __m; |
| 1721 | } |
| 1722 | }; |
| 1723 | |
| 1724 | template <unsigned long long __a, unsigned long long __c> |
| 1725 | struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> |
| 1726 | { |
| 1727 | typedef unsigned long long result_type; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1728 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1729 | static result_type next(result_type __x) |
| 1730 | { |
| 1731 | return __a * __x + __c; |
| 1732 | } |
| 1733 | }; |
| 1734 | |
| 1735 | // 32 |
| 1736 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1737 | template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> |
| 1738 | struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1739 | { |
| 1740 | typedef unsigned result_type; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1741 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1742 | static result_type next(result_type __x) |
| 1743 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1744 | const result_type __a = static_cast<result_type>(_Ap); |
| 1745 | const result_type __c = static_cast<result_type>(_Cp); |
| 1746 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1747 | // Schrage's algorithm |
| 1748 | const result_type __q = __m / __a; |
| 1749 | const result_type __r = __m % __a; |
| 1750 | const result_type __t0 = __a * (__x % __q); |
| 1751 | const result_type __t1 = __r * (__x / __q); |
| 1752 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1753 | __x += __c - (__x >= __m - __c) * __m; |
| 1754 | return __x; |
| 1755 | } |
| 1756 | }; |
| 1757 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1758 | template <unsigned long long _Ap, unsigned long long _Mp> |
| 1759 | struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1760 | { |
| 1761 | typedef unsigned result_type; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1762 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1763 | static result_type next(result_type __x) |
| 1764 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1765 | const result_type __a = static_cast<result_type>(_Ap); |
| 1766 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1767 | // Schrage's algorithm |
| 1768 | const result_type __q = __m / __a; |
| 1769 | const result_type __r = __m % __a; |
| 1770 | const result_type __t0 = __a * (__x % __q); |
| 1771 | const result_type __t1 = __r * (__x / __q); |
| 1772 | __x = __t0 + (__t0 < __t1) * __m - __t1; |
| 1773 | return __x; |
| 1774 | } |
| 1775 | }; |
| 1776 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1777 | template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> |
| 1778 | struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1779 | { |
| 1780 | typedef unsigned result_type; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1781 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1782 | static result_type next(result_type __x) |
| 1783 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1784 | const result_type __a = static_cast<result_type>(_Ap); |
| 1785 | const result_type __c = static_cast<result_type>(_Cp); |
| 1786 | const result_type __m = static_cast<result_type>(_Mp); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1787 | return (__a * __x + __c) % __m; |
| 1788 | } |
| 1789 | }; |
| 1790 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1791 | template <unsigned long long _Ap, unsigned long long _Cp> |
| 1792 | struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1793 | { |
| 1794 | typedef unsigned result_type; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1795 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1796 | static result_type next(result_type __x) |
| 1797 | { |
Howard Hinnant | 9996844 | 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); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1800 | return __a * __x + __c; |
| 1801 | } |
| 1802 | }; |
| 1803 | |
| 1804 | // 16 |
| 1805 | |
| 1806 | template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> |
| 1807 | struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> |
| 1808 | { |
| 1809 | typedef unsigned short result_type; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1810 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1811 | static result_type next(result_type __x) |
| 1812 | { |
| 1813 | return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); |
| 1814 | } |
| 1815 | }; |
| 1816 | |
| 1817 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1818 | class _LIBCPP_TEMPLATE_VIS linear_congruential_engine; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1819 | |
| 1820 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1821 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 1822 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1823 | basic_ostream<_CharT, _Traits>& |
| 1824 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1825 | const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1826 | |
| 1827 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1828 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1829 | basic_istream<_CharT, _Traits>& |
| 1830 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1831 | linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1832 | |
| 1833 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1834 | class _LIBCPP_TEMPLATE_VIS linear_congruential_engine |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1835 | { |
| 1836 | public: |
| 1837 | // types |
| 1838 | typedef _UIntType result_type; |
| 1839 | |
Howard Hinnant | ddb4e4c | 2013-05-21 21:19:35 +0000 | [diff] [blame] | 1840 | private: |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1841 | result_type __x_; |
| 1842 | |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1843 | static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1844 | |
| 1845 | static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); |
| 1846 | static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); |
| 1847 | public: |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1848 | static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; |
| 1849 | static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1850 | static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); |
| 1851 | |
| 1852 | // engine characteristics |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1853 | static _LIBCPP_CONSTEXPR const result_type multiplier = __a; |
| 1854 | static _LIBCPP_CONSTEXPR const result_type increment = __c; |
| 1855 | static _LIBCPP_CONSTEXPR const result_type modulus = __m; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1857 | static _LIBCPP_CONSTEXPR result_type min() {return _Min;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1858 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 1859 | static _LIBCPP_CONSTEXPR result_type max() {return _Max;} |
| 1860 | static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1861 | |
| 1862 | // constructors and seeding functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1863 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1864 | explicit linear_congruential_engine(result_type __s = default_seed) |
| 1865 | {seed(__s);} |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1866 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1867 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 1868 | explicit linear_congruential_engine(_Sseq& __q, |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1869 | typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1870 | {seed(__q);} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1871 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1872 | void seed(result_type __s = default_seed) |
| 1873 | {seed(integral_constant<bool, __m == 0>(), |
| 1874 | integral_constant<bool, __c == 0>(), __s);} |
| 1875 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1876 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1877 | typename enable_if |
| 1878 | < |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 1879 | __is_seed_sequence<_Sseq, linear_congruential_engine>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1880 | void |
| 1881 | >::type |
| 1882 | seed(_Sseq& __q) |
| 1883 | {__seed(__q, integral_constant<unsigned, |
| 1884 | 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 |
Howard Hinnant | 8f72d5c | 2013-05-21 21:05:12 +0000 | [diff] [blame] | 1885 | : (__m > 0x100000000ull))>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1886 | |
| 1887 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1888 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1889 | result_type operator()() |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1890 | {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1891 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1892 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 1893 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1894 | friend _LIBCPP_INLINE_VISIBILITY |
| 1895 | bool operator==(const linear_congruential_engine& __x, |
| 1896 | const linear_congruential_engine& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1897 | {return __x.__x_ == __y.__x_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1898 | friend _LIBCPP_INLINE_VISIBILITY |
| 1899 | bool operator!=(const linear_congruential_engine& __x, |
| 1900 | const linear_congruential_engine& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1901 | {return !(__x == __y);} |
| 1902 | |
| 1903 | private: |
| 1904 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1905 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1906 | void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1907 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1908 | void seed(true_type, false_type, result_type __s) {__x_ = __s;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1909 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1910 | void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? |
| 1911 | 1 : __s % __m;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1912 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1913 | void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} |
| 1914 | |
| 1915 | template<class _Sseq> |
| 1916 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 1917 | template<class _Sseq> |
| 1918 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 1919 | |
| 1920 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1921 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1922 | friend |
| 1923 | basic_ostream<_CharT, _Traits>& |
| 1924 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1925 | const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1926 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1927 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1928 | class _Up, _Up _Ap, _Up _Cp, _Up _Np> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1929 | friend |
| 1930 | basic_istream<_CharT, _Traits>& |
| 1931 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1932 | linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1933 | }; |
| 1934 | |
| 1935 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | 0a69fa1 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 1936 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1937 | linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; |
| 1938 | |
| 1939 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1940 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1941 | linear_congruential_engine<_UIntType, __a, __c, __m>::increment; |
| 1942 | |
| 1943 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1944 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1945 | linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; |
| 1946 | |
| 1947 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1948 | _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type |
| 1949 | linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; |
| 1950 | |
| 1951 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1952 | template<class _Sseq> |
| 1953 | void |
| 1954 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, |
| 1955 | integral_constant<unsigned, 1>) |
| 1956 | { |
| 1957 | const unsigned __k = 1; |
| 1958 | uint32_t __ar[__k+3]; |
| 1959 | __q.generate(__ar, __ar + __k + 3); |
| 1960 | result_type __s = static_cast<result_type>(__ar[3] % __m); |
| 1961 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; |
| 1962 | } |
| 1963 | |
| 1964 | template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1965 | template<class _Sseq> |
| 1966 | void |
| 1967 | linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, |
| 1968 | integral_constant<unsigned, 2>) |
| 1969 | { |
| 1970 | const unsigned __k = 2; |
| 1971 | uint32_t __ar[__k+3]; |
| 1972 | __q.generate(__ar, __ar + __k + 3); |
| 1973 | result_type __s = static_cast<result_type>((__ar[3] + |
Howard Hinnant | 8f72d5c | 2013-05-21 21:05:12 +0000 | [diff] [blame] | 1974 | ((uint64_t)__ar[4] << 32)) % __m); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1975 | __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; |
| 1976 | } |
| 1977 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1978 | template <class _CharT, class _Traits, |
| 1979 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 1980 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1981 | basic_ostream<_CharT, _Traits>& |
| 1982 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 1983 | const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) |
| 1984 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 1985 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1986 | __os.flags(ios_base::dec | ios_base::left); |
| 1987 | __os.fill(__os.widen(' ')); |
| 1988 | return __os << __x.__x_; |
| 1989 | } |
| 1990 | |
| 1991 | template <class _CharT, class _Traits, |
| 1992 | class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> |
| 1993 | basic_istream<_CharT, _Traits>& |
| 1994 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 1995 | linear_congruential_engine<_UIntType, __a, __c, __m>& __x) |
| 1996 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 1997 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1998 | __is.flags(ios_base::dec | ios_base::skipws); |
| 1999 | _UIntType __t; |
| 2000 | __is >> __t; |
| 2001 | if (!__is.fail()) |
| 2002 | __x.__x_ = __t; |
| 2003 | return __is; |
| 2004 | } |
| 2005 | |
| 2006 | typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> |
| 2007 | minstd_rand0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2008 | typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> |
| 2009 | minstd_rand; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 2010 | typedef minstd_rand default_random_engine; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2011 | // mersenne_twister_engine |
| 2012 | |
| 2013 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2014 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2015 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2016 | class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2017 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2018 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2019 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2020 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2021 | bool |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2022 | operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2023 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2024 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2025 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2026 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2027 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2028 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2029 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 2030 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2031 | bool |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2032 | operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2033 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2034 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2035 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2036 | |
| 2037 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2038 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2039 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2040 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2041 | basic_ostream<_CharT, _Traits>& |
| 2042 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2043 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2044 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2045 | |
| 2046 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2047 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2048 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2049 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2050 | basic_istream<_CharT, _Traits>& |
| 2051 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2052 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2053 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2054 | |
| 2055 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2056 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2057 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2058 | class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2059 | { |
| 2060 | public: |
| 2061 | // types |
| 2062 | typedef _UIntType result_type; |
| 2063 | |
| 2064 | private: |
| 2065 | result_type __x_[__n]; |
| 2066 | size_t __i_; |
| 2067 | |
| 2068 | static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); |
| 2069 | static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2070 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2071 | static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); |
| 2072 | static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); |
| 2073 | static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); |
| 2074 | static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); |
| 2075 | static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); |
| 2076 | static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); |
| 2077 | static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); |
| 2078 | public: |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2079 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 2080 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 2081 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2082 | static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); |
| 2083 | static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2084 | static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2085 | static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2086 | static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2087 | static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); |
| 2088 | |
| 2089 | // engine characteristics |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2090 | static _LIBCPP_CONSTEXPR const size_t word_size = __w; |
| 2091 | static _LIBCPP_CONSTEXPR const size_t state_size = __n; |
| 2092 | static _LIBCPP_CONSTEXPR const size_t shift_size = __m; |
| 2093 | static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; |
| 2094 | static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; |
| 2095 | static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; |
| 2096 | static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; |
| 2097 | static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; |
| 2098 | static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; |
| 2099 | static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; |
| 2100 | static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; |
| 2101 | static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; |
| 2102 | static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2103 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2104 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2105 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2106 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
| 2107 | static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2108 | |
| 2109 | // constructors and seeding functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2110 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2111 | explicit mersenne_twister_engine(result_type __sd = default_seed) |
| 2112 | {seed(__sd);} |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2113 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2114 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2115 | explicit mersenne_twister_engine(_Sseq& __q, |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2116 | typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2117 | {seed(__q);} |
| 2118 | void seed(result_type __sd = default_seed); |
| 2119 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2120 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2121 | typename enable_if |
| 2122 | < |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2123 | __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2124 | void |
| 2125 | >::type |
| 2126 | seed(_Sseq& __q) |
| 2127 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2128 | |
| 2129 | // generating functions |
| 2130 | result_type operator()(); |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2131 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2132 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2133 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2134 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2135 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2136 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2137 | friend |
| 2138 | bool |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2139 | operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2140 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2141 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2142 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2143 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2144 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2145 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2146 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2147 | friend |
| 2148 | bool |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2149 | operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2150 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2151 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2152 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2153 | |
| 2154 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2155 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2156 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2157 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2158 | friend |
| 2159 | basic_ostream<_CharT, _Traits>& |
| 2160 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2161 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2162 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2163 | |
| 2164 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2165 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2166 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2167 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2168 | friend |
| 2169 | basic_istream<_CharT, _Traits>& |
| 2170 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2171 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2172 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2173 | private: |
| 2174 | |
| 2175 | template<class _Sseq> |
| 2176 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 2177 | template<class _Sseq> |
| 2178 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 2179 | |
| 2180 | template <size_t __count> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2181 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2182 | static |
| 2183 | typename enable_if |
| 2184 | < |
| 2185 | __count < __w, |
| 2186 | result_type |
| 2187 | >::type |
| 2188 | __lshift(result_type __x) {return (__x << __count) & _Max;} |
| 2189 | |
| 2190 | template <size_t __count> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2191 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2192 | static |
| 2193 | typename enable_if |
| 2194 | < |
| 2195 | (__count >= __w), |
| 2196 | result_type |
| 2197 | >::type |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2198 | __lshift(result_type) {return result_type(0);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2199 | |
| 2200 | template <size_t __count> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2201 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2202 | static |
| 2203 | typename enable_if |
| 2204 | < |
| 2205 | __count < _Dt, |
| 2206 | result_type |
| 2207 | >::type |
| 2208 | __rshift(result_type __x) {return __x >> __count;} |
| 2209 | |
| 2210 | template <size_t __count> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2211 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2212 | static |
| 2213 | typename enable_if |
| 2214 | < |
| 2215 | (__count >= _Dt), |
| 2216 | result_type |
| 2217 | >::type |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2218 | __rshift(result_type) {return result_type(0);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2219 | }; |
| 2220 | |
| 2221 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2222 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2223 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Howard Hinnant | 0a69fa1 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2224 | _LIBCPP_CONSTEXPR const size_t |
| 2225 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; |
| 2226 | |
| 2227 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2228 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2229 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2230 | _LIBCPP_CONSTEXPR const size_t |
| 2231 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; |
| 2232 | |
| 2233 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2234 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2235 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2236 | _LIBCPP_CONSTEXPR const size_t |
| 2237 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; |
| 2238 | |
| 2239 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2240 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2241 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2242 | _LIBCPP_CONSTEXPR const size_t |
| 2243 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; |
| 2244 | |
| 2245 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2246 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2247 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2248 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2249 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; |
| 2250 | |
| 2251 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2252 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2253 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2254 | _LIBCPP_CONSTEXPR const size_t |
| 2255 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; |
| 2256 | |
| 2257 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2258 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2259 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2260 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2261 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; |
| 2262 | |
| 2263 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2264 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2265 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2266 | _LIBCPP_CONSTEXPR const size_t |
| 2267 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; |
| 2268 | |
| 2269 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2270 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2271 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2272 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2273 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; |
| 2274 | |
| 2275 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2276 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2277 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2278 | _LIBCPP_CONSTEXPR const size_t |
| 2279 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; |
| 2280 | |
| 2281 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2282 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2283 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2284 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2285 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; |
| 2286 | |
| 2287 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2288 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2289 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2290 | _LIBCPP_CONSTEXPR const size_t |
| 2291 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; |
| 2292 | |
| 2293 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2294 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2295 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2296 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2297 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; |
| 2298 | |
| 2299 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2300 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2301 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2302 | _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type |
| 2303 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; |
| 2304 | |
| 2305 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2306 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2307 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2308 | void |
| 2309 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2310 | __t, __c, __l, __f>::seed(result_type __sd) |
Marshall Clow | 60f8ad1 | 2017-09-11 18:10:33 +0000 | [diff] [blame] | 2311 | _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2312 | { // __w >= 2 |
| 2313 | __x_[0] = __sd & _Max; |
| 2314 | for (size_t __i = 1; __i < __n; ++__i) |
| 2315 | __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; |
| 2316 | __i_ = 0; |
| 2317 | } |
| 2318 | |
| 2319 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2320 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2321 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2322 | template<class _Sseq> |
| 2323 | void |
| 2324 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2325 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) |
| 2326 | { |
| 2327 | const unsigned __k = 1; |
| 2328 | uint32_t __ar[__n * __k]; |
| 2329 | __q.generate(__ar, __ar + __n * __k); |
| 2330 | for (size_t __i = 0; __i < __n; ++__i) |
| 2331 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); |
| 2332 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2333 | (result_type(1) << __r) - result_type(1); |
| 2334 | __i_ = 0; |
| 2335 | if ((__x_[0] & ~__mask) == 0) |
| 2336 | { |
| 2337 | for (size_t __i = 1; __i < __n; ++__i) |
| 2338 | if (__x_[__i] != 0) |
| 2339 | return; |
Hubert Tong | aec9e0e | 2018-08-16 23:56:54 +0000 | [diff] [blame] | 2340 | __x_[0] = result_type(1) << (__w - 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2341 | } |
| 2342 | } |
| 2343 | |
| 2344 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2345 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2346 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2347 | template<class _Sseq> |
| 2348 | void |
| 2349 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2350 | __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) |
| 2351 | { |
| 2352 | const unsigned __k = 2; |
| 2353 | uint32_t __ar[__n * __k]; |
| 2354 | __q.generate(__ar, __ar + __n * __k); |
| 2355 | for (size_t __i = 0; __i < __n; ++__i) |
| 2356 | __x_[__i] = static_cast<result_type>( |
| 2357 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); |
| 2358 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2359 | (result_type(1) << __r) - result_type(1); |
| 2360 | __i_ = 0; |
| 2361 | if ((__x_[0] & ~__mask) == 0) |
| 2362 | { |
| 2363 | for (size_t __i = 1; __i < __n; ++__i) |
| 2364 | if (__x_[__i] != 0) |
| 2365 | return; |
Hubert Tong | aec9e0e | 2018-08-16 23:56:54 +0000 | [diff] [blame] | 2366 | __x_[0] = result_type(1) << (__w - 1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2367 | } |
| 2368 | } |
| 2369 | |
| 2370 | template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, |
| 2371 | _UIntType __a, size_t __u, _UIntType __d, size_t __s, |
| 2372 | _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> |
| 2373 | _UIntType |
| 2374 | mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, |
| 2375 | __t, __c, __l, __f>::operator()() |
| 2376 | { |
| 2377 | const size_t __j = (__i_ + 1) % __n; |
| 2378 | const result_type __mask = __r == _Dt ? result_type(~0) : |
| 2379 | (result_type(1) << __r) - result_type(1); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2380 | const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2381 | const size_t __k = (__i_ + __m) % __n; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2382 | __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2383 | result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); |
| 2384 | __i_ = __j; |
| 2385 | __z ^= __lshift<__s>(__z) & __b; |
| 2386 | __z ^= __lshift<__t>(__z) & __c; |
| 2387 | return __z ^ __rshift<__l>(__z); |
| 2388 | } |
| 2389 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2390 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2391 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2392 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2393 | bool |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2394 | operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2395 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2396 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2397 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2398 | { |
| 2399 | if (__x.__i_ == __y.__i_) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2400 | return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2401 | if (__x.__i_ == 0 || __y.__i_ == 0) |
| 2402 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2403 | size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2404 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2405 | __y.__x_ + __y.__i_)) |
| 2406 | return false; |
| 2407 | if (__x.__i_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2408 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); |
| 2409 | return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2410 | } |
| 2411 | if (__x.__i_ < __y.__i_) |
| 2412 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2413 | size_t __j = _Np - __y.__i_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2414 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2415 | __y.__x_ + __y.__i_)) |
| 2416 | return false; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2417 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2418 | __y.__x_)) |
| 2419 | return false; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2420 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2421 | __y.__x_ + (_Np - (__x.__i_ + __j))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2422 | } |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2423 | size_t __j = _Np - __x.__i_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2424 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2425 | __x.__x_ + __x.__i_)) |
| 2426 | return false; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2427 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2428 | __x.__x_)) |
| 2429 | return false; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2430 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2431 | __x.__x_ + (_Np - (__y.__i_ + __j))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2432 | } |
| 2433 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2434 | template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2435 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2436 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2437 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2438 | bool |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2439 | operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2440 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2441 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2442 | _Bp, _Tp, _Cp, _Lp, _Fp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2443 | { |
| 2444 | return !(__x == __y); |
| 2445 | } |
| 2446 | |
| 2447 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2448 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2449 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2450 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2451 | basic_ostream<_CharT, _Traits>& |
| 2452 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2453 | const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2454 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2455 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2456 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2457 | __os.flags(ios_base::dec | ios_base::left); |
| 2458 | _CharT __sp = __os.widen(' '); |
| 2459 | __os.fill(__sp); |
| 2460 | __os << __x.__x_[__x.__i_]; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2461 | for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2462 | __os << __sp << __x.__x_[__j]; |
| 2463 | for (size_t __j = 0; __j < __x.__i_; ++__j) |
| 2464 | __os << __sp << __x.__x_[__j]; |
| 2465 | return __os; |
| 2466 | } |
| 2467 | |
| 2468 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2469 | class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, |
| 2470 | _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, |
| 2471 | _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2472 | basic_istream<_CharT, _Traits>& |
| 2473 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2474 | mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2475 | _Bp, _Tp, _Cp, _Lp, _Fp>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2476 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2477 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2478 | __is.flags(ios_base::dec | ios_base::skipws); |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2479 | _UInt __t[_Np]; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2480 | for (size_t __i = 0; __i < _Np; ++__i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2481 | __is >> __t[__i]; |
| 2482 | if (!__is.fail()) |
| 2483 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2484 | for (size_t __i = 0; __i < _Np; ++__i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2485 | __x.__x_[__i] = __t[__i]; |
| 2486 | __x.__i_ = 0; |
| 2487 | } |
| 2488 | return __is; |
| 2489 | } |
| 2490 | |
| 2491 | typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, |
| 2492 | 0x9908b0df, 11, 0xffffffff, |
| 2493 | 7, 0x9d2c5680, |
| 2494 | 15, 0xefc60000, |
| 2495 | 18, 1812433253> mt19937; |
| 2496 | typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, |
| 2497 | 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, |
| 2498 | 17, 0x71d67fffeda60000ULL, |
| 2499 | 37, 0xfff7eee000000000ULL, |
| 2500 | 43, 6364136223846793005ULL> mt19937_64; |
| 2501 | |
| 2502 | // subtract_with_carry_engine |
| 2503 | |
| 2504 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2505 | class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2506 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2507 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2508 | bool |
| 2509 | operator==( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2510 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2511 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2512 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2513 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | 33be35e | 2012-09-14 00:39:16 +0000 | [diff] [blame] | 2514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2515 | bool |
| 2516 | operator!=( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2517 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2518 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2519 | |
| 2520 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2521 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2522 | basic_ostream<_CharT, _Traits>& |
| 2523 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2524 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2525 | |
| 2526 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2527 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2528 | basic_istream<_CharT, _Traits>& |
| 2529 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2530 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2531 | |
| 2532 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2533 | class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2534 | { |
| 2535 | public: |
| 2536 | // types |
| 2537 | typedef _UIntType result_type; |
| 2538 | |
| 2539 | private: |
| 2540 | result_type __x_[__r]; |
| 2541 | result_type __c_; |
| 2542 | size_t __i_; |
| 2543 | |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2544 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2545 | static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); |
| 2546 | static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); |
| 2547 | static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); |
| 2548 | static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); |
| 2549 | public: |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2550 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 2551 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 2552 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2553 | static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); |
| 2554 | |
| 2555 | // engine characteristics |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2556 | static _LIBCPP_CONSTEXPR const size_t word_size = __w; |
| 2557 | static _LIBCPP_CONSTEXPR const size_t short_lag = __s; |
| 2558 | static _LIBCPP_CONSTEXPR const size_t long_lag = __r; |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2559 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2560 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2561 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2562 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
| 2563 | static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2564 | |
| 2565 | // constructors and seeding functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2566 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2567 | explicit subtract_with_carry_engine(result_type __sd = default_seed) |
| 2568 | {seed(__sd);} |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2569 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2570 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2571 | explicit subtract_with_carry_engine(_Sseq& __q, |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2572 | typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2573 | {seed(__q);} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2575 | void seed(result_type __sd = default_seed) |
| 2576 | {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2577 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2579 | typename enable_if |
| 2580 | < |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2581 | __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2582 | void |
| 2583 | >::type |
| 2584 | seed(_Sseq& __q) |
| 2585 | {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} |
| 2586 | |
| 2587 | // generating functions |
| 2588 | result_type operator()(); |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2589 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2590 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2591 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2592 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2593 | friend |
| 2594 | bool |
| 2595 | operator==( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2596 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2597 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2598 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2599 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2600 | friend |
| 2601 | bool |
| 2602 | operator!=( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2603 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2604 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2605 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2606 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2607 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2608 | friend |
| 2609 | basic_ostream<_CharT, _Traits>& |
| 2610 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2611 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2612 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2613 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2614 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2615 | friend |
| 2616 | basic_istream<_CharT, _Traits>& |
| 2617 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2618 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2619 | |
| 2620 | private: |
| 2621 | |
| 2622 | void seed(result_type __sd, integral_constant<unsigned, 1>); |
| 2623 | void seed(result_type __sd, integral_constant<unsigned, 2>); |
| 2624 | template<class _Sseq> |
| 2625 | void __seed(_Sseq& __q, integral_constant<unsigned, 1>); |
| 2626 | template<class _Sseq> |
| 2627 | void __seed(_Sseq& __q, integral_constant<unsigned, 2>); |
| 2628 | }; |
| 2629 | |
| 2630 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Howard Hinnant | 0a69fa1 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2631 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; |
| 2632 | |
| 2633 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2634 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; |
| 2635 | |
| 2636 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2637 | _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; |
| 2638 | |
| 2639 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2640 | _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type |
| 2641 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; |
| 2642 | |
| 2643 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2644 | void |
| 2645 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, |
| 2646 | integral_constant<unsigned, 1>) |
| 2647 | { |
| 2648 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> |
| 2649 | __e(__sd == 0u ? default_seed : __sd); |
| 2650 | for (size_t __i = 0; __i < __r; ++__i) |
| 2651 | __x_[__i] = static_cast<result_type>(__e() & _Max); |
| 2652 | __c_ = __x_[__r-1] == 0; |
| 2653 | __i_ = 0; |
| 2654 | } |
| 2655 | |
| 2656 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2657 | void |
| 2658 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, |
| 2659 | integral_constant<unsigned, 2>) |
| 2660 | { |
| 2661 | linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> |
| 2662 | __e(__sd == 0u ? default_seed : __sd); |
| 2663 | for (size_t __i = 0; __i < __r; ++__i) |
Howard Hinnant | 43edf2d | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2664 | { |
| 2665 | result_type __e0 = __e(); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2666 | __x_[__i] = static_cast<result_type>( |
Howard Hinnant | 43edf2d | 2011-08-15 17:22:22 +0000 | [diff] [blame] | 2667 | (__e0 + ((uint64_t)__e() << 32)) & _Max); |
| 2668 | } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2669 | __c_ = __x_[__r-1] == 0; |
| 2670 | __i_ = 0; |
| 2671 | } |
| 2672 | |
| 2673 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2674 | template<class _Sseq> |
| 2675 | void |
| 2676 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, |
| 2677 | integral_constant<unsigned, 1>) |
| 2678 | { |
| 2679 | const unsigned __k = 1; |
| 2680 | uint32_t __ar[__r * __k]; |
| 2681 | __q.generate(__ar, __ar + __r * __k); |
| 2682 | for (size_t __i = 0; __i < __r; ++__i) |
| 2683 | __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); |
| 2684 | __c_ = __x_[__r-1] == 0; |
| 2685 | __i_ = 0; |
| 2686 | } |
| 2687 | |
| 2688 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2689 | template<class _Sseq> |
| 2690 | void |
| 2691 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, |
| 2692 | integral_constant<unsigned, 2>) |
| 2693 | { |
| 2694 | const unsigned __k = 2; |
| 2695 | uint32_t __ar[__r * __k]; |
| 2696 | __q.generate(__ar, __ar + __r * __k); |
| 2697 | for (size_t __i = 0; __i < __r; ++__i) |
| 2698 | __x_[__i] = static_cast<result_type>( |
| 2699 | (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); |
| 2700 | __c_ = __x_[__r-1] == 0; |
| 2701 | __i_ = 0; |
| 2702 | } |
| 2703 | |
| 2704 | template<class _UIntType, size_t __w, size_t __s, size_t __r> |
| 2705 | _UIntType |
| 2706 | subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() |
| 2707 | { |
| 2708 | const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; |
| 2709 | result_type& __xr = __x_[__i_]; |
| 2710 | result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; |
| 2711 | __xr = (__xs - __xr - __c_) & _Max; |
| 2712 | __c_ = __new_c; |
| 2713 | __i_ = (__i_ + 1) % __r; |
| 2714 | return __xr; |
| 2715 | } |
| 2716 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2717 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2718 | bool |
| 2719 | operator==( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2720 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2721 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2722 | { |
| 2723 | if (__x.__c_ != __y.__c_) |
| 2724 | return false; |
| 2725 | if (__x.__i_ == __y.__i_) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2726 | return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2727 | if (__x.__i_ == 0 || __y.__i_ == 0) |
| 2728 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2729 | size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2730 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2731 | __y.__x_ + __y.__i_)) |
| 2732 | return false; |
| 2733 | if (__x.__i_ == 0) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2734 | return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); |
| 2735 | return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2736 | } |
| 2737 | if (__x.__i_ < __y.__i_) |
| 2738 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2739 | size_t __j = _Rp - __y.__i_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2740 | if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2741 | __y.__x_ + __y.__i_)) |
| 2742 | return false; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2743 | if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2744 | __y.__x_)) |
| 2745 | return false; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2746 | return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2747 | __y.__x_ + (_Rp - (__x.__i_ + __j))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2748 | } |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2749 | size_t __j = _Rp - __x.__i_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2750 | if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2751 | __x.__x_ + __x.__i_)) |
| 2752 | return false; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2753 | if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2754 | __x.__x_)) |
| 2755 | return false; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2756 | return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2757 | __x.__x_ + (_Rp - (__y.__i_ + __j))); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2758 | } |
| 2759 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2760 | template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2761 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2762 | bool |
| 2763 | operator!=( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2764 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, |
| 2765 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2766 | { |
| 2767 | return !(__x == __y); |
| 2768 | } |
| 2769 | |
| 2770 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2771 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2772 | basic_ostream<_CharT, _Traits>& |
| 2773 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2774 | const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2775 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2776 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2777 | __os.flags(ios_base::dec | ios_base::left); |
| 2778 | _CharT __sp = __os.widen(' '); |
| 2779 | __os.fill(__sp); |
| 2780 | __os << __x.__x_[__x.__i_]; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2781 | for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2782 | __os << __sp << __x.__x_[__j]; |
| 2783 | for (size_t __j = 0; __j < __x.__i_; ++__j) |
| 2784 | __os << __sp << __x.__x_[__j]; |
| 2785 | __os << __sp << __x.__c_; |
| 2786 | return __os; |
| 2787 | } |
| 2788 | |
| 2789 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2790 | class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2791 | basic_istream<_CharT, _Traits>& |
| 2792 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2793 | subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2794 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2795 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2796 | __is.flags(ios_base::dec | ios_base::skipws); |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2797 | _UInt __t[_Rp+1]; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2798 | for (size_t __i = 0; __i < _Rp+1; ++__i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2799 | __is >> __t[__i]; |
| 2800 | if (!__is.fail()) |
| 2801 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2802 | for (size_t __i = 0; __i < _Rp; ++__i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2803 | __x.__x_[__i] = __t[__i]; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2804 | __x.__c_ = __t[_Rp]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2805 | __x.__i_ = 0; |
| 2806 | } |
| 2807 | return __is; |
| 2808 | } |
| 2809 | |
| 2810 | typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; |
| 2811 | typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; |
| 2812 | |
| 2813 | // discard_block_engine |
| 2814 | |
| 2815 | template<class _Engine, size_t __p, size_t __r> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2816 | class _LIBCPP_TEMPLATE_VIS discard_block_engine |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2817 | { |
| 2818 | _Engine __e_; |
| 2819 | int __n_; |
| 2820 | |
| 2821 | static_assert( 0 < __r, "discard_block_engine invalid parameters"); |
| 2822 | static_assert(__r <= __p, "discard_block_engine invalid parameters"); |
Eric Fiselier | 50f6579 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 2823 | static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2824 | public: |
| 2825 | // types |
| 2826 | typedef typename _Engine::result_type result_type; |
| 2827 | |
| 2828 | // engine characteristics |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2829 | static _LIBCPP_CONSTEXPR const size_t block_size = __p; |
| 2830 | static _LIBCPP_CONSTEXPR const size_t used_block = __r; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2831 | |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2832 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2833 | static const result_type _Min = _Engine::_Min; |
| 2834 | static const result_type _Max = _Engine::_Max; |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2835 | #else |
| 2836 | static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); |
| 2837 | static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); |
| 2838 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2839 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2840 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2841 | static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2842 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2843 | static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2844 | |
| 2845 | // constructors and seeding functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2846 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2847 | discard_block_engine() : __n_(0) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2848 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2849 | explicit discard_block_engine(const _Engine& __e) |
| 2850 | : __e_(__e), __n_(0) {} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2851 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2852 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2853 | explicit discard_block_engine(_Engine&& __e) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2854 | : __e_(_VSTD::move(__e)), __n_(0) {} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 2855 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2856 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2857 | explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2858 | template<class _Sseq> |
| 2859 | _LIBCPP_INLINE_VISIBILITY |
| 2860 | explicit discard_block_engine(_Sseq& __q, |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2861 | typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2862 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2863 | : __e_(__q), __n_(0) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2864 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2865 | void seed() {__e_.seed(); __n_ = 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2866 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2867 | void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2868 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2869 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2870 | typename enable_if |
| 2871 | < |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 2872 | __is_seed_sequence<_Sseq, discard_block_engine>::value, |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 2873 | void |
| 2874 | >::type |
| 2875 | seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2876 | |
| 2877 | // generating functions |
| 2878 | result_type operator()(); |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2879 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2880 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 2881 | |
| 2882 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c83960a | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 2884 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2885 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2886 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2887 | friend |
| 2888 | bool |
| 2889 | operator==( |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2890 | const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2891 | const discard_block_engine<_Eng, _Pp, _Rp>& __y); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2892 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2893 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2894 | friend |
| 2895 | bool |
| 2896 | operator!=( |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2897 | const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2898 | const discard_block_engine<_Eng, _Pp, _Rp>& __y); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2899 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2900 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2901 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2902 | friend |
| 2903 | basic_ostream<_CharT, _Traits>& |
| 2904 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2905 | const discard_block_engine<_Eng, _Pp, _Rp>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 2906 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2907 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2908 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2909 | friend |
| 2910 | basic_istream<_CharT, _Traits>& |
| 2911 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2912 | discard_block_engine<_Eng, _Pp, _Rp>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2913 | }; |
| 2914 | |
| 2915 | template<class _Engine, size_t __p, size_t __r> |
Howard Hinnant | 0a69fa1 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2916 | _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; |
| 2917 | |
| 2918 | template<class _Engine, size_t __p, size_t __r> |
| 2919 | _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; |
| 2920 | |
| 2921 | template<class _Engine, size_t __p, size_t __r> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2922 | typename discard_block_engine<_Engine, __p, __r>::result_type |
| 2923 | discard_block_engine<_Engine, __p, __r>::operator()() |
| 2924 | { |
Eric Fiselier | 50f6579 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 2925 | if (__n_ >= static_cast<int>(__r)) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2926 | { |
| 2927 | __e_.discard(__p - __r); |
| 2928 | __n_ = 0; |
| 2929 | } |
| 2930 | ++__n_; |
| 2931 | return __e_(); |
| 2932 | } |
| 2933 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2934 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2935 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2936 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2937 | operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2938 | const discard_block_engine<_Eng, _Pp, _Rp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2939 | { |
| 2940 | return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; |
| 2941 | } |
| 2942 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2943 | template<class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 2944 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2945 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2946 | operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, |
| 2947 | const discard_block_engine<_Eng, _Pp, _Rp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2948 | { |
| 2949 | return !(__x == __y); |
| 2950 | } |
| 2951 | |
| 2952 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2953 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2954 | basic_ostream<_CharT, _Traits>& |
| 2955 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2956 | const discard_block_engine<_Eng, _Pp, _Rp>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2957 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2958 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2959 | __os.flags(ios_base::dec | ios_base::left); |
| 2960 | _CharT __sp = __os.widen(' '); |
| 2961 | __os.fill(__sp); |
| 2962 | return __os << __x.__e_ << __sp << __x.__n_; |
| 2963 | } |
| 2964 | |
| 2965 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2966 | class _Eng, size_t _Pp, size_t _Rp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2967 | basic_istream<_CharT, _Traits>& |
| 2968 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2969 | discard_block_engine<_Eng, _Pp, _Rp>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2970 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 2971 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2972 | __is.flags(ios_base::dec | ios_base::skipws); |
| 2973 | _Eng __e; |
| 2974 | int __n; |
| 2975 | __is >> __e >> __n; |
| 2976 | if (!__is.fail()) |
| 2977 | { |
| 2978 | __x.__e_ = __e; |
| 2979 | __x.__n_ = __n; |
| 2980 | } |
| 2981 | return __is; |
| 2982 | } |
| 2983 | |
| 2984 | typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; |
| 2985 | typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; |
| 2986 | |
| 2987 | // independent_bits_engine |
| 2988 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2989 | template<class _Engine, size_t __w, class _UIntType> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2990 | class _LIBCPP_TEMPLATE_VIS independent_bits_engine |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2991 | { |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2992 | template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2993 | class __get_n |
| 2994 | { |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2995 | static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 2996 | static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); |
| 2997 | static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 2998 | static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2999 | public: |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3000 | static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3001 | }; |
| 3002 | public: |
| 3003 | // types |
| 3004 | typedef _UIntType result_type; |
| 3005 | |
| 3006 | private: |
| 3007 | _Engine __e_; |
| 3008 | |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3009 | static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3010 | static_assert( 0 < __w, "independent_bits_engine invalid parameters"); |
| 3011 | static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); |
| 3012 | |
| 3013 | typedef typename _Engine::result_type _Engine_result_type; |
| 3014 | typedef typename conditional |
| 3015 | < |
| 3016 | sizeof(_Engine_result_type) <= sizeof(result_type), |
| 3017 | result_type, |
| 3018 | _Engine_result_type |
| 3019 | >::type _Working_result_type; |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3020 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3021 | static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3022 | + _Working_result_type(1); |
| 3023 | #else |
| 3024 | static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() |
| 3025 | + _Working_result_type(1); |
| 3026 | #endif |
| 3027 | static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; |
| 3028 | static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; |
| 3029 | static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; |
| 3030 | static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; |
| 3031 | static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; |
| 3032 | static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; |
| 3033 | static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : |
| 3034 | (_Rp >> __w0) << __w0; |
| 3035 | static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : |
| 3036 | (_Rp >> (__w0+1)) << (__w0+1); |
| 3037 | static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3038 | _Engine_result_type(~0) >> (_EDt - __w0) : |
| 3039 | _Engine_result_type(0); |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3040 | static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3041 | _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : |
| 3042 | _Engine_result_type(~0); |
| 3043 | public: |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3044 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 3045 | static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : |
| 3046 | (result_type(1) << __w) - result_type(1); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3047 | static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); |
| 3048 | |
| 3049 | // engine characteristics |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3050 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3051 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3052 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3053 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3054 | |
| 3055 | // constructors and seeding functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3056 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3057 | independent_bits_engine() {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3058 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3059 | explicit independent_bits_engine(const _Engine& __e) |
| 3060 | : __e_(__e) {} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3061 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3062 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3063 | explicit independent_bits_engine(_Engine&& __e) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3064 | : __e_(_VSTD::move(__e)) {} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3065 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3066 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3067 | explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3068 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3069 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3070 | explicit independent_bits_engine(_Sseq& __q, |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3071 | typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3072 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3073 | : __e_(__q) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3074 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3075 | void seed() {__e_.seed();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3076 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3077 | void seed(result_type __sd) {__e_.seed(__sd);} |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3078 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3079 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3080 | typename enable_if |
| 3081 | < |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3082 | __is_seed_sequence<_Sseq, independent_bits_engine>::value, |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3083 | void |
| 3084 | >::type |
| 3085 | seed(_Sseq& __q) {__e_.seed(__q);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3086 | |
| 3087 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3088 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3089 | result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3090 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3091 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 3092 | |
| 3093 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3094 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c83960a | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3095 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3096 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3097 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3098 | friend |
| 3099 | bool |
| 3100 | operator==( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3101 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3102 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3103 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3104 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3105 | friend |
| 3106 | bool |
| 3107 | operator!=( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3108 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3109 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3110 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3111 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3112 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3113 | friend |
| 3114 | basic_ostream<_CharT, _Traits>& |
| 3115 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3116 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3117 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3118 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3119 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3120 | friend |
| 3121 | basic_istream<_CharT, _Traits>& |
| 3122 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3123 | independent_bits_engine<_Eng, _Wp, _UInt>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3124 | |
| 3125 | private: |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3126 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 1e32db7 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3127 | result_type __eval(false_type); |
| 3128 | result_type __eval(true_type); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3129 | |
| 3130 | template <size_t __count> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3131 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3132 | static |
| 3133 | typename enable_if |
| 3134 | < |
| 3135 | __count < _Dt, |
| 3136 | result_type |
| 3137 | >::type |
| 3138 | __lshift(result_type __x) {return __x << __count;} |
| 3139 | |
| 3140 | template <size_t __count> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3141 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3142 | static |
| 3143 | typename enable_if |
| 3144 | < |
| 3145 | (__count >= _Dt), |
| 3146 | result_type |
| 3147 | >::type |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3148 | __lshift(result_type) {return result_type(0);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3149 | }; |
| 3150 | |
| 3151 | template<class _Engine, size_t __w, class _UIntType> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3152 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3153 | _UIntType |
Marshall Clow | 1e32db7 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3154 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3155 | { |
| 3156 | return static_cast<result_type>(__e_() & __mask0); |
| 3157 | } |
| 3158 | |
| 3159 | template<class _Engine, size_t __w, class _UIntType> |
| 3160 | _UIntType |
Marshall Clow | 1e32db7 | 2017-09-20 19:38:43 +0000 | [diff] [blame] | 3161 | independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3162 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3163 | result_type _Sp = 0; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3164 | for (size_t __k = 0; __k < __n0; ++__k) |
| 3165 | { |
| 3166 | _Engine_result_type __u; |
| 3167 | do |
| 3168 | { |
| 3169 | __u = __e_() - _Engine::min(); |
| 3170 | } while (__u >= __y0); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3171 | _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3172 | } |
| 3173 | for (size_t __k = __n0; __k < __n; ++__k) |
| 3174 | { |
| 3175 | _Engine_result_type __u; |
| 3176 | do |
| 3177 | { |
| 3178 | __u = __e_() - _Engine::min(); |
| 3179 | } while (__u >= __y1); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3180 | _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3181 | } |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3182 | return _Sp; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3183 | } |
| 3184 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3185 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3186 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3187 | bool |
| 3188 | operator==( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3189 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3190 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3191 | { |
| 3192 | return __x.base() == __y.base(); |
| 3193 | } |
| 3194 | |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3195 | template<class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3196 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3197 | bool |
| 3198 | operator!=( |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3199 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x, |
| 3200 | const independent_bits_engine<_Eng, _Wp, _UInt>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3201 | { |
| 3202 | return !(__x == __y); |
| 3203 | } |
| 3204 | |
| 3205 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3206 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3207 | basic_ostream<_CharT, _Traits>& |
| 3208 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3209 | const independent_bits_engine<_Eng, _Wp, _UInt>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3210 | { |
| 3211 | return __os << __x.base(); |
| 3212 | } |
| 3213 | |
| 3214 | template <class _CharT, class _Traits, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3215 | class _Eng, size_t _Wp, class _UInt> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3216 | basic_istream<_CharT, _Traits>& |
| 3217 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Eric Fiselier | ac633a2 | 2017-05-31 21:20:18 +0000 | [diff] [blame] | 3218 | independent_bits_engine<_Eng, _Wp, _UInt>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3219 | { |
| 3220 | _Eng __e; |
| 3221 | __is >> __e; |
| 3222 | if (!__is.fail()) |
| 3223 | __x.__e_ = __e; |
| 3224 | return __is; |
| 3225 | } |
| 3226 | |
| 3227 | // shuffle_order_engine |
| 3228 | |
| 3229 | template <uint64_t _Xp, uint64_t _Yp> |
| 3230 | struct __ugcd |
| 3231 | { |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3232 | static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3233 | }; |
| 3234 | |
| 3235 | template <uint64_t _Xp> |
| 3236 | struct __ugcd<_Xp, 0> |
| 3237 | { |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3238 | static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3239 | }; |
| 3240 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3241 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3242 | class __uratio |
| 3243 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3244 | static_assert(_Dp != 0, "__uratio divide by 0"); |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3245 | static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3246 | public: |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3247 | static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; |
| 3248 | static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3249 | |
| 3250 | typedef __uratio<num, den> type; |
| 3251 | }; |
| 3252 | |
| 3253 | template<class _Engine, size_t __k> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3254 | class _LIBCPP_TEMPLATE_VIS shuffle_order_engine |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3255 | { |
| 3256 | static_assert(0 < __k, "shuffle_order_engine invalid parameters"); |
| 3257 | public: |
| 3258 | // types |
| 3259 | typedef typename _Engine::result_type result_type; |
| 3260 | |
| 3261 | private: |
| 3262 | _Engine __e_; |
| 3263 | result_type _V_[__k]; |
| 3264 | result_type _Y_; |
| 3265 | |
| 3266 | public: |
| 3267 | // engine characteristics |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3268 | static _LIBCPP_CONSTEXPR const size_t table_size = __k; |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3269 | |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3270 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3271 | static const result_type _Min = _Engine::_Min; |
| 3272 | static const result_type _Max = _Engine::_Max; |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3273 | #else |
| 3274 | static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); |
| 3275 | static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); |
| 3276 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3277 | static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3278 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3279 | static _LIBCPP_CONSTEXPR result_type min() { return _Min; } |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3280 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3281 | static _LIBCPP_CONSTEXPR result_type max() { return _Max; } |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3282 | |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3283 | static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3284 | |
| 3285 | // constructors and seeding functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3286 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3287 | shuffle_order_engine() {__init();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3288 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3289 | explicit shuffle_order_engine(const _Engine& __e) |
| 3290 | : __e_(__e) {__init();} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3291 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3292 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3293 | explicit shuffle_order_engine(_Engine&& __e) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3294 | : __e_(_VSTD::move(__e)) {__init();} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3295 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3296 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3297 | explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3298 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3299 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 3300 | explicit shuffle_order_engine(_Sseq& __q, |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3301 | typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3302 | !is_convertible<_Sseq, _Engine>::value>::type* = 0) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3303 | : __e_(__q) {__init();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3304 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3305 | void seed() {__e_.seed(); __init();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3306 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3307 | void seed(result_type __sd) {__e_.seed(__sd); __init();} |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3308 | template<class _Sseq> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3309 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3310 | typename enable_if |
| 3311 | < |
Howard Hinnant | ef3b2e2 | 2011-04-11 18:22:12 +0000 | [diff] [blame] | 3312 | __is_seed_sequence<_Sseq, shuffle_order_engine>::value, |
Howard Hinnant | 3ec3184 | 2010-05-28 15:49:54 +0000 | [diff] [blame] | 3313 | void |
| 3314 | >::type |
| 3315 | seed(_Sseq& __q) {__e_.seed(__q); __init();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3316 | |
| 3317 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3318 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3319 | result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3320 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3321 | void discard(unsigned long long __z) {for (; __z; --__z) operator()();} |
| 3322 | |
| 3323 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3324 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c83960a | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3325 | const _Engine& base() const _NOEXCEPT {return __e_;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3326 | |
| 3327 | private: |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3328 | template<class _Eng, size_t _Kp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3329 | friend |
| 3330 | bool |
| 3331 | operator==( |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3332 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3333 | const shuffle_order_engine<_Eng, _Kp>& __y); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3334 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3335 | template<class _Eng, size_t _Kp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3336 | friend |
| 3337 | bool |
| 3338 | operator!=( |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3339 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3340 | const shuffle_order_engine<_Eng, _Kp>& __y); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3341 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3342 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3343 | class _Eng, size_t _Kp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3344 | friend |
| 3345 | basic_ostream<_CharT, _Traits>& |
| 3346 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3347 | const shuffle_order_engine<_Eng, _Kp>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3348 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3349 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3350 | class _Eng, size_t _Kp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3351 | friend |
| 3352 | basic_istream<_CharT, _Traits>& |
| 3353 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3354 | shuffle_order_engine<_Eng, _Kp>& __x); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3355 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3356 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3357 | void __init() |
| 3358 | { |
| 3359 | for (size_t __i = 0; __i < __k; ++__i) |
| 3360 | _V_[__i] = __e_(); |
| 3361 | _Y_ = __e_(); |
| 3362 | } |
| 3363 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3364 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3365 | result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3366 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3367 | result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3368 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3369 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3370 | result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3371 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3372 | result_type __eval2(true_type) {return __evalf<__k, 0>();} |
| 3373 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3374 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3375 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3376 | typename enable_if |
| 3377 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3378 | (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3379 | result_type |
| 3380 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3381 | __eval(__uratio<_Np, _Dp>) |
| 3382 | {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3383 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3384 | template <uint64_t _Np, uint64_t _Dp> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3385 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3386 | typename enable_if |
| 3387 | < |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3388 | __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3389 | result_type |
| 3390 | >::type |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3391 | __eval(__uratio<_Np, _Dp>) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3392 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3393 | const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min) |
| 3394 | / __uratio<_Np, _Dp>::den); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3395 | _Y_ = _V_[__j]; |
| 3396 | _V_[__j] = __e_(); |
| 3397 | return _Y_; |
| 3398 | } |
| 3399 | |
| 3400 | template <uint64_t __n, uint64_t __d> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3401 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3402 | result_type __evalf() |
| 3403 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3404 | const double _Fp = __d == 0 ? |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3405 | __n / (2. * 0x8000000000000000ull) : |
| 3406 | __n / (double)__d; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3407 | const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3408 | _Y_ = _V_[__j]; |
| 3409 | _V_[__j] = __e_(); |
| 3410 | return _Y_; |
| 3411 | } |
| 3412 | }; |
| 3413 | |
Howard Hinnant | 0a69fa1 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3414 | template<class _Engine, size_t __k> |
| 3415 | _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; |
| 3416 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3417 | template<class _Eng, size_t _Kp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3418 | bool |
| 3419 | operator==( |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3420 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3421 | const shuffle_order_engine<_Eng, _Kp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3422 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3423 | return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) && |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3424 | __x.__e_ == __y.__e_; |
| 3425 | } |
| 3426 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3427 | template<class _Eng, size_t _Kp> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3428 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3429 | bool |
| 3430 | operator!=( |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3431 | const shuffle_order_engine<_Eng, _Kp>& __x, |
| 3432 | const shuffle_order_engine<_Eng, _Kp>& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3433 | { |
| 3434 | return !(__x == __y); |
| 3435 | } |
| 3436 | |
| 3437 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3438 | class _Eng, size_t _Kp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3439 | basic_ostream<_CharT, _Traits>& |
| 3440 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3441 | const shuffle_order_engine<_Eng, _Kp>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3442 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3443 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3444 | __os.flags(ios_base::dec | ios_base::left); |
| 3445 | _CharT __sp = __os.widen(' '); |
| 3446 | __os.fill(__sp); |
| 3447 | __os << __x.__e_ << __sp << __x._V_[0]; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3448 | for (size_t __i = 1; __i < _Kp; ++__i) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3449 | __os << __sp << __x._V_[__i]; |
| 3450 | return __os << __sp << __x._Y_; |
| 3451 | } |
| 3452 | |
| 3453 | template <class _CharT, class _Traits, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3454 | class _Eng, size_t _Kp> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3455 | basic_istream<_CharT, _Traits>& |
| 3456 | operator>>(basic_istream<_CharT, _Traits>& __is, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3457 | shuffle_order_engine<_Eng, _Kp>& __x) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3458 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3459 | typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3460 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3461 | __is.flags(ios_base::dec | ios_base::skipws); |
| 3462 | _Eng __e; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3463 | result_type _Vp[_Kp+1]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3464 | __is >> __e; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3465 | for (size_t __i = 0; __i < _Kp+1; ++__i) |
| 3466 | __is >> _Vp[__i]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3467 | if (!__is.fail()) |
| 3468 | { |
| 3469 | __x.__e_ = __e; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3470 | for (size_t __i = 0; __i < _Kp; ++__i) |
| 3471 | __x._V_[__i] = _Vp[__i]; |
| 3472 | __x._Y_ = _Vp[_Kp]; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3473 | } |
| 3474 | return __is; |
| 3475 | } |
| 3476 | |
| 3477 | typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; |
| 3478 | |
| 3479 | // random_device |
| 3480 | |
Howard Hinnant | 83eade6 | 2013-03-06 23:30:19 +0000 | [diff] [blame] | 3481 | class _LIBCPP_TYPE_VIS random_device |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3482 | { |
Ed Schouten | 63e70b6 | 2015-03-10 07:46:06 +0000 | [diff] [blame] | 3483 | #ifdef _LIBCPP_USING_DEV_RANDOM |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3484 | int __f_; |
Ed Schouten | 63e70b6 | 2015-03-10 07:46:06 +0000 | [diff] [blame] | 3485 | #endif // defined(_LIBCPP_USING_DEV_RANDOM) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3486 | public: |
| 3487 | // types |
| 3488 | typedef unsigned result_type; |
| 3489 | |
| 3490 | // generator characteristics |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3491 | static _LIBCPP_CONSTEXPR const result_type _Min = 0; |
| 3492 | static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3493 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3494 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 27b4fd3 | 2012-04-02 00:40:41 +0000 | [diff] [blame] | 3495 | static _LIBCPP_CONSTEXPR result_type min() { return _Min;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3496 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 27b4fd3 | 2012-04-02 00:40:41 +0000 | [diff] [blame] | 3497 | static _LIBCPP_CONSTEXPR result_type max() { return _Max;} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3498 | |
| 3499 | // constructors |
| 3500 | explicit random_device(const string& __token = "/dev/urandom"); |
| 3501 | ~random_device(); |
| 3502 | |
| 3503 | // generating functions |
| 3504 | result_type operator()(); |
| 3505 | |
| 3506 | // property functions |
Howard Hinnant | c83960a | 2012-07-20 21:44:27 +0000 | [diff] [blame] | 3507 | double entropy() const _NOEXCEPT; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3508 | |
| 3509 | private: |
| 3510 | // no copy functions |
| 3511 | random_device(const random_device&); // = delete; |
| 3512 | random_device& operator=(const random_device&); // = delete; |
| 3513 | }; |
| 3514 | |
| 3515 | // seed_seq |
| 3516 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3517 | class _LIBCPP_TEMPLATE_VIS seed_seq |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3518 | { |
| 3519 | public: |
| 3520 | // types |
| 3521 | typedef uint32_t result_type; |
| 3522 | |
| 3523 | private: |
| 3524 | vector<result_type> __v_; |
| 3525 | |
| 3526 | template<class _InputIterator> |
| 3527 | void init(_InputIterator __first, _InputIterator __last); |
| 3528 | public: |
| 3529 | // constructors |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3530 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 65ccddb | 2013-10-23 05:56:47 +0000 | [diff] [blame] | 3531 | seed_seq() _NOEXCEPT {} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3532 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3533 | template<class _Tp> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3534 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3535 | seed_seq(initializer_list<_Tp> __il) {init(__il.begin(), __il.end());} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3536 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 3537 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3538 | template<class _InputIterator> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3540 | seed_seq(_InputIterator __first, _InputIterator __last) |
| 3541 | {init(__first, __last);} |
| 3542 | |
| 3543 | // generating functions |
| 3544 | template<class _RandomAccessIterator> |
| 3545 | void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); |
| 3546 | |
| 3547 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3548 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 65ccddb | 2013-10-23 05:56:47 +0000 | [diff] [blame] | 3549 | size_t size() const _NOEXCEPT {return __v_.size();} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3550 | template<class _OutputIterator> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3551 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3552 | void param(_OutputIterator __dest) const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3553 | {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3554 | |
| 3555 | private: |
| 3556 | // no copy functions |
| 3557 | seed_seq(const seed_seq&); // = delete; |
| 3558 | void operator=(const seed_seq&); // = delete; |
| 3559 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3560 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3561 | static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3562 | }; |
| 3563 | |
| 3564 | template<class _InputIterator> |
| 3565 | void |
| 3566 | seed_seq::init(_InputIterator __first, _InputIterator __last) |
| 3567 | { |
| 3568 | for (_InputIterator __s = __first; __s != __last; ++__s) |
| 3569 | __v_.push_back(*__s & 0xFFFFFFFF); |
| 3570 | } |
| 3571 | |
| 3572 | template<class _RandomAccessIterator> |
| 3573 | void |
| 3574 | seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) |
| 3575 | { |
| 3576 | if (__first != __last) |
| 3577 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3578 | _VSTD::fill(__first, __last, 0x8b8b8b8b); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3579 | const size_t __n = static_cast<size_t>(__last - __first); |
| 3580 | const size_t __s = __v_.size(); |
| 3581 | const size_t __t = (__n >= 623) ? 11 |
| 3582 | : (__n >= 68) ? 7 |
| 3583 | : (__n >= 39) ? 5 |
| 3584 | : (__n >= 7) ? 3 |
| 3585 | : (__n - 1) / 2; |
| 3586 | const size_t __p = (__n - __t) / 2; |
| 3587 | const size_t __q = __p + __t; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3588 | const size_t __m = _VSTD::max(__s + 1, __n); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3589 | // __k = 0; |
| 3590 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3591 | result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3592 | ^ __first[__n - 1]); |
| 3593 | __first[__p] += __r; |
| 3594 | __r += __s; |
| 3595 | __first[__q] += __r; |
| 3596 | __first[0] = __r; |
| 3597 | } |
| 3598 | for (size_t __k = 1; __k <= __s; ++__k) |
| 3599 | { |
| 3600 | const size_t __kmodn = __k % __n; |
| 3601 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3602 | result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3603 | ^ __first[(__k - 1) % __n]); |
| 3604 | __first[__kpmodn] += __r; |
| 3605 | __r += __kmodn + __v_[__k-1]; |
| 3606 | __first[(__k + __q) % __n] += __r; |
| 3607 | __first[__kmodn] = __r; |
| 3608 | } |
| 3609 | for (size_t __k = __s + 1; __k < __m; ++__k) |
| 3610 | { |
| 3611 | const size_t __kmodn = __k % __n; |
| 3612 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3613 | result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3614 | ^ __first[(__k - 1) % __n]); |
| 3615 | __first[__kpmodn] += __r; |
| 3616 | __r += __kmodn; |
| 3617 | __first[(__k + __q) % __n] += __r; |
| 3618 | __first[__kmodn] = __r; |
| 3619 | } |
| 3620 | for (size_t __k = __m; __k < __m + __n; ++__k) |
| 3621 | { |
| 3622 | const size_t __kmodn = __k % __n; |
| 3623 | const size_t __kpmodn = (__k + __p) % __n; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3624 | result_type __r = 1566083941 * _Tp(__first[__kmodn] + |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3625 | __first[__kpmodn] + |
| 3626 | __first[(__k - 1) % __n]); |
| 3627 | __first[__kpmodn] ^= __r; |
| 3628 | __r -= __kmodn; |
| 3629 | __first[(__k + __q) % __n] ^= __r; |
| 3630 | __first[__kmodn] = __r; |
| 3631 | } |
| 3632 | } |
| 3633 | } |
| 3634 | |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3635 | // generate_canonical |
| 3636 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3637 | template<class _RealType, size_t __bits, class _URNG> |
| 3638 | _RealType |
| 3639 | generate_canonical(_URNG& __g) |
| 3640 | { |
| 3641 | const size_t _Dt = numeric_limits<_RealType>::digits; |
| 3642 | const size_t __b = _Dt < __bits ? _Dt : __bits; |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 3643 | #ifdef _LIBCPP_CXX03_LANG |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3644 | const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3645 | #else |
| 3646 | const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; |
| 3647 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3648 | const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3649 | const _RealType _Rp = _URNG::max() - _URNG::min() + _RealType(1); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3650 | _RealType __base = _Rp; |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3651 | _RealType _Sp = __g() - _URNG::min(); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3652 | for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) |
Howard Hinnant | 8efd3da | 2012-04-02 21:00:45 +0000 | [diff] [blame] | 3653 | _Sp += (__g() - _URNG::min()) * __base; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3654 | return _Sp / __base; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3655 | } |
| 3656 | |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3657 | // uniform_int_distribution |
| 3658 | |
Howard Hinnant | c326721 | 2010-05-26 17:49:34 +0000 | [diff] [blame] | 3659 | // in <algorithm> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3660 | |
| 3661 | template <class _CharT, class _Traits, class _IT> |
| 3662 | basic_ostream<_CharT, _Traits>& |
| 3663 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 3664 | const uniform_int_distribution<_IT>& __x) |
| 3665 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3666 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3667 | __os.flags(ios_base::dec | ios_base::left); |
| 3668 | _CharT __sp = __os.widen(' '); |
| 3669 | __os.fill(__sp); |
| 3670 | return __os << __x.a() << __sp << __x.b(); |
| 3671 | } |
| 3672 | |
| 3673 | template <class _CharT, class _Traits, class _IT> |
| 3674 | basic_istream<_CharT, _Traits>& |
| 3675 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 3676 | uniform_int_distribution<_IT>& __x) |
| 3677 | { |
| 3678 | typedef uniform_int_distribution<_IT> _Eng; |
| 3679 | typedef typename _Eng::result_type result_type; |
| 3680 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3681 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3682 | __is.flags(ios_base::dec | ios_base::skipws); |
| 3683 | result_type __a; |
| 3684 | result_type __b; |
| 3685 | __is >> __a >> __b; |
| 3686 | if (!__is.fail()) |
| 3687 | __x.param(param_type(__a, __b)); |
| 3688 | return __is; |
| 3689 | } |
| 3690 | |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3691 | // uniform_real_distribution |
| 3692 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3693 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3694 | class _LIBCPP_TEMPLATE_VIS uniform_real_distribution |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3695 | { |
| 3696 | public: |
| 3697 | // types |
| 3698 | typedef _RealType result_type; |
| 3699 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3700 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3701 | { |
| 3702 | result_type __a_; |
| 3703 | result_type __b_; |
| 3704 | public: |
| 3705 | typedef uniform_real_distribution distribution_type; |
| 3706 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3707 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3708 | explicit param_type(result_type __a = 0, |
| 3709 | result_type __b = 1) |
| 3710 | : __a_(__a), __b_(__b) {} |
| 3711 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3712 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3713 | result_type a() const {return __a_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3714 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3715 | result_type b() const {return __b_;} |
| 3716 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3717 | friend _LIBCPP_INLINE_VISIBILITY |
| 3718 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3719 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3720 | friend _LIBCPP_INLINE_VISIBILITY |
| 3721 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3722 | {return !(__x == __y);} |
| 3723 | }; |
| 3724 | |
| 3725 | private: |
| 3726 | param_type __p_; |
| 3727 | |
| 3728 | public: |
| 3729 | // constructors and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3730 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3731 | explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) |
| 3732 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3733 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3734 | explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3735 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3736 | void reset() {} |
| 3737 | |
| 3738 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3739 | template<class _URNG> |
| 3740 | _LIBCPP_INLINE_VISIBILITY |
| 3741 | result_type operator()(_URNG& __g) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3742 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3743 | template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3744 | |
| 3745 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3746 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3747 | result_type a() const {return __p_.a();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3748 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3749 | result_type b() const {return __p_.b();} |
| 3750 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3751 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3752 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3753 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3754 | void param(const param_type& __p) {__p_ = __p;} |
| 3755 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3756 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3757 | result_type min() const {return a();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3758 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3759 | result_type max() const {return b();} |
| 3760 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3761 | friend _LIBCPP_INLINE_VISIBILITY |
| 3762 | bool operator==(const uniform_real_distribution& __x, |
| 3763 | const uniform_real_distribution& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3764 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3765 | friend _LIBCPP_INLINE_VISIBILITY |
| 3766 | bool operator!=(const uniform_real_distribution& __x, |
| 3767 | const uniform_real_distribution& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3768 | {return !(__x == __y);} |
| 3769 | }; |
| 3770 | |
| 3771 | template<class _RealType> |
| 3772 | template<class _URNG> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3773 | inline |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3774 | typename uniform_real_distribution<_RealType>::result_type |
| 3775 | uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 3776 | { |
| 3777 | return (__p.b() - __p.a()) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3778 | * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3779 | + __p.a(); |
| 3780 | } |
| 3781 | |
| 3782 | template <class _CharT, class _Traits, class _RT> |
| 3783 | basic_ostream<_CharT, _Traits>& |
| 3784 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 3785 | const uniform_real_distribution<_RT>& __x) |
| 3786 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3787 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 3788 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 3789 | ios_base::scientific); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3790 | _CharT __sp = __os.widen(' '); |
| 3791 | __os.fill(__sp); |
| 3792 | return __os << __x.a() << __sp << __x.b(); |
| 3793 | } |
| 3794 | |
| 3795 | template <class _CharT, class _Traits, class _RT> |
| 3796 | basic_istream<_CharT, _Traits>& |
| 3797 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 3798 | uniform_real_distribution<_RT>& __x) |
| 3799 | { |
| 3800 | typedef uniform_real_distribution<_RT> _Eng; |
| 3801 | typedef typename _Eng::result_type result_type; |
| 3802 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3803 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3804 | __is.flags(ios_base::dec | ios_base::skipws); |
| 3805 | result_type __a; |
| 3806 | result_type __b; |
| 3807 | __is >> __a >> __b; |
| 3808 | if (!__is.fail()) |
| 3809 | __x.param(param_type(__a, __b)); |
| 3810 | return __is; |
| 3811 | } |
| 3812 | |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3813 | // bernoulli_distribution |
| 3814 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3815 | class _LIBCPP_TEMPLATE_VIS bernoulli_distribution |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3816 | { |
| 3817 | public: |
| 3818 | // types |
| 3819 | typedef bool result_type; |
| 3820 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3821 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3822 | { |
| 3823 | double __p_; |
| 3824 | public: |
| 3825 | typedef bernoulli_distribution distribution_type; |
| 3826 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3827 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3828 | explicit param_type(double __p = 0.5) : __p_(__p) {} |
| 3829 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3830 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3831 | double p() const {return __p_;} |
| 3832 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3833 | friend _LIBCPP_INLINE_VISIBILITY |
| 3834 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3835 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3836 | friend _LIBCPP_INLINE_VISIBILITY |
| 3837 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3838 | {return !(__x == __y);} |
| 3839 | }; |
| 3840 | |
| 3841 | private: |
| 3842 | param_type __p_; |
| 3843 | |
| 3844 | public: |
| 3845 | // constructors and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3846 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3847 | explicit bernoulli_distribution(double __p = 0.5) |
| 3848 | : __p_(param_type(__p)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3849 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3850 | explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3851 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3852 | void reset() {} |
| 3853 | |
| 3854 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3855 | template<class _URNG> |
| 3856 | _LIBCPP_INLINE_VISIBILITY |
| 3857 | result_type operator()(_URNG& __g) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3858 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3859 | template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3860 | |
| 3861 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3862 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3863 | double p() const {return __p_.p();} |
| 3864 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3865 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3866 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3867 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3868 | void param(const param_type& __p) {__p_ = __p;} |
| 3869 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3870 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3871 | result_type min() const {return false;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3872 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3873 | result_type max() const {return true;} |
| 3874 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3875 | friend _LIBCPP_INLINE_VISIBILITY |
| 3876 | bool operator==(const bernoulli_distribution& __x, |
| 3877 | const bernoulli_distribution& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3878 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3879 | friend _LIBCPP_INLINE_VISIBILITY |
| 3880 | bool operator!=(const bernoulli_distribution& __x, |
| 3881 | const bernoulli_distribution& __y) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3882 | {return !(__x == __y);} |
| 3883 | }; |
| 3884 | |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3885 | template<class _URNG> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 3886 | inline |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3887 | bernoulli_distribution::result_type |
| 3888 | bernoulli_distribution::operator()(_URNG& __g, const param_type& __p) |
| 3889 | { |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 3890 | uniform_real_distribution<double> __gen; |
| 3891 | return __gen(__g) < __p.p(); |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3892 | } |
| 3893 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3894 | template <class _CharT, class _Traits> |
| 3895 | basic_ostream<_CharT, _Traits>& |
| 3896 | operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) |
| 3897 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3898 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 3899 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 3900 | ios_base::scientific); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3901 | _CharT __sp = __os.widen(' '); |
| 3902 | __os.fill(__sp); |
| 3903 | return __os << __x.p(); |
| 3904 | } |
| 3905 | |
| 3906 | template <class _CharT, class _Traits> |
| 3907 | basic_istream<_CharT, _Traits>& |
| 3908 | operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) |
| 3909 | { |
| 3910 | typedef bernoulli_distribution _Eng; |
| 3911 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 3912 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3913 | __is.flags(ios_base::dec | ios_base::skipws); |
| 3914 | double __p; |
| 3915 | __is >> __p; |
| 3916 | if (!__is.fail()) |
| 3917 | __x.param(param_type(__p)); |
| 3918 | return __is; |
| 3919 | } |
| 3920 | |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 3921 | // binomial_distribution |
| 3922 | |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3923 | template<class _IntType = int> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3924 | class _LIBCPP_TEMPLATE_VIS binomial_distribution |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3925 | { |
| 3926 | public: |
| 3927 | // types |
| 3928 | typedef _IntType result_type; |
| 3929 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 3930 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3931 | { |
| 3932 | result_type __t_; |
| 3933 | double __p_; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3934 | double __pr_; |
| 3935 | double __odds_ratio_; |
| 3936 | result_type __r0_; |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3937 | public: |
| 3938 | typedef binomial_distribution distribution_type; |
| 3939 | |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3940 | explicit param_type(result_type __t = 1, double __p = 0.5); |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3941 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3942 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3943 | result_type t() const {return __t_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3944 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3945 | double p() const {return __p_;} |
| 3946 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3947 | friend _LIBCPP_INLINE_VISIBILITY |
| 3948 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3949 | {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3950 | friend _LIBCPP_INLINE_VISIBILITY |
| 3951 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3952 | {return !(__x == __y);} |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 3953 | |
| 3954 | friend class binomial_distribution; |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3955 | }; |
| 3956 | |
| 3957 | private: |
| 3958 | param_type __p_; |
| 3959 | |
| 3960 | public: |
| 3961 | // constructors and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3962 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3963 | explicit binomial_distribution(result_type __t = 1, double __p = 0.5) |
| 3964 | : __p_(param_type(__t, __p)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3965 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3966 | explicit binomial_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3967 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3968 | void reset() {} |
| 3969 | |
| 3970 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3971 | template<class _URNG> |
| 3972 | _LIBCPP_INLINE_VISIBILITY |
| 3973 | result_type operator()(_URNG& __g) |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3974 | {return (*this)(__g, __p_);} |
| 3975 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 3976 | |
| 3977 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3978 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3979 | result_type t() const {return __p_.t();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3980 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3981 | double p() const {return __p_.p();} |
| 3982 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3983 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3984 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3985 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3986 | void param(const param_type& __p) {__p_ = __p;} |
| 3987 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3988 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3989 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3990 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3991 | result_type max() const {return t();} |
| 3992 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3993 | friend _LIBCPP_INLINE_VISIBILITY |
| 3994 | bool operator==(const binomial_distribution& __x, |
| 3995 | const binomial_distribution& __y) |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 3996 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 3997 | friend _LIBCPP_INLINE_VISIBILITY |
| 3998 | bool operator!=(const binomial_distribution& __x, |
| 3999 | const binomial_distribution& __y) |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4000 | {return !(__x == __y);} |
| 4001 | }; |
| 4002 | |
Eric Fiselier | a9f9f0b | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4003 | #ifndef _LIBCPP_MSVCRT |
Marshall Clow | 3320e88 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4004 | extern "C" double lgamma_r(double, int *); |
Eric Fiselier | a9f9f0b | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4005 | #endif |
| 4006 | |
| 4007 | inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { |
| 4008 | #if defined(_LIBCPP_MSVCRT) |
| 4009 | return lgamma(__d); |
| 4010 | #else |
| 4011 | int __sign; |
| 4012 | return lgamma_r(__d, &__sign); |
| 4013 | #endif |
| 4014 | } |
Marshall Clow | 3320e88 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4015 | |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4016 | template<class _IntType> |
Marshall Clow | 3320e88 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4017 | binomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4018 | : __t_(__t), __p_(__p) |
| 4019 | { |
| 4020 | if (0 < __p_ && __p_ < 1) |
| 4021 | { |
| 4022 | __r0_ = static_cast<result_type>((__t_ + 1) * __p_); |
Eric Fiselier | a9f9f0b | 2017-05-06 02:58:43 +0000 | [diff] [blame] | 4023 | __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - |
| 4024 | __libcpp_lgamma(__r0_ + 1.) - |
| 4025 | __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + |
Marshall Clow | 3320e88 | 2017-05-04 16:36:39 +0000 | [diff] [blame] | 4026 | (__t_ - __r0_) * _VSTD::log(1 - __p_)); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4027 | __odds_ratio_ = __p_ / (1 - __p_); |
| 4028 | } |
| 4029 | } |
| 4030 | |
Marshall Clow | 5ffb8d0 | 2014-09-17 18:33:58 +0000 | [diff] [blame] | 4031 | // Reference: Kemp, C.D. (1986). `A modal method for generating binomial |
| 4032 | // variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4033 | template<class _IntType> |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4034 | template<class _URNG> |
| 4035 | _IntType |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4036 | binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4037 | { |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4038 | if (__pr.__t_ == 0 || __pr.__p_ == 0) |
| 4039 | return 0; |
| 4040 | if (__pr.__p_ == 1) |
| 4041 | return __pr.__t_; |
| 4042 | uniform_real_distribution<double> __gen; |
| 4043 | double __u = __gen(__g) - __pr.__pr_; |
| 4044 | if (__u < 0) |
| 4045 | return __pr.__r0_; |
| 4046 | double __pu = __pr.__pr_; |
| 4047 | double __pd = __pu; |
| 4048 | result_type __ru = __pr.__r0_; |
| 4049 | result_type __rd = __ru; |
| 4050 | while (true) |
| 4051 | { |
| 4052 | if (__rd >= 1) |
| 4053 | { |
| 4054 | __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); |
| 4055 | __u -= __pd; |
| 4056 | if (__u < 0) |
| 4057 | return __rd - 1; |
| 4058 | } |
Marshall Clow | 5ffb8d0 | 2014-09-17 18:33:58 +0000 | [diff] [blame] | 4059 | if ( __rd != 0 ) |
| 4060 | --__rd; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4061 | ++__ru; |
| 4062 | if (__ru <= __pr.__t_) |
| 4063 | { |
| 4064 | __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; |
| 4065 | __u -= __pu; |
| 4066 | if (__u < 0) |
| 4067 | return __ru; |
| 4068 | } |
| 4069 | } |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | template <class _CharT, class _Traits, class _IntType> |
| 4073 | basic_ostream<_CharT, _Traits>& |
| 4074 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4075 | const binomial_distribution<_IntType>& __x) |
| 4076 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4077 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4078 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 4079 | ios_base::scientific); |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4080 | _CharT __sp = __os.widen(' '); |
| 4081 | __os.fill(__sp); |
| 4082 | return __os << __x.t() << __sp << __x.p(); |
| 4083 | } |
| 4084 | |
| 4085 | template <class _CharT, class _Traits, class _IntType> |
| 4086 | basic_istream<_CharT, _Traits>& |
| 4087 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4088 | binomial_distribution<_IntType>& __x) |
| 4089 | { |
| 4090 | typedef binomial_distribution<_IntType> _Eng; |
| 4091 | typedef typename _Eng::result_type result_type; |
| 4092 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4093 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 03aad81 | 2010-05-11 23:26:59 +0000 | [diff] [blame] | 4094 | __is.flags(ios_base::dec | ios_base::skipws); |
| 4095 | result_type __t; |
| 4096 | double __p; |
| 4097 | __is >> __t >> __p; |
| 4098 | if (!__is.fail()) |
| 4099 | __x.param(param_type(__t, __p)); |
| 4100 | return __is; |
| 4101 | } |
| 4102 | |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4103 | // exponential_distribution |
| 4104 | |
| 4105 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4106 | class _LIBCPP_TEMPLATE_VIS exponential_distribution |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4107 | { |
| 4108 | public: |
| 4109 | // types |
| 4110 | typedef _RealType result_type; |
| 4111 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4112 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4113 | { |
| 4114 | result_type __lambda_; |
| 4115 | public: |
| 4116 | typedef exponential_distribution distribution_type; |
| 4117 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4118 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4119 | explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} |
| 4120 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4121 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4122 | result_type lambda() const {return __lambda_;} |
| 4123 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4124 | friend _LIBCPP_INLINE_VISIBILITY |
| 4125 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4126 | {return __x.__lambda_ == __y.__lambda_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4127 | friend _LIBCPP_INLINE_VISIBILITY |
| 4128 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4129 | {return !(__x == __y);} |
| 4130 | }; |
| 4131 | |
| 4132 | private: |
| 4133 | param_type __p_; |
| 4134 | |
| 4135 | public: |
| 4136 | // constructors and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4138 | explicit exponential_distribution(result_type __lambda = 1) |
| 4139 | : __p_(param_type(__lambda)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4140 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4141 | explicit exponential_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4142 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4143 | void reset() {} |
| 4144 | |
| 4145 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4146 | template<class _URNG> |
| 4147 | _LIBCPP_INLINE_VISIBILITY |
| 4148 | result_type operator()(_URNG& __g) |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4149 | {return (*this)(__g, __p_);} |
| 4150 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4151 | |
| 4152 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4153 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4154 | result_type lambda() const {return __p_.lambda();} |
| 4155 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4156 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4157 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4158 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4159 | void param(const param_type& __p) {__p_ = __p;} |
| 4160 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4161 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4162 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4163 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | df40dc6 | 2010-05-16 17:56:20 +0000 | [diff] [blame] | 4164 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4165 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4166 | friend _LIBCPP_INLINE_VISIBILITY |
| 4167 | bool operator==(const exponential_distribution& __x, |
| 4168 | const exponential_distribution& __y) |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4169 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4170 | friend _LIBCPP_INLINE_VISIBILITY |
| 4171 | bool operator!=(const exponential_distribution& __x, |
| 4172 | const exponential_distribution& __y) |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4173 | {return !(__x == __y);} |
| 4174 | }; |
| 4175 | |
| 4176 | template <class _RealType> |
| 4177 | template<class _URNG> |
| 4178 | _RealType |
| 4179 | exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4180 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4181 | return -_VSTD::log |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4182 | ( |
| 4183 | result_type(1) - |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4184 | _VSTD::generate_canonical<result_type, |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4185 | numeric_limits<result_type>::digits>(__g) |
| 4186 | ) |
| 4187 | / __p.lambda(); |
| 4188 | } |
| 4189 | |
| 4190 | template <class _CharT, class _Traits, class _RealType> |
| 4191 | basic_ostream<_CharT, _Traits>& |
| 4192 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4193 | const exponential_distribution<_RealType>& __x) |
| 4194 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4195 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4196 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 4197 | ios_base::scientific); |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4198 | return __os << __x.lambda(); |
| 4199 | } |
| 4200 | |
| 4201 | template <class _CharT, class _Traits, class _RealType> |
| 4202 | basic_istream<_CharT, _Traits>& |
| 4203 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4204 | exponential_distribution<_RealType>& __x) |
| 4205 | { |
| 4206 | typedef exponential_distribution<_RealType> _Eng; |
| 4207 | typedef typename _Eng::result_type result_type; |
| 4208 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4209 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 30a840f | 2010-05-12 17:08:57 +0000 | [diff] [blame] | 4210 | __is.flags(ios_base::dec | ios_base::skipws); |
| 4211 | result_type __lambda; |
| 4212 | __is >> __lambda; |
| 4213 | if (!__is.fail()) |
| 4214 | __x.param(param_type(__lambda)); |
| 4215 | return __is; |
| 4216 | } |
| 4217 | |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4218 | // normal_distribution |
| 4219 | |
| 4220 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4221 | class _LIBCPP_TEMPLATE_VIS normal_distribution |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4222 | { |
| 4223 | public: |
| 4224 | // types |
| 4225 | typedef _RealType result_type; |
| 4226 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4227 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4228 | { |
| 4229 | result_type __mean_; |
| 4230 | result_type __stddev_; |
| 4231 | public: |
| 4232 | typedef normal_distribution distribution_type; |
| 4233 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4234 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4235 | explicit param_type(result_type __mean = 0, result_type __stddev = 1) |
| 4236 | : __mean_(__mean), __stddev_(__stddev) {} |
| 4237 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4238 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4239 | result_type mean() const {return __mean_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4240 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4241 | result_type stddev() const {return __stddev_;} |
| 4242 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4243 | friend _LIBCPP_INLINE_VISIBILITY |
| 4244 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4245 | {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4246 | friend _LIBCPP_INLINE_VISIBILITY |
| 4247 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4248 | {return !(__x == __y);} |
| 4249 | }; |
| 4250 | |
| 4251 | private: |
| 4252 | param_type __p_; |
| 4253 | result_type _V_; |
| 4254 | bool _V_hot_; |
| 4255 | |
| 4256 | public: |
| 4257 | // constructors and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4258 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4259 | explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1) |
| 4260 | : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4261 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4262 | explicit normal_distribution(const param_type& __p) |
| 4263 | : __p_(__p), _V_hot_(false) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4264 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4265 | void reset() {_V_hot_ = false;} |
| 4266 | |
| 4267 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4268 | template<class _URNG> |
| 4269 | _LIBCPP_INLINE_VISIBILITY |
| 4270 | result_type operator()(_URNG& __g) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4271 | {return (*this)(__g, __p_);} |
| 4272 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4273 | |
| 4274 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4275 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4276 | result_type mean() const {return __p_.mean();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4277 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4278 | result_type stddev() const {return __p_.stddev();} |
| 4279 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4280 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4281 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4282 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4283 | void param(const param_type& __p) {__p_ = __p;} |
| 4284 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4285 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4286 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4287 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4288 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4289 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4290 | friend _LIBCPP_INLINE_VISIBILITY |
| 4291 | bool operator==(const normal_distribution& __x, |
| 4292 | const normal_distribution& __y) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4293 | {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && |
| 4294 | (!__x._V_hot_ || __x._V_ == __y._V_);} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4295 | friend _LIBCPP_INLINE_VISIBILITY |
| 4296 | bool operator!=(const normal_distribution& __x, |
| 4297 | const normal_distribution& __y) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4298 | {return !(__x == __y);} |
| 4299 | |
| 4300 | template <class _CharT, class _Traits, class _RT> |
| 4301 | friend |
| 4302 | basic_ostream<_CharT, _Traits>& |
| 4303 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4304 | const normal_distribution<_RT>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4305 | |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4306 | template <class _CharT, class _Traits, class _RT> |
| 4307 | friend |
| 4308 | basic_istream<_CharT, _Traits>& |
| 4309 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4310 | normal_distribution<_RT>& __x); |
| 4311 | }; |
| 4312 | |
| 4313 | template <class _RealType> |
| 4314 | template<class _URNG> |
| 4315 | _RealType |
| 4316 | normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4317 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4318 | result_type _Up; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4319 | if (_V_hot_) |
| 4320 | { |
| 4321 | _V_hot_ = false; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4322 | _Up = _V_; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4323 | } |
| 4324 | else |
| 4325 | { |
| 4326 | uniform_real_distribution<result_type> _Uni(-1, 1); |
| 4327 | result_type __u; |
| 4328 | result_type __v; |
| 4329 | result_type __s; |
| 4330 | do |
| 4331 | { |
| 4332 | __u = _Uni(__g); |
| 4333 | __v = _Uni(__g); |
| 4334 | __s = __u * __u + __v * __v; |
| 4335 | } while (__s > 1 || __s == 0); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4336 | result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); |
| 4337 | _V_ = __v * _Fp; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4338 | _V_hot_ = true; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4339 | _Up = __u * _Fp; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4340 | } |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4341 | return _Up * __p.stddev() + __p.mean(); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | template <class _CharT, class _Traits, class _RT> |
| 4345 | basic_ostream<_CharT, _Traits>& |
| 4346 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4347 | const normal_distribution<_RT>& __x) |
| 4348 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4349 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4350 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 4351 | ios_base::scientific); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4352 | _CharT __sp = __os.widen(' '); |
| 4353 | __os.fill(__sp); |
| 4354 | __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; |
| 4355 | if (__x._V_hot_) |
| 4356 | __os << __sp << __x._V_; |
| 4357 | return __os; |
| 4358 | } |
| 4359 | |
| 4360 | template <class _CharT, class _Traits, class _RT> |
| 4361 | basic_istream<_CharT, _Traits>& |
| 4362 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4363 | normal_distribution<_RT>& __x) |
| 4364 | { |
| 4365 | typedef normal_distribution<_RT> _Eng; |
| 4366 | typedef typename _Eng::result_type result_type; |
| 4367 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4368 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4369 | __is.flags(ios_base::dec | ios_base::skipws); |
| 4370 | result_type __mean; |
| 4371 | result_type __stddev; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4372 | result_type _Vp = 0; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4373 | bool _V_hot = false; |
| 4374 | __is >> __mean >> __stddev >> _V_hot; |
| 4375 | if (_V_hot) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4376 | __is >> _Vp; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4377 | if (!__is.fail()) |
| 4378 | { |
| 4379 | __x.param(param_type(__mean, __stddev)); |
| 4380 | __x._V_hot_ = _V_hot; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 4381 | __x._V_ = _Vp; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4382 | } |
| 4383 | return __is; |
| 4384 | } |
| 4385 | |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4386 | // lognormal_distribution |
| 4387 | |
| 4388 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4389 | class _LIBCPP_TEMPLATE_VIS lognormal_distribution |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4390 | { |
| 4391 | public: |
| 4392 | // types |
| 4393 | typedef _RealType result_type; |
| 4394 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4395 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4396 | { |
| 4397 | normal_distribution<result_type> __nd_; |
| 4398 | public: |
| 4399 | typedef lognormal_distribution distribution_type; |
| 4400 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4401 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4402 | explicit param_type(result_type __m = 0, result_type __s = 1) |
| 4403 | : __nd_(__m, __s) {} |
| 4404 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4405 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4406 | result_type m() const {return __nd_.mean();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4407 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4408 | result_type s() const {return __nd_.stddev();} |
| 4409 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4410 | friend _LIBCPP_INLINE_VISIBILITY |
| 4411 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4412 | {return __x.__nd_ == __y.__nd_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4413 | friend _LIBCPP_INLINE_VISIBILITY |
| 4414 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4415 | {return !(__x == __y);} |
| 4416 | friend class lognormal_distribution; |
| 4417 | |
| 4418 | template <class _CharT, class _Traits, class _RT> |
| 4419 | friend |
| 4420 | basic_ostream<_CharT, _Traits>& |
| 4421 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4422 | const lognormal_distribution<_RT>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4423 | |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4424 | template <class _CharT, class _Traits, class _RT> |
| 4425 | friend |
| 4426 | basic_istream<_CharT, _Traits>& |
| 4427 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4428 | lognormal_distribution<_RT>& __x); |
| 4429 | }; |
| 4430 | |
| 4431 | private: |
| 4432 | param_type __p_; |
| 4433 | |
| 4434 | public: |
| 4435 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4436 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4437 | explicit lognormal_distribution(result_type __m = 0, result_type __s = 1) |
| 4438 | : __p_(param_type(__m, __s)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4439 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4440 | explicit lognormal_distribution(const param_type& __p) |
| 4441 | : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4442 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4443 | void reset() {__p_.__nd_.reset();} |
| 4444 | |
| 4445 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4446 | template<class _URNG> |
| 4447 | _LIBCPP_INLINE_VISIBILITY |
| 4448 | result_type operator()(_URNG& __g) |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4449 | {return (*this)(__g, __p_);} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4450 | template<class _URNG> |
| 4451 | _LIBCPP_INLINE_VISIBILITY |
| 4452 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4453 | {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4454 | |
| 4455 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4456 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4457 | result_type m() const {return __p_.m();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4458 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4459 | result_type s() const {return __p_.s();} |
| 4460 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4461 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4462 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4463 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 4464 | void param(const param_type& __p) {__p_ = __p;} |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4465 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4466 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4467 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4468 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4469 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4470 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4471 | friend _LIBCPP_INLINE_VISIBILITY |
| 4472 | bool operator==(const lognormal_distribution& __x, |
| 4473 | const lognormal_distribution& __y) |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4474 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4475 | friend _LIBCPP_INLINE_VISIBILITY |
| 4476 | bool operator!=(const lognormal_distribution& __x, |
| 4477 | const lognormal_distribution& __y) |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4478 | {return !(__x == __y);} |
| 4479 | |
| 4480 | template <class _CharT, class _Traits, class _RT> |
| 4481 | friend |
| 4482 | basic_ostream<_CharT, _Traits>& |
| 4483 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4484 | const lognormal_distribution<_RT>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 4485 | |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4486 | template <class _CharT, class _Traits, class _RT> |
| 4487 | friend |
| 4488 | basic_istream<_CharT, _Traits>& |
| 4489 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4490 | lognormal_distribution<_RT>& __x); |
| 4491 | }; |
| 4492 | |
| 4493 | template <class _CharT, class _Traits, class _RT> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4494 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4495 | basic_ostream<_CharT, _Traits>& |
| 4496 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4497 | const lognormal_distribution<_RT>& __x) |
| 4498 | { |
| 4499 | return __os << __x.__p_.__nd_; |
| 4500 | } |
| 4501 | |
| 4502 | template <class _CharT, class _Traits, class _RT> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4503 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bc36fc | 2010-05-17 18:31:53 +0000 | [diff] [blame] | 4504 | basic_istream<_CharT, _Traits>& |
| 4505 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4506 | lognormal_distribution<_RT>& __x) |
| 4507 | { |
| 4508 | return __is >> __x.__p_.__nd_; |
| 4509 | } |
| 4510 | |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4511 | // poisson_distribution |
| 4512 | |
| 4513 | template<class _IntType = int> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4514 | class _LIBCPP_TEMPLATE_VIS poisson_distribution |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4515 | { |
| 4516 | public: |
| 4517 | // types |
| 4518 | typedef _IntType result_type; |
| 4519 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4520 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4521 | { |
| 4522 | double __mean_; |
| 4523 | double __s_; |
| 4524 | double __d_; |
| 4525 | double __l_; |
| 4526 | double __omega_; |
| 4527 | double __c0_; |
| 4528 | double __c1_; |
| 4529 | double __c2_; |
| 4530 | double __c3_; |
| 4531 | double __c_; |
| 4532 | |
| 4533 | public: |
| 4534 | typedef poisson_distribution distribution_type; |
| 4535 | |
| 4536 | explicit param_type(double __mean = 1.0); |
| 4537 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4538 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4539 | double mean() const {return __mean_;} |
| 4540 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4541 | friend _LIBCPP_INLINE_VISIBILITY |
| 4542 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4543 | {return __x.__mean_ == __y.__mean_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4544 | friend _LIBCPP_INLINE_VISIBILITY |
| 4545 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4546 | {return !(__x == __y);} |
| 4547 | |
| 4548 | friend class poisson_distribution; |
| 4549 | }; |
| 4550 | |
| 4551 | private: |
| 4552 | param_type __p_; |
| 4553 | |
| 4554 | public: |
| 4555 | // constructors and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4556 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4557 | explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4558 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4559 | explicit poisson_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4560 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4561 | void reset() {} |
| 4562 | |
| 4563 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4564 | template<class _URNG> |
| 4565 | _LIBCPP_INLINE_VISIBILITY |
| 4566 | result_type operator()(_URNG& __g) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4567 | {return (*this)(__g, __p_);} |
| 4568 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4569 | |
| 4570 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4571 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4572 | double mean() const {return __p_.mean();} |
| 4573 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4574 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4575 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4577 | void param(const param_type& __p) {__p_ = __p;} |
| 4578 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4579 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4580 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4581 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4582 | result_type max() const {return numeric_limits<result_type>::max();} |
| 4583 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4584 | friend _LIBCPP_INLINE_VISIBILITY |
| 4585 | bool operator==(const poisson_distribution& __x, |
| 4586 | const poisson_distribution& __y) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4587 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4588 | friend _LIBCPP_INLINE_VISIBILITY |
| 4589 | bool operator!=(const poisson_distribution& __x, |
| 4590 | const poisson_distribution& __y) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4591 | {return !(__x == __y);} |
| 4592 | }; |
| 4593 | |
| 4594 | template<class _IntType> |
| 4595 | poisson_distribution<_IntType>::param_type::param_type(double __mean) |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4596 | // According to the standard `inf` is a valid input, but it causes the |
| 4597 | // distribution to hang, so we replace it with the maximum representable |
| 4598 | // mean. |
| 4599 | : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4600 | { |
| 4601 | if (__mean_ < 10) |
| 4602 | { |
| 4603 | __s_ = 0; |
| 4604 | __d_ = 0; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4605 | __l_ = _VSTD::exp(-__mean_); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4606 | __omega_ = 0; |
| 4607 | __c3_ = 0; |
| 4608 | __c2_ = 0; |
| 4609 | __c1_ = 0; |
| 4610 | __c0_ = 0; |
| 4611 | __c_ = 0; |
| 4612 | } |
| 4613 | else |
| 4614 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4615 | __s_ = _VSTD::sqrt(__mean_); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4616 | __d_ = 6 * __mean_ * __mean_; |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4617 | __l_ = std::trunc(__mean_ - 1.1484); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4618 | __omega_ = .3989423 / __s_; |
| 4619 | double __b1_ = .4166667E-1 / __mean_; |
| 4620 | double __b2_ = .3 * __b1_ * __b1_; |
| 4621 | __c3_ = .1428571 * __b1_ * __b2_; |
| 4622 | __c2_ = __b2_ - 15. * __c3_; |
| 4623 | __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; |
| 4624 | __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; |
| 4625 | __c_ = .1069 / __mean_; |
| 4626 | } |
| 4627 | } |
| 4628 | |
| 4629 | template <class _IntType> |
| 4630 | template<class _URNG> |
| 4631 | _IntType |
| 4632 | poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) |
| 4633 | { |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4634 | double __tx; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4635 | uniform_real_distribution<double> __urd; |
Howard Hinnant | 75f7695 | 2011-04-14 15:59:22 +0000 | [diff] [blame] | 4636 | if (__pr.__mean_ < 10) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4637 | { |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4638 | __tx = 0; |
| 4639 | for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4640 | __p *= __urd(__urng); |
| 4641 | } |
| 4642 | else |
| 4643 | { |
| 4644 | double __difmuk; |
| 4645 | double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); |
| 4646 | double __u; |
| 4647 | if (__g > 0) |
| 4648 | { |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4649 | __tx = std::trunc(__g); |
| 4650 | if (__tx >= __pr.__l_) |
| 4651 | return std::__clamp_to_integral<result_type>(__tx); |
| 4652 | __difmuk = __pr.__mean_ - __tx; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4653 | __u = __urd(__urng); |
| 4654 | if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4655 | return std::__clamp_to_integral<result_type>(__tx); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4656 | } |
| 4657 | exponential_distribution<double> __edist; |
| 4658 | for (bool __using_exp_dist = false; true; __using_exp_dist = true) |
| 4659 | { |
| 4660 | double __e; |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4661 | if (__using_exp_dist || __g <= 0) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4662 | { |
| 4663 | double __t; |
| 4664 | do |
| 4665 | { |
| 4666 | __e = __edist(__urng); |
| 4667 | __u = __urd(__urng); |
| 4668 | __u += __u - 1; |
| 4669 | __t = 1.8 + (__u < 0 ? -__e : __e); |
| 4670 | } while (__t <= -.6744); |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4671 | __tx = std::trunc(__pr.__mean_ + __pr.__s_ * __t); |
| 4672 | __difmuk = __pr.__mean_ - __tx; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4673 | __using_exp_dist = true; |
| 4674 | } |
| 4675 | double __px; |
| 4676 | double __py; |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4677 | if (__tx < 10 && __tx >= 0) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4678 | { |
Marshall Clow | 661dff0 | 2018-01-16 14:54:36 +0000 | [diff] [blame] | 4679 | const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4680 | 40320, 362880}; |
| 4681 | __px = -__pr.__mean_; |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4682 | __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)]; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4683 | } |
| 4684 | else |
| 4685 | { |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4686 | double __del = .8333333E-1 / __tx; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4687 | __del -= 4.8 * __del * __del * __del; |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4688 | double __v = __difmuk / __tx; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4689 | if (_VSTD::abs(__v) > 0.25) |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4690 | __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del; |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4691 | else |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4692 | __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) * |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4693 | __v + .1421878) * __v + -.1661269) * __v + .2000118) * |
| 4694 | __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4695 | __py = .3989423 / _VSTD::sqrt(__tx); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4696 | } |
| 4697 | double __r = (0.5 - __difmuk) / __pr.__s_; |
| 4698 | double __r2 = __r * __r; |
| 4699 | double __fx = -0.5 * __r2; |
| 4700 | double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * |
| 4701 | __r2 + __pr.__c1_) * __r2 + __pr.__c0_); |
| 4702 | if (__using_exp_dist) |
| 4703 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4704 | if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - |
| 4705 | __fy * _VSTD::exp(__fx + __e)) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4706 | break; |
| 4707 | } |
| 4708 | else |
| 4709 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4710 | if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4711 | break; |
| 4712 | } |
| 4713 | } |
| 4714 | } |
Dan Albert | 819e813 | 2019-09-10 21:52:53 -0700 | [diff] [blame] | 4715 | return std::__clamp_to_integral<result_type>(__tx); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | template <class _CharT, class _Traits, class _IntType> |
| 4719 | basic_ostream<_CharT, _Traits>& |
| 4720 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4721 | const poisson_distribution<_IntType>& __x) |
| 4722 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4723 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4724 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 4725 | ios_base::scientific); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4726 | return __os << __x.mean(); |
| 4727 | } |
| 4728 | |
| 4729 | template <class _CharT, class _Traits, class _IntType> |
| 4730 | basic_istream<_CharT, _Traits>& |
| 4731 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4732 | poisson_distribution<_IntType>& __x) |
| 4733 | { |
| 4734 | typedef poisson_distribution<_IntType> _Eng; |
| 4735 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4736 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 6add8dd | 2010-05-15 21:36:23 +0000 | [diff] [blame] | 4737 | __is.flags(ios_base::dec | ios_base::skipws); |
| 4738 | double __mean; |
| 4739 | __is >> __mean; |
| 4740 | if (!__is.fail()) |
| 4741 | __x.param(param_type(__mean)); |
| 4742 | return __is; |
| 4743 | } |
| 4744 | |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4745 | // weibull_distribution |
| 4746 | |
| 4747 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4748 | class _LIBCPP_TEMPLATE_VIS weibull_distribution |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4749 | { |
| 4750 | public: |
| 4751 | // types |
| 4752 | typedef _RealType result_type; |
| 4753 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4754 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4755 | { |
| 4756 | result_type __a_; |
| 4757 | result_type __b_; |
| 4758 | public: |
| 4759 | typedef weibull_distribution distribution_type; |
| 4760 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4761 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4762 | explicit param_type(result_type __a = 1, result_type __b = 1) |
| 4763 | : __a_(__a), __b_(__b) {} |
| 4764 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4765 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4766 | result_type a() const {return __a_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4767 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4768 | result_type b() const {return __b_;} |
| 4769 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4770 | friend _LIBCPP_INLINE_VISIBILITY |
| 4771 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4772 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4773 | friend _LIBCPP_INLINE_VISIBILITY |
| 4774 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4775 | {return !(__x == __y);} |
| 4776 | }; |
| 4777 | |
| 4778 | private: |
| 4779 | param_type __p_; |
| 4780 | |
| 4781 | public: |
| 4782 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4784 | explicit weibull_distribution(result_type __a = 1, result_type __b = 1) |
| 4785 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4786 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4787 | explicit weibull_distribution(const param_type& __p) |
| 4788 | : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4789 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4790 | void reset() {} |
| 4791 | |
| 4792 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4793 | template<class _URNG> |
| 4794 | _LIBCPP_INLINE_VISIBILITY |
| 4795 | result_type operator()(_URNG& __g) |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4796 | {return (*this)(__g, __p_);} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4797 | template<class _URNG> |
| 4798 | _LIBCPP_INLINE_VISIBILITY |
| 4799 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4800 | {return __p.b() * |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4801 | _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4802 | |
| 4803 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4804 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4805 | result_type a() const {return __p_.a();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4806 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4807 | result_type b() const {return __p_.b();} |
| 4808 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4809 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4810 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4811 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4812 | void param(const param_type& __p) {__p_ = __p;} |
| 4813 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4814 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4815 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4816 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4817 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4818 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4819 | friend _LIBCPP_INLINE_VISIBILITY |
| 4820 | bool operator==(const weibull_distribution& __x, |
| 4821 | const weibull_distribution& __y) |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4822 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4823 | friend _LIBCPP_INLINE_VISIBILITY |
| 4824 | bool operator!=(const weibull_distribution& __x, |
| 4825 | const weibull_distribution& __y) |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4826 | {return !(__x == __y);} |
| 4827 | }; |
| 4828 | |
| 4829 | template <class _CharT, class _Traits, class _RT> |
| 4830 | basic_ostream<_CharT, _Traits>& |
| 4831 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4832 | const weibull_distribution<_RT>& __x) |
| 4833 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4834 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4835 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 4836 | ios_base::scientific); |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4837 | _CharT __sp = __os.widen(' '); |
| 4838 | __os.fill(__sp); |
| 4839 | __os << __x.a() << __sp << __x.b(); |
| 4840 | return __os; |
| 4841 | } |
| 4842 | |
| 4843 | template <class _CharT, class _Traits, class _RT> |
| 4844 | basic_istream<_CharT, _Traits>& |
| 4845 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4846 | weibull_distribution<_RT>& __x) |
| 4847 | { |
| 4848 | typedef weibull_distribution<_RT> _Eng; |
| 4849 | typedef typename _Eng::result_type result_type; |
| 4850 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4851 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 9de6e30 | 2010-05-16 01:09:02 +0000 | [diff] [blame] | 4852 | __is.flags(ios_base::dec | ios_base::skipws); |
| 4853 | result_type __a; |
| 4854 | result_type __b; |
| 4855 | __is >> __a >> __b; |
| 4856 | if (!__is.fail()) |
| 4857 | __x.param(param_type(__a, __b)); |
| 4858 | return __is; |
| 4859 | } |
| 4860 | |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4861 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4862 | class _LIBCPP_TEMPLATE_VIS extreme_value_distribution |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4863 | { |
| 4864 | public: |
| 4865 | // types |
| 4866 | typedef _RealType result_type; |
| 4867 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4868 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4869 | { |
| 4870 | result_type __a_; |
| 4871 | result_type __b_; |
| 4872 | public: |
| 4873 | typedef extreme_value_distribution distribution_type; |
| 4874 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4875 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4876 | explicit param_type(result_type __a = 0, result_type __b = 1) |
| 4877 | : __a_(__a), __b_(__b) {} |
| 4878 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4879 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4880 | result_type a() const {return __a_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4881 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4882 | result_type b() const {return __b_;} |
| 4883 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4884 | friend _LIBCPP_INLINE_VISIBILITY |
| 4885 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4886 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4887 | friend _LIBCPP_INLINE_VISIBILITY |
| 4888 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4889 | {return !(__x == __y);} |
| 4890 | }; |
| 4891 | |
| 4892 | private: |
| 4893 | param_type __p_; |
| 4894 | |
| 4895 | public: |
| 4896 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4897 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4898 | explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1) |
| 4899 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4900 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4901 | explicit extreme_value_distribution(const param_type& __p) |
| 4902 | : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4903 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4904 | void reset() {} |
| 4905 | |
| 4906 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4907 | template<class _URNG> |
| 4908 | _LIBCPP_INLINE_VISIBILITY |
| 4909 | result_type operator()(_URNG& __g) |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4910 | {return (*this)(__g, __p_);} |
| 4911 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 4912 | |
| 4913 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4914 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4915 | result_type a() const {return __p_.a();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4916 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4917 | result_type b() const {return __p_.b();} |
| 4918 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4919 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4920 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4921 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4922 | void param(const param_type& __p) {__p_ = __p;} |
| 4923 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4924 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4925 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4926 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4927 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 4928 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4929 | friend _LIBCPP_INLINE_VISIBILITY |
| 4930 | bool operator==(const extreme_value_distribution& __x, |
| 4931 | const extreme_value_distribution& __y) |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4932 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4933 | friend _LIBCPP_INLINE_VISIBILITY |
| 4934 | bool operator!=(const extreme_value_distribution& __x, |
| 4935 | const extreme_value_distribution& __y) |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4936 | {return !(__x == __y);} |
| 4937 | }; |
| 4938 | |
| 4939 | template<class _RealType> |
| 4940 | template<class _URNG> |
| 4941 | _RealType |
| 4942 | extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 4943 | { |
| 4944 | return __p.a() - __p.b() * |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4945 | _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4946 | } |
| 4947 | |
| 4948 | template <class _CharT, class _Traits, class _RT> |
| 4949 | basic_ostream<_CharT, _Traits>& |
| 4950 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4951 | const extreme_value_distribution<_RT>& __x) |
| 4952 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4953 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 4954 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 4955 | ios_base::scientific); |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4956 | _CharT __sp = __os.widen(' '); |
| 4957 | __os.fill(__sp); |
| 4958 | __os << __x.a() << __sp << __x.b(); |
| 4959 | return __os; |
| 4960 | } |
| 4961 | |
| 4962 | template <class _CharT, class _Traits, class _RT> |
| 4963 | basic_istream<_CharT, _Traits>& |
| 4964 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4965 | extreme_value_distribution<_RT>& __x) |
| 4966 | { |
| 4967 | typedef extreme_value_distribution<_RT> _Eng; |
| 4968 | typedef typename _Eng::result_type result_type; |
| 4969 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 4970 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | c2b0dc7 | 2010-05-17 16:21:56 +0000 | [diff] [blame] | 4971 | __is.flags(ios_base::dec | ios_base::skipws); |
| 4972 | result_type __a; |
| 4973 | result_type __b; |
| 4974 | __is >> __a >> __b; |
| 4975 | if (!__is.fail()) |
| 4976 | __x.param(param_type(__a, __b)); |
| 4977 | return __is; |
| 4978 | } |
| 4979 | |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4980 | // gamma_distribution |
| 4981 | |
| 4982 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4983 | class _LIBCPP_TEMPLATE_VIS gamma_distribution |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4984 | { |
| 4985 | public: |
| 4986 | // types |
| 4987 | typedef _RealType result_type; |
| 4988 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 4989 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4990 | { |
| 4991 | result_type __alpha_; |
| 4992 | result_type __beta_; |
| 4993 | public: |
| 4994 | typedef gamma_distribution distribution_type; |
| 4995 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 4996 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 4997 | explicit param_type(result_type __alpha = 1, result_type __beta = 1) |
| 4998 | : __alpha_(__alpha), __beta_(__beta) {} |
| 4999 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5000 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5001 | result_type alpha() const {return __alpha_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5002 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5003 | result_type beta() const {return __beta_;} |
| 5004 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5005 | friend _LIBCPP_INLINE_VISIBILITY |
| 5006 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5007 | {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5008 | friend _LIBCPP_INLINE_VISIBILITY |
| 5009 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5010 | {return !(__x == __y);} |
| 5011 | }; |
| 5012 | |
| 5013 | private: |
| 5014 | param_type __p_; |
| 5015 | |
| 5016 | public: |
| 5017 | // constructors and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5018 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5019 | explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1) |
| 5020 | : __p_(param_type(__alpha, __beta)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5021 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5022 | explicit gamma_distribution(const param_type& __p) |
| 5023 | : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5024 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5025 | void reset() {} |
| 5026 | |
| 5027 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5028 | template<class _URNG> |
| 5029 | _LIBCPP_INLINE_VISIBILITY |
| 5030 | result_type operator()(_URNG& __g) |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5031 | {return (*this)(__g, __p_);} |
| 5032 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5033 | |
| 5034 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5035 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5036 | result_type alpha() const {return __p_.alpha();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5037 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5038 | result_type beta() const {return __p_.beta();} |
| 5039 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5040 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5041 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5042 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5043 | void param(const param_type& __p) {__p_ = __p;} |
| 5044 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5045 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5046 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5047 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5048 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5049 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5050 | friend _LIBCPP_INLINE_VISIBILITY |
| 5051 | bool operator==(const gamma_distribution& __x, |
| 5052 | const gamma_distribution& __y) |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5053 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5054 | friend _LIBCPP_INLINE_VISIBILITY |
| 5055 | bool operator!=(const gamma_distribution& __x, |
| 5056 | const gamma_distribution& __y) |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5057 | {return !(__x == __y);} |
| 5058 | }; |
| 5059 | |
| 5060 | template <class _RealType> |
| 5061 | template<class _URNG> |
| 5062 | _RealType |
| 5063 | gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5064 | { |
Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5065 | result_type __a = __p.alpha(); |
| 5066 | uniform_real_distribution<result_type> __gen(0, 1); |
| 5067 | exponential_distribution<result_type> __egen; |
| 5068 | result_type __x; |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5069 | if (__a == 1) |
Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5070 | __x = __egen(__g); |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5071 | else if (__a > 1) |
| 5072 | { |
| 5073 | const result_type __b = __a - 1; |
| 5074 | const result_type __c = 3 * __a - result_type(0.75); |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5075 | while (true) |
| 5076 | { |
| 5077 | const result_type __u = __gen(__g); |
| 5078 | const result_type __v = __gen(__g); |
| 5079 | const result_type __w = __u * (1 - __u); |
Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5080 | if (__w != 0) |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5081 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5082 | const result_type __y = _VSTD::sqrt(__c / __w) * |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5083 | (__u - result_type(0.5)); |
| 5084 | __x = __b + __y; |
| 5085 | if (__x >= 0) |
| 5086 | { |
| 5087 | const result_type __z = 64 * __w * __w * __w * __v * __v; |
| 5088 | if (__z <= 1 - 2 * __y * __y / __x) |
| 5089 | break; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5090 | if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5091 | break; |
| 5092 | } |
| 5093 | } |
| 5094 | } |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5095 | } |
Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5096 | else // __a < 1 |
| 5097 | { |
| 5098 | while (true) |
| 5099 | { |
| 5100 | const result_type __u = __gen(__g); |
| 5101 | const result_type __es = __egen(__g); |
| 5102 | if (__u <= 1 - __a) |
| 5103 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5104 | __x = _VSTD::pow(__u, 1 / __a); |
Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5105 | if (__x <= __es) |
| 5106 | break; |
| 5107 | } |
| 5108 | else |
| 5109 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5110 | const result_type __e = -_VSTD::log((1-__u)/__a); |
| 5111 | __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); |
Howard Hinnant | f417abe | 2010-05-14 18:43:10 +0000 | [diff] [blame] | 5112 | if (__x <= __e + __es) |
| 5113 | break; |
| 5114 | } |
| 5115 | } |
| 5116 | } |
| 5117 | return __x * __p.beta(); |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5118 | } |
| 5119 | |
| 5120 | template <class _CharT, class _Traits, class _RT> |
| 5121 | basic_ostream<_CharT, _Traits>& |
| 5122 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5123 | const gamma_distribution<_RT>& __x) |
| 5124 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5125 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5126 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 5127 | ios_base::scientific); |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5128 | _CharT __sp = __os.widen(' '); |
| 5129 | __os.fill(__sp); |
| 5130 | __os << __x.alpha() << __sp << __x.beta(); |
| 5131 | return __os; |
| 5132 | } |
| 5133 | |
| 5134 | template <class _CharT, class _Traits, class _RT> |
| 5135 | basic_istream<_CharT, _Traits>& |
| 5136 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5137 | gamma_distribution<_RT>& __x) |
| 5138 | { |
| 5139 | typedef gamma_distribution<_RT> _Eng; |
| 5140 | typedef typename _Eng::result_type result_type; |
| 5141 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5142 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | c7c4913 | 2010-05-13 17:58:28 +0000 | [diff] [blame] | 5143 | __is.flags(ios_base::dec | ios_base::skipws); |
| 5144 | result_type __alpha; |
| 5145 | result_type __beta; |
| 5146 | __is >> __alpha >> __beta; |
| 5147 | if (!__is.fail()) |
| 5148 | __x.param(param_type(__alpha, __beta)); |
| 5149 | return __is; |
| 5150 | } |
Howard Hinnant | a64111c | 2010-05-12 21:02:31 +0000 | [diff] [blame] | 5151 | |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5152 | // negative_binomial_distribution |
| 5153 | |
| 5154 | template<class _IntType = int> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5155 | class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5156 | { |
| 5157 | public: |
| 5158 | // types |
| 5159 | typedef _IntType result_type; |
| 5160 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5161 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5162 | { |
| 5163 | result_type __k_; |
| 5164 | double __p_; |
| 5165 | public: |
| 5166 | typedef negative_binomial_distribution distribution_type; |
| 5167 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5168 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5169 | explicit param_type(result_type __k = 1, double __p = 0.5) |
| 5170 | : __k_(__k), __p_(__p) {} |
| 5171 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5172 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5173 | result_type k() const {return __k_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5174 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5175 | double p() const {return __p_;} |
| 5176 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5177 | friend _LIBCPP_INLINE_VISIBILITY |
| 5178 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5179 | {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5180 | friend _LIBCPP_INLINE_VISIBILITY |
| 5181 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5182 | {return !(__x == __y);} |
| 5183 | }; |
| 5184 | |
| 5185 | private: |
| 5186 | param_type __p_; |
| 5187 | |
| 5188 | public: |
| 5189 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5190 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5191 | explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5) |
| 5192 | : __p_(__k, __p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5193 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5194 | explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5195 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5196 | void reset() {} |
| 5197 | |
| 5198 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5199 | template<class _URNG> |
| 5200 | _LIBCPP_INLINE_VISIBILITY |
| 5201 | result_type operator()(_URNG& __g) |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5202 | {return (*this)(__g, __p_);} |
| 5203 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5204 | |
| 5205 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5206 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5207 | result_type k() const {return __p_.k();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5208 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5209 | double p() const {return __p_.p();} |
| 5210 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5211 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5212 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5213 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5214 | void param(const param_type& __p) {__p_ = __p;} |
| 5215 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5216 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5217 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5218 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5219 | result_type max() const {return numeric_limits<result_type>::max();} |
| 5220 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5221 | friend _LIBCPP_INLINE_VISIBILITY |
| 5222 | bool operator==(const negative_binomial_distribution& __x, |
| 5223 | const negative_binomial_distribution& __y) |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5224 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5225 | friend _LIBCPP_INLINE_VISIBILITY |
| 5226 | bool operator!=(const negative_binomial_distribution& __x, |
| 5227 | const negative_binomial_distribution& __y) |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5228 | {return !(__x == __y);} |
| 5229 | }; |
| 5230 | |
| 5231 | template <class _IntType> |
| 5232 | template<class _URNG> |
| 5233 | _IntType |
| 5234 | negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) |
| 5235 | { |
| 5236 | result_type __k = __pr.k(); |
| 5237 | double __p = __pr.p(); |
| 5238 | if (__k <= 21 * __p) |
| 5239 | { |
| 5240 | bernoulli_distribution __gen(__p); |
| 5241 | result_type __f = 0; |
| 5242 | result_type __s = 0; |
| 5243 | while (__s < __k) |
| 5244 | { |
| 5245 | if (__gen(__urng)) |
| 5246 | ++__s; |
| 5247 | else |
| 5248 | ++__f; |
| 5249 | } |
| 5250 | return __f; |
| 5251 | } |
| 5252 | return poisson_distribution<result_type>(gamma_distribution<double> |
| 5253 | (__k, (1-__p)/__p)(__urng))(__urng); |
| 5254 | } |
| 5255 | |
| 5256 | template <class _CharT, class _Traits, class _IntType> |
| 5257 | basic_ostream<_CharT, _Traits>& |
| 5258 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5259 | const negative_binomial_distribution<_IntType>& __x) |
| 5260 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5261 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5262 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 5263 | ios_base::scientific); |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5264 | _CharT __sp = __os.widen(' '); |
| 5265 | __os.fill(__sp); |
| 5266 | return __os << __x.k() << __sp << __x.p(); |
| 5267 | } |
| 5268 | |
| 5269 | template <class _CharT, class _Traits, class _IntType> |
| 5270 | basic_istream<_CharT, _Traits>& |
| 5271 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5272 | negative_binomial_distribution<_IntType>& __x) |
| 5273 | { |
| 5274 | typedef negative_binomial_distribution<_IntType> _Eng; |
| 5275 | typedef typename _Eng::result_type result_type; |
| 5276 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5277 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | f2fe5d5 | 2010-05-17 00:09:38 +0000 | [diff] [blame] | 5278 | __is.flags(ios_base::dec | ios_base::skipws); |
| 5279 | result_type __k; |
| 5280 | double __p; |
| 5281 | __is >> __k >> __p; |
| 5282 | if (!__is.fail()) |
| 5283 | __x.param(param_type(__k, __p)); |
| 5284 | return __is; |
| 5285 | } |
| 5286 | |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5287 | // geometric_distribution |
| 5288 | |
| 5289 | template<class _IntType = int> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5290 | class _LIBCPP_TEMPLATE_VIS geometric_distribution |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5291 | { |
| 5292 | public: |
| 5293 | // types |
| 5294 | typedef _IntType result_type; |
| 5295 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5296 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5297 | { |
| 5298 | double __p_; |
| 5299 | public: |
| 5300 | typedef geometric_distribution distribution_type; |
| 5301 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5302 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5303 | explicit param_type(double __p = 0.5) : __p_(__p) {} |
| 5304 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5306 | double p() const {return __p_;} |
| 5307 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5308 | friend _LIBCPP_INLINE_VISIBILITY |
| 5309 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5310 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5311 | friend _LIBCPP_INLINE_VISIBILITY |
| 5312 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5313 | {return !(__x == __y);} |
| 5314 | }; |
| 5315 | |
| 5316 | private: |
| 5317 | param_type __p_; |
| 5318 | |
| 5319 | public: |
| 5320 | // constructors and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5321 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5322 | explicit geometric_distribution(double __p = 0.5) : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5323 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5324 | explicit geometric_distribution(const param_type& __p) : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5325 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5326 | void reset() {} |
| 5327 | |
| 5328 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5329 | template<class _URNG> |
| 5330 | _LIBCPP_INLINE_VISIBILITY |
| 5331 | result_type operator()(_URNG& __g) |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5332 | {return (*this)(__g, __p_);} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5333 | template<class _URNG> |
| 5334 | _LIBCPP_INLINE_VISIBILITY |
| 5335 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5336 | {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} |
| 5337 | |
| 5338 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5339 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5340 | double p() const {return __p_.p();} |
| 5341 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5342 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5343 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5344 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5345 | void param(const param_type& __p) {__p_ = __p;} |
| 5346 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5347 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5348 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5349 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5350 | result_type max() const {return numeric_limits<result_type>::max();} |
| 5351 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5352 | friend _LIBCPP_INLINE_VISIBILITY |
| 5353 | bool operator==(const geometric_distribution& __x, |
| 5354 | const geometric_distribution& __y) |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5355 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5356 | friend _LIBCPP_INLINE_VISIBILITY |
| 5357 | bool operator!=(const geometric_distribution& __x, |
| 5358 | const geometric_distribution& __y) |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5359 | {return !(__x == __y);} |
| 5360 | }; |
| 5361 | |
| 5362 | template <class _CharT, class _Traits, class _IntType> |
| 5363 | basic_ostream<_CharT, _Traits>& |
| 5364 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5365 | const geometric_distribution<_IntType>& __x) |
| 5366 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5367 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5368 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 5369 | ios_base::scientific); |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5370 | return __os << __x.p(); |
| 5371 | } |
| 5372 | |
| 5373 | template <class _CharT, class _Traits, class _IntType> |
| 5374 | basic_istream<_CharT, _Traits>& |
| 5375 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5376 | geometric_distribution<_IntType>& __x) |
| 5377 | { |
| 5378 | typedef geometric_distribution<_IntType> _Eng; |
| 5379 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5380 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 34e8a57 | 2010-05-17 13:44:27 +0000 | [diff] [blame] | 5381 | __is.flags(ios_base::dec | ios_base::skipws); |
| 5382 | double __p; |
| 5383 | __is >> __p; |
| 5384 | if (!__is.fail()) |
| 5385 | __x.param(param_type(__p)); |
| 5386 | return __is; |
| 5387 | } |
| 5388 | |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5389 | // chi_squared_distribution |
| 5390 | |
| 5391 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5392 | class _LIBCPP_TEMPLATE_VIS chi_squared_distribution |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5393 | { |
| 5394 | public: |
| 5395 | // types |
| 5396 | typedef _RealType result_type; |
| 5397 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5398 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5399 | { |
| 5400 | result_type __n_; |
| 5401 | public: |
| 5402 | typedef chi_squared_distribution distribution_type; |
| 5403 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5404 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5405 | explicit param_type(result_type __n = 1) : __n_(__n) {} |
| 5406 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5407 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5408 | result_type n() const {return __n_;} |
| 5409 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5410 | friend _LIBCPP_INLINE_VISIBILITY |
| 5411 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5412 | {return __x.__n_ == __y.__n_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5413 | friend _LIBCPP_INLINE_VISIBILITY |
| 5414 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5415 | {return !(__x == __y);} |
| 5416 | }; |
| 5417 | |
| 5418 | private: |
| 5419 | param_type __p_; |
| 5420 | |
| 5421 | public: |
| 5422 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5423 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5424 | explicit chi_squared_distribution(result_type __n = 1) |
| 5425 | : __p_(param_type(__n)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5426 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5427 | explicit chi_squared_distribution(const param_type& __p) |
| 5428 | : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5429 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5430 | void reset() {} |
| 5431 | |
| 5432 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5433 | template<class _URNG> |
| 5434 | _LIBCPP_INLINE_VISIBILITY |
| 5435 | result_type operator()(_URNG& __g) |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5436 | {return (*this)(__g, __p_);} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5437 | template<class _URNG> |
| 5438 | _LIBCPP_INLINE_VISIBILITY |
| 5439 | result_type operator()(_URNG& __g, const param_type& __p) |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5440 | {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} |
| 5441 | |
| 5442 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5443 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5444 | result_type n() const {return __p_.n();} |
| 5445 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5446 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5447 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5449 | void param(const param_type& __p) {__p_ = __p;} |
| 5450 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5451 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5452 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5453 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5454 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5455 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5456 | friend _LIBCPP_INLINE_VISIBILITY |
| 5457 | bool operator==(const chi_squared_distribution& __x, |
| 5458 | const chi_squared_distribution& __y) |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5459 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5460 | friend _LIBCPP_INLINE_VISIBILITY |
| 5461 | bool operator!=(const chi_squared_distribution& __x, |
| 5462 | const chi_squared_distribution& __y) |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5463 | {return !(__x == __y);} |
| 5464 | }; |
| 5465 | |
| 5466 | template <class _CharT, class _Traits, class _RT> |
| 5467 | basic_ostream<_CharT, _Traits>& |
| 5468 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5469 | const chi_squared_distribution<_RT>& __x) |
| 5470 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5471 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5472 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 5473 | ios_base::scientific); |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5474 | __os << __x.n(); |
| 5475 | return __os; |
| 5476 | } |
| 5477 | |
| 5478 | template <class _CharT, class _Traits, class _RT> |
| 5479 | basic_istream<_CharT, _Traits>& |
| 5480 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5481 | chi_squared_distribution<_RT>& __x) |
| 5482 | { |
| 5483 | typedef chi_squared_distribution<_RT> _Eng; |
| 5484 | typedef typename _Eng::result_type result_type; |
| 5485 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5486 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 97dc2f3 | 2010-05-15 23:36:00 +0000 | [diff] [blame] | 5487 | __is.flags(ios_base::dec | ios_base::skipws); |
| 5488 | result_type __n; |
| 5489 | __is >> __n; |
| 5490 | if (!__is.fail()) |
| 5491 | __x.param(param_type(__n)); |
| 5492 | return __is; |
| 5493 | } |
| 5494 | |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5495 | // cauchy_distribution |
| 5496 | |
| 5497 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5498 | class _LIBCPP_TEMPLATE_VIS cauchy_distribution |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5499 | { |
| 5500 | public: |
| 5501 | // types |
| 5502 | typedef _RealType result_type; |
| 5503 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5504 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5505 | { |
| 5506 | result_type __a_; |
| 5507 | result_type __b_; |
| 5508 | public: |
| 5509 | typedef cauchy_distribution distribution_type; |
| 5510 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5511 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5512 | explicit param_type(result_type __a = 0, result_type __b = 1) |
| 5513 | : __a_(__a), __b_(__b) {} |
| 5514 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5515 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5516 | result_type a() const {return __a_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5517 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5518 | result_type b() const {return __b_;} |
| 5519 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5520 | friend _LIBCPP_INLINE_VISIBILITY |
| 5521 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5522 | {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5523 | friend _LIBCPP_INLINE_VISIBILITY |
| 5524 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5525 | {return !(__x == __y);} |
| 5526 | }; |
| 5527 | |
| 5528 | private: |
| 5529 | param_type __p_; |
| 5530 | |
| 5531 | public: |
| 5532 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5533 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5534 | explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) |
| 5535 | : __p_(param_type(__a, __b)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5536 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5537 | explicit cauchy_distribution(const param_type& __p) |
| 5538 | : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5540 | void reset() {} |
| 5541 | |
| 5542 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5543 | template<class _URNG> |
| 5544 | _LIBCPP_INLINE_VISIBILITY |
| 5545 | result_type operator()(_URNG& __g) |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5546 | {return (*this)(__g, __p_);} |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5547 | template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5548 | |
| 5549 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5550 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5551 | result_type a() const {return __p_.a();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5552 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5553 | result_type b() const {return __p_.b();} |
| 5554 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5555 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5556 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5557 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5558 | void param(const param_type& __p) {__p_ = __p;} |
| 5559 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5560 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5561 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5562 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5563 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5564 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5565 | friend _LIBCPP_INLINE_VISIBILITY |
| 5566 | bool operator==(const cauchy_distribution& __x, |
| 5567 | const cauchy_distribution& __y) |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5568 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5569 | friend _LIBCPP_INLINE_VISIBILITY |
| 5570 | bool operator!=(const cauchy_distribution& __x, |
| 5571 | const cauchy_distribution& __y) |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5572 | {return !(__x == __y);} |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5573 | }; |
| 5574 | |
| 5575 | template <class _RealType> |
| 5576 | template<class _URNG> |
Evgeniy Stepanov | a3b25f8 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 5577 | inline |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5578 | _RealType |
| 5579 | cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5580 | { |
| 5581 | uniform_real_distribution<result_type> __gen; |
| 5582 | // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5583 | return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5584 | } |
| 5585 | |
| 5586 | template <class _CharT, class _Traits, class _RT> |
| 5587 | basic_ostream<_CharT, _Traits>& |
| 5588 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5589 | const cauchy_distribution<_RT>& __x) |
| 5590 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5591 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5592 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 5593 | ios_base::scientific); |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5594 | _CharT __sp = __os.widen(' '); |
| 5595 | __os.fill(__sp); |
| 5596 | __os << __x.a() << __sp << __x.b(); |
| 5597 | return __os; |
| 5598 | } |
| 5599 | |
| 5600 | template <class _CharT, class _Traits, class _RT> |
| 5601 | basic_istream<_CharT, _Traits>& |
| 5602 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5603 | cauchy_distribution<_RT>& __x) |
| 5604 | { |
| 5605 | typedef cauchy_distribution<_RT> _Eng; |
| 5606 | typedef typename _Eng::result_type result_type; |
| 5607 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5608 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | d7d0113 | 2010-05-17 21:55:46 +0000 | [diff] [blame] | 5609 | __is.flags(ios_base::dec | ios_base::skipws); |
| 5610 | result_type __a; |
| 5611 | result_type __b; |
| 5612 | __is >> __a >> __b; |
| 5613 | if (!__is.fail()) |
| 5614 | __x.param(param_type(__a, __b)); |
| 5615 | return __is; |
| 5616 | } |
| 5617 | |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5618 | // fisher_f_distribution |
| 5619 | |
| 5620 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5621 | class _LIBCPP_TEMPLATE_VIS fisher_f_distribution |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5622 | { |
| 5623 | public: |
| 5624 | // types |
| 5625 | typedef _RealType result_type; |
| 5626 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5627 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5628 | { |
| 5629 | result_type __m_; |
| 5630 | result_type __n_; |
| 5631 | public: |
| 5632 | typedef fisher_f_distribution distribution_type; |
| 5633 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5634 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5635 | explicit param_type(result_type __m = 1, result_type __n = 1) |
| 5636 | : __m_(__m), __n_(__n) {} |
| 5637 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5638 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5639 | result_type m() const {return __m_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5640 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5641 | result_type n() const {return __n_;} |
| 5642 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5643 | friend _LIBCPP_INLINE_VISIBILITY |
| 5644 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5645 | {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5646 | friend _LIBCPP_INLINE_VISIBILITY |
| 5647 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5648 | {return !(__x == __y);} |
| 5649 | }; |
| 5650 | |
| 5651 | private: |
| 5652 | param_type __p_; |
| 5653 | |
| 5654 | public: |
| 5655 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5656 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5657 | explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) |
| 5658 | : __p_(param_type(__m, __n)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5659 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5660 | explicit fisher_f_distribution(const param_type& __p) |
| 5661 | : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5662 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5663 | void reset() {} |
| 5664 | |
| 5665 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5666 | template<class _URNG> |
| 5667 | _LIBCPP_INLINE_VISIBILITY |
| 5668 | result_type operator()(_URNG& __g) |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5669 | {return (*this)(__g, __p_);} |
| 5670 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5671 | |
| 5672 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5673 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5674 | result_type m() const {return __p_.m();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5675 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5676 | result_type n() const {return __p_.n();} |
| 5677 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5678 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5679 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5680 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5681 | void param(const param_type& __p) {__p_ = __p;} |
| 5682 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5683 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5684 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5685 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5686 | result_type max() const {return numeric_limits<result_type>::infinity();} |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5687 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5688 | friend _LIBCPP_INLINE_VISIBILITY |
| 5689 | bool operator==(const fisher_f_distribution& __x, |
| 5690 | const fisher_f_distribution& __y) |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5691 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5692 | friend _LIBCPP_INLINE_VISIBILITY |
| 5693 | bool operator!=(const fisher_f_distribution& __x, |
| 5694 | const fisher_f_distribution& __y) |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5695 | {return !(__x == __y);} |
| 5696 | }; |
| 5697 | |
| 5698 | template <class _RealType> |
| 5699 | template<class _URNG> |
| 5700 | _RealType |
| 5701 | fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5702 | { |
| 5703 | gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); |
| 5704 | gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); |
| 5705 | return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); |
| 5706 | } |
| 5707 | |
| 5708 | template <class _CharT, class _Traits, class _RT> |
| 5709 | basic_ostream<_CharT, _Traits>& |
| 5710 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5711 | const fisher_f_distribution<_RT>& __x) |
| 5712 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5713 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5714 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 5715 | ios_base::scientific); |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5716 | _CharT __sp = __os.widen(' '); |
| 5717 | __os.fill(__sp); |
| 5718 | __os << __x.m() << __sp << __x.n(); |
| 5719 | return __os; |
| 5720 | } |
| 5721 | |
| 5722 | template <class _CharT, class _Traits, class _RT> |
| 5723 | basic_istream<_CharT, _Traits>& |
| 5724 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5725 | fisher_f_distribution<_RT>& __x) |
| 5726 | { |
| 5727 | typedef fisher_f_distribution<_RT> _Eng; |
| 5728 | typedef typename _Eng::result_type result_type; |
| 5729 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5730 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | d8bc09b | 2010-05-18 17:32:30 +0000 | [diff] [blame] | 5731 | __is.flags(ios_base::dec | ios_base::skipws); |
| 5732 | result_type __m; |
| 5733 | result_type __n; |
| 5734 | __is >> __m >> __n; |
| 5735 | if (!__is.fail()) |
| 5736 | __x.param(param_type(__m, __n)); |
| 5737 | return __is; |
| 5738 | } |
| 5739 | |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5740 | // student_t_distribution |
| 5741 | |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5742 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5743 | class _LIBCPP_TEMPLATE_VIS student_t_distribution |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5744 | { |
| 5745 | public: |
| 5746 | // types |
| 5747 | typedef _RealType result_type; |
| 5748 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5749 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5750 | { |
| 5751 | result_type __n_; |
| 5752 | public: |
| 5753 | typedef student_t_distribution distribution_type; |
| 5754 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5755 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5756 | explicit param_type(result_type __n = 1) : __n_(__n) {} |
| 5757 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5758 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5759 | result_type n() const {return __n_;} |
| 5760 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5761 | friend _LIBCPP_INLINE_VISIBILITY |
| 5762 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5763 | {return __x.__n_ == __y.__n_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5764 | friend _LIBCPP_INLINE_VISIBILITY |
| 5765 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5766 | {return !(__x == __y);} |
| 5767 | }; |
| 5768 | |
| 5769 | private: |
| 5770 | param_type __p_; |
| 5771 | normal_distribution<result_type> __nd_; |
| 5772 | |
| 5773 | public: |
| 5774 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5775 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5776 | explicit student_t_distribution(result_type __n = 1) |
| 5777 | : __p_(param_type(__n)) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5778 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5779 | explicit student_t_distribution(const param_type& __p) |
| 5780 | : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5781 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5782 | void reset() {__nd_.reset();} |
| 5783 | |
| 5784 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5785 | template<class _URNG> |
| 5786 | _LIBCPP_INLINE_VISIBILITY |
| 5787 | result_type operator()(_URNG& __g) |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5788 | {return (*this)(__g, __p_);} |
| 5789 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5790 | |
| 5791 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5793 | result_type n() const {return __p_.n();} |
| 5794 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5795 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5796 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5797 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5798 | void param(const param_type& __p) {__p_ = __p;} |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5799 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5800 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5801 | result_type min() const {return -numeric_limits<result_type>::infinity();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5803 | result_type max() const {return numeric_limits<result_type>::infinity();} |
| 5804 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5805 | friend _LIBCPP_INLINE_VISIBILITY |
| 5806 | bool operator==(const student_t_distribution& __x, |
| 5807 | const student_t_distribution& __y) |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5808 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5809 | friend _LIBCPP_INLINE_VISIBILITY |
| 5810 | bool operator!=(const student_t_distribution& __x, |
| 5811 | const student_t_distribution& __y) |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5812 | {return !(__x == __y);} |
| 5813 | }; |
| 5814 | |
| 5815 | template <class _RealType> |
| 5816 | template<class _URNG> |
| 5817 | _RealType |
| 5818 | student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 5819 | { |
| 5820 | gamma_distribution<result_type> __gd(__p.n() * .5, 2); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5821 | return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5822 | } |
| 5823 | |
| 5824 | template <class _CharT, class _Traits, class _RT> |
| 5825 | basic_ostream<_CharT, _Traits>& |
| 5826 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5827 | const student_t_distribution<_RT>& __x) |
| 5828 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5829 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 5830 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 5831 | ios_base::scientific); |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5832 | __os << __x.n(); |
| 5833 | return __os; |
| 5834 | } |
| 5835 | |
| 5836 | template <class _CharT, class _Traits, class _RT> |
| 5837 | basic_istream<_CharT, _Traits>& |
| 5838 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5839 | student_t_distribution<_RT>& __x) |
| 5840 | { |
| 5841 | typedef student_t_distribution<_RT> _Eng; |
| 5842 | typedef typename _Eng::result_type result_type; |
| 5843 | typedef typename _Eng::param_type param_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 5844 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 321b4bb | 2010-05-18 20:08:04 +0000 | [diff] [blame] | 5845 | __is.flags(ios_base::dec | ios_base::skipws); |
| 5846 | result_type __n; |
| 5847 | __is >> __n; |
| 5848 | if (!__is.fail()) |
| 5849 | __x.param(param_type(__n)); |
| 5850 | return __is; |
| 5851 | } |
| 5852 | |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5853 | // discrete_distribution |
| 5854 | |
| 5855 | template<class _IntType = int> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5856 | class _LIBCPP_TEMPLATE_VIS discrete_distribution |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5857 | { |
| 5858 | public: |
| 5859 | // types |
| 5860 | typedef _IntType result_type; |
| 5861 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 5862 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5863 | { |
| 5864 | vector<double> __p_; |
| 5865 | public: |
| 5866 | typedef discrete_distribution distribution_type; |
| 5867 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5868 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5869 | param_type() {} |
| 5870 | template<class _InputIterator> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5871 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5872 | param_type(_InputIterator __f, _InputIterator __l) |
| 5873 | : __p_(__f, __l) {__init();} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5874 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5875 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5876 | param_type(initializer_list<double> __wl) |
| 5877 | : __p_(__wl.begin(), __wl.end()) {__init();} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5878 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5879 | template<class _UnaryOperation> |
| 5880 | param_type(size_t __nw, double __xmin, double __xmax, |
| 5881 | _UnaryOperation __fw); |
| 5882 | |
| 5883 | vector<double> probabilities() const; |
| 5884 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5885 | friend _LIBCPP_INLINE_VISIBILITY |
| 5886 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5887 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5888 | friend _LIBCPP_INLINE_VISIBILITY |
| 5889 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5890 | {return !(__x == __y);} |
| 5891 | |
| 5892 | private: |
| 5893 | void __init(); |
| 5894 | |
| 5895 | friend class discrete_distribution; |
| 5896 | |
| 5897 | template <class _CharT, class _Traits, class _IT> |
| 5898 | friend |
| 5899 | basic_ostream<_CharT, _Traits>& |
| 5900 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5901 | const discrete_distribution<_IT>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5902 | |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5903 | template <class _CharT, class _Traits, class _IT> |
| 5904 | friend |
| 5905 | basic_istream<_CharT, _Traits>& |
| 5906 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5907 | discrete_distribution<_IT>& __x); |
| 5908 | }; |
| 5909 | |
| 5910 | private: |
| 5911 | param_type __p_; |
| 5912 | |
| 5913 | public: |
| 5914 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5915 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5916 | discrete_distribution() {} |
| 5917 | template<class _InputIterator> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5918 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5919 | discrete_distribution(_InputIterator __f, _InputIterator __l) |
| 5920 | : __p_(__f, __l) {} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5921 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5922 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5923 | discrete_distribution(initializer_list<double> __wl) |
| 5924 | : __p_(__wl) {} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 5925 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5926 | template<class _UnaryOperation> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5927 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5928 | discrete_distribution(size_t __nw, double __xmin, double __xmax, |
| 5929 | _UnaryOperation __fw) |
| 5930 | : __p_(__nw, __xmin, __xmax, __fw) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5931 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7f76450 | 2013-08-14 18:00:20 +0000 | [diff] [blame] | 5932 | explicit discrete_distribution(const param_type& __p) |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5933 | : __p_(__p) {} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5934 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5935 | void reset() {} |
| 5936 | |
| 5937 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5938 | template<class _URNG> |
| 5939 | _LIBCPP_INLINE_VISIBILITY |
| 5940 | result_type operator()(_URNG& __g) |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5941 | {return (*this)(__g, __p_);} |
| 5942 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 5943 | |
| 5944 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5945 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5946 | vector<double> probabilities() const {return __p_.probabilities();} |
| 5947 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5948 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5949 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5950 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5951 | void param(const param_type& __p) {__p_ = __p;} |
| 5952 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5953 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5954 | result_type min() const {return 0;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5955 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5956 | result_type max() const {return __p_.__p_.size();} |
| 5957 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5958 | friend _LIBCPP_INLINE_VISIBILITY |
| 5959 | bool operator==(const discrete_distribution& __x, |
| 5960 | const discrete_distribution& __y) |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5961 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 5962 | friend _LIBCPP_INLINE_VISIBILITY |
| 5963 | bool operator!=(const discrete_distribution& __x, |
| 5964 | const discrete_distribution& __y) |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5965 | {return !(__x == __y);} |
| 5966 | |
| 5967 | template <class _CharT, class _Traits, class _IT> |
| 5968 | friend |
| 5969 | basic_ostream<_CharT, _Traits>& |
| 5970 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 5971 | const discrete_distribution<_IT>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 5972 | |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 5973 | template <class _CharT, class _Traits, class _IT> |
| 5974 | friend |
| 5975 | basic_istream<_CharT, _Traits>& |
| 5976 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 5977 | discrete_distribution<_IT>& __x); |
| 5978 | }; |
| 5979 | |
| 5980 | template<class _IntType> |
| 5981 | template<class _UnaryOperation> |
| 5982 | discrete_distribution<_IntType>::param_type::param_type(size_t __nw, |
| 5983 | double __xmin, |
| 5984 | double __xmax, |
| 5985 | _UnaryOperation __fw) |
| 5986 | { |
| 5987 | if (__nw > 1) |
| 5988 | { |
| 5989 | __p_.reserve(__nw - 1); |
| 5990 | double __d = (__xmax - __xmin) / __nw; |
| 5991 | double __d2 = __d / 2; |
| 5992 | for (size_t __k = 0; __k < __nw; ++__k) |
| 5993 | __p_.push_back(__fw(__xmin + __k * __d + __d2)); |
| 5994 | __init(); |
| 5995 | } |
| 5996 | } |
| 5997 | |
| 5998 | template<class _IntType> |
| 5999 | void |
| 6000 | discrete_distribution<_IntType>::param_type::__init() |
| 6001 | { |
| 6002 | if (!__p_.empty()) |
| 6003 | { |
| 6004 | if (__p_.size() > 1) |
| 6005 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6006 | double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); |
| 6007 | for (_VSTD::vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6008 | __i < __e; ++__i) |
| 6009 | *__i /= __s; |
| 6010 | vector<double> __t(__p_.size() - 1); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6011 | _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6012 | swap(__p_, __t); |
| 6013 | } |
| 6014 | else |
| 6015 | { |
| 6016 | __p_.clear(); |
| 6017 | __p_.shrink_to_fit(); |
| 6018 | } |
| 6019 | } |
| 6020 | } |
| 6021 | |
| 6022 | template<class _IntType> |
| 6023 | vector<double> |
| 6024 | discrete_distribution<_IntType>::param_type::probabilities() const |
| 6025 | { |
| 6026 | size_t __n = __p_.size(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6027 | _VSTD::vector<double> __p(__n+1); |
| 6028 | _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6029 | if (__n > 0) |
| 6030 | __p[__n] = 1 - __p_[__n-1]; |
| 6031 | else |
| 6032 | __p[0] = 1; |
| 6033 | return __p; |
| 6034 | } |
| 6035 | |
| 6036 | template<class _IntType> |
| 6037 | template<class _URNG> |
| 6038 | _IntType |
| 6039 | discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) |
| 6040 | { |
| 6041 | uniform_real_distribution<double> __gen; |
| 6042 | return static_cast<_IntType>( |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6043 | _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6044 | __p.__p_.begin()); |
| 6045 | } |
| 6046 | |
| 6047 | template <class _CharT, class _Traits, class _IT> |
| 6048 | basic_ostream<_CharT, _Traits>& |
| 6049 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6050 | const discrete_distribution<_IT>& __x) |
| 6051 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6052 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6053 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 6054 | ios_base::scientific); |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6055 | _CharT __sp = __os.widen(' '); |
| 6056 | __os.fill(__sp); |
| 6057 | size_t __n = __x.__p_.__p_.size(); |
| 6058 | __os << __n; |
| 6059 | for (size_t __i = 0; __i < __n; ++__i) |
| 6060 | __os << __sp << __x.__p_.__p_[__i]; |
| 6061 | return __os; |
| 6062 | } |
| 6063 | |
| 6064 | template <class _CharT, class _Traits, class _IT> |
| 6065 | basic_istream<_CharT, _Traits>& |
| 6066 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6067 | discrete_distribution<_IT>& __x) |
| 6068 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6069 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6070 | __is.flags(ios_base::dec | ios_base::skipws); |
| 6071 | size_t __n; |
| 6072 | __is >> __n; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6073 | vector<double> __p(__n); |
Howard Hinnant | 551d8e4 | 2010-05-19 01:53:57 +0000 | [diff] [blame] | 6074 | for (size_t __i = 0; __i < __n; ++__i) |
| 6075 | __is >> __p[__i]; |
| 6076 | if (!__is.fail()) |
| 6077 | swap(__x.__p_.__p_, __p); |
| 6078 | return __is; |
| 6079 | } |
| 6080 | |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6081 | // piecewise_constant_distribution |
| 6082 | |
| 6083 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6084 | class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6085 | { |
| 6086 | public: |
| 6087 | // types |
| 6088 | typedef _RealType result_type; |
| 6089 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6090 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6091 | { |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6092 | vector<result_type> __b_; |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6093 | vector<result_type> __densities_; |
| 6094 | vector<result_type> __areas_; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6095 | public: |
| 6096 | typedef piecewise_constant_distribution distribution_type; |
| 6097 | |
| 6098 | param_type(); |
| 6099 | template<class _InputIteratorB, class _InputIteratorW> |
| 6100 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, |
| 6101 | _InputIteratorW __fW); |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6102 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6103 | template<class _UnaryOperation> |
| 6104 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6105 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6106 | template<class _UnaryOperation> |
| 6107 | param_type(size_t __nw, result_type __xmin, result_type __xmax, |
| 6108 | _UnaryOperation __fw); |
Howard Hinnant | 3c143ad | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6109 | param_type & operator=(const param_type& __rhs); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6110 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6111 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6112 | vector<result_type> intervals() const {return __b_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6113 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6114 | vector<result_type> densities() const {return __densities_;} |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6115 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6116 | friend _LIBCPP_INLINE_VISIBILITY |
| 6117 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6118 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6119 | friend _LIBCPP_INLINE_VISIBILITY |
| 6120 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6121 | {return !(__x == __y);} |
| 6122 | |
| 6123 | private: |
| 6124 | void __init(); |
| 6125 | |
| 6126 | friend class piecewise_constant_distribution; |
| 6127 | |
| 6128 | template <class _CharT, class _Traits, class _RT> |
| 6129 | friend |
| 6130 | basic_ostream<_CharT, _Traits>& |
| 6131 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6132 | const piecewise_constant_distribution<_RT>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6133 | |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6134 | template <class _CharT, class _Traits, class _RT> |
| 6135 | friend |
| 6136 | basic_istream<_CharT, _Traits>& |
| 6137 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6138 | piecewise_constant_distribution<_RT>& __x); |
| 6139 | }; |
| 6140 | |
| 6141 | private: |
| 6142 | param_type __p_; |
| 6143 | |
| 6144 | public: |
| 6145 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6146 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6147 | piecewise_constant_distribution() {} |
| 6148 | template<class _InputIteratorB, class _InputIteratorW> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6149 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6150 | piecewise_constant_distribution(_InputIteratorB __fB, |
| 6151 | _InputIteratorB __lB, |
| 6152 | _InputIteratorW __fW) |
| 6153 | : __p_(__fB, __lB, __fW) {} |
| 6154 | |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6155 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6156 | template<class _UnaryOperation> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6157 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6158 | piecewise_constant_distribution(initializer_list<result_type> __bl, |
| 6159 | _UnaryOperation __fw) |
| 6160 | : __p_(__bl, __fw) {} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6161 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6162 | |
| 6163 | template<class _UnaryOperation> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6164 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6165 | piecewise_constant_distribution(size_t __nw, result_type __xmin, |
| 6166 | result_type __xmax, _UnaryOperation __fw) |
| 6167 | : __p_(__nw, __xmin, __xmax, __fw) {} |
| 6168 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6169 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6170 | explicit piecewise_constant_distribution(const param_type& __p) |
| 6171 | : __p_(__p) {} |
| 6172 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6173 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6174 | void reset() {} |
| 6175 | |
| 6176 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6177 | template<class _URNG> |
| 6178 | _LIBCPP_INLINE_VISIBILITY |
| 6179 | result_type operator()(_URNG& __g) |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6180 | {return (*this)(__g, __p_);} |
| 6181 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6182 | |
| 6183 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6184 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6185 | vector<result_type> intervals() const {return __p_.intervals();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6186 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6187 | vector<result_type> densities() const {return __p_.densities();} |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6188 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6189 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6190 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6191 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6192 | void param(const param_type& __p) {__p_ = __p;} |
| 6193 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6194 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6195 | result_type min() const {return __p_.__b_.front();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6196 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6197 | result_type max() const {return __p_.__b_.back();} |
| 6198 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6199 | friend _LIBCPP_INLINE_VISIBILITY |
| 6200 | bool operator==(const piecewise_constant_distribution& __x, |
| 6201 | const piecewise_constant_distribution& __y) |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6202 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6203 | friend _LIBCPP_INLINE_VISIBILITY |
| 6204 | bool operator!=(const piecewise_constant_distribution& __x, |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6205 | const piecewise_constant_distribution& __y) |
| 6206 | {return !(__x == __y);} |
| 6207 | |
| 6208 | template <class _CharT, class _Traits, class _RT> |
| 6209 | friend |
| 6210 | basic_ostream<_CharT, _Traits>& |
| 6211 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6212 | const piecewise_constant_distribution<_RT>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6213 | |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6214 | template <class _CharT, class _Traits, class _RT> |
| 6215 | friend |
| 6216 | basic_istream<_CharT, _Traits>& |
| 6217 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6218 | piecewise_constant_distribution<_RT>& __x); |
| 6219 | }; |
| 6220 | |
| 6221 | template<class _RealType> |
Howard Hinnant | 3c143ad | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6222 | typename piecewise_constant_distribution<_RealType>::param_type & |
| 6223 | piecewise_constant_distribution<_RealType>::param_type::operator= |
| 6224 | (const param_type& __rhs) |
| 6225 | { |
| 6226 | // These can throw |
| 6227 | __b_.reserve (__rhs.__b_.size ()); |
| 6228 | __densities_.reserve(__rhs.__densities_.size()); |
| 6229 | __areas_.reserve (__rhs.__areas_.size()); |
| 6230 | |
| 6231 | // These can not throw |
| 6232 | __b_ = __rhs.__b_; |
| 6233 | __densities_ = __rhs.__densities_; |
| 6234 | __areas_ = __rhs.__areas_; |
| 6235 | return *this; |
| 6236 | } |
| 6237 | |
| 6238 | template<class _RealType> |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6239 | void |
| 6240 | piecewise_constant_distribution<_RealType>::param_type::__init() |
| 6241 | { |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6242 | // __densities_ contains non-normalized areas |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6243 | result_type __total_area = _VSTD::accumulate(__densities_.begin(), |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6244 | __densities_.end(), |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6245 | result_type()); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6246 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
| 6247 | __densities_[__i] /= __total_area; |
| 6248 | // __densities_ contains normalized areas |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6249 | __areas_.assign(__densities_.size(), result_type()); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6250 | _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6251 | __areas_.begin() + 1); |
| 6252 | // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] |
| 6253 | __densities_.back() = 1 - __areas_.back(); // correct round off error |
| 6254 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
| 6255 | __densities_[__i] /= (__b_[__i+1] - __b_[__i]); |
| 6256 | // __densities_ now contains __densities_ |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6257 | } |
| 6258 | |
| 6259 | template<class _RealType> |
| 6260 | piecewise_constant_distribution<_RealType>::param_type::param_type() |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6261 | : __b_(2), |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6262 | __densities_(1, 1.0), |
| 6263 | __areas_(1, 0.0) |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6264 | { |
| 6265 | __b_[1] = 1; |
| 6266 | } |
| 6267 | |
| 6268 | template<class _RealType> |
| 6269 | template<class _InputIteratorB, class _InputIteratorW> |
| 6270 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6271 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) |
| 6272 | : __b_(__fB, __lB) |
| 6273 | { |
| 6274 | if (__b_.size() < 2) |
| 6275 | { |
| 6276 | __b_.resize(2); |
| 6277 | __b_[0] = 0; |
| 6278 | __b_[1] = 1; |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6279 | __densities_.assign(1, 1.0); |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6280 | __areas_.assign(1, 0.0); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6281 | } |
| 6282 | else |
| 6283 | { |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6284 | __densities_.reserve(__b_.size() - 1); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6285 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6286 | __densities_.push_back(*__fW); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6287 | __init(); |
| 6288 | } |
| 6289 | } |
| 6290 | |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6291 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6292 | |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6293 | template<class _RealType> |
| 6294 | template<class _UnaryOperation> |
| 6295 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6296 | initializer_list<result_type> __bl, _UnaryOperation __fw) |
| 6297 | : __b_(__bl.begin(), __bl.end()) |
| 6298 | { |
| 6299 | if (__b_.size() < 2) |
| 6300 | { |
| 6301 | __b_.resize(2); |
| 6302 | __b_[0] = 0; |
| 6303 | __b_[1] = 1; |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6304 | __densities_.assign(1, 1.0); |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6305 | __areas_.assign(1, 0.0); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6306 | } |
| 6307 | else |
| 6308 | { |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6309 | __densities_.reserve(__b_.size() - 1); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6310 | for (size_t __i = 0; __i < __b_.size() - 1; ++__i) |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6311 | __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6312 | __init(); |
| 6313 | } |
| 6314 | } |
| 6315 | |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6316 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6317 | |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6318 | template<class _RealType> |
| 6319 | template<class _UnaryOperation> |
| 6320 | piecewise_constant_distribution<_RealType>::param_type::param_type( |
| 6321 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) |
| 6322 | : __b_(__nw == 0 ? 2 : __nw + 1) |
| 6323 | { |
| 6324 | size_t __n = __b_.size() - 1; |
| 6325 | result_type __d = (__xmax - __xmin) / __n; |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6326 | __densities_.reserve(__n); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6327 | for (size_t __i = 0; __i < __n; ++__i) |
| 6328 | { |
| 6329 | __b_[__i] = __xmin + __i * __d; |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6330 | __densities_.push_back(__fw(__b_[__i] + __d*.5)); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6331 | } |
| 6332 | __b_[__n] = __xmax; |
| 6333 | __init(); |
| 6334 | } |
| 6335 | |
| 6336 | template<class _RealType> |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6337 | template<class _URNG> |
| 6338 | _RealType |
| 6339 | piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 6340 | { |
| 6341 | typedef uniform_real_distribution<result_type> _Gen; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6342 | result_type __u = _Gen()(__g); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6343 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6344 | __u) - __p.__areas_.begin() - 1; |
| 6345 | return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6346 | } |
| 6347 | |
| 6348 | template <class _CharT, class _Traits, class _RT> |
| 6349 | basic_ostream<_CharT, _Traits>& |
| 6350 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6351 | const piecewise_constant_distribution<_RT>& __x) |
| 6352 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6353 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6354 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 6355 | ios_base::scientific); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6356 | _CharT __sp = __os.widen(' '); |
| 6357 | __os.fill(__sp); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6358 | size_t __n = __x.__p_.__b_.size(); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6359 | __os << __n; |
| 6360 | for (size_t __i = 0; __i < __n; ++__i) |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6361 | __os << __sp << __x.__p_.__b_[__i]; |
| 6362 | __n = __x.__p_.__densities_.size(); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6363 | __os << __sp << __n; |
| 6364 | for (size_t __i = 0; __i < __n; ++__i) |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6365 | __os << __sp << __x.__p_.__densities_[__i]; |
| 6366 | __n = __x.__p_.__areas_.size(); |
| 6367 | __os << __sp << __n; |
| 6368 | for (size_t __i = 0; __i < __n; ++__i) |
| 6369 | __os << __sp << __x.__p_.__areas_[__i]; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6370 | return __os; |
| 6371 | } |
| 6372 | |
| 6373 | template <class _CharT, class _Traits, class _RT> |
| 6374 | basic_istream<_CharT, _Traits>& |
| 6375 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6376 | piecewise_constant_distribution<_RT>& __x) |
| 6377 | { |
| 6378 | typedef piecewise_constant_distribution<_RT> _Eng; |
| 6379 | typedef typename _Eng::result_type result_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6380 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6381 | __is.flags(ios_base::dec | ios_base::skipws); |
| 6382 | size_t __n; |
| 6383 | __is >> __n; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6384 | vector<result_type> __b(__n); |
| 6385 | for (size_t __i = 0; __i < __n; ++__i) |
| 6386 | __is >> __b[__i]; |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6387 | __is >> __n; |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6388 | vector<result_type> __densities(__n); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6389 | for (size_t __i = 0; __i < __n; ++__i) |
| 6390 | __is >> __densities[__i]; |
| 6391 | __is >> __n; |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6392 | vector<result_type> __areas(__n); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6393 | for (size_t __i = 0; __i < __n; ++__i) |
| 6394 | __is >> __areas[__i]; |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6395 | if (!__is.fail()) |
| 6396 | { |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6397 | swap(__x.__p_.__b_, __b); |
Howard Hinnant | 2a59254 | 2010-05-24 00:35:40 +0000 | [diff] [blame] | 6398 | swap(__x.__p_.__densities_, __densities); |
| 6399 | swap(__x.__p_.__areas_, __areas); |
Howard Hinnant | d6d1171 | 2010-05-20 15:11:46 +0000 | [diff] [blame] | 6400 | } |
| 6401 | return __is; |
| 6402 | } |
| 6403 | |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6404 | // piecewise_linear_distribution |
| 6405 | |
| 6406 | template<class _RealType = double> |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6407 | class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6408 | { |
| 6409 | public: |
| 6410 | // types |
| 6411 | typedef _RealType result_type; |
| 6412 | |
Eric Fiselier | c3589a8 | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 6413 | class _LIBCPP_TEMPLATE_VIS param_type |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6414 | { |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6415 | vector<result_type> __b_; |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6416 | vector<result_type> __densities_; |
| 6417 | vector<result_type> __areas_; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6418 | public: |
| 6419 | typedef piecewise_linear_distribution distribution_type; |
| 6420 | |
| 6421 | param_type(); |
| 6422 | template<class _InputIteratorB, class _InputIteratorW> |
| 6423 | param_type(_InputIteratorB __fB, _InputIteratorB __lB, |
| 6424 | _InputIteratorW __fW); |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6425 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6426 | template<class _UnaryOperation> |
| 6427 | param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6428 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6429 | template<class _UnaryOperation> |
| 6430 | param_type(size_t __nw, result_type __xmin, result_type __xmax, |
| 6431 | _UnaryOperation __fw); |
Howard Hinnant | 3c143ad | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6432 | param_type & operator=(const param_type& __rhs); |
| 6433 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6434 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6435 | vector<result_type> intervals() const {return __b_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6436 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6437 | vector<result_type> densities() const {return __densities_;} |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6438 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6439 | friend _LIBCPP_INLINE_VISIBILITY |
| 6440 | bool operator==(const param_type& __x, const param_type& __y) |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6441 | {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6442 | friend _LIBCPP_INLINE_VISIBILITY |
| 6443 | bool operator!=(const param_type& __x, const param_type& __y) |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6444 | {return !(__x == __y);} |
| 6445 | |
| 6446 | private: |
| 6447 | void __init(); |
| 6448 | |
| 6449 | friend class piecewise_linear_distribution; |
| 6450 | |
| 6451 | template <class _CharT, class _Traits, class _RT> |
| 6452 | friend |
| 6453 | basic_ostream<_CharT, _Traits>& |
| 6454 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6455 | const piecewise_linear_distribution<_RT>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6456 | |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6457 | template <class _CharT, class _Traits, class _RT> |
| 6458 | friend |
| 6459 | basic_istream<_CharT, _Traits>& |
| 6460 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6461 | piecewise_linear_distribution<_RT>& __x); |
| 6462 | }; |
| 6463 | |
| 6464 | private: |
| 6465 | param_type __p_; |
| 6466 | |
| 6467 | public: |
| 6468 | // constructor and reset functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6469 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6470 | piecewise_linear_distribution() {} |
| 6471 | template<class _InputIteratorB, class _InputIteratorW> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6472 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6473 | piecewise_linear_distribution(_InputIteratorB __fB, |
| 6474 | _InputIteratorB __lB, |
| 6475 | _InputIteratorW __fW) |
| 6476 | : __p_(__fB, __lB, __fW) {} |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6477 | |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6478 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6479 | template<class _UnaryOperation> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6480 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6481 | piecewise_linear_distribution(initializer_list<result_type> __bl, |
| 6482 | _UnaryOperation __fw) |
| 6483 | : __p_(__bl, __fw) {} |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6484 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6485 | |
| 6486 | template<class _UnaryOperation> |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6487 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6488 | piecewise_linear_distribution(size_t __nw, result_type __xmin, |
| 6489 | result_type __xmax, _UnaryOperation __fw) |
| 6490 | : __p_(__nw, __xmin, __xmax, __fw) {} |
| 6491 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6492 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6493 | explicit piecewise_linear_distribution(const param_type& __p) |
| 6494 | : __p_(__p) {} |
| 6495 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6496 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6497 | void reset() {} |
| 6498 | |
| 6499 | // generating functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6500 | template<class _URNG> |
| 6501 | _LIBCPP_INLINE_VISIBILITY |
| 6502 | result_type operator()(_URNG& __g) |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6503 | {return (*this)(__g, __p_);} |
| 6504 | template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); |
| 6505 | |
| 6506 | // property functions |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6507 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6508 | vector<result_type> intervals() const {return __p_.intervals();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6509 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6510 | vector<result_type> densities() const {return __p_.densities();} |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6511 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6512 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6513 | param_type param() const {return __p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6515 | void param(const param_type& __p) {__p_ = __p;} |
| 6516 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6517 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6518 | result_type min() const {return __p_.__b_.front();} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6519 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6520 | result_type max() const {return __p_.__b_.back();} |
| 6521 | |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6522 | friend _LIBCPP_INLINE_VISIBILITY |
| 6523 | bool operator==(const piecewise_linear_distribution& __x, |
| 6524 | const piecewise_linear_distribution& __y) |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6525 | {return __x.__p_ == __y.__p_;} |
Howard Hinnant | b9af2ea | 2010-09-22 18:02:38 +0000 | [diff] [blame] | 6526 | friend _LIBCPP_INLINE_VISIBILITY |
| 6527 | bool operator!=(const piecewise_linear_distribution& __x, |
| 6528 | const piecewise_linear_distribution& __y) |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6529 | {return !(__x == __y);} |
| 6530 | |
| 6531 | template <class _CharT, class _Traits, class _RT> |
| 6532 | friend |
| 6533 | basic_ostream<_CharT, _Traits>& |
| 6534 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6535 | const piecewise_linear_distribution<_RT>& __x); |
Howard Hinnant | 324bb03 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 6536 | |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6537 | template <class _CharT, class _Traits, class _RT> |
| 6538 | friend |
| 6539 | basic_istream<_CharT, _Traits>& |
| 6540 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6541 | piecewise_linear_distribution<_RT>& __x); |
| 6542 | }; |
| 6543 | |
| 6544 | template<class _RealType> |
Howard Hinnant | 3c143ad | 2010-10-13 14:37:09 +0000 | [diff] [blame] | 6545 | typename piecewise_linear_distribution<_RealType>::param_type & |
| 6546 | piecewise_linear_distribution<_RealType>::param_type::operator= |
| 6547 | (const param_type& __rhs) |
| 6548 | { |
| 6549 | // These can throw |
| 6550 | __b_.reserve (__rhs.__b_.size ()); |
| 6551 | __densities_.reserve(__rhs.__densities_.size()); |
| 6552 | __areas_.reserve (__rhs.__areas_.size()); |
| 6553 | |
| 6554 | // These can not throw |
| 6555 | __b_ = __rhs.__b_; |
| 6556 | __densities_ = __rhs.__densities_; |
| 6557 | __areas_ = __rhs.__areas_; |
| 6558 | return *this; |
| 6559 | } |
| 6560 | |
| 6561 | |
| 6562 | template<class _RealType> |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6563 | void |
| 6564 | piecewise_linear_distribution<_RealType>::param_type::__init() |
| 6565 | { |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6566 | __areas_.assign(__densities_.size() - 1, result_type()); |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6567 | result_type _Sp = 0; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6568 | for (size_t __i = 0; __i < __areas_.size(); ++__i) |
| 6569 | { |
| 6570 | __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * |
| 6571 | (__b_[__i+1] - __b_[__i]) * .5; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6572 | _Sp += __areas_[__i]; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6573 | } |
| 6574 | for (size_t __i = __areas_.size(); __i > 1;) |
| 6575 | { |
| 6576 | --__i; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6577 | __areas_[__i] = __areas_[__i-1] / _Sp; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6578 | } |
| 6579 | __areas_[0] = 0; |
| 6580 | for (size_t __i = 1; __i < __areas_.size(); ++__i) |
| 6581 | __areas_[__i] += __areas_[__i-1]; |
| 6582 | for (size_t __i = 0; __i < __densities_.size(); ++__i) |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6583 | __densities_[__i] /= _Sp; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6584 | } |
| 6585 | |
| 6586 | template<class _RealType> |
| 6587 | piecewise_linear_distribution<_RealType>::param_type::param_type() |
| 6588 | : __b_(2), |
| 6589 | __densities_(2, 1.0), |
| 6590 | __areas_(1, 0.0) |
| 6591 | { |
| 6592 | __b_[1] = 1; |
| 6593 | } |
| 6594 | |
| 6595 | template<class _RealType> |
| 6596 | template<class _InputIteratorB, class _InputIteratorW> |
| 6597 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6598 | _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) |
| 6599 | : __b_(__fB, __lB) |
| 6600 | { |
| 6601 | if (__b_.size() < 2) |
| 6602 | { |
| 6603 | __b_.resize(2); |
| 6604 | __b_[0] = 0; |
| 6605 | __b_[1] = 1; |
| 6606 | __densities_.assign(2, 1.0); |
| 6607 | __areas_.assign(1, 0.0); |
| 6608 | } |
| 6609 | else |
| 6610 | { |
| 6611 | __densities_.reserve(__b_.size()); |
| 6612 | for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) |
| 6613 | __densities_.push_back(*__fW); |
| 6614 | __init(); |
| 6615 | } |
| 6616 | } |
| 6617 | |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6618 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6619 | |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6620 | template<class _RealType> |
| 6621 | template<class _UnaryOperation> |
| 6622 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6623 | initializer_list<result_type> __bl, _UnaryOperation __fw) |
| 6624 | : __b_(__bl.begin(), __bl.end()) |
| 6625 | { |
| 6626 | if (__b_.size() < 2) |
| 6627 | { |
| 6628 | __b_.resize(2); |
| 6629 | __b_[0] = 0; |
| 6630 | __b_[1] = 1; |
| 6631 | __densities_.assign(2, 1.0); |
| 6632 | __areas_.assign(1, 0.0); |
| 6633 | } |
| 6634 | else |
| 6635 | { |
| 6636 | __densities_.reserve(__b_.size()); |
| 6637 | for (size_t __i = 0; __i < __b_.size(); ++__i) |
| 6638 | __densities_.push_back(__fw(__b_[__i])); |
| 6639 | __init(); |
| 6640 | } |
| 6641 | } |
| 6642 | |
Eric Fiselier | 97db517 | 2017-04-19 00:23:45 +0000 | [diff] [blame] | 6643 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6644 | |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6645 | template<class _RealType> |
| 6646 | template<class _UnaryOperation> |
| 6647 | piecewise_linear_distribution<_RealType>::param_type::param_type( |
| 6648 | size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) |
| 6649 | : __b_(__nw == 0 ? 2 : __nw + 1) |
| 6650 | { |
| 6651 | size_t __n = __b_.size() - 1; |
| 6652 | result_type __d = (__xmax - __xmin) / __n; |
| 6653 | __densities_.reserve(__b_.size()); |
| 6654 | for (size_t __i = 0; __i < __n; ++__i) |
| 6655 | { |
| 6656 | __b_[__i] = __xmin + __i * __d; |
| 6657 | __densities_.push_back(__fw(__b_[__i])); |
| 6658 | } |
| 6659 | __b_[__n] = __xmax; |
| 6660 | __densities_.push_back(__fw(__b_[__n])); |
| 6661 | __init(); |
| 6662 | } |
| 6663 | |
| 6664 | template<class _RealType> |
| 6665 | template<class _URNG> |
| 6666 | _RealType |
| 6667 | piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) |
| 6668 | { |
| 6669 | typedef uniform_real_distribution<result_type> _Gen; |
| 6670 | result_type __u = _Gen()(__g); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6671 | ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6672 | __u) - __p.__areas_.begin() - 1; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6673 | __u -= __p.__areas_[__k]; |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6674 | const result_type __dk = __p.__densities_[__k]; |
| 6675 | const result_type __dk1 = __p.__densities_[__k+1]; |
| 6676 | const result_type __deltad = __dk1 - __dk; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6677 | const result_type __bk = __p.__b_[__k]; |
| 6678 | if (__deltad == 0) |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6679 | return __u / __dk + __bk; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6680 | const result_type __bk1 = __p.__b_[__k+1]; |
| 6681 | const result_type __deltab = __bk1 - __bk; |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6682 | return (__bk * __dk1 - __bk1 * __dk + |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6683 | _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6684 | __deltad; |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6685 | } |
| 6686 | |
| 6687 | template <class _CharT, class _Traits, class _RT> |
| 6688 | basic_ostream<_CharT, _Traits>& |
| 6689 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 6690 | const piecewise_linear_distribution<_RT>& __x) |
| 6691 | { |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6692 | __save_flags<_CharT, _Traits> __lx(__os); |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6693 | __os.flags(ios_base::dec | ios_base::left | ios_base::fixed | |
| 6694 | ios_base::scientific); |
| 6695 | _CharT __sp = __os.widen(' '); |
| 6696 | __os.fill(__sp); |
| 6697 | size_t __n = __x.__p_.__b_.size(); |
| 6698 | __os << __n; |
| 6699 | for (size_t __i = 0; __i < __n; ++__i) |
| 6700 | __os << __sp << __x.__p_.__b_[__i]; |
| 6701 | __n = __x.__p_.__densities_.size(); |
| 6702 | __os << __sp << __n; |
| 6703 | for (size_t __i = 0; __i < __n; ++__i) |
| 6704 | __os << __sp << __x.__p_.__densities_[__i]; |
| 6705 | __n = __x.__p_.__areas_.size(); |
| 6706 | __os << __sp << __n; |
| 6707 | for (size_t __i = 0; __i < __n; ++__i) |
| 6708 | __os << __sp << __x.__p_.__areas_[__i]; |
| 6709 | return __os; |
| 6710 | } |
| 6711 | |
| 6712 | template <class _CharT, class _Traits, class _RT> |
| 6713 | basic_istream<_CharT, _Traits>& |
| 6714 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 6715 | piecewise_linear_distribution<_RT>& __x) |
| 6716 | { |
| 6717 | typedef piecewise_linear_distribution<_RT> _Eng; |
| 6718 | typedef typename _Eng::result_type result_type; |
Howard Hinnant | 9c0df14 | 2012-10-30 19:06:59 +0000 | [diff] [blame] | 6719 | __save_flags<_CharT, _Traits> __lx(__is); |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6720 | __is.flags(ios_base::dec | ios_base::skipws); |
| 6721 | size_t __n; |
| 6722 | __is >> __n; |
| 6723 | vector<result_type> __b(__n); |
| 6724 | for (size_t __i = 0; __i < __n; ++__i) |
| 6725 | __is >> __b[__i]; |
| 6726 | __is >> __n; |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6727 | vector<result_type> __densities(__n); |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6728 | for (size_t __i = 0; __i < __n; ++__i) |
| 6729 | __is >> __densities[__i]; |
| 6730 | __is >> __n; |
Howard Hinnant | 9650b6c | 2010-11-18 17:01:36 +0000 | [diff] [blame] | 6731 | vector<result_type> __areas(__n); |
Howard Hinnant | 5430540 | 2010-05-25 00:27:34 +0000 | [diff] [blame] | 6732 | for (size_t __i = 0; __i < __n; ++__i) |
| 6733 | __is >> __areas[__i]; |
| 6734 | if (!__is.fail()) |
| 6735 | { |
| 6736 | swap(__x.__p_.__b_, __b); |
| 6737 | swap(__x.__p_.__densities_, __densities); |
| 6738 | swap(__x.__p_.__areas_, __areas); |
| 6739 | } |
| 6740 | return __is; |
| 6741 | } |
| 6742 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6743 | _LIBCPP_END_NAMESPACE_STD |
| 6744 | |
Eric Fiselier | 018a3d5 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 6745 | _LIBCPP_POP_MACROS |
| 6746 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6747 | #endif // _LIBCPP_RANDOM |