32 #ifndef VSMC_RNG_INTERNAL_COMMON_HPP 33 #define VSMC_RNG_INTERNAL_COMMON_HPP 38 #include <mkl_version.h> 42 #define VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM(flag, Name) \ 43 VSMC_RUNTIME_ASSERT((flag), \ 44 "**" #Name "Distribution** CONSTRUCTED WITH INVALID PARAMETERS") 46 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_0(Name, T, t, Type) \ 50 static_assert(std::is_##t<T>::value, \ 51 "**" #Name "Distribution::param_type** USED WITH " #T \ 52 " OTHER THAN " #Type " INTEGER TYPES"); \ 55 using result_type = T; \ 56 using distribution_type = Name##Distribution<T>; \ 58 friend bool operator==(const param_type &, const param_type &) \ 63 friend bool operator!=(const param_type &, const param_type &) \ 68 template <typename CharT, typename Traits> \ 69 friend std::basic_ostream<CharT, Traits> &operator<<( \ 70 std::basic_ostream<CharT, Traits> &os, const param_type &) \ 75 template <typename CharT, typename Traits> \ 76 friend std::basic_istream<CharT, Traits> &operator>>( \ 77 std::basic_istream<CharT, Traits> &is, param_type &) \ 83 friend distribution_type; \ 84 }; // class param_type 86 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_1(Name, name, p1, v1) \ 90 static_assert(std::is_floating_point<RealType>::value, \ 91 "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \ 92 "THAN FLOATING POINT TYPES"); \ 95 using result_type = RealType; \ 96 using distribution_type = Name##Distribution<RealType>; \ 98 explicit param_type(result_type p1 = v1) : p1##_(p1) \ 100 VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \ 101 internal::name##_distribution_check_param(p1), Name); \ 104 result_type p1() const { return p1##_; } \ 106 friend bool operator==( \ 107 const param_type ¶m1, const param_type ¶m2) \ 109 if (!internal::is_equal(param1.p1##_, param2.p1##_)) \ 114 friend bool operator!=( \ 115 const param_type ¶m1, const param_type ¶m2) \ 117 return !(param1 == param2); \ 120 template <typename CharT, typename Traits> \ 121 friend std::basic_ostream<CharT, Traits> &operator<<( \ 122 std::basic_ostream<CharT, Traits> &os, const param_type ¶m) \ 132 template <typename CharT, typename Traits> \ 133 friend std::basic_istream<CharT, Traits> &operator>>( \ 134 std::basic_istream<CharT, Traits> &is, param_type ¶m) \ 139 result_type p1 = 0; \ 140 is >> std::ws >> p1; \ 143 if (internal::name##_distribution_check_param(p1)) { \ 146 is.setstate(std::ios_base::failbit); \ 156 friend distribution_type; \ 157 }; // class param_type 159 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_2(Name, name, p1, v1, p2, v2) \ 163 static_assert(std::is_floating_point<RealType>::value, \ 164 "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \ 165 "THAN FLOATING POINT TYPES"); \ 168 using result_type = RealType; \ 169 using distribution_type = Name##Distribution<RealType>; \ 171 explicit param_type(result_type p1 = v1, result_type p2 = v2) \ 172 : p1##_(p1), p2##_(p2) \ 174 VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \ 175 internal::name##_distribution_check_param(p1, p2), Name); \ 178 result_type p1() const { return p1##_; } \ 179 result_type p2() const { return p2##_; } \ 181 friend bool operator==( \ 182 const param_type ¶m1, const param_type ¶m2) \ 184 if (!internal::is_equal(param1.p1##_, param2.p1##_)) \ 186 if (!internal::is_equal(param1.p2##_, param2.p2##_)) \ 191 friend bool operator!=( \ 192 const param_type ¶m1, const param_type ¶m2) \ 194 return !(param1 == param2); \ 197 template <typename CharT, typename Traits> \ 198 friend std::basic_ostream<CharT, Traits> &operator<<( \ 199 std::basic_ostream<CharT, Traits> &os, const param_type ¶m) \ 204 os << param.p1##_ << ' '; \ 210 template <typename CharT, typename Traits> \ 211 friend std::basic_istream<CharT, Traits> &operator>>( \ 212 std::basic_istream<CharT, Traits> &is, param_type ¶m) \ 217 result_type p1 = 0; \ 218 result_type p2 = 0; \ 219 is >> std::ws >> p1; \ 220 is >> std::ws >> p2; \ 223 if (internal::name##_distribution_check_param(p1, p2)) { \ 227 is.setstate(std::ios_base::failbit); \ 238 friend distribution_type; \ 239 }; // class param_type 241 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_3( \ 242 Name, name, p1, v1, p2, v2, p3, v3) \ 246 static_assert(std::is_floating_point<RealType>::value, \ 247 "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \ 248 "THAN FLOATING POINT TYPES"); \ 251 using result_type = RealType; \ 252 using distribution_type = Name##Distribution<RealType>; \ 254 explicit param_type( \ 255 result_type p1 = v1, result_type p2 = v2, result_type p3 = v3) \ 256 : p1##_(p1), p2##_(p2), p3##_(p3) \ 258 VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \ 259 internal::name##_distribution_check_param(p1, p2, p3), Name); \ 262 result_type p1() const { return p1##_; } \ 263 result_type p2() const { return p2##_; } \ 264 result_type p3() const { return p3##_; } \ 266 friend bool operator==( \ 267 const param_type ¶m1, const param_type ¶m2) \ 269 if (!internal::is_equal(param1.p1##_, param2.p1##_)) \ 271 if (!internal::is_equal(param1.p2##_, param2.p2##_)) \ 273 if (!internal::is_equal(param1.p3##_, param2.p3##_)) \ 278 friend bool operator!=( \ 279 const param_type ¶m1, const param_type ¶m2) \ 281 return !(param1 == param2); \ 284 template <typename CharT, typename Traits> \ 285 friend std::basic_ostream<CharT, Traits> &operator<<( \ 286 std::basic_ostream<CharT, Traits> &os, const param_type ¶m) \ 291 os << param.p1##_ << ' '; \ 292 os << param.p2##_ << ' '; \ 298 template <typename CharT, typename Traits> \ 299 friend std::basic_istream<CharT, Traits> &operator>>( \ 300 std::basic_istream<CharT, Traits> &is, param_type ¶m) \ 305 result_type p1 = 0; \ 306 result_type p2 = 0; \ 307 result_type p3 = 0; \ 308 is >> std::ws >> p1; \ 309 is >> std::ws >> p2; \ 310 is >> std::ws >> p3; \ 313 if (internal::name##_distribution_check_param(p1, p2, p3)) { \ 318 is.setstate(std::ios_base::failbit); \ 330 friend distribution_type; \ 331 }; // class param_type 333 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_4( \ 334 Name, name, p1, v1, p2, v2, p3, v3, p4, v4) \ 338 static_assert(std::is_floating_point<RealType>::value, \ 339 "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \ 340 "THAN FLOATING POINT TYPES"); \ 343 using result_type = RealType; \ 344 using distribution_type = Name##Distribution<RealType>; \ 346 explicit param_type(result_type p1 = v1, result_type p2 = v2, \ 347 result_type p3 = v3, result_type p4 = v4) \ 348 : p1##_(p1), p2##_(p2), p3##_(p3), p4##_(p4) \ 350 VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \ 351 internal::name##_distribution_check_param(p1, p2, p3, p4), \ 355 result_type p1() const { return p1##_; } \ 356 result_type p2() const { return p2##_; } \ 357 result_type p3() const { return p3##_; } \ 358 result_type p4() const { return p4##_; } \ 360 friend bool operator==( \ 361 const param_type ¶m1, const param_type ¶m2) \ 363 if (!internal::is_equal(param1.p1##_, param2.p1##_)) \ 365 if (!internal::is_equal(param1.p2##_, param2.p2##_)) \ 367 if (!internal::is_equal(param1.p3##_, param2.p3##_)) \ 369 if (!internal::is_equal(param1.p4##_, param2.p4##_)) \ 374 friend bool operator!=( \ 375 const param_type ¶m1, const param_type ¶m2) \ 377 return !(param1 == param2); \ 380 template <typename CharT, typename Traits> \ 381 friend std::basic_ostream<CharT, Traits> &operator<<( \ 382 std::basic_ostream<CharT, Traits> &os, const param_type ¶m) \ 387 os << param.p1##_ << ' '; \ 388 os << param.p2##_ << ' '; \ 389 os << param.p3##_ << ' '; \ 395 template <typename CharT, typename Traits> \ 396 friend std::basic_istream<CharT, Traits> &operator>>( \ 397 std::basic_istream<CharT, Traits> &is, param_type ¶m) \ 402 result_type p1 = 0; \ 403 result_type p2 = 0; \ 404 result_type p3 = 0; \ 405 result_type p4 = 0; \ 406 is >> std::ws >> p1; \ 407 is >> std::ws >> p2; \ 408 is >> std::ws >> p3; \ 409 is >> std::ws >> p4; \ 412 if (internal::name##_distribution_check_param( \ 419 is.setstate(std::ios_base::failbit); \ 432 friend distribution_type; \ 433 }; // class param_type 435 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_0(Name, T) \ 437 using result_type = T; \ 438 using distribution_type = Name##Distribution<T>; \ 440 Name##Distribution() = default; \ 441 explicit Name##Distribution(const param_type &) {} 443 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_1(Name, p1, v1) \ 445 using result_type = RealType; \ 446 using distribution_type = Name##Distribution<RealType>; \ 448 explicit Name##Distribution(result_type p1 = v1) : param_(p1) \ 453 explicit Name##Distribution(const param_type ¶m) : param_(param) \ 458 result_type p1() const { return param_.p1(); } 460 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_2(Name, p1, v1, p2, v2) \ 462 using result_type = RealType; \ 463 using distribution_type = Name##Distribution<RealType>; \ 465 explicit Name##Distribution(result_type p1 = v1, result_type p2 = v2) \ 471 explicit Name##Distribution(const param_type ¶m) : param_(param) \ 476 result_type p1() const { return param_.p1(); } \ 477 result_type p2() const { return param_.p2(); } 479 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_3( \ 480 Name, p1, v1, p2, v2, p3, v3) \ 482 using result_type = RealType; \ 483 using distribution_type = Name##Distribution<RealType>; \ 485 explicit Name##Distribution( \ 486 result_type p1 = v1, result_type p2 = v2, result_type p3 = v3) \ 487 : param_(p1, p2, p3) \ 492 explicit Name##Distribution(const param_type ¶m) : param_(param) \ 497 result_type p1() const { return param_.p1(); } \ 498 result_type p2() const { return param_.p2(); } \ 499 result_type p3() const { return param_.p3(); } 501 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_4( \ 502 Name, p1, v1, p2, v2, p3, v3, p4, v4) \ 504 using result_type = RealType; \ 505 using distribution_type = Name##Distribution<RealType>; \ 507 explicit Name##Distribution(result_type p1 = v1, result_type p2 = v2, \ 508 result_type p3 = v3, result_type p4 = v4) \ 509 : param_(p1, p2, p3, p4) \ 514 explicit Name##Distribution(const param_type ¶m) : param_(param) \ 519 result_type p1() const { return param_.p1(); } \ 520 result_type p2() const { return param_.p2(); } \ 521 result_type p3() const { return param_.p3(); } \ 522 result_type p4() const { return param_.p4(); } 524 #define VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name) \ 526 const param_type ¶m() const { return param_; } \ 528 void param(const param_type ¶m) \ 534 void pram(param_type &¶m) \ 536 param_ = std::move(param); \ 540 template <typename RNGType> \ 541 result_type operator()(RNGType &rng) \ 543 return operator()(rng, param_); \ 546 template <typename RNGType> \ 547 result_type operator()(RNGType &rng, const param_type ¶m) \ 549 return generate(rng, param); \ 552 template <typename RNGType> \ 553 void operator()(RNGType &rng, std::size_t n, result_type *r) \ 555 operator()(rng, n, r, param_); \ 558 template <typename RNGType> \ 560 RNGType &rng, std::size_t n, result_type *r, const param_type ¶m) \ 563 for (std::size_t i = 0; i != n; ++i) \ 564 r[i] = operator()(rng, param); \ 566 name##_distribution(rng, n, r, param); \ 570 friend bool operator==( \ 571 const distribution_type &dist1, const distribution_type &dist2) \ 573 return dist1.param_ == dist2.param_ && dist1.is_equal(dist2); \ 576 friend bool operator!=( \ 577 const distribution_type &dist1, const distribution_type &dist2) \ 579 return !(dist1 == dist2); \ 582 template <typename CharT, typename Traits> \ 583 friend std::basic_ostream<CharT, Traits> &operator<<( \ 584 std::basic_ostream<CharT, Traits> &os, const distribution_type &dist) \ 595 template <typename CharT, typename Traits> \ 596 friend std::basic_istream<CharT, Traits> &operator>>( \ 597 std::basic_istream<CharT, Traits> &is, distribution_type &dist) \ 602 is >> std::ws >> dist.param_; \ 612 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_0 \ 614 bool is_equal(const distribution_type &) const { return true; } \ 616 template <typename CharT, typename Traits> \ 617 void ostream(std::basic_ostream<CharT, Traits> &) const \ 621 template <typename CharT, typename Traits> \ 622 void istream(std::basic_istream<CharT, Traits> &) \ 626 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_1(T1, m1) \ 630 bool is_equal(const distribution_type &other) const \ 632 if (!internal::is_equal(m1, other.m1)) \ 637 template <typename CharT, typename Traits> \ 638 void ostream(std::basic_ostream<CharT, Traits> &os) const \ 646 template <typename CharT, typename Traits> \ 647 void istream(std::basic_istream<CharT, Traits> &is) \ 653 is >> std::ws >> tmp1; \ 655 m1 = std::move(tmp1); \ 659 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_2(T1, m1, T2, m2) \ 664 bool is_equal(const distribution_type &other) const \ 666 if (!internal::is_equal(m1, other.m1)) \ 668 if (!internal::is_equal(m2, other.m2)) \ 673 template <typename CharT, typename Traits> \ 674 void ostream(std::basic_ostream<CharT, Traits> &os) const \ 683 template <typename CharT, typename Traits> \ 684 void istream(std::basic_istream<CharT, Traits> &is) \ 691 is >> std::ws >> tmp1; \ 692 is >> std::ws >> tmp2; \ 694 m1 = std::move(tmp1); \ 695 m2 = std::move(tmp2); \ 699 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_3(T1, m1, T2, m2, T3, m3) \ 705 bool is_equal(const distribution_type &other) const \ 707 if (!internal::is_equal(m1, other.m1)) \ 709 if (!internal::is_equal(m2, other.m2)) \ 711 if (!internal::is_equal(m3, other.m3)) \ 716 template <typename CharT, typename Traits> \ 717 void ostream(std::basic_ostream<CharT, Traits> &os) const \ 727 template <typename CharT, typename Traits> \ 728 void istream(std::basic_istream<CharT, Traits> &is) \ 736 is >> std::ws >> tmp1; \ 737 is >> std::ws >> tmp2; \ 738 is >> std::ws >> tmp3; \ 740 m1 = std::move(tmp1); \ 741 m2 = std::move(tmp2); \ 742 m3 = std::move(tmp3); \ 746 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_4(T1, m1, T2, m2, T3, m3, T4, m4) \ 753 bool is_equal(const distribution_type &other) const \ 755 if (!internal::is_equal(m1, other.m1)) \ 757 if (!internal::is_equal(m2, other.m2)) \ 759 if (!internal::is_equal(m3, other.m3)) \ 761 if (!internal::is_equal(m4, other.m4)) \ 766 template <typename CharT, typename Traits> \ 767 void ostream(std::basic_ostream<CharT, Traits> &os) const \ 778 template <typename CharT, typename Traits> \ 779 void istream(std::basic_istream<CharT, Traits> &is) \ 788 is >> std::ws >> tmp1; \ 789 is >> std::ws >> tmp2; \ 790 is >> std::ws >> tmp3; \ 791 is >> std::ws >> tmp4; \ 793 m1 = std::move(tmp1); \ 794 m2 = std::move(tmp2); \ 795 m3 = std::move(tmp3); \ 796 m4 = std::move(tmp4); \ 800 #define VSMC_DEFINE_RNG_DISTRIBUTION_0(Name, name, T, t, Type) \ 801 VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_0(Name, T, t, Type) \ 802 VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_0(Name, T) \ 803 VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name) 805 #define VSMC_DEFINE_RNG_DISTRIBUTION_1(Name, name, p1, v1) \ 806 VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_1(Name, name, p1, v1) \ 807 VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_1(Name, p1, v1) \ 808 VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name) 810 #define VSMC_DEFINE_RNG_DISTRIBUTION_2(Name, name, p1, v1, p2, v2) \ 811 VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_2(Name, name, p1, v1, p2, v2) \ 812 VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_2(Name, p1, v1, p2, v2) \ 813 VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name) 815 #define VSMC_DEFINE_RNG_DISTRIBUTION_3(Name, name, p1, v1, p2, v2, p3, v3) \ 816 VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_3( \ 817 Name, name, p1, v1, p2, v2, p3, v3) \ 818 VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_3(Name, p1, v1, p2, v2, p3, v3) \ 819 VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name) 821 #define VSMC_DEFINE_RNG_DISTRIBUTION_4( \ 822 Name, name, p1, v1, p2, v2, p3, v3, p4, v4) \ 823 VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_4( \ 824 Name, name, p1, v1, p2, v2, p3, v3, p4, v4) \ 825 VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_3( \ 826 Name, p1, v1, p2, v2, p3, v3, p4, v4) \ 827 VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name) 829 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_0(name) \ 830 template <typename RealType, typename RNGType> \ 831 inline void name##_distribution(RNGType &rng, std::size_t n, RealType *r) \ 833 static_assert(std::is_floating_point<RealType>::value, \ 834 "**" #name "_distribution** USED WITH RealType OTHER THAN " \ 835 "FLOATING POINT TYPES"); \ 837 const std::size_t K = internal::BufferSize<RealType>::value; \ 838 const std::size_t M = n / K; \ 839 const std::size_t L = n % K; \ 840 for (std::size_t i = 0; i != M; ++i, r += K) \ 841 internal::name##_distribution_impl<K>(rng, K, r); \ 842 internal::name##_distribution_impl<K>(rng, L, r); \ 845 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_1(name, p1) \ 846 template <typename RealType, typename RNGType> \ 847 inline void name##_distribution( \ 848 RNGType &rng, std::size_t N, RealType *r, RealType p1) \ 850 static_assert(std::is_floating_point<RealType>::value, \ 851 "**" #name "_distribution** USED WITH RealType OTHER THAN " \ 852 "FLOATING POINT TYPES"); \ 854 const std::size_t K = internal::BufferSize<RealType>::value; \ 855 const std::size_t M = N / K; \ 856 const std::size_t L = N % K; \ 857 for (std::size_t i = 0; i != M; ++i, r += K) \ 858 internal::name##_distribution_impl<K>(rng, K, r, p1); \ 859 internal::name##_distribution_impl<K>(rng, L, r, p1); \ 862 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_2(name, p1, p2) \ 863 template <typename RealType, typename RNGType> \ 864 inline void name##_distribution( \ 865 RNGType &rng, std::size_t N, RealType *r, RealType p1, RealType p2) \ 867 static_assert(std::is_floating_point<RealType>::value, \ 868 "**" #name "_distribution** USED WITH RealType OTHER THAN " \ 869 "FLOATING POINT TYPES"); \ 871 const std::size_t K = internal::BufferSize<RealType>::value; \ 872 const std::size_t M = N / K; \ 873 const std::size_t L = N % K; \ 874 for (std::size_t i = 0; i != M; ++i, r += K) \ 875 internal::name##_distribution_impl<K>(rng, K, r, p1, p2); \ 876 internal::name##_distribution_impl<K>(rng, L, r, p1, p2); \ 879 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_3(name, p1, p2, p3) \ 880 template <typename RealType, typename RNGType> \ 881 inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \ 882 RealType p1, RealType p2, RealType p3) \ 884 static_assert(std::is_floating_point<RealType>::value, \ 885 "**" #name "_distribution** USED WITH RealType OTHER THAN " \ 886 "FLOATING POINT TYPES"); \ 888 const std::size_t K = internal::BufferSize<RealType>::value; \ 889 const std::size_t M = N / K; \ 890 const std::size_t L = N % K; \ 891 for (std::size_t i = 0; i != M; ++i, r += K) \ 892 internal::name##_distribution_impl<K>(rng, K, r, p1, p2, p3); \ 893 internal::name##_distribution_impl<K>(rng, L, r, p1, p2, p3); \ 896 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_4(name, p1, p2, p3, p4) \ 897 template <typename RealType, typename RNGType> \ 898 inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \ 899 RealType p1, RealType p2, RealType p3, RealType p4) \ 901 static_assert(std::is_floating_point<RealType>::value, \ 902 "**" #name "_distribution** USED WITH RealType OTHER THAN " \ 903 "FLOATING POINT TYPES"); \ 905 const std::size_t K = internal::BufferSize<RealType>::value; \ 906 const std::size_t M = N / K; \ 907 const std::size_t L = N % K; \ 908 for (std::size_t i = 0; i != M; ++i, r += K) \ 909 internal::name##_distribution_impl<K>(rng, K, r, p1, p2, p3, p4); \ 910 internal::name##_distribution_impl<K>(rng, L, r, p1, p2, p3, p4); \ 913 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_0(Name, name, T) \ 914 template <typename T, typename RNGType> \ 915 inline void name##_distribution(RNGType &rng, std::size_t N, T *r, \ 916 const typename Name##Distribution<T>::param_type &) \ 918 name##_distribution(rng, N, r); \ 921 template <typename T, typename RNGType> \ 923 RNGType &rng, Name##Distribution<T> &dist, std::size_t N, T *r) \ 928 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_1(Name, name, p1) \ 929 template <typename RealType, typename RNGType> \ 930 inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \ 931 const typename Name##Distribution<RealType>::param_type ¶m) \ 933 name##_distribution(rng, N, r, param.p1()); \ 936 template <typename RealType, typename RNGType> \ 937 inline void rand(RNGType &rng, Name##Distribution<RealType> &dist, \ 938 std::size_t N, RealType *r) \ 943 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_2(Name, name, p1, p2) \ 944 template <typename RealType, typename RNGType> \ 945 inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \ 946 const typename Name##Distribution<RealType>::param_type ¶m) \ 948 name##_distribution(rng, N, r, param.p1(), param.p2()); \ 951 template <typename RealType, typename RNGType> \ 952 inline void rand(RNGType &rng, Name##Distribution<RealType> &dist, \ 953 std::size_t N, RealType *r) \ 958 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_3(Name, name, p1, p2, p3) \ 959 template <typename RealType, typename RNGType> \ 960 inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \ 961 const typename Name##Distribution<RealType>::param_type ¶m) \ 963 name##_distribution(rng, N, r, param.p1(), param.p2(), param.p3()); \ 966 template <typename RealType, typename RNGType> \ 967 inline void rand(RNGType &rng, Name##Distribution<RealType> &dist, \ 968 std::size_t N, RealType *r) \ 973 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_4(Name, name, p1, p2, p3, p4) \ 974 template <typename RealType, typename RNGType> \ 975 inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \ 976 const typename Name##Distribution<RealType>::param_type ¶m) \ 978 name##_distribution( \ 979 rng, N, r, param.p1(), param.p2(), param.p3, p4()); \ 982 template <typename RealType, typename RNGType> \ 983 inline void rand(RNGType &rng, Name##Distribution<RealType> &dist, \ 984 std::size_t N, RealType *r) \ 1002 template <typename RNGType>
1005 using result_type =
typename RNGType::result_type;
1007 static constexpr
typename RNGType::result_type R_ = RNGType::min() == 0 &&
1008 RNGType::max() == std::numeric_limits<result_type>::max() ?
1010 RNGType::max() - RNGType::min() +
static_cast<result_type
>(1);
1015 static constexpr
bool is_full_range =
1016 RNGType::min() == 0 && (R_ & (R_ - 1)) == 0;
1031 template <
typename RNGType>
1032 inline void rand(RNGType &rng, std::size_t n,
typename RNGType::result_type *r)
1034 for (std::size_t i = 0; i != n; ++i)
1040 template <
typename RNGType,
typename DistributionType>
1041 inline void rand(RNGType &rng,
const DistributionType &distribution,
1042 std::size_t n,
typename DistributionType::result_type *r)
1044 DistributionType dist(distribution);
1045 for (std::size_t i = 0; i != n; ++i)
1049 template <
typename,
typename>
1052 template <
typename =
double, std::
size_t = Dynamic>
1055 template <
typename =
double, std::
size_t = Dynamic, std::
size_t = Dynamic>
1058 template <
typename =
double>
1061 template <
typename =
double, std::
size_t = Dynamic>
1064 template <
typename =
double>
1067 template <
typename =
double>
1070 template <
typename =
double>
1073 template <
typename =
int>
1076 template <
typename =
double>
1079 template <
typename =
double>
1082 template <
typename =
double>
1085 template <
typename =
double>
1088 template <
typename =
double>
1091 template <
typename =
double>
1094 template <
typename =
double>
1097 template <
typename =
double>
1100 template <
typename =
double>
1103 template <
typename =
double, std::
size_t = Dynamic>
1106 template <
typename =
double>
1109 template <
typename =
double>
1112 template <
typename =
double>
1115 template <
typename =
double>
1118 template <
typename =
double,
typename = Open,
typename = Closed>
1121 template <
typename =
unsigned>
1124 template <
typename =
double>
1127 template <
typename =
double>
1130 template <
typename ResultType,
typename Generator>
1134 template <
typename RealType,
typename RNGType>
1138 template <
typename RealType,
typename RNGType>
1142 template <
typename RealType,
typename RNGType>
1146 template <
typename RealType,
typename RNGType>
1150 template <
typename RealType,
typename RNGType>
1154 template <
typename RealType,
typename RNGType>
1158 template <
typename RealType,
typename RNGType>
1162 template <
typename RealType,
typename RNGType>
1166 template <
typename RealType,
typename RNGType>
1170 template <
typename RealType,
typename RNGType>
1174 template <
typename RealType,
typename RNGType>
1178 template <
typename RealType,
typename RNGType>
1182 template <
typename RealType,
typename RNGType>
1186 template <
typename RealType, std::
size_t Dim,
typename RNGType>
1190 template <
typename RealType,
typename RNGType>
1194 template <
typename RealType,
typename RNGType>
1198 template <
typename RealType,
typename RNGType>
1202 template <
typename RealType,
typename RNGType>
1206 template <
typename RealType,
typename RNGType,
typename Lower,
typename Upper>
1208 std::size_t, RealType *);
1210 template <
typename UIntType,
typename RNGType>
1214 template <
typename RealType,
typename RNGType>
1218 template <
typename RealType,
typename RNGType>
1222 template <
typename RealType,
typename RNGType>
1224 RNGType &, std::size_t, RealType *, RealType, RealType);
1226 template <
typename RealType,
typename RNGType>
1228 RNGType &, std::size_t, RealType *, RealType, RealType);
1230 template <
typename RealType,
typename RNGType>
1232 RNGType &, std::size_t, RealType *, RealType);
1234 template <
typename RealType,
typename RNGType>
1236 RNGType &, std::size_t, RealType *, RealType);
1238 template <
typename RealType,
typename RNGType>
1240 RNGType &, std::size_t, RealType *, RealType, RealType);
1242 template <
typename RealType,
typename RNGType>
1244 RNGType &, std::size_t, RealType *, RealType, RealType);
1246 template <
typename RealType,
typename RNGType>
1248 RNGType &, std::size_t, RealType *, RealType, RealType);
1250 template <
typename RealType,
typename RNGType>
1252 RNGType &, std::size_t, RealType *, RealType, RealType);
1254 template <
typename RealType,
typename RNGType>
1256 RNGType &, std::size_t, RealType *, RealType, RealType);
1258 template <
typename RealType,
typename RNGType>
1260 RNGType &, std::size_t, RealType *, RealType, RealType);
1262 template <
typename RealType,
typename RNGType>
1264 RNGType &, std::size_t, RealType *, RealType, RealType);
1266 template <
typename RealType,
typename RNGType>
1268 RNGType &, std::size_t, RealType *, RealType, RealType);
1270 template <
typename RealType,
typename RNGType>
1272 std::size_t,
const RealType *,
const RealType *);
1274 template <
typename RealType,
typename RNGType>
1276 RNGType &, std::size_t, RealType *, RealType, RealType);
1278 template <
typename RealType,
typename RNGType>
1280 RNGType &, std::size_t, RealType *, RealType);
1282 template <
typename RealType,
typename RNGType>
1284 RNGType &, std::size_t, RealType *, RealType);
1286 template <
typename RealType,
typename RNGType>
1289 template <
typename,
typename,
typename RealType,
typename RNGType>
1292 template <
typename UIntType,
typename RNGType>
1295 template <
typename RealType,
typename RNGType>
1297 RNGType &, std::size_t, RealType *, RealType, RealType);
1299 template <
typename RealType,
typename RNGType>
1301 RNGType &, std::size_t, RealType *, RealType, RealType);
1307 template <MKL_INT,
int>
1310 template <MKL_INT BRNG,
int Bits>
1314 template <MKL_INT BRNG,
int Bits>
1318 template <MKL_INT BRNG,
int Bits>
1322 template <MKL_INT BRNG,
int Bits>
1326 template <MKL_INT BRNG,
int Bits>
1330 template <MKL_INT BRNG,
int Bits>
1334 template <MKL_INT BRNG,
int Bits>
1338 template <MKL_INT BRNG,
int Bits>
1342 template <MKL_INT BRNG,
int Bits>
1346 template <MKL_INT BRNG,
int Bits>
1350 template <MKL_INT BRNG,
int Bits>
1354 template <MKL_INT BRNG,
int Bits>
1358 template <MKL_INT BRNG,
int Bits>
1362 template <MKL_INT BRNG,
int Bits>
1366 template <MKL_INT BRNG,
int Bits>
1370 template <MKL_INT BRNG,
int Bits>
1374 template <MKL_INT BRNG,
int Bits>
1378 template <MKL_INT BRNG,
int Bits>
1380 float *, std::size_t,
const float *,
const float *);
1382 template <MKL_INT BRNG,
int Bits>
1384 double *, std::size_t,
const double *,
const double *);
1386 template <MKL_INT BRNG,
int Bits>
1390 template <MKL_INT BRNG,
int Bits>
1394 template <MKL_INT BRNG,
int Bits>
1397 template <MKL_INT BRNG,
int Bits>
1400 template <MKL_INT BRNG,
int Bits>
1404 template <MKL_INT BRNG,
int Bits>
1408 template <MKL_INT BRNG,
int Bits>
1412 template <MKL_INT BRNG,
int Bits>
1416 #endif // VSMC_HAS_MKL 1420 #endif // VSMC_RNG_INTERNAL_COMMON_HPP #define VSMC_DEFINE_TYPE_DISPATCH_TRAIT(Outer, Inner, Default)
void cauchy_distribution(RNGType &rng, std::size_t N, RealType *r, RealType a, RealType b)
Generating Cauchy random variates.
Extreme value distribution.
void normal_mv_distribution(RNGType &, std::size_t, RealType *, std::size_t, const RealType *, const RealType *)
Generating multivariate Normal random varaites.
void u01_lr_distribution(RNGType &, std::size_t, RealType *)
Random walk MCMC update with test function.
typename CtrTypeTrait< T >::type CtrType
Counter based RNG engine.
void logistic_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating logistic random variates.
void rayleigh_distribution(RNGType &, std::size_t, RealType *, RealType)
Generating rayleigh random variates.
void levy_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating levy random variates.
void u01_distribution(RNGType &, std::size_t, RealType *)
Generate standard uniform random variates.
void extreme_value_distribution(RNGType &rng, std::size_t N, RealType *r, RealType a, RealType b)
Generating extreme value random variates.
void normal_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating Normal random variates.
void fisher_f_distribution(RNGType &rng, std::size_t N, RealType *r, RealType m, RealType n)
Generating Fisher-F random variates.
typename KeyTypeTrait< T >::type KeyType
Exponential distribution.
Multivariate Normal distribution.
Normal random walk proposal.
void pareto_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating pareto random variates.
void lognormal_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating lognormal random variates.
void rand(RNGType &rng, ArcsineDistribution< RealType > &dist, std::size_t N, RealType *r)
void laplace_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating laplace random variates.
MKL VSLStreamStatePtr wrapper.
void chi_squared_distribution(RNGType &rng, std::size_t n, RealType *r, RealType df)
Generating random variates.
void uniform_real_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generate uniform real random variates with open/closed variants.
void beta_distribution(RNGType &rng, std::size_t n, RealType *r, RealType alpha, RealType beta)
Generating Beta random variates.
void weibull_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating weibull random variates.
void exponential_distribution(RNGType &rng, std::size_t N, RealType *r, RealType lambda)
Generating exponential random variates.
void uniform_bits_distribution(RNGType &, std::size_t, UIntType *)
Multivariate Normal random walk proposal.
Draw a single sample given weights.
void gamma_distribution(RNGType &rng, std::size_t n, RealType *r, RealType alpha, RealType beta)
Generating gamma random variates.
internal::MKLResultType< Bits > result_type
void student_t_distribution(RNGType &, std::size_t, RealType *, RealType)
Generating student-t random variates.