MCKL
Monte Carlo Kernel Library
threefry_constants.hpp
Go to the documentation of this file.
1 //============================================================================
2 // MCKL/include/mckl/random/internal/threefry_constants.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_INTERNAL_THREEFRY_CONSTANTS_HPP
33 #define MCKL_RANDOM_INTERNAL_THREEFRY_CONSTANTS_HPP
34 
36 
37 namespace mckl {
38 
39 namespace internal {
40 
41 template <typename T, int = std::numeric_limits<T>::digits>
43 
44 template <typename T>
46 {
47  public:
48  static constexpr T value = 0x1BD11BDA;
49 }; // class ThreefryConstantsParity
50 
51 template <typename T>
53 {
54  public:
55  static constexpr T value = 0x1BD11BDAA9FC1A22;
56 }; // class ThreefryConstantsParity
57 
58 template <typename T, std::size_t, int = std::numeric_limits<T>::digits>
60 
61 template <typename T>
62 class ThreefryConstantsRotate<T, 2, 32>
63 {
64  public:
65  static constexpr int value[1][8] = {{13, 15, 26, 6, 17, 29, 16, 24}};
66 }; // class ThreefryConstantsRotate
67 
68 template <typename T>
69 class ThreefryConstantsRotate<T, 4, 32>
70 {
71  public:
72  static constexpr int value[2][8] = {
73  {10, 11, 13, 23, 6, 17, 25, 18}, {26, 21, 27, 5, 20, 11, 10, 20}};
74 }; // class ThreefryConstantsRotate
75 
76 template <typename T>
77 class ThreefryConstantsRotate<T, 2, 64>
78 {
79  public:
80  static constexpr int value[1][8] = {{16, 42, 12, 31, 16, 32, 24, 21}};
81 }; // class ThreefryConstantsRotate
82 
83 template <typename T>
84 class ThreefryConstantsRotate<T, 4, 64>
85 {
86  public:
87  static constexpr int value[2][8] = {
88  {14, 52, 23, 5, 25, 46, 58, 32}, {16, 57, 40, 37, 33, 12, 22, 32}};
89 }; // class ThreefryConstantsRotate
90 
91 template <typename T>
92 class ThreefryConstantsRotate<T, 8, 64>
93 {
94  public:
95  static constexpr int value[4][8] = {{46, 33, 17, 44, 39, 13, 25, 8},
96  {36, 27, 49, 9, 30, 50, 29, 35}, {19, 14, 36, 54, 34, 10, 39, 56},
97  {37, 42, 39, 56, 24, 17, 43, 22}};
98 }; // class ThreefryConstantsRotate
99 
100 template <typename T>
101 class ThreefryConstantsRotate<T, 16, 64>
102 {
103  public:
104  static constexpr int value[8][8] = {{24, 38, 33, 5, 41, 16, 31, 9},
105  {13, 19, 4, 20, 9, 34, 44, 48}, {8, 10, 51, 48, 37, 56, 47, 35},
106  {47, 55, 13, 41, 31, 51, 46, 52}, {8, 49, 34, 47, 12, 4, 19, 23},
107  {17, 18, 41, 28, 47, 53, 42, 31}, {22, 23, 59, 16, 44, 42, 44, 37},
108  {37, 52, 17, 25, 30, 41, 25, 20}};
109 }; // class ThreefryConstantsRotate
110 
111 template <std::size_t>
113 
114 template <>
116 {
117  public:
118  static constexpr std::size_t value[2] = {0, 1};
119 }; // class ThreefryConstantsPermute
120 
121 template <>
123 {
124  public:
125  static constexpr std::size_t value[4] = {0, 3, 2, 1};
126 }; // class ThreefryConstantsPermute
127 
128 template <>
130 {
131  public:
132  static constexpr std::size_t value[8] = {2, 1, 4, 7, 6, 5, 0, 3};
133 }; // class ThreefryConstantsPermute
134 
135 template <>
137 {
138  static constexpr std::size_t value[16] = {
139  0, 9, 2, 13, 6, 11, 4, 15, 10, 7, 12, 3, 14, 5, 8, 1};
140 }; // class ThreefryConstantsPermute
141 
142 } // namespace internal
143 
146 template <typename T, std::size_t K>
148 {
149  public:
153 }; // class ThreefryConstants
154 
155 } // namespace mckl
156 
157 #endif // MCKL_RANDOM_INTERNAL_THREEFRY_CONSTANTS_HPP
Default Threefry constants.
Definition: mcmc.hpp:40