MCKL
Monte Carlo Kernel Library
u01.hpp
Go to the documentation of this file.
1 //============================================================================
2 // MCKL/include/mckl/random/u01.hpp
3 //----------------------------------------------------------------------------
4 // MCKL: Monte Carlo Kernel Library
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013-2018, 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 MCKL_RANDOM_U01_HPP
33 #define MCKL_RANDOM_U01_HPP
34 
37 
38 #if MCKL_HAS_AVX2
40 #endif
41 
42 #if MCKL_HAS_AVX512
44 #endif
45 
46 namespace mckl {
47 
48 namespace internal {
49 
50 #if MCKL_USE_AVX512
51 
52 template <typename UIntType, typename RealType, typename Lower, typename Upper>
53 using U01Impl = U01AVX512Impl<UIntType, RealType, Lower, Upper>;
54 
55 template <typename UIntType, typename RealType, int M>
56 using U01CanonicalImpl = U01CanonicalAVX512Impl<UIntType, RealType, M>;
57 
58 #elif MCKL_USE_AVX2
59 
60 template <typename UIntType, typename RealType, typename Lower, typename Upper>
62 
63 template <typename UIntType, typename RealType, int M>
65 
66 #else // MCKL_USE_AVX2
67 
68 template <typename UIntType, typename RealType, typename Lower, typename Upper>
70 
71 template <typename UIntType, typename RealType, int M>
72 using U01CanonicalImpl = U01CanonicalGenericImpl<UIntType, RealType, M>;
73 
74 #endif // MCKL_USE_AVX2
75 
76 } // namespace internal
77 
87 template <typename UIntType, typename RealType, typename Lower, typename Upper>
88 inline RealType u01(UIntType u)
89 {
90  static_assert(std::is_unsigned<UIntType>::value,
91  "**u01** used with UIntType other than unsigned integer "
92  "types");
93 
94  static_assert(std::is_floating_point<RealType>::value,
95  "**u01** used with RealType other than floating point "
96  "types");
97 
99 }
100 
103 template <typename UIntType, typename RealType, typename Lower, typename Upper>
104 inline void u01(std::size_t n, const UIntType *u, RealType *r)
105 {
106  static_assert(std::is_unsigned<UIntType>::value,
107  "**u01** used with UIntType other than unsigned integer "
108  "types");
109 
110  static_assert(std::is_floating_point<RealType>::value,
111  "**u01** used with RealType other than floating point "
112  "types");
113 
115 }
116 
119 template <typename UIntType, typename RealType>
120 inline RealType u01_cc(UIntType u)
121 {
122  return u01<UIntType, RealType, Closed, Closed>(u);
123 }
124 
127 template <typename UIntType, typename RealType>
128 inline RealType u01_co(UIntType u)
129 {
130  return u01<UIntType, RealType, Closed, Open>(u);
131 }
132 
135 template <typename UIntType, typename RealType>
136 inline RealType u01_oc(UIntType u)
137 {
138  return u01<UIntType, RealType, Open, Closed>(u);
139 }
140 
143 template <typename UIntType, typename RealType>
144 inline RealType u01_oo(UIntType u)
145 {
146  return u01<UIntType, RealType, Open, Open>(u);
147 }
148 
151 template <typename UIntType, typename RealType>
152 inline void u01_cc(std::size_t n, const UIntType *u, RealType *r)
153 {
154  u01<UIntType, RealType, Closed, Closed>(n, u, r);
155 }
156 
159 template <typename UIntType, typename RealType>
160 inline void u01_co(std::size_t n, const UIntType *u, RealType *r)
161 {
162  u01<UIntType, RealType, Closed, Open>(n, u, r);
163 }
164 
167 template <typename UIntType, typename RealType>
168 inline void u01_oc(std::size_t n, const UIntType *u, RealType *r)
169 {
170  u01<UIntType, RealType, Open, Closed>(n, u, r);
171 }
172 
175 template <typename UIntType, typename RealType>
176 inline void u01_oo(std::size_t n, const UIntType *u, RealType *r)
177 {
178  u01<UIntType, RealType, Open, Open>(n, u, r);
179 }
180 
184 template <typename UIntType, typename RealType, std::size_t M>
185 inline RealType u01_canonical(const UIntType *u)
186 {
187  static_assert(std::is_unsigned<UIntType>::value,
188  "**u01_canonical** used with UIntType other than unsigned integer "
189  "types");
190 
191  static_assert(std::is_floating_point<RealType>::value,
192  "**u01_canonical** used with RealType other than floating point "
193  "types");
194 
196 }
197 
201 template <typename UIntType, typename RealType, std::size_t M>
202 inline void u01_canonical(std::size_t n, const UIntType *u, RealType *r)
203 {
204  static_assert(std::is_unsigned<UIntType>::value,
205  "**u01_canonical** used with UIntType other than unsigned integer "
206  "types");
207 
208  static_assert(std::is_floating_point<RealType>::value,
209  "**u01_canonical** used with RealType other than floating point "
210  "types");
211 
213 }
214 
215 } // namespace mckl
216 
217 #endif // MCKL_RANDOM_U01_HPP
U01CanonicalAVX2Impl< UIntType, RealType, M > U01CanonicalImpl
Definition: u01.hpp:64
U01AVX2Impl< UIntType, RealType, Lower, Upper > U01Impl
Definition: u01.hpp:61
RealType u01_cc(UIntType u)
Convert uniform unsigned integers to floating points on [0, 1].
Definition: u01.hpp:120
RealType u01_oc(UIntType u)
Convert uniform unsigned integers to floating points on (0, 1].
Definition: u01.hpp:136
RealType u01(UIntType u)
Convert uniform unsigned integers to floating points within [0, 1].
Definition: u01.hpp:88
static RealType eval(const UIntType *u)
RealType u01_co(UIntType u)
Convert uniform unsigned integers to floating points on [0, 1)
Definition: u01.hpp:128
Definition: mcmc.hpp:40
RealType u01_canonical(const UIntType *u)
Convert uniform multiple unsigned integers to one floating points within [0, 1].
Definition: u01.hpp:185
RealType u01_oo(UIntType u)
Convert uniform unsigned integers to floating points on (0, 1)
Definition: u01.hpp:144