vSMC
vSMC: Scalable Monte Carlo
mkl.hpp
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/rng/mkl.hpp
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013,2014, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef VSMC_RNG_MKL_HPP
33 #define VSMC_RNG_MKL_HPP
34 
36 #include <mkl.h>
37 
38 #define VSMC_STATIC_ASSERT_RNG_MKL_VSL_DISTRIBUTION_FP_TYPE(FPType, Dist) \
39  VSMC_STATIC_ASSERT( \
40  (cxx11::is_same<FPType, float>::value || \
41  cxx11::is_same<FPType, double>::value), \
42  USE_MKL##Dist##Distribution_##WITH_A_RESULT_TYPE_OTHER_THAN_float_OR_double)
43 
44 #define VSMC_RUNTIME_ASSERT_RNG_MKL_VSL_OFFSET(offset) \
45  VSMC_RUNTIME_ASSERT((offset < max VSMC_MNE ()), \
46  ("**MKLOffsetDynamic** " \
47  "EXCESS MAXIMUM NUMBER OF INDEPDENT RNG STREAMS"))
48 
49 #ifndef VSMC_RNG_MKL_VSL_BUFFER_SIZE
50 #define VSMC_RNG_MKL_VSL_BUFFER_SIZE 1024
51 #endif
52 
53 #define VSMC_DEFINE_RNG_MKL_VSL_BRNG(BRNG) case BRNG : return #BRNG
54 
55 #define VSMC_DEFINE_RNG_MKL_VSL_ERR(STATUS) case STATUS : return #STATUS
56 
57 namespace vsmc {
58 
59 template <MKL_INT> class MKLStream;
60 template <typename, typename> class MKLDistribution;
61 template <MKL_INT, typename> class MKLEngine;
62 
65 
66 template <typename, MKL_INT = VSL_RNG_METHOD_UNIFORM_STD>
68 
69 template <MKL_INT = VSL_RNG_METHOD_BERNOULLI_ICDF>
71 template <MKL_INT = VSL_RNG_METHOD_GEOMETRIC_ICDF>
73 template <MKL_INT = VSL_RNG_METHOD_BINOMIAL_BTPE>
75 template <MKL_INT = VSL_RNG_METHOD_HYPERGEOMETRIC_H2PE>
77 template <MKL_INT = VSL_RNG_METHOD_POISSON_PTPE>
79 template <MKL_INT = VSL_RNG_METHOD_NEGBINOMIAL_NBAR>
81 template <typename = double, MKL_INT = VSL_RNG_METHOD_GAUSSIAN_BOXMULLER2>
83 template <typename = double, MKL_INT = VSL_RNG_METHOD_EXPONENTIAL_ICDF>
85 template <typename = double, MKL_INT = VSL_RNG_METHOD_LAPLACE_ICDF>
87 template <typename = double, MKL_INT = VSL_RNG_METHOD_WEIBULL_ICDF>
89 template <typename = double, MKL_INT = VSL_RNG_METHOD_CAUCHY_ICDF>
91 template <typename = double, MKL_INT = VSL_RNG_METHOD_RAYLEIGH_ICDF>
93 template <typename = double, MKL_INT = VSL_RNG_METHOD_LOGNORMAL_BOXMULLER2>
95 template <typename = double, MKL_INT = VSL_RNG_METHOD_GUMBEL_ICDF>
97 template <typename = double, MKL_INT = VSL_RNG_METHOD_GAMMA_GNORM>
99 template <typename = double, MKL_INT = VSL_RNG_METHOD_BETA_CJA>
101 
102 namespace internal {
103 
104 inline std::string mkl_vsl_brng_str (MKL_INT BRNG)
105 {
106  switch (BRNG) {
107  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_MCG31);
108  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_R250);
109  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_MRG32K3A);
110  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_WH);
111  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_MCG59);
112  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_MT19937);
113  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_MT2203);
114  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_SFMT19937);
115  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_SOBOL);
116  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_NIEDERR);
117  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_IABSTRACT);
118  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_DABSTRACT);
119  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_SABSTRACT);
120  VSMC_DEFINE_RNG_MKL_VSL_BRNG(VSL_BRNG_NONDETERM);
121  default : return "Unknown";
122  }
123 }
124 
125 inline std::string mkl_vsl_error_str (int status)
126 {
127  switch (status) {
128  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_ERROR_OK);
129  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_ERROR_BADARGS);
130  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_ERROR_CPU_NOT_SUPPORTED);
131  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_ERROR_FEATURE_NOT_IMPLEMENTED);
132  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_ERROR_MEM_FAILURE);
133  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_ERROR_NULL_PTR);
134  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_ERROR_UNKNOWN);
135  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BAD_FILE_FORMAT);
136  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BAD_MEM_FORMAT);
137  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BAD_NBITS);
138  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BAD_NSEEDS);
139  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BAD_STREAM);
140  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BAD_STREAM_STATE_SIZE);
141  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BAD_UPDATE);
142  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BAD_WORD_SIZE);
143  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BRNG_NOT_SUPPORTED);
144  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BRNG_TABLE_FULL);
145  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_BRNGS_INCOMPATIBLE);
146  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_FILE_CLOSE);
147  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_FILE_OPEN);
148  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_FILE_READ);
149  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_FILE_WRITE);
150  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_INVALID_ABSTRACT_STREAM);
151  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_INVALID_BRNG_INDEX);
152  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_LEAPFROG_UNSUPPORTED);
153  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_NO_NUMBERS);
154  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_QRNG_PERIOD_ELAPSED);
155  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_SKIPAHEAD_UNSUPPORTED);
156  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_UNSUPPORTED_FILE_VER);
157  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_NONDETERM_NOT_SUPPORTED);
158  VSMC_DEFINE_RNG_MKL_VSL_ERR(VSL_RNG_ERROR_NONDETERM_NRETRIES_EXCEEDED);
159  default : return "UNKNOWN";
160  }
161 }
162 
163 #if VSMC_NO_RUNTIME_ASSERT
164 inline void mkl_vsl_error_check (MKL_INT, int, const char *, const char *) {}
165 #else
166 inline void mkl_vsl_error_check (MKL_INT BRNG, int status,
167  const char *func, const char *mklf)
168 {
169  if (status == VSL_ERROR_OK)
170  return;
171 
172  std::string msg("**vsmc::");
173  msg += func;
174  msg += " failure";
175  msg += "; MKL function: ";
176  msg += mklf;
177 
178  msg += "; BRNG: ";
179  msg += mkl_vsl_brng_str(BRNG);
180  msg += "; Error code: ";
181  msg += mkl_vsl_error_str(status);
182 
183  VSMC_RUNTIME_ASSERT((status == VSL_ERROR_OK), msg.c_str());
184 } // error_check
185 #endif
186 
187 } // namespace vsmc::internal
188 
189 namespace traits {
190 
203 template <MKL_INT, typename> struct MKLUniformBitsTrait;
204 
207 template <MKL_INT BRNG> struct MKLUniformBitsTrait<BRNG, unsigned>
208 {
210  static VSMC_CONSTEXPR const unsigned min VSMC_MNE = 0;
211  static VSMC_CONSTEXPR const unsigned max VSMC_MNE =
212  static_cast<unsigned>(~(static_cast<unsigned>(0)));
213 }; // struct MKLUniformBitsTrait
214 
218 template <MKL_INT BRNG> struct MKLUniformBitsTrait<BRNG, unsigned MKL_INT64>
219 {
221  static VSMC_CONSTEXPR const unsigned MKL_INT64 min VSMC_MNE = 0;
222  static VSMC_CONSTEXPR const unsigned MKL_INT64 max VSMC_MNE =
223  static_cast<unsigned MKL_INT64>(~(static_cast<unsigned MKL_INT64>(0)));
224 }; // struct MKLUniformBitsTrait
225 
228 template <MKL_INT> struct MKLSeedTrait :
229  public cxx11::integral_constant<MKL_UINT, 101> {};
230 
232 template <> struct MKLSeedTrait<VSL_BRNG_SOBOL> :
233  public cxx11::integral_constant<MKL_UINT, 10> {};
234 
236 template <> struct MKLSeedTrait<VSL_BRNG_NIEDERR> :
237  public cxx11::integral_constant<MKL_UINT, 10> {};
238 
239 } // namespace traits
240 
241 namespace internal {
242 
244 {
245  static VSMC_CONSTEXPR MKL_INT min VSMC_MNE () {return 0;}
246  static VSMC_CONSTEXPR MKL_INT max VSMC_MNE () {return 0;}
247  static void offset (MKL_INT) {}
248  static VSMC_CONSTEXPR MKL_INT offset () {return 0;}
249 }; // struct OffsetZero
250 
251 template <MKL_INT MaxOffset>
253 {
254  MKLOffsetDynamic () : offset_(0) {}
255 
256  static VSMC_CONSTEXPR MKL_INT min VSMC_MNE () {return 0;}
257  static VSMC_CONSTEXPR MKL_INT max VSMC_MNE () {return MaxOffset;}
258 
259  void offset (MKL_INT n)
260  {
262  offset_ = n;
263  }
264 
265  MKL_INT offset () const {return offset_;}
266 
267  private :
268 
269  MKL_INT offset_;
270 }; // struct OffsetDynamic
271 
272 template <MKL_INT> struct MKLOffset {typedef MKLOffsetZero type;};
273 
274 template <>
275 struct MKLOffset<VSL_BRNG_MT2203> {typedef MKLOffsetDynamic<6024> type;};
276 
277 template <>
278 struct MKLOffset<VSL_BRNG_WH> {typedef MKLOffsetDynamic<273> type;};
279 
281 {
282  typedef long long size_type;
283 
284  template <MKL_INT BRNG>
285  void operator() (MKLStream<BRNG> &stream, size_type nskip)
286  {
287  if (nskip == 0)
288  return;
289 
290  int status = ::vslSkipAheadStream(stream.ptr(), nskip);
291  internal::mkl_vsl_error_check(BRNG, status,
292  "MKLSkipAheadVSL::skip", "::vslSkipAheadStream");
293  }
294 
295  static void buffer_size (MKL_INT) {}
296  static MKL_INT buffer_size () {return 0;}
297 }; // struct SkipAheadVSL
298 
299 template <MKL_INT BRNG, typename ResultType>
301 {
303 
305 
306  void operator() (MKLStream<BRNG> &stream, size_type nskip)
307  {
308  if (nskip == 0)
309  return;
310 
311  if (nskip < buffer_size_) {
312  if (buffer_.size() < nskip)
313  buffer_.resize(nskip);
314  uniform_bits_(stream, nskip, &buffer_[0]);
315  } else {
316  buffer_.resize(buffer_size_);
317  size_type repeat = nskip / buffer_size_;
318  size_type remain = nskip - repeat * buffer_size_;
319  for (size_type r = 1; r != repeat + 1; ++r) {
320  size_type n = r * buffer_size_;
321  uniform_bits_(stream, n, &buffer_[0]);
322  }
323  uniform_bits_(stream, remain, &buffer_[0]);
324  }
325  }
326 
327  void buffer_size (MKL_INT size)
328  {buffer_size_ = size > 0 ? size : VSMC_RNG_MKL_VSL_BUFFER_SIZE;}
329 
330  MKL_INT buffer_size () {return buffer_size_;}
331 
332  private :
333 
334  std::vector<ResultType, AlignedAllocator<ResultType> > buffer_;
336  MKL_INT buffer_size_;
337 }; // strut SkipAheadForce
338 
339 template <MKL_INT BRNG, typename ResultType>
342 
343 template <typename ResultType>
344 struct MKLSkipAhead<VSL_BRNG_MCG31, ResultType>
346 
347 template <typename ResultType>
348 struct MKLSkipAhead<VSL_BRNG_MCG59, ResultType>
350 
351 template <typename ResultType>
352 struct MKLSkipAhead<VSL_BRNG_MRG32K3A, ResultType>
354 
355 template <typename ResultType>
356 struct MKLSkipAhead<VSL_BRNG_SOBOL, ResultType>
358 
359 template <typename ResultType>
360 struct MKLSkipAhead<VSL_BRNG_NIEDERR, ResultType>
362 
363 } // namespace vsmc::internal
364 
367 template <MKL_INT BRNG>
368 class MKLStream : public internal::MKLOffset<BRNG>::type
369 {
370  public :
371 
373  MKL_INT offset = 0) :
374  seed_(s), stream_ptr_(VSMC_NULLPTR), property_()
375  {
376  this->offset(offset);
377  int status = VSL_ERROR_OK;
378 
379  status = ::vslNewStream(&stream_ptr_, BRNG + this->offset(), seed_);
380  internal::mkl_vsl_error_check(BRNG, status,
381  "MKLStream::Stream", "::vslNewStream");
382 
383  status = ::vslGetBrngProperties(BRNG, &property_);
384  internal::mkl_vsl_error_check(BRNG, status,
385  "MKLStream::Stream", "::vslGetBrngProperties");
386  }
387 
388  template <typename SeedSeq>
389  explicit MKLStream (SeedSeq &seq,
390  typename cxx11::enable_if<internal::is_seed_seq<SeedSeq,
391  MKL_UINT, MKLStream<BRNG> >::value>::type * = VSMC_NULLPTR) :
392  seed_(0), stream_ptr_(VSMC_NULLPTR), property_()
393  {
394  seq.generate(&seed_, &seed_ + 1);
395  int status = VSL_ERROR_OK;
396 
397  status = ::vslNewStream(&stream_ptr_, BRNG + this->offset(), seed_);
398  internal::mkl_vsl_error_check(BRNG, status,
399  "MKLStream::Stream", "::vslNewStream");
400 
401  status = ::vslGetBrngProperties(BRNG, &property_);
402  internal::mkl_vsl_error_check(BRNG, status,
403  "MKLStream::Stream", "::vslGetBrngProperties");
404  }
405 
406  MKLStream (const MKLStream<BRNG> &other) :
407  internal::MKLOffset<BRNG>::type(other),
408  seed_(other.seed_), property_(other.property_)
409  {
410  int status = ::vslCopyStream(&stream_ptr_, other.stream_ptr_);
411  internal::mkl_vsl_error_check(BRNG, status,
412  "MKLStream::Stream", "::vslCopyStream");
413  }
414 
416  {
417  if (this != &other) {
419  int status = ::vslCopyStreamState(stream_ptr_, other.stream_ptr_);
420  internal::mkl_vsl_error_check(BRNG, status,
421  "MKLStream::operator=", "::vslCopyStreamState");
422  property_ = other.property_;
423  }
424 
425  return *this;
426  }
427 
428 #if VSMC_HAS_CXX11_RVALUE_REFERENCES
430  internal::MKLOffset<BRNG>::type(cxx11::move(other)),
431  seed_(other.seed_), stream_ptr_(other.stream_ptr_),
432  property_(other.property_) {other.stream_ptr_ = VSMC_NULLPTR;}
433 
435  {
436  using std::swap;
437 
438  if (this != other) {
440  swap(seed_, other.seed_);
441  swap(stream_ptr_, other.stream_ptr_);
442  swap(property_, other.property_);
443  }
444 
445  return *this;
446  }
447 #endif
448 
450  {
451  if (stream_ptr_ != VSMC_NULLPTR)
452  ::vslDeleteStream(&stream_ptr_);
453  }
454 
455  void seed (MKL_UINT s)
456  {
457  seed_ = s;
458  int status = VSL_ERROR_OK;
459 
460  if (stream_ptr_ == VSMC_NULLPTR) {
461  status = ::vslNewStream(&stream_ptr_, BRNG + this->offset(), s);
462  internal::mkl_vsl_error_check(BRNG, status,
463  "MKLStream::seed", "::vslNewStream");
464  } else {
465  VSLStreamStatePtr new_stream_ptr;
466 
467  status = ::vslNewStream(&new_stream_ptr, BRNG + this->offset(), s);
468  internal::mkl_vsl_error_check(BRNG, status,
469  "MKLStream::seed", "::vslNewStream");
470 
471  status = ::vslCopyStreamState(stream_ptr_, new_stream_ptr);
472  internal::mkl_vsl_error_check(BRNG, status,
473  "MKLStream::seed", "::vslCopyStreamState");
474 
475  status = ::vslDeleteStream(&new_stream_ptr);
476  internal::mkl_vsl_error_check(BRNG, status,
477  "MKLStream::seed", "::vslDeleteStream");
478  }
479 
480  }
481 
482  template <typename SeedSeq>
483  void seed (SeedSeq &seq,
484  typename cxx11::enable_if<internal::is_seed_seq<SeedSeq,
485  MKL_UINT, MKLStream<BRNG> >::value>::type * = VSMC_NULLPTR)
486  {
487  seq.generate(&seed_, &seed_ + 1);
488  seed(seed_);
489  }
490 
491  VSLStreamStatePtr ptr () const {return stream_ptr_;}
492 
493  const VSLBRngProperties &property () const {return property_;}
494 
495  private :
496 
497  MKL_UINT seed_;
498  VSLStreamStatePtr stream_ptr_;
499  VSLBRngProperties property_;
500 }; // class MKLStream
501 
504 template <MKL_INT BRNG, typename ResultType>
505 class MKLEngine
506 {
507  public :
508 
509  typedef ResultType result_type;
511 
513  MKL_INT offset = 0) :
514  stream_(s, offset), buffer_size_(VSMC_RNG_MKL_VSL_BUFFER_SIZE),
515  index_(buffer_size_) {}
516 
517  template <typename SeedSeq>
518  explicit MKLEngine (SeedSeq &seq,
519  typename cxx11::enable_if<internal::is_seed_seq<SeedSeq,
521  >::value>::type * = VSMC_NULLPTR) :
522  stream_(seq), buffer_size_(VSMC_RNG_MKL_VSL_BUFFER_SIZE),
523  index_(buffer_size_) {}
524 
525  void seed (MKL_UINT s) {stream_.seed(s);}
526 
527  template <typename SeedSeq>
528  void seed (SeedSeq &seq,
529  typename cxx11::enable_if<internal::is_seed_seq<SeedSeq,
531  >::value>::type * = VSMC_NULLPTR)
532  {stream_.seed(seq);}
533 
534  result_type operator() ()
535  {
536  if (index_ == buffer_size_) {
537  buffer_.resize(static_cast<std::size_t>(buffer_size_));
538  uniform_bits_(stream_, buffer_size_, &buffer_[0]);
539  index_ = 0;
540  }
541 
542  return buffer_[static_cast<std::size_t>(index_++)];
543  }
544 
552  void discard (std::size_t nskip)
553  {
554  skip_ahead_(stream_, static_cast<typename
556  >(nskip));
557  index_ = buffer_size_;
558  }
559 
560  static VSMC_CONSTEXPR const result_type _Min =
562  static VSMC_CONSTEXPR const result_type _Max =
564 
565  static VSMC_CONSTEXPR result_type min VSMC_MNE () {return _Min;}
566  static VSMC_CONSTEXPR result_type max VSMC_MNE () {return _Max;}
567 
568  stream_type &stream () {return stream_;}
569  const stream_type &stream () const {return stream_;}
570 
572  void buffer_size (MKL_INT size)
573  {buffer_size_ = size > 0 ? size : VSMC_RNG_MKL_VSL_BUFFER_SIZE;}
574 
575  MKL_INT buffer_size () {return buffer_size_;}
576 
577  private :
578 
579  stream_type stream_;
582  std::vector<result_type, AlignedAllocator<result_type> > buffer_;
583  MKL_INT buffer_size_;
584  MKL_INT index_;
585 }; // class MKLEngine
586 
590 
594 
598 
602 
606 
610 
615 
619 
623 
626 template <typename ResultType, typename Derived>
627 class MKLDistribution
628 {
629  public :
630 
631  typedef ResultType result_type;
632 
634  buffer_size_(VSMC_RNG_MKL_VSL_BUFFER_SIZE), index_(buffer_size_) {}
635 
636  template <MKL_INT BRNG>
637  result_type operator() (MKLStream<BRNG> &stream)
638  {
639  if (index_ == buffer_size_) {
640  buffer_.resize(static_cast<std::size_t>(buffer_size_));
641  static_cast<Derived *>(this)->generate(stream, buffer_size_,
642  &buffer_[0]);
643  index_ = 0;
644  }
645 
646  return buffer_[index_++];
647  }
648 
649  template <MKL_INT BRNG>
650  void operator() (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
651  {static_cast<Derived *>(this)->generate(stream, n, r);}
652 
653  void reset () {index_ = buffer_size_;}
654 
656  void buffer_size (MKL_INT size)
657  {buffer_size_ = size > 0 ? size : VSMC_RNG_MKL_VSL_BUFFER_SIZE;}
658 
659  MKL_INT buffer_size () const {return buffer_size_;}
660 
661  protected :
662 
663  template <MKL_INT BRNG>
664  void generate_error_check (int status, const char *name)
665  {
666  if (status == VSL_ERROR_OK)
667  return;
668 
669  std::string dist_name(name);
670  dist_name = "MKL" + dist_name + "Distribution::generate";
671  std::string mkl_vsl_name(mkl_vsl_name_prefix(
672  static_cast<result_type>(0)));
673  mkl_vsl_name += "Rng";
674  mkl_vsl_name += name;
675  internal::mkl_vsl_error_check(BRNG, status,
676  dist_name.c_str(), mkl_vsl_name.c_str());
677  }
678 
679  private :
680 
681  std::vector<result_type, AlignedAllocator<result_type> > buffer_;
682  MKL_INT buffer_size_;
683  MKL_INT index_;
684 
685  std::string mkl_vsl_name_prefix (MKL_INT) {return "vi";}
686  std::string mkl_vsl_name_prefix (unsigned) {return "vi";}
687  std::string mkl_vsl_name_prefix (unsigned MKL_INT64) {return "vi";}
688  std::string mkl_vsl_name_prefix (float) {return "vs";}
689  std::string mkl_vsl_name_prefix (double) {return "vd";}
690 }; // class MKLDistribution
691 
695  public MKLDistribution<unsigned, MKLUniformBits32Distribution>
696 {
697  public :
698 
699  typedef unsigned result_type;
700 
701  template <MKL_INT BRNG>
702  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
703  {
704  int status = ::viRngUniformBits32(VSL_RNG_METHOD_UNIFORMBITS32_STD,
705  stream.ptr(), n, r);
706  this->template generate_error_check<BRNG>(status, "UniformBits32");
707  }
708 }; // class MKLUniformBits32Distribution
709 
714 {
715  public :
716 
717  typedef unsigned MKL_INT64 result_type;
718 
719  template <MKL_INT BRNG>
720  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
721  {
722  int status = ::viRngUniformBits64(VSL_RNG_METHOD_UNIFORMBITS64_STD,
723  stream.ptr(), n, r);
724  this->template generate_error_check<BRNG>(status, "UniformBits64");
725  }
726 }; // class MKLUniformBits64Distribution
727 
730 template <typename ResultType, MKL_INT Method>
731 class MKLUniformDistribution :
732  public MKLDistribution<ResultType,
733  MKLUniformDistribution<ResultType, Method> >
734 {
735  public :
736 
737  typedef ResultType result_type;
738 
739  explicit MKLUniformDistribution (result_type a = 0, result_type b = 1) :
740  a_(a), b_(b) {}
741 
742  template <MKL_INT BRNG>
743  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
744  {
745  int status = generate(stream.ptr(), n, r);
746  this->template generate_error_check<BRNG>(status, "Uniform");
747  }
748 
749  private :
750 
751  result_type a_;
752  result_type b_;
753 
754  int generate (VSLStreamStatePtr ptr, MKL_INT n, MKL_INT *r)
755  {return ::viRngUniform(Method, ptr, n, r, a_, b_);}
756 
757  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
758  {return ::vsRngUniform(Method, ptr, n, r, a_, b_);}
759 
760  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
761  {return ::vdRngUniform(Method, ptr, n, r, a_, b_);}
762 }; // class MKLUniformDistribution
763 
766 template <MKL_INT Method>
767 class MKLBernoulliDistribution :
768  public MKLDistribution<MKL_INT, MKLBernoulliDistribution<Method> >
769 {
770  public :
771 
773 
774  explicit MKLBernoulliDistribution (double p = 0.5) : p_(p) {}
775 
776  template <MKL_INT BRNG>
777  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
778  {
779  int status = ::viRngBernoulli(Method, stream.ptr(), n, r, p_);
780  this->template generate_error_check<BRNG>(status, "Bernoulli");
781  }
782 
783  private :
784 
785  double p_;
786 }; // class MKLBernoulliDistribution
787 
790 template <MKL_INT Method>
791 class MKLGeometricDistribution :
792  public MKLDistribution<MKL_INT, MKLGeometricDistribution<Method> >
793 {
794  public :
795 
797 
798  explicit MKLGeometricDistribution (double p = 0.5) : p_(p) {}
799 
800  template <MKL_INT BRNG>
801  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
802  {
803  int status = ::viRngGeometric(Method, stream.ptr(), n, r, p_);
804  this->template generate_error_check<BRNG>(status, "Geometric");
805  }
806 
807  private :
808 
809  double p_;
810 }; // class MKLGeometricDistribution
811 
814 template <MKL_INT Method>
815 class MKLBinomialDistribution :
816  public MKLDistribution<MKL_INT, MKLBinomialDistribution<Method> >
817 {
818  public :
819 
821 
822  explicit MKLBinomialDistribution (result_type ntrial = 1, double p = 0.5) :
823  ntrial_(ntrial), p_(p) {}
824 
825  template <MKL_INT BRNG>
826  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
827  {
828  int status = ::viRngBinomial(Method, stream.ptr(), n, r, ntrial_, p_);
829  this->template generate_error_check<BRNG>(status, "Binomial");
830  }
831 
832  private :
833 
834  result_type ntrial_;
835  double p_;
836 }; // class MKLBinomialDistribution
837 
840 template <MKL_INT Method>
841 class MKLHypergeometricDistribution :
842  public MKLDistribution<MKL_INT, MKLHypergeometricDistribution<Method> >
843 {
844  public :
845 
847 
848  MKLHypergeometricDistribution (result_type population, result_type sample,
849  result_type mask) :
850  l_(population), s_(sample), m_(mask) {}
851 
852  template <MKL_INT BRNG>
853  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
854  {
855  int status = ::viRngHypergeometric(Method, stream.ptr(),
856  n, r, l_, s_, m_);
857  this->template generate_error_check<BRNG>(status, "Hypergeometric");
858  }
859 
860  private :
861 
862  result_type l_;
863  result_type s_;
864  result_type m_;
865 }; // class MKLHypergeometricDistribution
866 
869 template <MKL_INT Method>
870 class MKLPoissonDistribution :
871  public MKLDistribution<MKL_INT, MKLPoissonDistribution<Method> >
872 {
873  public :
874 
876 
877  explicit MKLPoissonDistribution (double lambda = 1) : lambda_(lambda) {}
878 
879  template <MKL_INT BRNG>
880  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
881  {
882  int status = ::viRngPoisson(Method, stream.ptr(), n, r, lambda_);
883  this->template generate_error_check<BRNG>(status, "Poisson");
884  }
885 
886  private :
887 
888  double lambda_;
889 }; // class MKLPoissonDistribution
890 
893 template <MKL_INT Method>
894 class MKLNegBinomialDistribution :
895  public MKLDistribution<MKL_INT, MKLNegBinomialDistribution<Method> >
896 {
897  public :
898 
900 
901  explicit MKLNegBinomialDistribution (double ntrial = 1, double p = 0.5) :
902  ntrial_(ntrial), p_(p) {}
903 
904  template <MKL_INT BRNG>
905  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
906  {
907  int status = ::viRngNegBinomial(Method, stream.ptr(),
908  n, r, ntrial_, p_);
909  this->template generate_error_check<BRNG>(status, "NegBinomial");
910  }
911 
912  private :
913 
914  double ntrial_;
915  double p_;
916 }; // class MKLNegBinomialDistribution
917 
920 template <typename FPType, MKL_INT Method>
921 class MKLGaussianDistribution :
922  public MKLDistribution<FPType, MKLGaussianDistribution<FPType, Method> >
923 {
924  public :
925 
926  typedef FPType result_type;
927 
928  explicit MKLGaussianDistribution (result_type mean = 0,
929  result_type sd = 1) : mean_(mean), sd_(sd)
931 
932  template <MKL_INT BRNG>
933  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
934  {
935  int status = generate(stream.ptr(), n, r);
936  this->template generate_error_check<BRNG>(status, "Gaussian");
937  }
938 
939  private :
940 
941  result_type mean_;
942  result_type sd_;
943 
944  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
945  {return ::vsRngGaussian(Method, ptr, n, r, mean_, sd_);}
946 
947  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
948  {return ::vdRngGaussian(Method, ptr, n, r, mean_, sd_);}
949 }; // class MKLGaussianDistribution
950 
953 template <typename FPType, MKL_INT Method>
954 class MKLExponentialDistribution :
955  public MKLDistribution<FPType, MKLExponentialDistribution<FPType, Method> >
956 {
957  public :
958 
959  typedef FPType result_type;
960 
961  explicit MKLExponentialDistribution (result_type displacement = 0,
962  result_type scale = 1) : disp_(displacement), scale_(scale)
964 
965  template <MKL_INT BRNG>
966  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
967  {
968  int status = generate(stream.ptr(), n, r);
969  this->template generate_error_check<BRNG>(status, "Exponential");
970  }
971 
972  private :
973 
974  result_type disp_;
975  result_type scale_;
976 
977  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
978  {return ::vsRngExponential(Method, ptr, n, r, disp_, scale_);}
979 
980  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
981  {return ::vdRngExponential(Method, ptr, n, r, disp_, scale_);}
982 }; // class MKLExponentialDistribution
983 
986 template <typename FPType, MKL_INT Method>
987 class MKLLaplaceDistribution :
988  public MKLDistribution<FPType, MKLLaplaceDistribution<FPType, Method> >
989 {
990  public :
991 
992  typedef FPType result_type;
993 
994  explicit MKLLaplaceDistribution (result_type mean = 0,
995  result_type scale = 1) : mean_(mean), scale_(scale)
997 
998  template <MKL_INT BRNG>
999  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
1000  {
1001  int status = generate(stream.ptr(), n, r);
1002  this->template generate_error_check<BRNG>(status, "Laplace");
1003  }
1004 
1005  private :
1006 
1007  result_type mean_;
1008  result_type scale_;
1009 
1010  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
1011  {return ::vsRngLaplace(Method, ptr, n, r, mean_, scale_);}
1012 
1013  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
1014  {return ::vdRngLaplace(Method, ptr, n, r, mean_, scale_);}
1015 }; // class MKLLaplaceDistribution
1016 
1019 template <typename FPType, MKL_INT Method>
1020 class MKLWeibullDistribution :
1021  public MKLDistribution<FPType, MKLWeibullDistribution<FPType, Method> >
1022 {
1023  public :
1024 
1025  typedef FPType result_type;
1026 
1027  explicit MKLWeibullDistribution (result_type shape = 1,
1028  result_type displacement = 0, result_type scale = 1) :
1029  shape_(shape), disp_(displacement), scale_(scale)
1031 
1032  template <MKL_INT BRNG>
1033  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
1034  {
1035  int status = generate(stream.ptr(), n, r);
1036  this->template generate_error_check<BRNG>(status, "Weibull");
1037  }
1038 
1039  private :
1040 
1041  result_type shape_;
1042  result_type disp_;
1043  result_type scale_;
1044 
1045  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
1046  {return ::vsRngWeibull(Method, ptr, n, r, shape_, disp_, scale_);}
1047 
1048  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
1049  {return ::vdRngWeibull(Method, ptr, n, r, shape_, disp_, scale_);}
1050 }; // class MKLWeibullDistribution
1051 
1054 template <typename FPType, MKL_INT Method>
1055 class MKLCauchyDistribution :
1056  public MKLDistribution<FPType, MKLCauchyDistribution<FPType, Method> >
1057 {
1058  public :
1059 
1060  typedef FPType result_type;
1061 
1062  explicit MKLCauchyDistribution (result_type displacement = 0,
1063  result_type scale = 1) : disp_(displacement), scale_(scale)
1065 
1066  template <MKL_INT BRNG>
1067  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
1068  {
1069  int status = generate(stream.ptr(), n, r);
1070  this->template generate_error_check<BRNG>(status, "Cauchy");
1071  }
1072 
1073  private :
1074 
1075  result_type disp_;
1076  result_type scale_;
1077 
1078  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
1079  {return ::vsRngCauchy(Method, ptr, n, r, disp_, scale_);}
1080 
1081  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
1082  {return ::vdRngCauchy(Method, ptr, n, r, disp_, scale_);}
1083 }; // class MKLCauchyDistribution
1084 
1087 template <typename FPType, MKL_INT Method>
1088 class MKLRayleighDistribution :
1089  public MKLDistribution<FPType, MKLRayleighDistribution<FPType, Method> >
1090 {
1091  public :
1092 
1093  typedef FPType result_type;
1094 
1095  explicit MKLRayleighDistribution (result_type displacement = 0,
1096  result_type scale = 1) : disp_(displacement), scale_(scale)
1098 
1099  template <MKL_INT BRNG>
1100  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
1101  {
1102  int status = generate(stream.ptr(), n, r);
1103  this->template generate_error_check<BRNG>(status, "Rayleigh");
1104  }
1105 
1106  private :
1107 
1108  result_type disp_;
1109  result_type scale_;
1110 
1111  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
1112  {return ::vsRngRayleigh(Method, ptr, n, r, disp_, scale_);}
1113 
1114  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
1115  {return ::vdRngRayleigh(Method, ptr, n, r, disp_, scale_);}
1116 }; // class MKLRayleighDistribution
1117 
1120 template <typename FPType, MKL_INT Method>
1121 class MKLLognormalDistribution :
1122  public MKLDistribution<FPType, MKLLognormalDistribution<FPType, Method> >
1123 {
1124  public :
1125 
1126  typedef FPType result_type;
1127 
1129  result_type mean = 0, result_type sd = 1,
1130  result_type displacement = 0, result_type scale = 1) :
1131  mean_(mean), sd_(sd), disp_(displacement), scale_(scale)
1133 
1134  template <MKL_INT BRNG>
1135  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
1136  {
1137  int status = generate(stream.ptr(), n, r);
1138  this->template generate_error_check<BRNG>(status, "Lognormal");
1139  }
1140 
1141  private :
1142 
1143  result_type mean_;
1144  result_type sd_;
1145  result_type disp_;
1146  result_type scale_;
1147 
1148  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
1149  {return ::vsRngLognormal(Method, ptr, n, r, mean_, sd_, disp_, scale_);}
1150 
1151  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
1152  {return ::vdRngLognormal(Method, ptr, n, r, mean_, sd_, disp_, scale_);}
1153 }; // class MKLLognormalDistribution
1154 
1157 template <typename FPType, MKL_INT Method>
1158 class MKLGumbelDistribution :
1159  public MKLDistribution<FPType, MKLGumbelDistribution<FPType, Method> >
1160 {
1161  public :
1162 
1163  typedef FPType result_type;
1164 
1165  explicit MKLGumbelDistribution (result_type displacement = 0,
1166  result_type scale = 1) : disp_(displacement), scale_(scale)
1168 
1169  template <MKL_INT BRNG>
1170  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
1171  {
1172  int status = generate(stream.ptr(), n, r);
1173  this->template generate_error_check<BRNG>(status, "Gumbel");
1174  }
1175 
1176  private :
1177 
1178  result_type disp_;
1179  result_type scale_;
1180 
1181  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
1182  {return ::vsRngGumbel(Method, ptr, n, r, disp_, scale_);}
1183 
1184  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
1185  {return ::vdRngGumbel(Method, ptr, n, r, disp_, scale_);}
1186 }; // class MKLGumbelDistribution
1187 
1190 template <typename FPType, MKL_INT Method>
1191 class MKLGammaDistribution :
1192  public MKLDistribution<FPType, MKLGammaDistribution<FPType, Method> >
1193 {
1194  public :
1195 
1196  typedef FPType result_type;
1197 
1198  explicit MKLGammaDistribution (result_type shape = 1,
1199  result_type displacement = 0, result_type scale = 1) :
1200  shape_(shape), disp_(displacement), scale_(scale)
1202 
1203  template <MKL_INT BRNG>
1204  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
1205  {
1206  int status = generate(stream.ptr(), n, r);
1207  this->template generate_error_check<BRNG>(status, "Gamma");
1208  }
1209 
1210  private :
1211 
1212  result_type shape_;
1213  result_type disp_;
1214  result_type scale_;
1215 
1216  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
1217  {return ::vsRngGamma(Method, ptr, n, r, shape_, disp_, scale_);}
1218 
1219  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
1220  {return ::vdRngGamma(Method, ptr, n, r, shape_, disp_, scale_);}
1221 }; // class MKLGammaDistribution
1222 
1225 template <typename FPType, MKL_INT Method>
1226 class MKLBetaDistribution :
1227  public MKLDistribution<FPType, MKLBetaDistribution<FPType, Method> >
1228 {
1229  public :
1230 
1231  typedef FPType result_type;
1232 
1234  result_type shape1 = 1, result_type shape2 = 1,
1235  result_type displacement = 0, result_type scale = 1) :
1236  shape1_(shape1), shape2_(shape2), disp_(displacement), scale_(scale)
1238 
1239  template <MKL_INT BRNG>
1240  void generate (MKLStream<BRNG> &stream, MKL_INT n, result_type *r)
1241  {
1242  int status = generate(stream.ptr(), n, r);
1243  this->template generate_error_check<BRNG>(status, "Beta");
1244  }
1245 
1246  private :
1247 
1248  result_type shape1_;
1249  result_type shape2_;
1250  result_type disp_;
1251  result_type scale_;
1252 
1253  int generate (VSLStreamStatePtr ptr, MKL_INT n, float *r)
1254  {return ::vsRngBeta(Method, ptr, n, r, shape1_, shape2_, disp_, scale_);}
1255 
1256  int generate (VSLStreamStatePtr ptr, MKL_INT n, double *r)
1257  {return ::vdRngBeta(Method, ptr, n, r, shape1_, shape2_, disp_, scale_);}
1258 }; // class MKLBetaDistribution
1259 
1260 } // namespace vsmc
1261 
1262 #endif // VSMC_RNG_MKL_HPP
static constexpr const result_type _Min
Definition: mkl.hpp:560
unsigned MKL_INT64 result_type
Definition: mkl.hpp:717
Definition: adapter.hpp:37
ResultType result_type
Definition: mkl.hpp:509
MKLSkipAheadForce< BRNG, ResultType > type
Definition: mkl.hpp:341
MKLExponentialDistribution(result_type displacement=0, result_type scale=1)
Definition: mkl.hpp:961
MKLUniformDistribution(result_type a=0, result_type b=1)
Definition: mkl.hpp:739
MKLEngine< VSL_BRNG_NONDETERM, unsigned MKL_INT64 > MKL_NONDETERM_64
A non-determinstic random number generator (64-bits)
Definition: mkl.hpp:622
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:1240
MKLEngine< VSL_BRNG_MT19937, unsigned > MKL_MT19937
A Mersenne-Twister pseudoranom number genertor.
Definition: mkl.hpp:593
static constexpr result_type min()
Definition: mkl.hpp:565
Default seed for MKL RNG.
Definition: mkl.hpp:228
MKLEngine< VSL_BRNG_MT19937, unsigned MKL_INT64 > MKL_MT19937_64
A Mersenne-Twister pseudoranom number genertor (64-bits)
Definition: mkl.hpp:597
static constexpr MKL_INT max()
Definition: mkl.hpp:246
MKL_INT buffer_size() const
Definition: mkl.hpp:659
void seed(MKL_UINT s)
Definition: mkl.hpp:455
#define VSMC_CONSTEXPR
constexpr
Definition: defines.hpp:55
MKLStream(MKLStream< BRNG > &&other)
Definition: mkl.hpp:429
MKL Hypergeometric distribution.
Definition: mkl.hpp:76
static constexpr MKL_INT offset()
Definition: mkl.hpp:248
MKLGaussianDistribution(result_type mean=0, result_type sd=1)
Definition: mkl.hpp:928
std::string mkl_vsl_brng_str(MKL_INT BRNG)
Definition: mkl.hpp:104
#define VSMC_RNG_MKL_VSL_BUFFER_SIZE
Definition: mkl.hpp:50
ResultType result_type
Definition: mkl.hpp:631
MKLLognormalDistribution(result_type mean=0, result_type sd=1, result_type displacement=0, result_type scale=1)
Definition: mkl.hpp:1128
MKLStream< BRNG > & operator=(const MKLStream< BRNG > &other)
Definition: mkl.hpp:415
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:933
MKL_INT offset() const
Definition: mkl.hpp:265
MKL Uniform distribution.
Definition: mkl.hpp:67
MKLEngine< VSL_BRNG_MT2203, unsigned MKL_INT64 > MKL_MT2203_64
A set of 6024 Mersenne-Twister pseudoranom number genertor (64-bits)
Definition: mkl.hpp:605
void buffer_size(MKL_INT size)
Set the buffer size, zero or negative value restore the default.
Definition: mkl.hpp:656
void buffer_size(MKL_INT size)
Set the buffer size, zero or negative value restore the default.
Definition: mkl.hpp:572
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:1033
MKLGeometricDistribution(double p=0.5)
Definition: mkl.hpp:798
MKLPoissonDistribution(double lambda=1)
Definition: mkl.hpp:877
MKLLaplaceDistribution(result_type mean=0, result_type scale=1)
Definition: mkl.hpp:994
MKLStream(SeedSeq &seq, typename cxx11::enable_if< internal::is_seed_seq< SeedSeq, MKL_UINT, MKLStream< BRNG > >::value >::type *=nullptr)
Definition: mkl.hpp:389
void generate_error_check(int status, const char *name)
Definition: mkl.hpp:664
MKLStream(MKL_UINT s=traits::MKLSeedTrait< BRNG >::value, MKL_INT offset=0)
Definition: mkl.hpp:372
MKL RNG C++11 engine.
Definition: mkl.hpp:61
void operator()(MKLStream< BRNG > &stream, size_type nskip)
Definition: mkl.hpp:306
MKLEngine< VSL_BRNG_NONDETERM, unsigned > MKL_NONDETERM
A non-determinstic random number generator.
Definition: mkl.hpp:618
MKL Geometric distribution.
Definition: mkl.hpp:72
MKL uniform bits distribution (64-bits)
Definition: mkl.hpp:712
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:1204
const VSLBRngProperties & property() const
Definition: mkl.hpp:493
const stream_type & stream() const
Definition: mkl.hpp:569
stream_type & stream()
Definition: mkl.hpp:568
#define VSMC_RUNTIME_ASSERT(cond, msg)
Definition: assert.hpp:64
MKLNegBinomialDistribution(double ntrial=1, double p=0.5)
Definition: mkl.hpp:901
static constexpr MKL_INT min()
Definition: mkl.hpp:256
MKLEngine< VSL_BRNG_MCG59, unsigned > MKL_MCG59
A 59-bits multiplicative congruential generator.
Definition: mkl.hpp:589
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:743
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:702
#define VSMC_DEFINE_RNG_MKL_VSL_ERR(STATUS)
Definition: mkl.hpp:55
MKLBinomialDistribution(result_type ntrial=1, double p=0.5)
Definition: mkl.hpp:822
result_type operator()()
Definition: mkl.hpp:534
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:999
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:826
MKL NegBinomial distribution.
Definition: mkl.hpp:80
MKLGumbelDistribution(result_type displacement=0, result_type scale=1)
Definition: mkl.hpp:1165
void buffer_size(MKL_INT size)
Definition: mkl.hpp:327
MKL Poisson distribution.
Definition: mkl.hpp:78
MKLBetaDistribution(result_type shape1=1, result_type shape2=1, result_type displacement=0, result_type scale=1)
Definition: mkl.hpp:1233
MKLOffsetZero type
Definition: mkl.hpp:272
MKLOffsetDynamic< 6024 > type
Definition: mkl.hpp:275
void discard(std::size_t nskip)
Discard results.
Definition: mkl.hpp:552
#define VSMC_MNE
Avoid MSVC stupid behavior: MNE = Macro No Expansion.
Definition: defines.hpp:38
#define VSMC_DEFINE_RNG_MKL_VSL_BRNG(BRNG)
Definition: mkl.hpp:53
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:777
MKLEngine< VSL_BRNG_SFMT19937, unsigned MKL_INT64 > MKL_SFMT19937_64
A SIMD-oriented fast Mersenne-Twister pseudoranom number genertor (64-bits)
Definition: mkl.hpp:614
Base class of MKL distribution.
Definition: mkl.hpp:60
MKLCauchyDistribution(result_type displacement=0, result_type scale=1)
Definition: mkl.hpp:1062
static constexpr const result_type _Max
Definition: mkl.hpp:562
MKLEngine< VSL_BRNG_SFMT19937, unsigned > MKL_SFMT19937
A SIMD-oriented fast Mersenne-Twister pseudoranom number genertor.
Definition: mkl.hpp:609
MKLStream(const MKLStream< BRNG > &other)
Definition: mkl.hpp:406
MKL Exponential distribution.
Definition: mkl.hpp:84
MKLStream< BRNG > stream_type
Definition: mkl.hpp:510
static constexpr result_type max()
Definition: mkl.hpp:566
remove_reference< T >::type && move(T &&t) noexcept
void seed(SeedSeq &seq, typename cxx11::enable_if< internal::is_seed_seq< SeedSeq, MKL_UINT, MKLStream< BRNG > >::value >::type *=nullptr)
Definition: mkl.hpp:483
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:853
void seed(SeedSeq &seq, typename cxx11::enable_if< internal::is_seed_seq< SeedSeq, MKL_UINT, MKLEngine< BRNG, ResultType > >::value >::type *=nullptr)
Definition: mkl.hpp:528
static constexpr MKL_INT min()
Definition: mkl.hpp:245
MKL Binomial distribution.
Definition: mkl.hpp:74
VSLStreamStatePtr ptr() const
Definition: mkl.hpp:491
MKLBernoulliDistribution(double p=0.5)
Definition: mkl.hpp:774
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:905
MKL Gamma distribution.
Definition: mkl.hpp:98
#define VSMC_NULLPTR
nullptr
Definition: defines.hpp:79
void mkl_vsl_error_check(MKL_INT BRNG, int status, const char *func, const char *mklf)
Definition: mkl.hpp:166
MKL Rayleigh distribution.
Definition: mkl.hpp:92
void swap(Array< T, N > &ary1, Array< T, N > &ary2)
Array ADL of swap.
Definition: array.hpp:317
#define VSMC_RUNTIME_ASSERT_RNG_MKL_VSL_OFFSET(offset)
Definition: mkl.hpp:44
MKLEngine(MKL_UINT s=traits::MKLSeedTrait< BRNG >::value, MKL_INT offset=0)
Definition: mkl.hpp:512
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:1135
MKLEngine uniform bits trait.
Definition: mkl.hpp:203
MKLRayleighDistribution(result_type displacement=0, result_type scale=1)
Definition: mkl.hpp:1095
MKL RNG C++11 engine stream.
Definition: mkl.hpp:59
void operator()(MKLStream< BRNG > &stream, size_type nskip)
Definition: mkl.hpp:285
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:720
MKL Laplace distribution.
Definition: mkl.hpp:86
MKLOffsetDynamic< 273 > type
Definition: mkl.hpp:278
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:801
MKL Gumbel distribution.
Definition: mkl.hpp:96
static constexpr MKL_INT max()
Definition: mkl.hpp:257
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:966
static void offset(MKL_INT)
Definition: mkl.hpp:247
MKLEngine(SeedSeq &seq, typename cxx11::enable_if< internal::is_seed_seq< SeedSeq, MKL_UINT, MKLEngine< BRNG, ResultType > >::value >::type *=nullptr)
Definition: mkl.hpp:518
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:1170
MKLGammaDistribution(result_type shape=1, result_type displacement=0, result_type scale=1)
Definition: mkl.hpp:1198
MKL Lognormal distribution.
Definition: mkl.hpp:94
static void buffer_size(MKL_INT)
Definition: mkl.hpp:295
std::string mkl_vsl_error_str(int status)
Definition: mkl.hpp:125
MKL Weibull distribution.
Definition: mkl.hpp:88
MKL_INT buffer_size()
Definition: mkl.hpp:575
MKL Bernoulli distribution.
Definition: mkl.hpp:70
static MKL_INT buffer_size()
Definition: mkl.hpp:296
MKLWeibullDistribution(result_type shape=1, result_type displacement=0, result_type scale=1)
Definition: mkl.hpp:1027
MKL Beta distribution.
Definition: mkl.hpp:100
void offset(MKL_INT n)
Definition: mkl.hpp:259
MKL Gaussian distribution.
Definition: mkl.hpp:82
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:1100
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:880
MKLEngine< VSL_BRNG_MT2203, unsigned > MKL_MT2203
A set of 6024 Mersenne-Twister pseudoranom number genertor.
Definition: mkl.hpp:601
MKL Cauchy distribution.
Definition: mkl.hpp:90
void seed(MKL_UINT s)
Definition: mkl.hpp:525
#define VSMC_STATIC_ASSERT_RNG_MKL_VSL_DISTRIBUTION_FP_TYPE(FPType, Dist)
Definition: mkl.hpp:38
void generate(MKLStream< BRNG > &stream, MKL_INT n, result_type *r)
Definition: mkl.hpp:1067
MKLHypergeometricDistribution(result_type population, result_type sample, result_type mask)
Definition: mkl.hpp:848
MKL uniform bits distribution (32-bits)
Definition: mkl.hpp:694
result_type operator()(MKLStream< BRNG > &stream)
Definition: mkl.hpp:637