vSMC
vSMC: Scalable Monte Carlo
common.hpp
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/rng/internal/common.hpp
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013-2016, 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_INTERNAL_COMMON_HPP
33 #define VSMC_RNG_INTERNAL_COMMON_HPP
34 
35 #include <vsmc/internal/common.hpp>
36 #include <vsmc/utility/simd.hpp>
37 #if VSMC_HAS_MKL
38 #include <vsmc/utility/mkl.hpp>
39 #endif
40 
41 #define VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM(flag, Name) \
42  VSMC_RUNTIME_ASSERT((flag), \
43  "**" #Name "Distribution** CONSTRUCTED WITH INVALID PARAMETERS")
44 
45 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_0(Name, T, t, Type) \
46  public: \
47  class param_type \
48  { \
49  static_assert(std::is_##t<T>::value, \
50  "**" #Name "Distribution::param_type** USED WITH " #T \
51  " OTHER THAN " #Type " INTEGER TYPES"); \
52  \
53  public: \
54  using result_type = T; \
55  using distribution_type = Name##Distribution<T>; \
56  \
57  friend bool operator==(const param_type &, const param_type &) \
58  { \
59  return true; \
60  } \
61  \
62  friend bool operator!=(const param_type &, const param_type &) \
63  { \
64  return false; \
65  } \
66  \
67  template <typename CharT, typename Traits> \
68  friend std::basic_ostream<CharT, Traits> &operator<<( \
69  std::basic_ostream<CharT, Traits> &os, const param_type &) \
70  { \
71  return os; \
72  } \
73  \
74  template <typename CharT, typename Traits> \
75  friend std::basic_istream<CharT, Traits> &operator>>( \
76  std::basic_istream<CharT, Traits> &is, param_type &) \
77  { \
78  return is; \
79  } \
80  \
81  private: \
82  friend distribution_type; \
83  }; // class param_type
84 
85 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_1(Name, name, p1, v1) \
86  public: \
87  class param_type \
88  { \
89  static_assert(std::is_floating_point<RealType>::value, \
90  "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \
91  "THAN FLOATING POINT TYPES"); \
92  \
93  public: \
94  using result_type = RealType; \
95  using distribution_type = Name##Distribution<RealType>; \
96  \
97  explicit param_type(result_type p1 = v1) : p1##_(p1) \
98  { \
99  VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \
100  internal::name##_distribution_check_param(p1), Name); \
101  } \
102  \
103  result_type p1() const { return p1##_; } \
104  \
105  friend bool operator==( \
106  const param_type &param1, const param_type &param2) \
107  { \
108  if (!internal::is_equal(param1.p1##_, param2.p1##_)) \
109  return false; \
110  return true; \
111  } \
112  \
113  friend bool operator!=( \
114  const param_type &param1, const param_type &param2) \
115  { \
116  return !(param1 == param2); \
117  } \
118  \
119  template <typename CharT, typename Traits> \
120  friend std::basic_ostream<CharT, Traits> &operator<<( \
121  std::basic_ostream<CharT, Traits> &os, const param_type &param) \
122  { \
123  if (!os.good()) \
124  return os; \
125  \
126  os << param.p1##_; \
127  \
128  return os; \
129  } \
130  \
131  template <typename CharT, typename Traits> \
132  friend std::basic_istream<CharT, Traits> &operator>>( \
133  std::basic_istream<CharT, Traits> &is, param_type &param) \
134  { \
135  if (!is.good()) \
136  return is; \
137  \
138  result_type p1 = 0; \
139  is >> std::ws >> p1; \
140  \
141  if (is.good()) { \
142  if (internal::name##_distribution_check_param(p1)) \
143  param.p1##_ = p1; \
144  else \
145  is.setstate(std::ios_base::failbit); \
146  } \
147  \
148  return is; \
149  } \
150  \
151  private: \
152  result_type p1##_; \
153  \
154  friend distribution_type; \
155  }; // class param_type
156 
157 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_2(Name, name, p1, v1, p2, v2) \
158  public: \
159  class param_type \
160  { \
161  static_assert(std::is_floating_point<RealType>::value, \
162  "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \
163  "THAN FLOATING POINT TYPES"); \
164  \
165  public: \
166  using result_type = RealType; \
167  using distribution_type = Name##Distribution<RealType>; \
168  \
169  explicit param_type(result_type p1 = v1, result_type p2 = v2) \
170  : p1##_(p1), p2##_(p2) \
171  { \
172  VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \
173  internal::name##_distribution_check_param(p1, p2), Name); \
174  } \
175  \
176  result_type p1() const { return p1##_; } \
177  result_type p2() const { return p2##_; } \
178  \
179  friend bool operator==( \
180  const param_type &param1, const param_type &param2) \
181  { \
182  if (!internal::is_equal(param1.p1##_, param2.p1##_)) \
183  return false; \
184  if (!internal::is_equal(param1.p2##_, param2.p2##_)) \
185  return false; \
186  return true; \
187  } \
188  \
189  friend bool operator!=( \
190  const param_type &param1, const param_type &param2) \
191  { \
192  return !(param1 == param2); \
193  } \
194  \
195  template <typename CharT, typename Traits> \
196  friend std::basic_ostream<CharT, Traits> &operator<<( \
197  std::basic_ostream<CharT, Traits> &os, const param_type &param) \
198  { \
199  if (!os.good()) \
200  return os; \
201  \
202  os << param.p1##_ << ' '; \
203  os << param.p2##_; \
204  \
205  return os; \
206  } \
207  \
208  template <typename CharT, typename Traits> \
209  friend std::basic_istream<CharT, Traits> &operator>>( \
210  std::basic_istream<CharT, Traits> &is, param_type &param) \
211  { \
212  if (!is.good()) \
213  return is; \
214  \
215  result_type p1 = 0; \
216  result_type p2 = 0; \
217  is >> std::ws >> p1; \
218  is >> std::ws >> p2; \
219  \
220  if (is.good()) { \
221  if (internal::name##_distribution_check_param(p1, p2)) { \
222  param.p1##_ = p1; \
223  param.p2##_ = p2; \
224  } else { \
225  is.setstate(std::ios_base::failbit); \
226  } \
227  } \
228  \
229  return is; \
230  } \
231  \
232  private: \
233  result_type p1##_; \
234  result_type p2##_; \
235  \
236  friend distribution_type; \
237  }; // class param_type
238 
239 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_0(Name, T) \
240  public: \
241  using result_type = T; \
242  using distribution_type = Name##Distribution<T>; \
243  \
244  Name##Distribution() = default; \
245  explicit Name##Distribution(const param_type &) {}
246 
247 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_1(Name, p1, v1) \
248  public: \
249  using result_type = RealType; \
250  using distribution_type = Name##Distribution<RealType>; \
251  \
252  explicit Name##Distribution(result_type p1 = v1) : param_(p1) \
253  { \
254  reset(); \
255  } \
256  \
257  explicit Name##Distribution(const param_type &param) : param_(param) \
258  { \
259  reset(); \
260  } \
261  \
262  result_type p1() const { return param_.p1(); }
263 
264 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_2(Name, p1, v1, p2, v2) \
265  public: \
266  using result_type = RealType; \
267  using distribution_type = Name##Distribution<RealType>; \
268  \
269  explicit Name##Distribution(result_type p1 = v1, result_type p2 = v2) \
270  : param_(p1, p2) \
271  { \
272  reset(); \
273  } \
274  \
275  explicit Name##Distribution(const param_type &param) : param_(param) \
276  { \
277  reset(); \
278  } \
279  \
280  result_type p1() const { return param_.p1(); } \
281  result_type p2() const { return param_.p2(); }
282 
283 #define VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name) \
284  public: \
285  const param_type &param() const { return param_; } \
286  \
287  void param(const param_type &param) \
288  { \
289  param_ = param; \
290  reset(); \
291  } \
292  \
293  void pram(param_type &&param) \
294  { \
295  param_ = std::move(param); \
296  reset(); \
297  } \
298  \
299  template <typename RNGType> \
300  result_type operator()(RNGType &rng) \
301  { \
302  return operator()(rng, param_); \
303  } \
304  \
305  template <typename RNGType> \
306  result_type operator()(RNGType &rng, const param_type &param) \
307  { \
308  return generate(rng, param); \
309  } \
310  \
311  template <typename RNGType> \
312  void operator()(RNGType &rng, std::size_t n, result_type *r) \
313  { \
314  operator()(rng, n, r, param_); \
315  } \
316  \
317  template <typename RNGType> \
318  void operator()( \
319  RNGType &rng, std::size_t n, result_type *r, const param_type &param) \
320  { \
321  if (n < 100) { \
322  for (std::size_t i = 0; i != n; ++i) \
323  r[i] = operator()(rng, param); \
324  } else { \
325  name##_distribution(rng, n, r, param); \
326  } \
327  } \
328  \
329  friend bool operator==( \
330  const distribution_type &dist1, const distribution_type &dist2) \
331  { \
332  return dist1.param_ == dist2.param_; \
333  } \
334  \
335  friend bool operator!=( \
336  const distribution_type &dist1, const distribution_type &dist2) \
337  { \
338  return !(dist1 == dist2); \
339  } \
340  \
341  template <typename CharT, typename Traits> \
342  friend std::basic_ostream<CharT, Traits> &operator<<( \
343  std::basic_ostream<CharT, Traits> &os, const distribution_type &dist) \
344  { \
345  os << dist.param_; \
346  \
347  return os; \
348  } \
349  \
350  template <typename CharT, typename Traits> \
351  friend std::basic_istream<CharT, Traits> &operator>>( \
352  std::basic_istream<CharT, Traits> &is, distribution_type &dist) \
353  { \
354  is >> std::ws >> dist.param_; \
355  if (is.good()) \
356  dist.reset(); \
357  \
358  return is; \
359  } \
360  \
361  private: \
362  param_type param_;
363 
364 #define VSMC_DEFINE_RNG_DISTRIBUTION_0(Name, name, T, t, Type) \
365  VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_0(Name, T, t, Type) \
366  VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_0(Name, T) \
367  VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name)
368 
369 #define VSMC_DEFINE_RNG_DISTRIBUTION_1(Name, name, p1, v1) \
370  VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_1(Name, name, p1, v1) \
371  VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_1(Name, p1, v1) \
372  VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name)
373 
374 #define VSMC_DEFINE_RNG_DISTRIBUTION_2(Name, name, p1, v1, p2, v2) \
375  VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_2(Name, name, p1, v1, p2, v2) \
376  VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_2(Name, p1, v1, p2, v2) \
377  VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name)
378 
379 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_0(Name, name, T) \
380  template <typename T, typename RNGType> \
381  inline void name##_distribution(RNGType &rng, std::size_t n, T *r, \
382  const typename Name##Distribution<T>::param_type &) \
383  { \
384  name##_distribution(rng, n, r); \
385  } \
386  \
387  template <typename T, typename RNGType> \
388  inline void rng_rand( \
389  RNGType &rng, Name##Distribution<T> &dist, std::size_t n, T *r) \
390  { \
391  dist(rng, n, r); \
392  }
393 
394 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_1(Name, name, p1) \
395  template <typename RealType, typename RNGType> \
396  inline void name##_distribution(RNGType &rng, std::size_t n, RealType *r, \
397  const typename Name##Distribution<RealType>::param_type &param) \
398  { \
399  name##_distribution(rng, n, r, param.p1()); \
400  } \
401  \
402  template <typename RealType, typename RNGType> \
403  inline void rng_rand(RNGType &rng, Name##Distribution<RealType> &dist, \
404  std::size_t n, RealType *r) \
405  { \
406  dist(rng, n, r); \
407  }
408 
409 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_2(Name, name, p1, p2) \
410  template <typename RealType, typename RNGType> \
411  inline void name##_distribution(RNGType &rng, std::size_t n, RealType *r, \
412  const typename Name##Distribution<RealType>::param_type &param) \
413  { \
414  name##_distribution(rng, n, r, param.p1(), param.p2()); \
415  } \
416  \
417  template <typename RealType, typename RNGType> \
418  inline void rng_rand(RNGType &rng, Name##Distribution<RealType> &dist, \
419  std::size_t n, RealType *r) \
420  { \
421  dist(rng, n, r); \
422  }
423 
424 namespace vsmc
425 {
426 
427 namespace internal
428 {
429 
431 
432 template <typename UIntType, UIntType U,
433  int N = std::numeric_limits<UIntType>::digits>
435 {
436  static constexpr int M = std::numeric_limits<UIntType>::digits - N;
437 
438  public:
439  static constexpr int value =
440  (U >> M) == 0 ? M : RNGMinBitsImpl<UIntType, U, N - 1>::value;
441 }; // class RNGMinBitsImpl
442 
443 template <typename UIntType, UIntType U>
444 class RNGMinBitsImpl<UIntType, U, 0>
445 {
446  public:
447  static constexpr int value = std::numeric_limits<UIntType>::digits;
448 }; // class RNGMinBitsImpl
449 
450 } // namespace vsmc::internal
451 
454 template <typename RNGType>
455 class RNGMinBits : public std::integral_constant<int,
456  internal::RNGMinBitsImpl<typename RNGType::result_type,
457  RNGType::min()>::value>
458 {
459 }; // class RNGMinBits
460 
461 namespace internal
462 {
463 
464 template <typename UIntType, UIntType U,
465  int N = std::numeric_limits<UIntType>::digits>
467 {
468  static constexpr UIntType bmax = std::numeric_limits<UIntType>::max() >>
469  (std::numeric_limits<UIntType>::digits - N);
470 
471  public:
472  static constexpr int value =
473  U < bmax ? RNGMaxBitsImpl<UIntType, U, N - 1>::value : N;
474 }; // class RNGMaxBitsImpl
475 
476 template <typename UIntType, UIntType U>
477 class RNGMaxBitsImpl<UIntType, U, 0>
478 {
479  public:
480  static constexpr int value = 0;
481 }; // class RNGMaxBitsImpl
482 
483 } // namespace vsmc::internal
484 
490 template <typename RNGType>
491 class RNGMaxBits : public std::integral_constant<int,
492  internal::RNGMaxBitsImpl<typename RNGType::result_type,
493  RNGType::max()>::value>
494 {
495 }; // class RNGMaxBits
496 
507 template <typename RNGType>
508 class RNGBits : public std::integral_constant<int,
509  RNGMaxBits<RNGType>::value - RNGMinBits<RNGType>::value>
510 {
511 }; // class RNGBits
512 
515 class Open;
516 
519 class Closed;
520 
523 template <typename RNGType>
524 void rng_rand(RNGType &rng, std::size_t n, typename RNGType::result_type *r)
525 {
526  for (std::size_t i = 0; i != n; ++i)
527  r[i] = rng();
528 }
529 
530 template <typename>
531 class CounterEngine;
532 
533 template <typename = double, std::size_t = Dynamic>
535 
536 template <typename = double, std::size_t = Dynamic, std::size_t = Dynamic>
538 
539 template <typename = double>
541 
542 template <typename = double, std::size_t = Dynamic>
544 
545 template <typename = double>
546 class BetaDistribution;
547 
548 template <typename = double>
549 class CauchyDistribution;
550 
551 template <typename = double>
553 
554 template <typename = int>
556 
557 template <typename = double>
559 
560 template <typename = double>
562 
563 template <typename = double>
564 class FisherFDistribution;
565 
566 template <typename = double>
567 class GammaDistribution;
568 
569 template <typename = double>
571 
572 template <typename = double>
574 
575 template <typename = double>
577 
578 template <typename = double>
580 
581 template <typename = double>
583 
584 template <typename = double, std::size_t = Dynamic>
586 
587 template <typename = double>
589 
590 template <typename = double>
592 
593 template <typename = double>
595 
596 template <typename = double>
598 
599 template <typename = double, typename = Open, typename = Closed>
601 
602 template <typename = unsigned>
604 
605 template <typename = double>
607 
608 template <typename = double>
610 
611 template <typename Generator>
612 inline void rng_rand(CounterEngine<Generator> &, std::size_t,
614 
615 template <typename RealType, typename RNGType>
616 inline void rng_rand(
617  RNGType &, BetaDistribution<RealType> &, std::size_t, RealType *);
618 
619 template <typename RealType, typename RNGType>
620 inline void rng_rand(
621  RNGType &, CauchyDistribution<RealType> &, std::size_t, RealType *);
622 
623 template <typename RealType, typename RNGType>
624 inline void rng_rand(
625  RNGType &, ChiSquaredDistribution<RealType> &, std::size_t, RealType *);
626 
627 template <typename RealType, typename RNGType>
628 inline void rng_rand(
629  RNGType &, DiscreteDistribution<RealType> &, std::size_t, RealType *);
630 
631 template <typename RealType, typename RNGType>
632 inline void rng_rand(
633  RNGType &, ExponentialDistribution<RealType> &, std::size_t, RealType *);
634 
635 template <typename RealType, typename RNGType>
636 inline void rng_rand(
637  RNGType &, ExtremeValueDistribution<RealType> &, std::size_t, RealType *);
638 
639 template <typename RealType, typename RNGType>
640 inline void rng_rand(
641  RNGType &, FisherFDistribution<RealType> &, std::size_t, RealType *);
642 
643 template <typename RealType, typename RNGType>
644 inline void rng_rand(
645  RNGType &, GammaDistribution<RealType> &, std::size_t, RealType *);
646 
647 template <typename RealType, typename RNGType>
648 inline void rng_rand(
649  RNGType &, LaplaceDistribution<RealType> &, std::size_t, RealType *);
650 
651 template <typename RealType, typename RNGType>
652 inline void rng_rand(
653  RNGType &, LevyDistribution<RealType> &, std::size_t, RealType *);
654 
655 template <typename RealType, typename RNGType>
656 inline void rng_rand(
657  RNGType &, LogisticDistribution<RealType> &, std::size_t, RealType *);
658 
659 template <typename RealType, typename RNGType>
660 inline void rng_rand(
661  RNGType &, LognormalDistribution<RealType> &, std::size_t, RealType *);
662 
663 template <typename RealType, typename RNGType>
664 inline void rng_rand(
665  RNGType &, NormalDistribution<RealType> &, std::size_t, RealType *);
666 
667 template <typename RealType, std::size_t Dim, typename RNGType>
668 inline void rng_rand(
669  RNGType &, NormalMVDistribution<RealType, Dim> &, std::size_t, RealType *);
670 
671 template <typename RealType, typename RNGType>
672 inline void rng_rand(
673  RNGType &, ParetoDistribution<RealType> &, std::size_t, RealType *);
674 
675 template <typename RealType, typename RNGType>
676 inline void rng_rand(
677  RNGType &, RayleighDistribution<RealType> &, std::size_t, RealType *);
678 
679 template <typename RealType, typename RNGType>
680 inline void rng_rand(
681  RNGType &, StudentTDistribution<RealType> &, std::size_t, RealType *);
682 
683 template <typename RealType, typename RNGType>
684 inline void rng_rand(
685  RNGType &, U01Distribution<RealType> &, std::size_t, RealType *);
686 
687 template <typename RealType, typename RNGType, typename Left, typename Right>
688 inline void rng_rand(RNGType &, U01LRDistribution<RealType, Left, Right> &,
689  std::size_t, RealType *);
690 
691 template <typename UIntType, typename RNGType>
692 inline void rng_rand(
693  RNGType &, UniformBitsDistribution<UIntType> &, std::size_t, UIntType *);
694 
695 template <typename RealType, typename RNGType>
696 inline void rng_rand(
697  RNGType &, UniformRealDistribution<RealType> &, std::size_t, RealType *);
698 
699 template <typename RealType, typename RNGType>
700 inline void rng_rand(
701  RNGType &, WeibullDistribution<RealType> &, std::size_t, RealType *);
702 
703 template <typename RealType, typename RNGType>
704 inline void beta_distribution(
705  RNGType &, std::size_t, RealType *, RealType, RealType);
706 
707 template <typename RealType, typename RNGType>
708 inline void cauchy_distribution(
709  RNGType &, std::size_t, RealType *, RealType, RealType);
710 
711 template <typename RealType, typename RNGType>
712 inline void chi_squared_distribution(
713  RNGType &, std::size_t, RealType *, RealType);
714 
715 template <typename RealType, typename RNGType>
716 inline void exponential_distribution(
717  RNGType &, std::size_t, RealType *, RealType);
718 
719 template <typename RealType, typename RNGType>
720 inline void extreme_value_distribution(
721  RNGType &, std::size_t, RealType *, RealType, RealType);
722 
723 template <typename RealType, typename RNGType>
724 inline void fisher_f_distribution(
725  RNGType &, std::size_t, RealType *, RealType, RealType);
726 
727 template <typename RealType, typename RNGType>
728 inline void gamma_distribution(
729  RNGType &, std::size_t, RealType *, RealType, RealType);
730 
731 template <typename RealType, typename RNGType>
732 inline void laplace_distribution(
733  RNGType &, std::size_t, RealType *, RealType, RealType);
734 
735 template <typename RealType, typename RNGType>
736 inline void levy_distribution(
737  RNGType &, std::size_t, RealType *, RealType, RealType);
738 
739 template <typename RealType, typename RNGType>
740 inline void logistic_distribution(
741  RNGType &, std::size_t, RealType *, RealType, RealType);
742 
743 template <typename RealType, typename RNGType>
744 inline void lognormal_distribution(
745  RNGType &, std::size_t, RealType *, RealType, RealType);
746 
747 template <typename RealType, typename RNGType>
748 inline void normal_distribution(
749  RNGType &, std::size_t, RealType *, RealType, RealType);
750 
751 template <typename RealType, typename RNGType>
752 inline void normal_mv_distribution(RNGType &, std::size_t, RealType *,
753  std::size_t, const RealType *, const RealType *);
754 
755 template <typename RealType, typename RNGType>
756 inline void pareto_distribution(
757  RNGType &, std::size_t, RealType *, RealType, RealType);
758 
759 template <typename RealType, typename RNGType>
760 inline void rayleigh_distribution(
761  RNGType &, std::size_t, RealType *, RealType);
762 
763 template <typename RealType, typename RNGType>
764 inline void student_t_distribution(
765  RNGType &, std::size_t, RealType *, RealType);
766 
767 template <typename RealType, typename RNGType>
768 inline void u01_distribution(RNGType &, std::size_t, RealType *);
769 
770 template <typename, typename, typename RealType, typename RNGType>
771 inline void u01_lr_distribution(RNGType &, std::size_t, RealType *);
772 
773 template <typename UIntType, typename RNGType>
774 inline void uniform_bits_distribution(RNGType &, std::size_t, UIntType *);
775 
776 template <typename RealType, typename RNGType>
777 inline void uniform_real_distribution(
778  RNGType &, std::size_t, RealType *, RealType, RealType);
779 
780 template <typename RealType, typename RNGType>
781 inline void weibull_distribution(
782  RNGType &, std::size_t, RealType *, RealType, RealType);
783 
784 #if VSMC_HAS_MKL
785 
786 template <MKL_INT, int>
787 class MKLEngine;
788 
789 template <MKL_INT BRNG, int Bits>
790 inline void rng_rand(MKLEngine<BRNG, Bits> &, std::size_t,
792 
793 template <MKL_INT BRNG, int Bits>
794 inline void beta_distribution(
795  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
796 
797 template <MKL_INT BRNG, int Bits>
798 inline void beta_distribution(
799  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
800 
801 template <MKL_INT BRNG, int Bits>
802 inline void cauchy_distribution(
803  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
804 
805 template <MKL_INT BRNG, int Bits>
806 inline void cauchy_distribution(
807  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
808 
809 template <MKL_INT BRNG, int Bits>
810 inline void exponential_distribution(
811  MKLEngine<BRNG, Bits> &, std::size_t, float *, float);
812 
813 template <MKL_INT BRNG, int Bits>
814 inline void exponential_distribution(
815  MKLEngine<BRNG, Bits> &, std::size_t, double *, double);
816 
817 template <MKL_INT BRNG, int Bits>
818 inline void extreme_value_distribution(
819  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
820 
821 template <MKL_INT BRNG, int Bits>
822 inline void extreme_value_distribution(
823  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
824 
825 template <MKL_INT BRNG, int Bits>
826 inline void gamma_distribution(
827  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
828 
829 template <MKL_INT BRNG, int Bits>
830 inline void gamma_distribution(
831  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
832 
833 template <MKL_INT BRNG, int Bits>
834 inline void laplace_distribution(
835  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
836 
837 template <MKL_INT BRNG, int Bits>
838 inline void laplace_distribution(
839  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
840 
841 template <MKL_INT BRNG, int Bits>
842 inline void lognormal_distribution(
843  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
844 
845 template <MKL_INT BRNG, int Bits>
846 inline void lognormal_distribution(
847  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
848 
849 template <MKL_INT BRNG, int Bits>
850 inline void normal_distribution(
851  MKLEngine<BRNG, Bits> &, std::size_t, float *r, float, float);
852 
853 template <MKL_INT BRNG, int Bits>
854 inline void normal_distribution(
855  MKLEngine<BRNG, Bits> &, std::size_t, double *r, double, double);
856 
857 template <MKL_INT BRNG, int Bits>
858 inline void normal_mv_distribution(MKLEngine<BRNG, Bits> &, std::size_t,
859  float *, std::size_t, const float *, const float *);
860 
861 template <MKL_INT BRNG, int Bits>
862 inline void normal_mv_distribution(MKLEngine<BRNG, Bits> &, std::size_t,
863  double *, std::size_t, const double *, const double *);
864 
865 template <MKL_INT BRNG, int Bits>
866 inline void rayleigh_distribution(
867  MKLEngine<BRNG, Bits> &, std::size_t, float *, float);
868 
869 template <MKL_INT BRNG, int Bits>
870 inline void rayleigh_distribution(
871  MKLEngine<BRNG, Bits> &, std::size_t, double *, double);
872 
873 template <MKL_INT BRNG, int Bits>
874 inline void u01_distribution(MKLEngine<BRNG, Bits> &, std::size_t, float *);
875 
876 template <MKL_INT BRNG, int Bits>
877 inline void u01_distribution(MKLEngine<BRNG, Bits> &, std::size_t, double *);
878 
879 template <MKL_INT BRNG, int Bits>
880 inline void uniform_real_distribution(
881  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
882 
883 template <MKL_INT BRNG, int Bits>
884 inline void uniform_real_distribution(
885  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
886 
887 template <MKL_INT BRNG, int Bits>
888 inline void weibull_distribution(
889  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
890 
891 template <MKL_INT BRNG, int Bits>
892 inline void weibull_distribution(
893  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
894 
895 #endif // VSMC_HAS_MKL
896 
897 } // namespace vsmc
898 
899 #endif // VSMC_RNG_INTERNAL_COMMON_HPP
#define VSMC_DEFINE_TYPE_DISPATCH_TRAIT(Outer, Inner, Default)
Definition: traits.hpp:40
Definition: monitor.hpp:49
Rayleigh distribution.
Definition: common.hpp:591
void laplace_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating laplace random variates.
void normal_mv_distribution(RNGType &, std::size_t, RealType *, std::size_t, const RealType *, const RealType *)
Generating multivariate Normal random varaites.
void student_t_distribution(RNGType &, std::size_t, RealType *, RealType)
Generating student-t random variates.
void logistic_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating logistic random variates.
void u01_lr_distribution(RNGType &, std::size_t, RealType *)
Uniform real distribution.
Definition: common.hpp:606
Random walk MCMC update with test function.
Definition: common.hpp:537
Find the smallest N such that (RNGType::min() >> N) == 0
Definition: common.hpp:455
void cauchy_distribution(RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
Generating cauchy random variates.
Random walk MCMC update.
Definition: common.hpp:534
STL namespace.
Find the largest N such that RNGType::max() >= (M >> (W - N)) where M = std::numeric_limits<typename ...
Definition: common.hpp:491
void lognormal_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating lognormal random variates.
void rng_rand(RNGType &rng, BetaDistribution< RealType > &dist, std::size_t n, RealType *r)
Counter based RNG engine.
Definition: counter.hpp:289
MKL RNG C++11 engine.
Definition: common.hpp:787
void exponential_distribution(RNGType &rng, std::size_t n, RealType *r, RealType lambda)
Generating exponential random variates.
Student-t distribution.
Definition: common.hpp:594
void u01_distribution(RNGType &, std::size_t, RealType *)
Generate standard uniform random variates.
static constexpr int value
Definition: common.hpp:439
void normal_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating Normal random variates.
void rayleigh_distribution(RNGType &, std::size_t, RealType *, RealType)
Generating rayleigh random variates.
void pareto_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating pareto random variates.
typename KeyTypeTrait< T >::type KeyType
Definition: common.hpp:430
Normal distribution.
Definition: common.hpp:582
typename Generator::result_type result_type
Definition: counter.hpp:292
void weibull_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating weibull random variates.
void extreme_value_distribution(RNGType &rng, std::size_t n, RealType *r, RealType a, RealType b)
Generating extreme_value random variates.
Multivariate Normal distribution.
Definition: common.hpp:585
Levy distribution.
Definition: common.hpp:573
Normal random walk proposal.
Definition: common.hpp:540
void chi_squared_distribution(RNGType &rng, std::size_t n, RealType *r, RealType df)
Generating random variates.
void beta_distribution(RNGType &rng, std::size_t n, RealType *r, RealType alpha, RealType beta)
Generating beta random variates.
void uniform_bits_distribution(RNGType &, std::size_t, UIntType *)
Standard uniform distribution.
Definition: common.hpp:597
Multivariate Normal random walk proposal.
Definition: common.hpp:543
Draw a single sample given weights.
void fisher_f_distribution(RNGType &rng, std::size_t n, RealType *r, RealType df1, RealType df2)
Generating Fisher-F random variates.
void uniform_real_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generate uniform real random variates with open/closed variants.
The value of RNGMaxBits<RNGType>::value - RNGMinBits<RNGType>::value.
Definition: common.hpp:508
Uniform bits distribution.
Definition: common.hpp:603
Weibull distribution.
Definition: common.hpp:609
Lognormal distribution.
Definition: common.hpp:579
void gamma_distribution(RNGType &rng, std::size_t n, RealType *r, RealType alpha, RealType beta)
Generating gamma random variates.
Laplace distribution.
Definition: common.hpp:570
internal::MKLResultType< Bits > result_type
Definition: mkl.hpp:214
Pareto distribution.
Definition: common.hpp:588
void levy_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating levy random variates.
Logistic distribution.
Definition: common.hpp:576