32 #ifndef VSMC_RNG_MKL_HPP 33 #define VSMC_RNG_MKL_HPP 38 #define VSMC_RUNTIME_WARNING_RNG_MKL_OFFSET \ 39 VSMC_RUNTIME_WARNING((offset < MaxOffset), \ 40 "**MKLEngine** EXCESS MAXIMUM NUMBER OF INDEPDENT RNG STREAMS") 42 #define VSMC_RUNTIME_ASSERT_RNG_MKL_DISCARD \ 43 VSMC_RUNTIME_ASSERT( \ 44 (nskip >= 0), "**MKLEngine::discard** INPUT IS NEGATIVE") 52 #if VSMC_NO_RUNTIME_ASSERT 57 #else // VSMC_NO_RUNTIME_ASSERT 60 if (status == VSL_ERROR_OK)
68 msg +=
"; MKL function: ";
70 msg +=
"; Error code: ";
71 msg += std::to_string(status);
77 #endif // VSMC_NO_RUNTIME_ASSERT 86 explicit MKLStream(::VSLStreamStatePtr ptr =
nullptr) : ptr_(nullptr)
92 MKLStream(MKL_INT brng, MKL_UINT seed) : ptr_(nullptr)
98 MKLStream(MKL_INT brng, MKL_INT n,
unsigned *params) : ptr_(nullptr)
100 reset(brng, n, params);
106 ::VSLStreamStatePtr ptr =
nullptr;
108 "MKLStream::MKLStream",
"::vslCopyStream") == VSL_ERROR_OK) {
116 if (
this != &other) {
117 ::VSLStreamStatePtr ptr =
nullptr;
119 "MKLStream::operator=",
120 "::vslCopyStream") == VSL_ERROR_OK) {
132 if (
this != &other) {
135 other.ptr_ =
nullptr;
146 int status = release();
153 int reset(MKL_INT brng, MKL_UINT seed)
155 ::VSLStreamStatePtr ptr =
nullptr;
158 "MKLStream::reset",
"::vslNewStream");
159 if (status == VSL_ERROR_OK)
166 int reset(MKL_INT brng, MKL_INT n,
unsigned *params)
168 ::VSLStreamStatePtr ptr =
nullptr;
171 "MKLStream::reset",
"::vslNewStreamEx");
172 if (status == VSL_ERROR_OK)
185 "MKLStream::release",
"::vslDeleteStream");
191 bool empty()
const {
return ptr_ ==
nullptr; }
194 int save_f(
const std::string &fname)
const 197 "MKLStream::save_f",
"::vslSaveStreamF");
203 ::VSLStreamStatePtr ptr =
nullptr;
206 "MKLStream::load_f",
"::vslSaveStreamF");
207 if (status == VSL_ERROR_OK)
217 "MKLStream::save_m",
"::vslSaveStreamM");
223 ::VSLStreamStatePtr ptr =
nullptr;
225 "MKLStream::load_m",
"::vslLoadStreamM");
226 if (status == VSL_ERROR_OK)
233 int get_size()
const { return ::vslGetStreamSize(ptr_); }
239 ::vslLeapfrogStream(ptr_, k, nstreams),
"MKLStream::leapfrog",
240 "::vslLeapfrogStream");
247 "MKLStream::skip_ahead",
"::vslSkipAheadStream");
251 int get_brng()
const { return ::vslGetStreamStateBrng(ptr_); }
258 MKL_INT brng, ::VSLBRngProperties *properties)
261 ::vslGetBrngProperties(brng, properties),
262 "MKLStream::get_brng_properties",
"::vslGetBrngProperties");
270 return ::vslLeapfrogStream(stream.ptr_, 1, 2) == VSL_ERROR_OK;
278 return ::vslSkipAheadStream(stream.ptr_, 1) == VSL_ERROR_OK;
283 MKL_INT brng, MKL_INT method = VSL_RNG_METHOD_UNIFORMBITS32_STD)
288 return ::viRngUniformBits32(method, stream.ptr_, 1, &r) ==
294 MKL_INT brng, MKL_INT method = VSL_RNG_METHOD_UNIFORMBITS64_STD)
297 unsigned MKL_INT64 r;
299 return ::viRngUniformBits64(method, stream.ptr_, 1, &r) ==
304 int uniform(MKL_INT n,
float *r,
float a,
float b,
305 MKL_INT method = VSL_RNG_METHOD_UNIFORM_STD)
308 ::vsRngUniform(method, ptr_, n, r, a, b),
"MKLStream::uniform",
313 int uniform(MKL_INT n,
double *r,
double a,
double b,
314 MKL_INT method = VSL_RNG_METHOD_UNIFORM_STD)
317 ::vdRngUniform(method, ptr_, n, r, a, b),
"MKLStream::uniform",
322 int gaussian(MKL_INT n,
float *r,
float a,
float sigma,
323 MKL_INT method = VSL_RNG_METHOD_GAUSSIAN_BOXMULLER2)
326 ::vsRngGaussian(method, ptr_, n, r, a, sigma),
327 "MKLStream::gaussian",
"::vsRngGaussian");
331 int gaussian(MKL_INT n,
double *r,
double a,
double sigma,
332 MKL_INT method = VSL_RNG_METHOD_GAUSSIAN_BOXMULLER2)
335 ::vdRngGaussian(method, ptr_, n, r, a, sigma),
336 "MKLStream::gaussian",
"::vdRngGaussian");
340 int gaussian_mv(MKL_INT n,
float *r, MKL_INT dimen, MKL_INT mstorage,
341 const float *a,
const float *t,
342 MKL_INT method = VSL_RNG_METHOD_GAUSSIANMV_BOXMULLER2)
345 ::vsRngGaussianMV(method, ptr_, n, r, dimen, mstorage, a, t),
346 "MKLStream::gaussian_mv",
"::vsRngGaussianMV");
350 int gaussian_mv(MKL_INT n,
double *r, MKL_INT dimen, MKL_INT mstorage,
351 const double *a,
const double *t,
352 MKL_INT method = VSL_RNG_METHOD_GAUSSIANMV_BOXMULLER2)
355 ::vdRngGaussianMV(method, ptr_, n, r, dimen, mstorage, a, t),
356 "MKLStream::gaussian_mv",
"::vdRngGaussianMV");
361 MKL_INT method = VSL_RNG_METHOD_EXPONENTIAL_ICDF)
364 ::vsRngExponential(method, ptr_, n, r, a, beta),
365 "MKLStream::exponential",
"::vsRngExponential");
370 MKL_INT method = VSL_RNG_METHOD_EXPONENTIAL_ICDF)
373 ::vdRngExponential(method, ptr_, n, r, a, beta),
374 "MKLStream::exponential",
"::vdRngExponential");
378 int laplace(MKL_INT n,
float *r,
float a,
float beta,
379 MKL_INT method = VSL_RNG_METHOD_LAPLACE_ICDF)
382 ::vsRngLaplace(method, ptr_, n, r, a, beta),
"MKLStream::laplace",
387 int laplace(MKL_INT n,
double *r,
double a,
double beta,
388 MKL_INT method = VSL_RNG_METHOD_LAPLACE_ICDF)
391 ::vdRngLaplace(method, ptr_, n, r, a, beta),
"MKLStream::laplace",
396 int weibull(MKL_INT n,
float *r,
float alpha,
float a,
float beta,
397 MKL_INT method = VSL_RNG_METHOD_WEIBULL_ICDF)
400 ::vsRngWeibull(method, ptr_, n, r, alpha, a, beta),
401 "MKLStream::weibull",
"::vsRngWeibull");
405 int weibull(MKL_INT n,
double *r,
double alpha,
double a,
double beta,
406 MKL_INT method = VSL_RNG_METHOD_WEIBULL_ICDF)
409 ::vdRngWeibull(method, ptr_, n, r, alpha, a, beta),
410 "MKLStream::weibull",
"::vdRngWeibull");
414 int cauchy(MKL_INT n,
float *r,
float a,
float beta,
415 MKL_INT method = VSL_RNG_METHOD_CAUCHY_ICDF)
418 ::vsRngCauchy(method, ptr_, n, r, a, beta),
"MKLStream::cauchy",
423 int cauchy(MKL_INT n,
double *r,
double a,
double beta,
424 MKL_INT method = VSL_RNG_METHOD_CAUCHY_ICDF)
427 ::vdRngCauchy(method, ptr_, n, r, a, beta),
"MKLStream::cauchy",
432 int rayleigh(MKL_INT n,
float *r,
float a,
float beta,
433 MKL_INT method = VSL_RNG_METHOD_RAYLEIGH_ICDF)
436 ::vsRngRayleigh(method, ptr_, n, r, a, beta),
437 "MKLStream::rayleigh",
"::vsRngRayleigh");
441 int rayleigh(MKL_INT n,
double *r,
double a,
double beta,
442 MKL_INT method = VSL_RNG_METHOD_RAYLEIGH_ICDF)
445 ::vdRngRayleigh(method, ptr_, n, r, a, beta),
446 "MKLStream::rayleigh",
"::vdRngRayleigh");
450 int lognormal(MKL_INT n,
float *r,
float a,
float sigma,
float b,
451 float beta, MKL_INT method = VSL_RNG_METHOD_LOGNORMAL_BOXMULLER2)
454 ::vsRngLognormal(method, ptr_, n, r, a, sigma, b, beta),
455 "MKLStream::lognormal",
"::vsRngLognormal");
459 int lognormal(MKL_INT n,
double *r,
double a,
double sigma,
double b,
460 double beta, MKL_INT method = VSL_RNG_METHOD_LOGNORMAL_BOXMULLER2)
463 ::vdRngLognormal(method, ptr_, n, r, a, sigma, b, beta),
464 "MKLStream::lognormal",
"::vdRngLognormal");
468 int gumbel(MKL_INT n,
float *r,
float a,
float beta,
469 MKL_INT method = VSL_RNG_METHOD_GUMBEL_ICDF)
472 ::vsRngGumbel(method, ptr_, n, r, a, beta),
"MKLStream::gumbel",
477 int gumbel(MKL_INT n,
double *r,
double a,
double beta,
478 MKL_INT method = VSL_RNG_METHOD_GUMBEL_ICDF)
481 ::vdRngGumbel(method, ptr_, n, r, a, beta),
"MKLStream::gumbel",
486 int gamma(MKL_INT n,
float *r,
float alpha,
float a,
float beta,
487 MKL_INT method = VSL_RNG_METHOD_GAMMA_GNORM)
490 ::vsRngGamma(method, ptr_, n, r, alpha, a, beta),
491 "MKLStream::gamma",
"::vsRngGamma");
495 int gamma(MKL_INT n,
double *r,
double alpha,
double a,
double beta,
496 MKL_INT method = VSL_RNG_METHOD_GAMMA_GNORM)
499 ::vdRngGamma(method, ptr_, n, r, alpha, a, beta),
500 "MKLStream::gamma",
"::vdRngGamma");
504 int beta(MKL_INT n,
float *r,
float p,
float q,
float a,
float beta,
505 MKL_INT method = VSL_RNG_METHOD_BETA_CJA)
508 ::vsRngBeta(method, ptr_, n, r, p, q, a, beta),
"MKLStream::beta",
513 int beta(MKL_INT n,
double *r,
double p,
double q,
double a,
double beta,
514 MKL_INT method = VSL_RNG_METHOD_BETA_CJA)
517 ::vdRngBeta(method, ptr_, n, r, p, q, a, beta),
"MKLStream::beta",
523 MKL_INT method = VSL_RNG_METHOD_UNIFORM_STD)
526 ::viRngUniform(method, ptr_, n, r, a, b),
"MKLStream::uniform",
532 MKL_INT method = VSL_RNG_METHOD_UNIFORMBITS_STD)
535 ::viRngUniformBits(method, ptr_, n, r),
"MKLStream::uniform_bits",
536 "::viRngUniformBits");
541 MKL_INT method = VSL_RNG_METHOD_UNIFORMBITS32_STD)
544 ::viRngUniformBits32(method, ptr_, n, r),
545 "MKLStream::uniform_bits32",
"::viRngUniformBits32");
550 MKL_INT method = VSL_RNG_METHOD_UNIFORMBITS64_STD)
553 ::viRngUniformBits64(method, ptr_, n, r),
554 "MKLStream::uniform_bits64",
"::viRngUniformBits64");
559 MKL_INT method = VSL_RNG_METHOD_BERNOULLI_ICDF)
562 ::viRngBernoulli(method, ptr_, n, r, p),
"MKLStream::bernoulli",
568 MKL_INT method = VSL_RNG_METHOD_GEOMETRIC_ICDF)
571 ::viRngGeometric(method, ptr_, n, r, p),
"MKLStream::geometric",
576 int binomial(MKL_INT n,
int *r,
int ntrial,
double p,
577 MKL_INT method = VSL_RNG_METHOD_BINOMIAL_BTPE)
580 ::viRngBinomial(method, ptr_, n, r, ntrial, p),
581 "MKLStream::binomial",
"::viRngBinomial");
586 MKL_INT method = VSL_RNG_METHOD_HYPERGEOMETRIC_H2PE)
589 ::viRngHypergeometric(method, ptr_, n, r, l, s, m),
590 "MKLStream::hypergeometric",
"::viRngHypergeometric");
595 MKL_INT method = VSL_RNG_METHOD_POISSON_PTPE)
598 ::viRngPoisson(method, ptr_, n, r, lambda),
"MKLStream::poisson",
604 MKL_INT method = VSL_RNG_METHOD_POISSONV_POISNORM)
607 ::viRngPoissonV(method, ptr_, n, r, lambda),
608 "MKLStream::poisson_v",
"::viRngPoissonV");
613 MKL_INT method = VSL_RNG_METHOD_NEGBINOMIAL_NBAR)
616 ::viRngNegbinomial(method, ptr_, n, r, a, p),
617 "MKLStream::neg_binomial",
"::viRngNegbinomial");
621 ::VSLStreamStatePtr ptr_;
632 if (brng1 == VSL_BRNG_NONDETERM)
635 std::size_t n =
static_cast<std::size_t
>(stream1.
get_size());
638 stream1.
save_m(s1.data());
639 stream2.
save_m(s2.data());
650 return !(stream1 == stream2);
655 template <
typename CharT,
typename Traits>
657 std::basic_ostream<CharT, Traits> &os,
const MKLStream &stream)
662 std::size_t n =
static_cast<std::size_t
>(stream.
get_size());
663 std::size_t m =
sizeof(std::uintmax_t);
668 stream.
save_m(reinterpret_cast<char *>(s.data()));
678 template <
typename CharT,
typename Traits>
680 std::basic_istream<CharT, Traits> &is,
MKLStream &stream)
687 is >> std::ws >> brng;
692 tmp.
load_m(reinterpret_cast<const char *>(s.data()));
693 stream = std::move(tmp);
702 template <MKL_INT BRNG>
709 :
public std::integral_constant<MKL_INT, 6024>
714 class MKLMaxOffset<VSL_BRNG_WH> :
public std::integral_constant<MKL_INT, 273>
718 template <MKL_INT BRNG, MKL_INT MaxOffset = MKLMaxOffset<BRNG>::value>
722 static MKL_INT
eval(MKL_INT offset)
726 return BRNG + offset % MaxOffset;
730 template <MKL_INT BRNG>
734 static MKL_INT
eval(MKL_INT) {
return BRNG; }
751 using type =
unsigned MKL_INT64;
790 template <MKL_INT BRNG,
int Bits>
793 static_assert(Bits == 32 || Bits == 64,
794 "**MKLEngine** USED WITH Bits OTHER THAN 32, OR 64");
801 template <
typename SeedSeq>
813 "**MKLEngine** DOES NOT SUPPORT OFFSETING");
818 template <
typename SeedSeq>
825 "**MKLEngine** DOES NOT SUPPORT OFFSETING");
832 s %=
static_cast<result_type>(std::numeric_limits<MKL_UINT>::max());
833 MKL_INT brng = stream_.empty() ? BRNG : stream_.get_brng();
834 stream_.reset(brng, static_cast<MKL_UINT>(s));
838 template <
typename SeedSeq>
843 MKL_INT brng = stream_.empty() ? BRNG : stream_.get_brng();
845 MKL_INT n = seed_params(brng, seq, params);
846 stream_.reset(brng, n, params.data());
853 "**MKLEngine** DOES NOT SUPPORT OFFSETING");
855 s %=
static_cast<result_type>(std::numeric_limits<MKL_UINT>::max());
857 stream_.reset(brng, static_cast<MKL_UINT>(s));
861 template <
typename SeedSeq>
862 void seed(MKL_INT offset, SeedSeq &seq,
863 typename std::enable_if<
867 "**MKLEngine** DOES NOT SUPPORT OFFSETING");
871 MKL_INT n = seed_params(brng, seq, params);
872 stream_.reset(brng, n, params.data());
883 return buffer_[index_++];
888 internal::size_check<MKL_INT>(n,
"MKLEngine::operator()");
890 const std::size_t remain = M_ - index_;
893 std::copy_n(buffer_.data() + index_, n, r);
898 std::copy_n(buffer_.data() + index_, remain, r);
903 const std::size_t m = n / M_ * M_;
904 const std::size_t l = n % M_;
906 stream_, static_cast<MKL_INT>(m), r);
910 std::copy_n(buffer_.data(), l, r);
917 const std::size_t remain = M_ - index_;
930 const long long remain =
static_cast<long long>(M_ - index_);
931 if (nskip <= remain) {
932 index_ +=
static_cast<std::size_t
>(nskip);
938 ::VSLBRngProperties properties;
940 const int bits = properties.NBits;
941 const long long M =
static_cast<long long>(M_);
942 long long m = nskip / M * M;
944 m *= Bits / bits + (Bits % bits == 0 ? 0 : 1);
945 switch (stream_.get_brng()) {
946 case VSL_BRNG_MCG31: stream_.skip_ahead(m);
break;
947 case VSL_BRNG_MRG32K3A: stream_.skip_ahead(m);
break;
948 case VSL_BRNG_MCG59: stream_.skip_ahead(m);
break;
949 case VSL_BRNG_WH: stream_.skip_ahead(m);
break;
950 case VSL_BRNG_MT19937: stream_.skip_ahead(m);
break;
951 case VSL_BRNG_SFMT19937: stream_.skip_ahead(m);
break;
952 case VSL_BRNG_SOBOL: stream_.skip_ahead(m);
break;
953 case VSL_BRNG_NIEDERR: stream_.skip_ahead(m);
break;
954 #if INTEL_MKL_VERSION >= 110300 955 case VSL_BRNG_PHILOX4X32X10: stream_.skip_ahead(m);
break;
956 case VSL_BRNG_ARS5: stream_.skip_ahead(m);
break;
965 index_ =
static_cast<std::size_t
>(nskip % M);
970 return std::numeric_limits<result_type>::min();
975 return std::numeric_limits<result_type>::max();
987 if (eng1.stream_ != eng2.stream_)
989 if (eng1.buffer_ != eng2.buffer_)
991 if (eng1.index_ != eng2.index_)
1002 return !(eng1 == eng2);
1005 template <
typename CharT,
typename Traits>
1007 std::basic_ostream<CharT, Traits> &os,
1013 os << eng.stream_ <<
' ';
1014 os << eng.buffer_ <<
' ';
1020 template <
typename CharT,
typename Traits>
1030 is >> std::ws >> stream;
1031 is >> std::ws >> buffer;
1032 is >> std::ws >> index;
1035 eng.stream_ = std::move(stream);
1036 eng.buffer_ = std::move(buffer);
1054 stream_, static_cast<MKL_INT>(M_), buffer_.data());
1057 template <
typename SeedSeq>
1060 ::VSLBRngProperties properties;
1062 MKL_INT n = properties.NSeeds;
1063 params.resize(static_cast<std::size_t>(n));
1064 seq.generate(params.begin(), params.end());
1112 #if INTEL_MKL_VERSION >= 110300 1130 #endif // INTEL_MKL_VERSION >= 110300 1132 template <MKL_INT BRNG,
int Bits>
1139 template <MKL_INT BRNG,
int Bits>
1141 float *r,
float alpha,
float beta)
1143 internal::size_check<MKL_INT>(n,
"beta_distribution)");
1144 rng.
stream().beta(static_cast<MKL_INT>(n), r, alpha, beta, 0, 1);
1147 template <MKL_INT BRNG,
int Bits>
1149 double *r,
double alpha,
double beta)
1151 internal::size_check<MKL_INT>(n,
"beta_distribution)");
1152 rng.
stream().beta(static_cast<MKL_INT>(n), r, alpha, beta, 0, 1);
1155 template <MKL_INT BRNG,
int Bits>
1159 internal::size_check<MKL_INT>(n,
"cauchy_distribution)");
1160 rng.
stream().cauchy(static_cast<MKL_INT>(n), r, a, b);
1163 template <MKL_INT BRNG,
int Bits>
1167 internal::size_check<MKL_INT>(n,
"cauchy_distribution)");
1168 rng.
stream().cauchy(static_cast<MKL_INT>(n), r, a, b);
1171 template <MKL_INT BRNG,
int Bits>
1175 internal::size_check<MKL_INT>(n,
"exponential_distribution)");
1176 rng.
stream().exponential(static_cast<MKL_INT>(n), r, 0, 1 / lambda);
1179 template <MKL_INT BRNG,
int Bits>
1183 internal::size_check<MKL_INT>(n,
"exponential_distribution)");
1184 rng.
stream().exponential(static_cast<MKL_INT>(n), r, 0, 1 / lambda);
1187 template <MKL_INT BRNG,
int Bits>
1191 internal::size_check<MKL_INT>(n,
"extreme_value_distribution)");
1192 rng.
stream().gumbel(static_cast<MKL_INT>(n), r, a, b);
1193 sub(n, 2 * a, r, r);
1196 template <MKL_INT BRNG,
int Bits>
1200 internal::size_check<MKL_INT>(n,
"extreme_value_distribution)");
1201 rng.
stream().gumbel(static_cast<MKL_INT>(n), r, a, b);
1202 sub(n, 2 * a, r, r);
1205 template <MKL_INT BRNG,
int Bits>
1207 float *r,
float alpha,
float beta)
1209 internal::size_check<MKL_INT>(n,
"gamma_distribution)");
1210 rng.
stream().gamma(static_cast<MKL_INT>(n), r, alpha, 0, beta);
1213 template <MKL_INT BRNG,
int Bits>
1215 double *r,
double alpha,
double beta)
1217 internal::size_check<MKL_INT>(n,
"gamma_distribution)");
1218 rng.
stream().gamma(static_cast<MKL_INT>(n), r, alpha, 0, beta);
1221 template <MKL_INT BRNG,
int Bits>
1223 float *r,
float location,
float scale)
1225 internal::size_check<MKL_INT>(n,
"lapace_distribution)");
1226 rng.
stream().laplace(static_cast<MKL_INT>(n), r, location, scale);
1229 template <MKL_INT BRNG,
int Bits>
1231 double *r,
double location,
double scale)
1233 internal::size_check<MKL_INT>(n,
"lapace_distribution)");
1234 rng.
stream().laplace(static_cast<MKL_INT>(n), r, location, scale);
1237 template <MKL_INT BRNG,
int Bits>
1241 internal::size_check<MKL_INT>(n,
"lognormal_distribution)");
1242 rng.
stream().lognormal(static_cast<MKL_INT>(n), r, m, s, 0, 1);
1245 template <MKL_INT BRNG,
int Bits>
1249 internal::size_check<MKL_INT>(n,
"lognormal_distribution)");
1250 rng.
stream().lognormal(static_cast<MKL_INT>(n), r, m, s, 0, 1);
1253 template <MKL_INT BRNG,
int Bits>
1255 float *r,
float mean,
float stddev)
1257 internal::size_check<MKL_INT>(n,
"normal_distribution)");
1258 rng.
stream().gaussian(static_cast<MKL_INT>(n), r, mean, stddev);
1261 template <MKL_INT BRNG,
int Bits>
1263 double *r,
double mean,
double stddev)
1265 internal::size_check<MKL_INT>(n,
"normal_distribution)");
1266 rng.
stream().gaussian(static_cast<MKL_INT>(n), r, mean, stddev);
1269 template <MKL_INT BRNG,
int Bits>
1271 float *r, std::size_t m,
const float *mean,
const float *chol)
1273 internal::size_check<MKL_INT>(n,
"normal_mv_distribution)");
1274 internal::size_check<MKL_INT>(m,
"normal_mv_distribution)");
1275 rng.
stream().gaussian_mv(static_cast<MKL_INT>(n), r,
1276 static_cast<MKL_INT>(m), VSL_MATRIX_STORAGE_PACKED, mean, chol);
1279 template <MKL_INT BRNG,
int Bits>
1281 double *r, std::size_t m,
const double *mean,
const double *chol)
1283 internal::size_check<MKL_INT>(n,
"normal_mv_distribution)");
1284 internal::size_check<MKL_INT>(m,
"normal_mv_distribution)");
1285 rng.
stream().gaussian_mv(static_cast<MKL_INT>(n), r,
1286 static_cast<MKL_INT>(m), VSL_MATRIX_STORAGE_PACKED, mean, chol);
1289 template <MKL_INT BRNG,
int Bits>
1293 internal::size_check<MKL_INT>(n,
"rayleigh_distribution)");
1298 template <MKL_INT BRNG,
int Bits>
1302 internal::size_check<MKL_INT>(n,
"rayleigh_distribution)");
1307 template <MKL_INT BRNG,
int Bits>
1311 internal::size_check<MKL_INT>(n,
"u01_distribution)");
1312 rng.
stream().uniform(static_cast<MKL_INT>(n), r, 0, 1);
1315 template <MKL_INT BRNG,
int Bits>
1319 internal::size_check<MKL_INT>(n,
"u01_distribution)");
1320 rng.
stream().uniform(static_cast<MKL_INT>(n), r, 0, 1);
1323 template <MKL_INT BRNG,
int Bits>
1327 internal::size_check<MKL_INT>(n,
"u01_co_distribution)");
1328 rng.
stream().uniform(static_cast<MKL_INT>(n), r, 0, 1);
1331 template <MKL_INT BRNG,
int Bits>
1335 internal::size_check<MKL_INT>(n,
"u01_co_distribution)");
1336 rng.
stream().uniform(static_cast<MKL_INT>(n), r, 0, 1);
1339 template <MKL_INT BRNG,
int Bits>
1343 internal::size_check<MKL_INT>(n,
"uniform_real_distribution)");
1344 rng.
stream().uniform(static_cast<MKL_INT>(n), r, a, b);
1347 template <MKL_INT BRNG,
int Bits>
1351 internal::size_check<MKL_INT>(n,
"uniform_real_distribution)");
1352 rng.
stream().uniform(static_cast<MKL_INT>(n), r, a, b);
1355 template <MKL_INT BRNG,
int Bits>
1359 internal::size_check<MKL_INT>(n,
"weibull_distribution)");
1360 rng.
stream().weibull(static_cast<MKL_INT>(n), r, a, 0, b);
1363 template <MKL_INT BRNG,
int Bits>
1367 internal::size_check<MKL_INT>(n,
"weibull_distribution)");
1368 rng.
stream().weibull(static_cast<MKL_INT>(n), r, a, 0, b);
1374 template <
typename RNGType>
1378 unsigned reserved1[2];
1379 unsigned reserved2[2];
1383 template <
typename RNGType>
1386 return (
sizeof(
typename RNGType::ctr_type) +
1387 sizeof(
typename RNGType::key_type)) /
1391 template <
typename RNGType>
1397 template <
typename RNGType>
1400 return mkl_nseeds<RNGType>(std::integral_constant<
1401 bool, (std::is_same<CtrType<RNGType>, NullType>::value ||
1402 std::is_same<KeyType<RNGType>, NullType>::value)>());
1405 template <
typename RNGType>
1407 RNGType &rng,
int n,
const unsigned *param, std::false_type)
1409 int nc =
static_cast<int>(
1410 sizeof(
typename RNGType::ctr_type) /
sizeof(
unsigned));
1411 int nk =
static_cast<int>(
1412 sizeof(
typename RNGType::key_type) /
sizeof(
unsigned));
1413 new (
static_cast<void *
>(&rng)) RNGType();
1417 static_cast<std::size_t
>(std::min(n, nk)) *
sizeof(
unsigned);
1418 typename RNGType::key_type key;
1419 std::fill(key.begin(), key.end(), 0);
1420 std::memcpy(key.data(), param, size);
1428 static_cast<std::size_t
>(std::min(n, nc)) *
sizeof(
unsigned);
1429 typename RNGType::ctr_type ctr;
1430 std::fill(ctr.begin(), ctr.end(), 0);
1431 std::memcpy(ctr.data(), param, size);
1438 template <
typename RNGType>
1439 inline int mkl_init(RNGType &rng,
int n,
const unsigned *param, std::true_type)
1442 new (
static_cast<void *
>(&rng)) RNGType();
1444 new (
static_cast<void *
>(&rng))
1445 RNGType(static_cast<typename RNGType::result_type>(param[0]));
1451 template <
typename RNGType>
1453 int method, ::VSLStreamStatePtr stream,
int n,
const unsigned *param)
1457 if (method == VSL_INIT_METHOD_STANDARD) {
1460 std::integral_constant<
1465 if (method == VSL_INIT_METHOD_LEAPFROG)
1466 return VSL_RNG_ERROR_LEAPFROG_UNSUPPORTED;
1468 if (method == VSL_INIT_METHOD_SKIPAHEAD)
1469 rng.discard(static_cast<unsigned>(n));
1474 template <
typename RNGType,
typename RealType>
1476 ::VSLStreamStatePtr stream,
int n, RealType *r, RealType a, RealType b)
1484 template <
typename RNGType>
1501 template <
typename RNGType>
1504 static ::VSLBRngProperties properties = {
1506 internal::mkl_nseeds<RNGType>(), 1, 4, 32, internal::mkl_init<RNGType>,
1507 internal::mkl_uniform_real<RNGType, float>,
1508 internal::mkl_uniform_real<RNGType, double>,
1509 internal::mkl_uniform_int<RNGType>};
1510 static int brng = ::vslRegisterBrng(&properties);
1517 #endif // VSMC_RNG_MKL_HPP std::vector< T, Alloc > Vector
std::vector with Allocator as default allocator
int gumbel(MKL_INT n, float *r, float a, float beta, MKL_INT method=VSL_RNG_METHOD_GUMBEL_ICDF)
vsRngGumbel
MKLStream & operator=(MKLStream &&other)
void cauchy_distribution(RNGType &rng, std::size_t N, RealType *r, RealType a, RealType b)
Generating Cauchy random variates.
static int get_num_reg_brngs()
vslGetNumRegBrngs
static MKL_INT eval(MKL_INT)
std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &is, std::array< T, N > &ary)
MKLStream(MKL_INT brng, MKL_INT n, unsigned *params)
vslNewStreamEx
int gamma(MKL_INT n, double *r, double alpha, double a, double beta, MKL_INT method=VSL_RNG_METHOD_GAMMA_GNORM)
vdRngGamma
int exponential(MKL_INT n, float *r, float a, float beta, MKL_INT method=VSL_RNG_METHOD_EXPONENTIAL_ICDF)
vsRngExponential
int uniform_bits32(MKL_INT n, unsigned *r, MKL_INT method=VSL_RNG_METHOD_UNIFORMBITS32_STD)
viRngUniform32
int gaussian_mv(MKL_INT n, float *r, MKL_INT dimen, MKL_INT mstorage, const float *a, const float *t, MKL_INT method=VSL_RNG_METHOD_GAUSSIANMV_BOXMULLER2)
vsRngGaussianMV
std::size_t discard()
Discard the buffer.
#define VSMC_RUNTIME_WARNING_RNG_MKL_OFFSET
int geometric(MKL_INT n, int *r, double p, MKL_INT method=VSL_RNG_METHOD_GEOMETRIC_ICDF)
viRngGeometric
int gaussian(MKL_INT n, double *r, double a, double sigma, MKL_INT method=VSL_RNG_METHOD_GAUSSIAN_BOXMULLER2)
vdRngGaussian
void normal_mv_distribution(RNGType &, std::size_t, RealType *, std::size_t, const RealType *, const RealType *)
Generating multivariate Normal random varaites.
int gaussian(MKL_INT n, float *r, float a, float sigma, MKL_INT method=VSL_RNG_METHOD_GAUSSIAN_BOXMULLER2)
vsRngGaussian
constexpr double const_sqrt_2< double >() noexcept
int rayleigh(MKL_INT n, double *r, double a, double beta, MKL_INT method=VSL_RNG_METHOD_RAYLEIGH_ICDF)
vdRngRayleigh
static bool has_leap_frog(MKL_INT brng)
Test if vslLeapfrogStream is supported.
int release()
vslDeleteStream
int leapfrog(MKL_INT k, MKL_INT nstreams)
vslLeapfrogStream
int get_size() const
vslGetStreamSize
int neg_binomial(MKL_INT n, int *r, double a, double p, MKL_INT method=VSL_RNG_METHOD_NEGBINOMIAL_NBAR)
viRngNegbinomial
MKLStream(MKL_INT brng, MKL_UINT seed)
vslNewStream
#define VSMC_RUNTIME_ASSERT(cond, msg)
typename CtrTypeTrait< T >::type CtrType
int gumbel(MKL_INT n, double *r, double a, double beta, MKL_INT method=VSL_RNG_METHOD_GUMBEL_ICDF)
vdRngGumbel
int get_brng() const
vslGetStreamStateBrng
void seed(SeedSeq &seq, typename std::enable_if< internal::is_seed_seq< SeedSeq, MKL_INT, result_type >::value >::type *=nullptr)
int hypergeometric(MKL_INT n, int *r, int l, int s, int m, MKL_INT method=VSL_RNG_METHOD_HYPERGEOMETRIC_H2PE)
viRngHypergeometric
static int get_brng_properties(MKL_INT brng,::VSLBRngProperties *properties)
vslGetBrngProperties
void seed(MKL_INT offset, result_type s)
constexpr int mkl_nseeds(std::false_type)
friend bool operator==(const MKLEngine< BRNG, Bits > &eng1, const MKLEngine< BRNG, Bits > &eng2)
eng1 == eng2 is a sufficent condition for subsequent call of operator() output the same results...
static bool has_uniform_bits32(MKL_INT brng, MKL_INT method=VSL_RNG_METHOD_UNIFORMBITS32_STD)
Test if viRngUniformBits32 is supported.
MKLStream(MKLStream &&other)
int uniform(MKL_INT n, float *r, float a, float b, MKL_INT method=VSL_RNG_METHOD_UNIFORM_STD)
vsRngUniform
int poisson_v(MKL_INT n, int *r, const double *lambda, MKL_INT method=VSL_RNG_METHOD_POISSONV_POISNORM)
viRngPoissonV
void rayleigh_distribution(RNGType &, std::size_t, RealType *, RealType)
Generating rayleigh random variates.
static bool has_skip_ahead(MKL_INT brng)
Test if vslSkipAheadStream is supported.
bool operator!=(const SingleParticle< T > &sp1, const SingleParticle< T > &sp2)
int poisson(MKL_INT n, int *r, double lambda, MKL_INT method=VSL_RNG_METHOD_POISSON_PTPE)
viRngPoisson
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.
int uniform(MKL_INT n, double *r, double a, double b, MKL_INT method=VSL_RNG_METHOD_UNIFORM_STD)
vdRngUniform
static MKL_INT eval(MKL_INT offset)
int reset(::VSLStreamStatePtr ptr)
MKLStream(::VSLStreamStatePtr ptr=nullptr)
int uniform(MKL_INT n, int *r, int a, int b, MKL_INT method=VSL_RNG_METHOD_UNIFORM_STD)
viRngUniform
int reset(MKL_INT brng, MKL_INT n, unsigned *params)
vslNewStreamEx
void discard(long long nskip)
void normal_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating Normal random variates.
int save_m(char *memptr) const
vslSaveStreamM
static constexpr result_type min()
int beta(MKL_INT n, float *r, float p, float q, float a, float beta, MKL_INT method=VSL_RNG_METHOD_BETA_CJA)
vsRngBeta
typename KeyTypeTrait< T >::type KeyType
int beta(MKL_INT n, double *r, double p, double q, double a, double beta, MKL_INT method=VSL_RNG_METHOD_BETA_CJA)
vdRngBeta
int reset(MKL_INT brng, MKL_UINT seed)
vslNewStream
MKLEngine(MKL_INT offset, SeedSeq &seq, typename std::enable_if< internal::is_seed_seq< SeedSeq, MKL_INT, MKL_UINT, MKLEngine< BRNG, Bits >>::value >::type *=nullptr)
const MKLStream & stream() const
int weibull(MKL_INT n, double *r, double alpha, double a, double beta, MKL_INT method=VSL_RNG_METHOD_WEIBULL_ICDF)
vdRngWeibull
int gaussian_mv(MKL_INT n, double *r, MKL_INT dimen, MKL_INT mstorage, const double *a, const double *t, MKL_INT method=VSL_RNG_METHOD_GAUSSIANMV_BOXMULLER2)
vdRngGaussianMV
bool operator==(const SingleParticle< T > &sp1, const SingleParticle< T > &sp2)
int lognormal(MKL_INT n, float *r, float a, float sigma, float b, float beta, MKL_INT method=VSL_RNG_METHOD_LOGNORMAL_BOXMULLER2)
vsRngLognormal
int skip_ahead(long long nskip)
vslSkipAheadStream
int load_f(const std::string &fname)
vslSaveStreamF
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const std::array< T, N > &ary)
int weibull(MKL_INT n, float *r, float alpha, float a, float beta, MKL_INT method=VSL_RNG_METHOD_WEIBULL_ICDF)
vsRngWeibull
friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &is, MKLEngine< BRNG, Bits > &eng)
static bool has_uniform_bits64(MKL_INT brng, MKL_INT method=VSL_RNG_METHOD_UNIFORMBITS64_STD)
Test if viRngUniformBits64 is supported.
int load_m(const char *memptr)
vslLoadStreamM
int uniform_bits64(MKL_INT n, unsigned MKL_INT64 *r, MKL_INT method=VSL_RNG_METHOD_UNIFORMBITS64_STD)
viRngUniform64
int mkl_uniform_int(::VSLStreamStatePtr stream, int n, unsigned *r)
int bernoulli(MKL_INT n, int *r, double p, MKL_INT method=VSL_RNG_METHOD_BERNOULLI_ICDF)
viRngBernoulli
constexpr float const_sqrt_2< float >() noexcept
int cauchy(MKL_INT n, double *r, double a, double beta, MKL_INT method=VSL_RNG_METHOD_CAUCHY_ICDF)
vdRngCauchy
friend bool operator!=(const MKLEngine< BRNG, Bits > &eng1, const MKLEngine< BRNG, Bits > &eng2)
eng1 != eng2 is a necessary condition for subsequent call of operator() output different results...
int mkl_uniform_real(::VSLStreamStatePtr stream, int n, RealType *r, RealType a, RealType b)
int lognormal(MKL_INT n, double *r, double a, double sigma, double b, double beta, MKL_INT method=VSL_RNG_METHOD_LOGNORMAL_BOXMULLER2)
vdRngLognormal
void sub(std::size_t n, const float *a, const float *b, float *y)
MKLEngine(MKL_INT offset, result_type s)
int mkl_error_check(int status, const char *cpp, const char *c)
MKLEngine(SeedSeq &seq, typename std::enable_if< internal::is_seed_seq< SeedSeq, MKL_INT, result_type, MKLEngine< BRNG, Bits >>::value >::type *=nullptr)
int rayleigh(MKL_INT n, float *r, float a, float beta, MKL_INT method=VSL_RNG_METHOD_RAYLEIGH_ICDF)
vsRngRayleigh
void lognormal_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating lognormal random variates.
MKLEngine(result_type s=1)
void seed(MKL_INT offset, SeedSeq &seq, typename std::enable_if< internal::is_seed_seq< SeedSeq, MKL_UINT >::value >::type *=nullptr)
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.
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const MKLEngine< BRNG, Bits > &eng)
int save_f(const std::string &fname) const
vslSaveStreamF
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.
static constexpr result_type max()
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 *)
int gamma(MKL_INT n, float *r, float alpha, float a, float beta, MKL_INT method=VSL_RNG_METHOD_GAMMA_GNORM)
vsRngGamma
int mkl_brng()
Register a C++11 RNG as MKL BRNG.
int laplace(MKL_INT n, float *r, float a, float beta, MKL_INT method=VSL_RNG_METHOD_LAPLACE_ICDF)
vsRngLaplace
~MKLStream()
vslDeleteStream
MKLStream(const MKLStream &other)
vslCopyStream
void operator()(std::size_t n, result_type *r)
int uniform_bits(MKL_INT n, unsigned *r, MKL_INT method=VSL_RNG_METHOD_UNIFORMBITS_STD)
viRngUniform
int binomial(MKL_INT n, int *r, int ntrial, double p, MKL_INT method=VSL_RNG_METHOD_BINOMIAL_BTPE)
viRngBinomial
int mkl_init(RNGType &rng, int n, const unsigned *param, std::false_type)
int exponential(MKL_INT n, double *r, double a, double beta, MKL_INT method=VSL_RNG_METHOD_EXPONENTIAL_ICDF)
vdRngExponential
void gamma_distribution(RNGType &rng, std::size_t n, RealType *r, RealType alpha, RealType beta)
Generating gamma random variates.
MKLStream & operator=(const MKLStream &other)
vslCopyStream/vslCopySreamState
int laplace(MKL_INT n, double *r, double a, double beta, MKL_INT method=VSL_RNG_METHOD_LAPLACE_ICDF)
vdRngLaplace
internal::MKLResultType< Bits > result_type
typename MKLResultTypeTrait< Bits >::type MKLResultType
void u01_co_distribution(MKLEngine< BRNG, Bits > &rng, std::size_t n, float *r)
#define VSMC_RUNTIME_ASSERT_RNG_MKL_DISCARD
int cauchy(MKL_INT n, float *r, float a, float beta, MKL_INT method=VSL_RNG_METHOD_CAUCHY_ICDF)
vsRngCauchy