vSMC  v3.0.0
Scalable Monte Carlo
rng/internal/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 
37 #if VSMC_HAS_MKL
38 #include <mkl_version.h>
39 #include <mkl_vsl.h>
40 #endif
41 
42 #define VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM(flag, Name) \
43  VSMC_RUNTIME_ASSERT((flag), \
44  "**" #Name "Distribution** CONSTRUCTED WITH INVALID PARAMETERS")
45 
46 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_0(Name, T, t, Type) \
47  public: \
48  class param_type \
49  { \
50  static_assert(std::is_##t<T>::value, \
51  "**" #Name "Distribution::param_type** USED WITH " #T \
52  " OTHER THAN " #Type " INTEGER TYPES"); \
53  \
54  public: \
55  using result_type = T; \
56  using distribution_type = Name##Distribution<T>; \
57  \
58  friend bool operator==(const param_type &, const param_type &) \
59  { \
60  return true; \
61  } \
62  \
63  friend bool operator!=(const param_type &, const param_type &) \
64  { \
65  return false; \
66  } \
67  \
68  template <typename CharT, typename Traits> \
69  friend std::basic_ostream<CharT, Traits> &operator<<( \
70  std::basic_ostream<CharT, Traits> &os, const param_type &) \
71  { \
72  return os; \
73  } \
74  \
75  template <typename CharT, typename Traits> \
76  friend std::basic_istream<CharT, Traits> &operator>>( \
77  std::basic_istream<CharT, Traits> &is, param_type &) \
78  { \
79  return is; \
80  } \
81  \
82  private: \
83  friend distribution_type; \
84  }; // class param_type
85 
86 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_1(Name, name, p1, v1) \
87  public: \
88  class param_type \
89  { \
90  static_assert(std::is_floating_point<RealType>::value, \
91  "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \
92  "THAN FLOATING POINT TYPES"); \
93  \
94  public: \
95  using result_type = RealType; \
96  using distribution_type = Name##Distribution<RealType>; \
97  \
98  explicit param_type(result_type p1 = v1) : p1##_(p1) \
99  { \
100  VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \
101  internal::name##_distribution_check_param(p1), Name); \
102  } \
103  \
104  result_type p1() const { return p1##_; } \
105  \
106  friend bool operator==( \
107  const param_type &param1, const param_type &param2) \
108  { \
109  if (!internal::is_equal(param1.p1##_, param2.p1##_)) \
110  return false; \
111  return true; \
112  } \
113  \
114  friend bool operator!=( \
115  const param_type &param1, const param_type &param2) \
116  { \
117  return !(param1 == param2); \
118  } \
119  \
120  template <typename CharT, typename Traits> \
121  friend std::basic_ostream<CharT, Traits> &operator<<( \
122  std::basic_ostream<CharT, Traits> &os, const param_type &param) \
123  { \
124  if (!os) \
125  return os; \
126  \
127  os << param.p1##_; \
128  \
129  return os; \
130  } \
131  \
132  template <typename CharT, typename Traits> \
133  friend std::basic_istream<CharT, Traits> &operator>>( \
134  std::basic_istream<CharT, Traits> &is, param_type &param) \
135  { \
136  if (!is) \
137  return is; \
138  \
139  result_type p1 = 0; \
140  is >> std::ws >> p1; \
141  \
142  if (is) { \
143  if (internal::name##_distribution_check_param(p1)) { \
144  param.p1##_ = p1; \
145  } else { \
146  is.setstate(std::ios_base::failbit); \
147  } \
148  } \
149  \
150  return is; \
151  } \
152  \
153  private: \
154  result_type p1##_; \
155  \
156  friend distribution_type; \
157  }; // class param_type
158 
159 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_2(Name, name, p1, v1, p2, v2) \
160  public: \
161  class param_type \
162  { \
163  static_assert(std::is_floating_point<RealType>::value, \
164  "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \
165  "THAN FLOATING POINT TYPES"); \
166  \
167  public: \
168  using result_type = RealType; \
169  using distribution_type = Name##Distribution<RealType>; \
170  \
171  explicit param_type(result_type p1 = v1, result_type p2 = v2) \
172  : p1##_(p1), p2##_(p2) \
173  { \
174  VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \
175  internal::name##_distribution_check_param(p1, p2), Name); \
176  } \
177  \
178  result_type p1() const { return p1##_; } \
179  result_type p2() const { return p2##_; } \
180  \
181  friend bool operator==( \
182  const param_type &param1, const param_type &param2) \
183  { \
184  if (!internal::is_equal(param1.p1##_, param2.p1##_)) \
185  return false; \
186  if (!internal::is_equal(param1.p2##_, param2.p2##_)) \
187  return false; \
188  return true; \
189  } \
190  \
191  friend bool operator!=( \
192  const param_type &param1, const param_type &param2) \
193  { \
194  return !(param1 == param2); \
195  } \
196  \
197  template <typename CharT, typename Traits> \
198  friend std::basic_ostream<CharT, Traits> &operator<<( \
199  std::basic_ostream<CharT, Traits> &os, const param_type &param) \
200  { \
201  if (!os) \
202  return os; \
203  \
204  os << param.p1##_ << ' '; \
205  os << param.p2##_; \
206  \
207  return os; \
208  } \
209  \
210  template <typename CharT, typename Traits> \
211  friend std::basic_istream<CharT, Traits> &operator>>( \
212  std::basic_istream<CharT, Traits> &is, param_type &param) \
213  { \
214  if (!is) \
215  return is; \
216  \
217  result_type p1 = 0; \
218  result_type p2 = 0; \
219  is >> std::ws >> p1; \
220  is >> std::ws >> p2; \
221  \
222  if (is) { \
223  if (internal::name##_distribution_check_param(p1, p2)) { \
224  param.p1##_ = p1; \
225  param.p2##_ = p2; \
226  } else { \
227  is.setstate(std::ios_base::failbit); \
228  } \
229  } \
230  \
231  return is; \
232  } \
233  \
234  private: \
235  result_type p1##_; \
236  result_type p2##_; \
237  \
238  friend distribution_type; \
239  }; // class param_type
240 
241 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_3( \
242  Name, name, p1, v1, p2, v2, p3, v3) \
243  public: \
244  class param_type \
245  { \
246  static_assert(std::is_floating_point<RealType>::value, \
247  "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \
248  "THAN FLOATING POINT TYPES"); \
249  \
250  public: \
251  using result_type = RealType; \
252  using distribution_type = Name##Distribution<RealType>; \
253  \
254  explicit param_type( \
255  result_type p1 = v1, result_type p2 = v2, result_type p3 = v3) \
256  : p1##_(p1), p2##_(p2), p3##_(p3) \
257  { \
258  VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \
259  internal::name##_distribution_check_param(p1, p2, p3), Name); \
260  } \
261  \
262  result_type p1() const { return p1##_; } \
263  result_type p2() const { return p2##_; } \
264  result_type p3() const { return p3##_; } \
265  \
266  friend bool operator==( \
267  const param_type &param1, const param_type &param2) \
268  { \
269  if (!internal::is_equal(param1.p1##_, param2.p1##_)) \
270  return false; \
271  if (!internal::is_equal(param1.p2##_, param2.p2##_)) \
272  return false; \
273  if (!internal::is_equal(param1.p3##_, param2.p3##_)) \
274  return false; \
275  return true; \
276  } \
277  \
278  friend bool operator!=( \
279  const param_type &param1, const param_type &param2) \
280  { \
281  return !(param1 == param2); \
282  } \
283  \
284  template <typename CharT, typename Traits> \
285  friend std::basic_ostream<CharT, Traits> &operator<<( \
286  std::basic_ostream<CharT, Traits> &os, const param_type &param) \
287  { \
288  if (!os) \
289  return os; \
290  \
291  os << param.p1##_ << ' '; \
292  os << param.p2##_ << ' '; \
293  os << param.p3##_; \
294  \
295  return os; \
296  } \
297  \
298  template <typename CharT, typename Traits> \
299  friend std::basic_istream<CharT, Traits> &operator>>( \
300  std::basic_istream<CharT, Traits> &is, param_type &param) \
301  { \
302  if (!is) \
303  return is; \
304  \
305  result_type p1 = 0; \
306  result_type p2 = 0; \
307  result_type p3 = 0; \
308  is >> std::ws >> p1; \
309  is >> std::ws >> p2; \
310  is >> std::ws >> p3; \
311  \
312  if (is) { \
313  if (internal::name##_distribution_check_param(p1, p2, p3)) { \
314  param.p1##_ = p1; \
315  param.p2##_ = p2; \
316  param.p3##_ = p3; \
317  } else { \
318  is.setstate(std::ios_base::failbit); \
319  } \
320  } \
321  \
322  return is; \
323  } \
324  \
325  private: \
326  result_type p1##_; \
327  result_type p2##_; \
328  result_type p3##_; \
329  \
330  friend distribution_type; \
331  }; // class param_type
332 
333 #define VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_4( \
334  Name, name, p1, v1, p2, v2, p3, v3, p4, v4) \
335  public: \
336  class param_type \
337  { \
338  static_assert(std::is_floating_point<RealType>::value, \
339  "**" #Name "Distribution::param_type** USED WITH RealType OTHER " \
340  "THAN FLOATING POINT TYPES"); \
341  \
342  public: \
343  using result_type = RealType; \
344  using distribution_type = Name##Distribution<RealType>; \
345  \
346  explicit param_type(result_type p1 = v1, result_type p2 = v2, \
347  result_type p3 = v3, result_type p4 = v4) \
348  : p1##_(p1), p2##_(p2), p3##_(p3), p4##_(p4) \
349  { \
350  VSMC_RUNTIME_ASSERT_RNG_DISTRIBUTION_PARAM( \
351  internal::name##_distribution_check_param(p1, p2, p3, p4), \
352  Name); \
353  } \
354  \
355  result_type p1() const { return p1##_; } \
356  result_type p2() const { return p2##_; } \
357  result_type p3() const { return p3##_; } \
358  result_type p4() const { return p4##_; } \
359  \
360  friend bool operator==( \
361  const param_type &param1, const param_type &param2) \
362  { \
363  if (!internal::is_equal(param1.p1##_, param2.p1##_)) \
364  return false; \
365  if (!internal::is_equal(param1.p2##_, param2.p2##_)) \
366  return false; \
367  if (!internal::is_equal(param1.p3##_, param2.p3##_)) \
368  return false; \
369  if (!internal::is_equal(param1.p4##_, param2.p4##_)) \
370  return false; \
371  return true; \
372  } \
373  \
374  friend bool operator!=( \
375  const param_type &param1, const param_type &param2) \
376  { \
377  return !(param1 == param2); \
378  } \
379  \
380  template <typename CharT, typename Traits> \
381  friend std::basic_ostream<CharT, Traits> &operator<<( \
382  std::basic_ostream<CharT, Traits> &os, const param_type &param) \
383  { \
384  if (!os) \
385  return os; \
386  \
387  os << param.p1##_ << ' '; \
388  os << param.p2##_ << ' '; \
389  os << param.p3##_ << ' '; \
390  os << param.p4##_; \
391  \
392  return os; \
393  } \
394  \
395  template <typename CharT, typename Traits> \
396  friend std::basic_istream<CharT, Traits> &operator>>( \
397  std::basic_istream<CharT, Traits> &is, param_type &param) \
398  { \
399  if (!is) \
400  return is; \
401  \
402  result_type p1 = 0; \
403  result_type p2 = 0; \
404  result_type p3 = 0; \
405  result_type p4 = 0; \
406  is >> std::ws >> p1; \
407  is >> std::ws >> p2; \
408  is >> std::ws >> p3; \
409  is >> std::ws >> p4; \
410  \
411  if (is) { \
412  if (internal::name##_distribution_check_param( \
413  p1, p2, p3, p4)) { \
414  param.p1##_ = p1; \
415  param.p2##_ = p2; \
416  param.p3##_ = p3; \
417  param.p4##_ = p4; \
418  } else { \
419  is.setstate(std::ios_base::failbit); \
420  } \
421  } \
422  \
423  return is; \
424  } \
425  \
426  private: \
427  result_type p1##_; \
428  result_type p2##_; \
429  result_type p3##_; \
430  result_type p4##_; \
431  \
432  friend distribution_type; \
433  }; // class param_type
434 
435 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_0(Name, T) \
436  public: \
437  using result_type = T; \
438  using distribution_type = Name##Distribution<T>; \
439  \
440  Name##Distribution() = default; \
441  explicit Name##Distribution(const param_type &) {}
442 
443 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_1(Name, p1, v1) \
444  public: \
445  using result_type = RealType; \
446  using distribution_type = Name##Distribution<RealType>; \
447  \
448  explicit Name##Distribution(result_type p1 = v1) : param_(p1) \
449  { \
450  reset(); \
451  } \
452  \
453  explicit Name##Distribution(const param_type &param) : param_(param) \
454  { \
455  reset(); \
456  } \
457  \
458  result_type p1() const { return param_.p1(); }
459 
460 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_2(Name, p1, v1, p2, v2) \
461  public: \
462  using result_type = RealType; \
463  using distribution_type = Name##Distribution<RealType>; \
464  \
465  explicit Name##Distribution(result_type p1 = v1, result_type p2 = v2) \
466  : param_(p1, p2) \
467  { \
468  reset(); \
469  } \
470  \
471  explicit Name##Distribution(const param_type &param) : param_(param) \
472  { \
473  reset(); \
474  } \
475  \
476  result_type p1() const { return param_.p1(); } \
477  result_type p2() const { return param_.p2(); }
478 
479 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_3( \
480  Name, p1, v1, p2, v2, p3, v3) \
481  public: \
482  using result_type = RealType; \
483  using distribution_type = Name##Distribution<RealType>; \
484  \
485  explicit Name##Distribution( \
486  result_type p1 = v1, result_type p2 = v2, result_type p3 = v3) \
487  : param_(p1, p2, p3) \
488  { \
489  reset(); \
490  } \
491  \
492  explicit Name##Distribution(const param_type &param) : param_(param) \
493  { \
494  reset(); \
495  } \
496  \
497  result_type p1() const { return param_.p1(); } \
498  result_type p2() const { return param_.p2(); } \
499  result_type p3() const { return param_.p3(); }
500 
501 #define VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_4( \
502  Name, p1, v1, p2, v2, p3, v3, p4, v4) \
503  public: \
504  using result_type = RealType; \
505  using distribution_type = Name##Distribution<RealType>; \
506  \
507  explicit Name##Distribution(result_type p1 = v1, result_type p2 = v2, \
508  result_type p3 = v3, result_type p4 = v4) \
509  : param_(p1, p2, p3, p4) \
510  { \
511  reset(); \
512  } \
513  \
514  explicit Name##Distribution(const param_type &param) : param_(param) \
515  { \
516  reset(); \
517  } \
518  \
519  result_type p1() const { return param_.p1(); } \
520  result_type p2() const { return param_.p2(); } \
521  result_type p3() const { return param_.p3(); } \
522  result_type p4() const { return param_.p4(); }
523 
524 #define VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name) \
525  public: \
526  const param_type &param() const { return param_; } \
527  \
528  void param(const param_type &param) \
529  { \
530  param_ = param; \
531  reset(); \
532  } \
533  \
534  void pram(param_type &&param) \
535  { \
536  param_ = std::move(param); \
537  reset(); \
538  } \
539  \
540  template <typename RNGType> \
541  result_type operator()(RNGType &rng) \
542  { \
543  return operator()(rng, param_); \
544  } \
545  \
546  template <typename RNGType> \
547  result_type operator()(RNGType &rng, const param_type &param) \
548  { \
549  return generate(rng, param); \
550  } \
551  \
552  template <typename RNGType> \
553  void operator()(RNGType &rng, std::size_t n, result_type *r) \
554  { \
555  operator()(rng, n, r, param_); \
556  } \
557  \
558  template <typename RNGType> \
559  void operator()( \
560  RNGType &rng, std::size_t n, result_type *r, const param_type &param) \
561  { \
562  if (n < 100) { \
563  for (std::size_t i = 0; i != n; ++i) \
564  r[i] = operator()(rng, param); \
565  } else { \
566  name##_distribution(rng, n, r, param); \
567  } \
568  } \
569  \
570  friend bool operator==( \
571  const distribution_type &dist1, const distribution_type &dist2) \
572  { \
573  return dist1.param_ == dist2.param_ && dist1.is_equal(dist2); \
574  } \
575  \
576  friend bool operator!=( \
577  const distribution_type &dist1, const distribution_type &dist2) \
578  { \
579  return !(dist1 == dist2); \
580  } \
581  \
582  template <typename CharT, typename Traits> \
583  friend std::basic_ostream<CharT, Traits> &operator<<( \
584  std::basic_ostream<CharT, Traits> &os, const distribution_type &dist) \
585  { \
586  if (!os) \
587  return os; \
588  \
589  os << dist.param_; \
590  dist.ostream(os); \
591  \
592  return os; \
593  } \
594  \
595  template <typename CharT, typename Traits> \
596  friend std::basic_istream<CharT, Traits> &operator>>( \
597  std::basic_istream<CharT, Traits> &is, distribution_type &dist) \
598  { \
599  if (!is) \
600  return is; \
601  \
602  is >> std::ws >> dist.param_; \
603  if (is) \
604  dist.istream(is); \
605  \
606  return is; \
607  } \
608  \
609  private: \
610  param_type param_;
611 
612 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_0 \
613  private: \
614  bool is_equal(const distribution_type &) const { return true; } \
615  \
616  template <typename CharT, typename Traits> \
617  void ostream(std::basic_ostream<CharT, Traits> &) const \
618  { \
619  } \
620  \
621  template <typename CharT, typename Traits> \
622  void istream(std::basic_istream<CharT, Traits> &) \
623  { \
624  }
625 
626 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_1(T1, m1) \
627  private: \
628  T1 m1; \
629  \
630  bool is_equal(const distribution_type &other) const \
631  { \
632  if (!internal::is_equal(m1, other.m1)) \
633  return false; \
634  return true; \
635  } \
636  \
637  template <typename CharT, typename Traits> \
638  void ostream(std::basic_ostream<CharT, Traits> &os) const \
639  { \
640  if (!os) \
641  return; \
642  \
643  os << ' ' << m1; \
644  } \
645  \
646  template <typename CharT, typename Traits> \
647  void istream(std::basic_istream<CharT, Traits> &is) \
648  { \
649  if (!is) \
650  return; \
651  \
652  T1 tmp1; \
653  is >> std::ws >> tmp1; \
654  if (is) { \
655  m1 = std::move(tmp1); \
656  } \
657  }
658 
659 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_2(T1, m1, T2, m2) \
660  private: \
661  T1 m1; \
662  T2 m2; \
663  \
664  bool is_equal(const distribution_type &other) const \
665  { \
666  if (!internal::is_equal(m1, other.m1)) \
667  return false; \
668  if (!internal::is_equal(m2, other.m2)) \
669  return false; \
670  return true; \
671  } \
672  \
673  template <typename CharT, typename Traits> \
674  void ostream(std::basic_ostream<CharT, Traits> &os) const \
675  { \
676  if (!os) \
677  return; \
678  \
679  os << ' ' << m1; \
680  os << ' ' << m2; \
681  } \
682  \
683  template <typename CharT, typename Traits> \
684  void istream(std::basic_istream<CharT, Traits> &is) \
685  { \
686  if (!is) \
687  return; \
688  \
689  T1 tmp1; \
690  T2 tmp2; \
691  is >> std::ws >> tmp1; \
692  is >> std::ws >> tmp2; \
693  if (is) { \
694  m1 = std::move(tmp1); \
695  m2 = std::move(tmp2); \
696  } \
697  }
698 
699 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_3(T1, m1, T2, m2, T3, m3) \
700  private: \
701  T1 m1; \
702  T2 m2; \
703  T3 m3; \
704  \
705  bool is_equal(const distribution_type &other) const \
706  { \
707  if (!internal::is_equal(m1, other.m1)) \
708  return false; \
709  if (!internal::is_equal(m2, other.m2)) \
710  return false; \
711  if (!internal::is_equal(m3, other.m3)) \
712  return false; \
713  return true; \
714  } \
715  \
716  template <typename CharT, typename Traits> \
717  void ostream(std::basic_ostream<CharT, Traits> &os) const \
718  { \
719  if (!os) \
720  return; \
721  \
722  os << ' ' << m1; \
723  os << ' ' << m2; \
724  os << ' ' << m3; \
725  } \
726  \
727  template <typename CharT, typename Traits> \
728  void istream(std::basic_istream<CharT, Traits> &is) \
729  { \
730  if (!is) \
731  return; \
732  \
733  T1 tmp1; \
734  T2 tmp2; \
735  T3 tmp3; \
736  is >> std::ws >> tmp1; \
737  is >> std::ws >> tmp2; \
738  is >> std::ws >> tmp3; \
739  if (is) { \
740  m1 = std::move(tmp1); \
741  m2 = std::move(tmp2); \
742  m3 = std::move(tmp3); \
743  } \
744  }
745 
746 #define VSMC_DEFINE_RNG_DISTRIBUTION_MEMBER_4(T1, m1, T2, m2, T3, m3, T4, m4) \
747  private: \
748  T1 m1; \
749  T2 m2; \
750  T3 m3; \
751  T4 m4; \
752  \
753  bool is_equal(const distribution_type &other) const \
754  { \
755  if (!internal::is_equal(m1, other.m1)) \
756  return false; \
757  if (!internal::is_equal(m2, other.m2)) \
758  return false; \
759  if (!internal::is_equal(m3, other.m3)) \
760  return false; \
761  if (!internal::is_equal(m4, other.m4)) \
762  return false; \
763  return true; \
764  } \
765  \
766  template <typename CharT, typename Traits> \
767  void ostream(std::basic_ostream<CharT, Traits> &os) const \
768  { \
769  if (!os) \
770  return; \
771  \
772  os << ' ' << m1; \
773  os << ' ' << m2; \
774  os << ' ' << m3; \
775  os << ' ' << m4; \
776  } \
777  \
778  template <typename CharT, typename Traits> \
779  void istream(std::basic_istream<CharT, Traits> &is) \
780  { \
781  if (!is) \
782  return; \
783  \
784  T1 tmp1; \
785  T2 tmp2; \
786  T3 tmp3; \
787  T4 tmp4; \
788  is >> std::ws >> tmp1; \
789  is >> std::ws >> tmp2; \
790  is >> std::ws >> tmp3; \
791  is >> std::ws >> tmp4; \
792  if (is) { \
793  m1 = std::move(tmp1); \
794  m2 = std::move(tmp2); \
795  m3 = std::move(tmp3); \
796  m4 = std::move(tmp4); \
797  } \
798  }
799 
800 #define VSMC_DEFINE_RNG_DISTRIBUTION_0(Name, name, T, t, Type) \
801  VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_0(Name, T, t, Type) \
802  VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_0(Name, T) \
803  VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name)
804 
805 #define VSMC_DEFINE_RNG_DISTRIBUTION_1(Name, name, p1, v1) \
806  VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_1(Name, name, p1, v1) \
807  VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_1(Name, p1, v1) \
808  VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name)
809 
810 #define VSMC_DEFINE_RNG_DISTRIBUTION_2(Name, name, p1, v1, p2, v2) \
811  VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_2(Name, name, p1, v1, p2, v2) \
812  VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_2(Name, p1, v1, p2, v2) \
813  VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name)
814 
815 #define VSMC_DEFINE_RNG_DISTRIBUTION_3(Name, name, p1, v1, p2, v2, p3, v3) \
816  VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_3( \
817  Name, name, p1, v1, p2, v2, p3, v3) \
818  VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_3(Name, p1, v1, p2, v2, p3, v3) \
819  VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name)
820 
821 #define VSMC_DEFINE_RNG_DISTRIBUTION_4( \
822  Name, name, p1, v1, p2, v2, p3, v3, p4, v4) \
823  VSMC_DEFINE_RNG_DISTRIBUTION_PARAM_TYPE_4( \
824  Name, name, p1, v1, p2, v2, p3, v3, p4, v4) \
825  VSMC_DEFINE_RNG_DISTRIBUTION_CONSTRUCTOR_3( \
826  Name, p1, v1, p2, v2, p3, v3, p4, v4) \
827  VSMC_DEFINE_RNG_DISTRIBUTION_OPERATOR(Name, name)
828 
829 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_0(name) \
830  template <typename RealType, typename RNGType> \
831  inline void name##_distribution(RNGType &rng, std::size_t n, RealType *r) \
832  { \
833  static_assert(std::is_floating_point<RealType>::value, \
834  "**" #name "_distribution** USED WITH RealType OTHER THAN " \
835  "FLOATING POINT TYPES"); \
836  \
837  const std::size_t K = internal::BufferSize<RealType>::value; \
838  const std::size_t M = n / K; \
839  const std::size_t L = n % K; \
840  for (std::size_t i = 0; i != M; ++i, r += K) \
841  internal::name##_distribution_impl<K>(rng, K, r); \
842  internal::name##_distribution_impl<K>(rng, L, r); \
843  }
844 
845 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_1(name, p1) \
846  template <typename RealType, typename RNGType> \
847  inline void name##_distribution( \
848  RNGType &rng, std::size_t N, RealType *r, RealType p1) \
849  { \
850  static_assert(std::is_floating_point<RealType>::value, \
851  "**" #name "_distribution** USED WITH RealType OTHER THAN " \
852  "FLOATING POINT TYPES"); \
853  \
854  const std::size_t K = internal::BufferSize<RealType>::value; \
855  const std::size_t M = N / K; \
856  const std::size_t L = N % K; \
857  for (std::size_t i = 0; i != M; ++i, r += K) \
858  internal::name##_distribution_impl<K>(rng, K, r, p1); \
859  internal::name##_distribution_impl<K>(rng, L, r, p1); \
860  }
861 
862 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_2(name, p1, p2) \
863  template <typename RealType, typename RNGType> \
864  inline void name##_distribution( \
865  RNGType &rng, std::size_t N, RealType *r, RealType p1, RealType p2) \
866  { \
867  static_assert(std::is_floating_point<RealType>::value, \
868  "**" #name "_distribution** USED WITH RealType OTHER THAN " \
869  "FLOATING POINT TYPES"); \
870  \
871  const std::size_t K = internal::BufferSize<RealType>::value; \
872  const std::size_t M = N / K; \
873  const std::size_t L = N % K; \
874  for (std::size_t i = 0; i != M; ++i, r += K) \
875  internal::name##_distribution_impl<K>(rng, K, r, p1, p2); \
876  internal::name##_distribution_impl<K>(rng, L, r, p1, p2); \
877  }
878 
879 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_3(name, p1, p2, p3) \
880  template <typename RealType, typename RNGType> \
881  inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \
882  RealType p1, RealType p2, RealType p3) \
883  { \
884  static_assert(std::is_floating_point<RealType>::value, \
885  "**" #name "_distribution** USED WITH RealType OTHER THAN " \
886  "FLOATING POINT TYPES"); \
887  \
888  const std::size_t K = internal::BufferSize<RealType>::value; \
889  const std::size_t M = N / K; \
890  const std::size_t L = N % K; \
891  for (std::size_t i = 0; i != M; ++i, r += K) \
892  internal::name##_distribution_impl<K>(rng, K, r, p1, p2, p3); \
893  internal::name##_distribution_impl<K>(rng, L, r, p1, p2, p3); \
894  }
895 
896 #define VSMC_DEFINE_RNG_DISTRIBUTION_IMPL_4(name, p1, p2, p3, p4) \
897  template <typename RealType, typename RNGType> \
898  inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \
899  RealType p1, RealType p2, RealType p3, RealType p4) \
900  { \
901  static_assert(std::is_floating_point<RealType>::value, \
902  "**" #name "_distribution** USED WITH RealType OTHER THAN " \
903  "FLOATING POINT TYPES"); \
904  \
905  const std::size_t K = internal::BufferSize<RealType>::value; \
906  const std::size_t M = N / K; \
907  const std::size_t L = N % K; \
908  for (std::size_t i = 0; i != M; ++i, r += K) \
909  internal::name##_distribution_impl<K>(rng, K, r, p1, p2, p3, p4); \
910  internal::name##_distribution_impl<K>(rng, L, r, p1, p2, p3, p4); \
911  }
912 
913 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_0(Name, name, T) \
914  template <typename T, typename RNGType> \
915  inline void name##_distribution(RNGType &rng, std::size_t N, T *r, \
916  const typename Name##Distribution<T>::param_type &) \
917  { \
918  name##_distribution(rng, N, r); \
919  } \
920  \
921  template <typename T, typename RNGType> \
922  inline void rand( \
923  RNGType &rng, Name##Distribution<T> &dist, std::size_t N, T *r) \
924  { \
925  dist(rng, N, r); \
926  }
927 
928 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_1(Name, name, p1) \
929  template <typename RealType, typename RNGType> \
930  inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \
931  const typename Name##Distribution<RealType>::param_type &param) \
932  { \
933  name##_distribution(rng, N, r, param.p1()); \
934  } \
935  \
936  template <typename RealType, typename RNGType> \
937  inline void rand(RNGType &rng, Name##Distribution<RealType> &dist, \
938  std::size_t N, RealType *r) \
939  { \
940  dist(rng, N, r); \
941  }
942 
943 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_2(Name, name, p1, p2) \
944  template <typename RealType, typename RNGType> \
945  inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \
946  const typename Name##Distribution<RealType>::param_type &param) \
947  { \
948  name##_distribution(rng, N, r, param.p1(), param.p2()); \
949  } \
950  \
951  template <typename RealType, typename RNGType> \
952  inline void rand(RNGType &rng, Name##Distribution<RealType> &dist, \
953  std::size_t N, RealType *r) \
954  { \
955  dist(rng, N, r); \
956  }
957 
958 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_3(Name, name, p1, p2, p3) \
959  template <typename RealType, typename RNGType> \
960  inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \
961  const typename Name##Distribution<RealType>::param_type &param) \
962  { \
963  name##_distribution(rng, N, r, param.p1(), param.p2(), param.p3()); \
964  } \
965  \
966  template <typename RealType, typename RNGType> \
967  inline void rand(RNGType &rng, Name##Distribution<RealType> &dist, \
968  std::size_t N, RealType *r) \
969  { \
970  dist(rng, N, r); \
971  }
972 
973 #define VSMC_DEFINE_RNG_DISTRIBUTION_RAND_4(Name, name, p1, p2, p3, p4) \
974  template <typename RealType, typename RNGType> \
975  inline void name##_distribution(RNGType &rng, std::size_t N, RealType *r, \
976  const typename Name##Distribution<RealType>::param_type &param) \
977  { \
978  name##_distribution( \
979  rng, N, r, param.p1(), param.p2(), param.p3, p4()); \
980  } \
981  \
982  template <typename RealType, typename RNGType> \
983  inline void rand(RNGType &rng, Name##Distribution<RealType> &dist, \
984  std::size_t N, RealType *r) \
985  { \
986  dist(rng, N, r); \
987  }
988 
989 namespace vsmc
990 {
991 
992 namespace internal
993 {
994 
997 
998 } // namespace vsmc::internal
999 
1002 template <typename RNGType>
1004 {
1005  using result_type = typename RNGType::result_type;
1006 
1007  static constexpr typename RNGType::result_type R_ = RNGType::min() == 0 &&
1008  RNGType::max() == std::numeric_limits<result_type>::max() ?
1009  0 :
1010  RNGType::max() - RNGType::min() + static_cast<result_type>(1);
1011 
1012  public:
1015  static constexpr bool is_full_range =
1016  RNGType::min() == 0 && (R_ & (R_ - 1)) == 0;
1017 
1018  static constexpr int bits = internal::Log2<result_type, R_>::value;
1019 }; // class RNGTraits;
1020 
1023 class Closed;
1024 
1027 class Open;
1028 
1031 template <typename RNGType>
1032 inline void rand(RNGType &rng, std::size_t n, typename RNGType::result_type *r)
1033 {
1034  for (std::size_t i = 0; i != n; ++i)
1035  r[i] = rng();
1036 }
1037 
1040 template <typename RNGType, typename DistributionType>
1041 inline void rand(RNGType &rng, const DistributionType &distribution,
1042  std::size_t n, typename DistributionType::result_type *r)
1043 {
1044  DistributionType dist(distribution);
1045  for (std::size_t i = 0; i != n; ++i)
1046  r[i] = dist(rng);
1047 }
1048 
1049 template <typename, typename>
1050 class CounterEngine;
1051 
1052 template <typename = double, std::size_t = Dynamic>
1054 
1055 template <typename = double, std::size_t = Dynamic, std::size_t = Dynamic>
1057 
1058 template <typename = double>
1060 
1061 template <typename = double, std::size_t = Dynamic>
1063 
1064 template <typename = double>
1065 class BetaDistribution;
1066 
1067 template <typename = double>
1068 class CauchyDistribution;
1069 
1070 template <typename = double>
1072 
1073 template <typename = int>
1074 class DiscreteDistribution;
1075 
1076 template <typename = double>
1078 
1079 template <typename = double>
1081 
1082 template <typename = double>
1083 class FisherFDistribution;
1084 
1085 template <typename = double>
1086 class GammaDistribution;
1087 
1088 template <typename = double>
1090 
1091 template <typename = double>
1093 
1094 template <typename = double>
1096 
1097 template <typename = double>
1099 
1100 template <typename = double>
1102 
1103 template <typename = double, std::size_t = Dynamic>
1105 
1106 template <typename = double>
1108 
1109 template <typename = double>
1111 
1112 template <typename = double>
1114 
1115 template <typename = double>
1117 
1118 template <typename = double, typename = Open, typename = Closed>
1120 
1121 template <typename = unsigned>
1123 
1124 template <typename = double>
1126 
1127 template <typename = double>
1129 
1130 template <typename ResultType, typename Generator>
1131 inline void rand(
1132  CounterEngine<ResultType, Generator> &, std::size_t, ResultType *);
1133 
1134 template <typename RealType, typename RNGType>
1135 inline void rand(
1136  RNGType &, BetaDistribution<RealType> &, std::size_t, RealType *);
1137 
1138 template <typename RealType, typename RNGType>
1139 inline void rand(
1140  RNGType &, CauchyDistribution<RealType> &, std::size_t, RealType *);
1141 
1142 template <typename RealType, typename RNGType>
1143 inline void rand(
1144  RNGType &, ChiSquaredDistribution<RealType> &, std::size_t, RealType *);
1145 
1146 template <typename RealType, typename RNGType>
1147 inline void rand(
1148  RNGType &, DiscreteDistribution<RealType> &, std::size_t, RealType *);
1149 
1150 template <typename RealType, typename RNGType>
1151 inline void rand(
1152  RNGType &, ExponentialDistribution<RealType> &, std::size_t, RealType *);
1153 
1154 template <typename RealType, typename RNGType>
1155 inline void rand(
1156  RNGType &, ExtremeValueDistribution<RealType> &, std::size_t, RealType *);
1157 
1158 template <typename RealType, typename RNGType>
1159 inline void rand(
1160  RNGType &, FisherFDistribution<RealType> &, std::size_t, RealType *);
1161 
1162 template <typename RealType, typename RNGType>
1163 inline void rand(
1164  RNGType &, GammaDistribution<RealType> &, std::size_t, RealType *);
1165 
1166 template <typename RealType, typename RNGType>
1167 inline void rand(
1168  RNGType &, LaplaceDistribution<RealType> &, std::size_t, RealType *);
1169 
1170 template <typename RealType, typename RNGType>
1171 inline void rand(
1172  RNGType &, LevyDistribution<RealType> &, std::size_t, RealType *);
1173 
1174 template <typename RealType, typename RNGType>
1175 inline void rand(
1176  RNGType &, LogisticDistribution<RealType> &, std::size_t, RealType *);
1177 
1178 template <typename RealType, typename RNGType>
1179 inline void rand(
1180  RNGType &, LognormalDistribution<RealType> &, std::size_t, RealType *);
1181 
1182 template <typename RealType, typename RNGType>
1183 inline void rand(
1184  RNGType &, NormalDistribution<RealType> &, std::size_t, RealType *);
1185 
1186 template <typename RealType, std::size_t Dim, typename RNGType>
1187 inline void rand(
1188  RNGType &, NormalMVDistribution<RealType, Dim> &, std::size_t, RealType *);
1189 
1190 template <typename RealType, typename RNGType>
1191 inline void rand(
1192  RNGType &, ParetoDistribution<RealType> &, std::size_t, RealType *);
1193 
1194 template <typename RealType, typename RNGType>
1195 inline void rand(
1196  RNGType &, RayleighDistribution<RealType> &, std::size_t, RealType *);
1197 
1198 template <typename RealType, typename RNGType>
1199 inline void rand(
1200  RNGType &, StudentTDistribution<RealType> &, std::size_t, RealType *);
1201 
1202 template <typename RealType, typename RNGType>
1203 inline void rand(
1204  RNGType &, U01Distribution<RealType> &, std::size_t, RealType *);
1205 
1206 template <typename RealType, typename RNGType, typename Lower, typename Upper>
1207 inline void rand(RNGType &, U01LRDistribution<RealType, Lower, Upper> &,
1208  std::size_t, RealType *);
1209 
1210 template <typename UIntType, typename RNGType>
1211 inline void rand(
1212  RNGType &, UniformBitsDistribution<UIntType> &, std::size_t, UIntType *);
1213 
1214 template <typename RealType, typename RNGType>
1215 inline void rand(
1216  RNGType &, UniformRealDistribution<RealType> &, std::size_t, RealType *);
1217 
1218 template <typename RealType, typename RNGType>
1219 inline void rand(
1220  RNGType &, WeibullDistribution<RealType> &, std::size_t, RealType *);
1221 
1222 template <typename RealType, typename RNGType>
1223 inline void beta_distribution(
1224  RNGType &, std::size_t, RealType *, RealType, RealType);
1225 
1226 template <typename RealType, typename RNGType>
1227 inline void cauchy_distribution(
1228  RNGType &, std::size_t, RealType *, RealType, RealType);
1229 
1230 template <typename RealType, typename RNGType>
1231 inline void chi_squared_distribution(
1232  RNGType &, std::size_t, RealType *, RealType);
1233 
1234 template <typename RealType, typename RNGType>
1235 inline void exponential_distribution(
1236  RNGType &, std::size_t, RealType *, RealType);
1237 
1238 template <typename RealType, typename RNGType>
1239 inline void extreme_value_distribution(
1240  RNGType &, std::size_t, RealType *, RealType, RealType);
1241 
1242 template <typename RealType, typename RNGType>
1243 inline void fisher_f_distribution(
1244  RNGType &, std::size_t, RealType *, RealType, RealType);
1245 
1246 template <typename RealType, typename RNGType>
1247 inline void gamma_distribution(
1248  RNGType &, std::size_t, RealType *, RealType, RealType);
1249 
1250 template <typename RealType, typename RNGType>
1251 inline void laplace_distribution(
1252  RNGType &, std::size_t, RealType *, RealType, RealType);
1253 
1254 template <typename RealType, typename RNGType>
1255 inline void levy_distribution(
1256  RNGType &, std::size_t, RealType *, RealType, RealType);
1257 
1258 template <typename RealType, typename RNGType>
1259 inline void logistic_distribution(
1260  RNGType &, std::size_t, RealType *, RealType, RealType);
1261 
1262 template <typename RealType, typename RNGType>
1263 inline void lognormal_distribution(
1264  RNGType &, std::size_t, RealType *, RealType, RealType);
1265 
1266 template <typename RealType, typename RNGType>
1267 inline void normal_distribution(
1268  RNGType &, std::size_t, RealType *, RealType, RealType);
1269 
1270 template <typename RealType, typename RNGType>
1271 inline void normal_mv_distribution(RNGType &, std::size_t, RealType *,
1272  std::size_t, const RealType *, const RealType *);
1273 
1274 template <typename RealType, typename RNGType>
1275 inline void pareto_distribution(
1276  RNGType &, std::size_t, RealType *, RealType, RealType);
1277 
1278 template <typename RealType, typename RNGType>
1279 inline void rayleigh_distribution(
1280  RNGType &, std::size_t, RealType *, RealType);
1281 
1282 template <typename RealType, typename RNGType>
1283 inline void student_t_distribution(
1284  RNGType &, std::size_t, RealType *, RealType);
1285 
1286 template <typename RealType, typename RNGType>
1287 inline void u01_distribution(RNGType &, std::size_t, RealType *);
1288 
1289 template <typename, typename, typename RealType, typename RNGType>
1290 inline void u01_lr_distribution(RNGType &, std::size_t, RealType *);
1291 
1292 template <typename UIntType, typename RNGType>
1293 inline void uniform_bits_distribution(RNGType &, std::size_t, UIntType *);
1294 
1295 template <typename RealType, typename RNGType>
1296 inline void uniform_real_distribution(
1297  RNGType &, std::size_t, RealType *, RealType, RealType);
1298 
1299 template <typename RealType, typename RNGType>
1300 inline void weibull_distribution(
1301  RNGType &, std::size_t, RealType *, RealType, RealType);
1302 
1303 #if VSMC_HAS_MKL
1304 
1305 class MKLStream;
1306 
1307 template <MKL_INT, int>
1309 
1310 template <MKL_INT BRNG, int Bits>
1311 inline void rand(MKLEngine<BRNG, Bits> &, std::size_t,
1313 
1314 template <MKL_INT BRNG, int Bits>
1315 inline void beta_distribution(
1316  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
1317 
1318 template <MKL_INT BRNG, int Bits>
1319 inline void beta_distribution(
1320  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
1321 
1322 template <MKL_INT BRNG, int Bits>
1323 inline void cauchy_distribution(
1324  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
1325 
1326 template <MKL_INT BRNG, int Bits>
1327 inline void cauchy_distribution(
1328  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
1329 
1330 template <MKL_INT BRNG, int Bits>
1331 inline void exponential_distribution(
1332  MKLEngine<BRNG, Bits> &, std::size_t, float *, float);
1333 
1334 template <MKL_INT BRNG, int Bits>
1335 inline void exponential_distribution(
1336  MKLEngine<BRNG, Bits> &, std::size_t, double *, double);
1337 
1338 template <MKL_INT BRNG, int Bits>
1339 inline void extreme_value_distribution(
1340  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
1341 
1342 template <MKL_INT BRNG, int Bits>
1343 inline void extreme_value_distribution(
1344  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
1345 
1346 template <MKL_INT BRNG, int Bits>
1347 inline void gamma_distribution(
1348  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
1349 
1350 template <MKL_INT BRNG, int Bits>
1351 inline void gamma_distribution(
1352  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
1353 
1354 template <MKL_INT BRNG, int Bits>
1355 inline void laplace_distribution(
1356  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
1357 
1358 template <MKL_INT BRNG, int Bits>
1359 inline void laplace_distribution(
1360  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
1361 
1362 template <MKL_INT BRNG, int Bits>
1363 inline void lognormal_distribution(
1364  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
1365 
1366 template <MKL_INT BRNG, int Bits>
1367 inline void lognormal_distribution(
1368  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
1369 
1370 template <MKL_INT BRNG, int Bits>
1371 inline void normal_distribution(
1372  MKLEngine<BRNG, Bits> &, std::size_t, float *r, float, float);
1373 
1374 template <MKL_INT BRNG, int Bits>
1375 inline void normal_distribution(
1376  MKLEngine<BRNG, Bits> &, std::size_t, double *r, double, double);
1377 
1378 template <MKL_INT BRNG, int Bits>
1379 inline void normal_mv_distribution(MKLEngine<BRNG, Bits> &, std::size_t,
1380  float *, std::size_t, const float *, const float *);
1381 
1382 template <MKL_INT BRNG, int Bits>
1383 inline void normal_mv_distribution(MKLEngine<BRNG, Bits> &, std::size_t,
1384  double *, std::size_t, const double *, const double *);
1385 
1386 template <MKL_INT BRNG, int Bits>
1387 inline void rayleigh_distribution(
1388  MKLEngine<BRNG, Bits> &, std::size_t, float *, float);
1389 
1390 template <MKL_INT BRNG, int Bits>
1391 inline void rayleigh_distribution(
1392  MKLEngine<BRNG, Bits> &, std::size_t, double *, double);
1393 
1394 template <MKL_INT BRNG, int Bits>
1395 inline void u01_distribution(MKLEngine<BRNG, Bits> &, std::size_t, float *);
1396 
1397 template <MKL_INT BRNG, int Bits>
1398 inline void u01_distribution(MKLEngine<BRNG, Bits> &, std::size_t, double *);
1399 
1400 template <MKL_INT BRNG, int Bits>
1401 inline void uniform_real_distribution(
1402  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
1403 
1404 template <MKL_INT BRNG, int Bits>
1405 inline void uniform_real_distribution(
1406  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
1407 
1408 template <MKL_INT BRNG, int Bits>
1409 inline void weibull_distribution(
1410  MKLEngine<BRNG, Bits> &, std::size_t, float *, float, float);
1411 
1412 template <MKL_INT BRNG, int Bits>
1413 inline void weibull_distribution(
1414  MKLEngine<BRNG, Bits> &, std::size_t, double *, double, double);
1415 
1416 #endif // VSMC_HAS_MKL
1417 
1418 } // namespace vsmc
1419 
1420 #endif // VSMC_RNG_INTERNAL_COMMON_HPP
#define VSMC_DEFINE_TYPE_DISPATCH_TRAIT(Outer, Inner, Default)
Definition: traits.hpp:40
void cauchy_distribution(RNGType &rng, std::size_t N, RealType *r, RealType a, RealType b)
Generating Cauchy random variates.
Definition: monitor.hpp:48
void normal_mv_distribution(RNGType &, std::size_t, RealType *, std::size_t, const RealType *, const RealType *)
Generating multivariate Normal random varaites.
void u01_lr_distribution(RNGType &, std::size_t, RealType *)
Uniform real distribution.
Random walk MCMC update with test function.
Random walk MCMC update.
typename CtrTypeTrait< T >::type CtrType
Counter based RNG engine.
Definition: counter.hpp:187
void logistic_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating logistic random variates.
MKL RNG C++11 engine.
void rayleigh_distribution(RNGType &, std::size_t, RealType *, RealType)
Generating rayleigh random variates.
void levy_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating levy random variates.
Student-t distribution.
void u01_distribution(RNGType &, std::size_t, RealType *)
Generate standard uniform random variates.
void extreme_value_distribution(RNGType &rng, std::size_t N, RealType *r, RealType a, RealType b)
Generating extreme value random variates.
void normal_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating Normal random variates.
void fisher_f_distribution(RNGType &rng, std::size_t N, RealType *r, RealType m, RealType n)
Generating Fisher-F random variates.
typename KeyTypeTrait< T >::type KeyType
Traits of RNG engines.
Multivariate Normal distribution.
Normal random walk proposal.
void pareto_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating pareto random variates.
void lognormal_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating lognormal random variates.
void rand(RNGType &rng, ArcsineDistribution< RealType > &dist, std::size_t N, RealType *r)
void laplace_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating laplace random variates.
MKL VSLStreamStatePtr wrapper.
Definition: mkl.hpp:83
void chi_squared_distribution(RNGType &rng, std::size_t n, RealType *r, RealType df)
Generating random variates.
void uniform_real_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generate uniform real random variates with open/closed variants.
void beta_distribution(RNGType &rng, std::size_t n, RealType *r, RealType alpha, RealType beta)
Generating Beta random variates.
void weibull_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating weibull random variates.
void exponential_distribution(RNGType &rng, std::size_t N, RealType *r, RealType lambda)
Generating exponential random variates.
void uniform_bits_distribution(RNGType &, std::size_t, UIntType *)
Multivariate Normal random walk proposal.
Draw a single sample given weights.
Uniform bits distribution.
void gamma_distribution(RNGType &rng, std::size_t n, RealType *r, RealType alpha, RealType beta)
Generating gamma random variates.
internal::MKLResultType< Bits > result_type
Definition: mkl.hpp:797
void student_t_distribution(RNGType &, std::size_t, RealType *, RealType)
Generating student-t random variates.