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,2014, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef VSMC_RNG_INTERNAL_COMMON_HPP
33 #define VSMC_RNG_INTERNAL_COMMON_HPP
34 
35 #include <vsmc/internal/common.hpp>
37 #include <vsmc/utility/array.hpp>
38 #include <vsmc/utility/counter.hpp>
39 
40 #ifndef UINT64_C
41 #error __STDC_CONSTANT_MACROS not defined before #<stdint.h>
42 #endif
43 
44 namespace vsmc {
45 
46 namespace internal {
47 
48 template <std::size_t K, std::size_t, std::size_t, typename T>
50 
51 template <std::size_t K, std::size_t A, std::size_t I, typename T>
53 {
54  state[Position<I>()] = state[Position<I + A>()];
55  rng_array_left_assign<K, A, I + 1>(state,
57 }
58 
59 template <std::size_t K, std::size_t, typename T>
61 
62 template <std::size_t K, std::size_t I, typename T>
64 {
65  state[Position<I>()] = 0;
66  rng_array_left_zero<K, I + 1>(state,
68 }
69 
70 template <std::size_t K, std::size_t A, bool fillzero, typename T>
71 inline void rng_array_left_shift (Array<T, K> &state)
72 {
73  rng_array_left_assign<K, A, 0>(state,
75  rng_array_left_zero<K, K - A>(state,
77 }
78 
79 template <std::size_t K, std::size_t, std::size_t, typename T>
81 
82 template <std::size_t K, std::size_t A, std::size_t I, typename T>
84 {
85  state[Position<I>()] = state[Position<I - A>()];
86  rng_array_right_assign<K, A, I - 1>(state,
88 }
89 
90 template <std::size_t K, std::size_t, typename T>
92 
93 template <std::size_t K, std::size_t I, typename T>
95 {
96  state[Position<I>()] = 0;
97  rng_array_right_zero<K, I - 1>(state,
99 }
100 
101 template <std::size_t K, std::size_t A, bool fillzero, typename T>
102 inline void rng_array_right_shift (Array<T, K> &state)
103 {
104  rng_array_right_assign<K, A, K - 1>(state,
105  cxx11::integral_constant<bool, (A > 0 && A < K)>());
106  rng_array_right_zero<K, A - 1>(state,
108 }
109 
110 template <typename SeedSeq, typename U, typename V = U, typename W = V>
111 struct is_seed_seq :
112  public cxx11::integral_constant<bool,
113  !cxx11::is_convertible<SeedSeq, U>::value &&
114  !cxx11::is_convertible<SeedSeq, V>::value &&
115  !cxx11::is_convertible<SeedSeq, W>::value &&
116  !cxx11::is_same<typename cxx11::remove_cv<SeedSeq>::type, U>::value &&
117  !cxx11::is_same<typename cxx11::remove_cv<SeedSeq>::type, V>::value &&
118  !cxx11::is_same<typename cxx11::remove_cv<SeedSeq>::type, W>::value> {};
119 
120 } // namespace vsmc::internal
121 
122 } // namespace vsmc
123 
124 #endif // VSMC_RNG_INTERNAL_COMMON_HPP
Definition: adapter.hpp:37
void rng_array_right_assign(Array< T, K > &, cxx11::false_type)
Definition: common.hpp:80
Function template argument used for position.
Definition: defines.hpp:126
void rng_array_left_assign(Array< T, K > &, cxx11::false_type)
Definition: common.hpp:49
void rng_array_right_shift(Array< T, K > &state)
Definition: common.hpp:102
void rng_array_right_zero(Array< T, K > &, cxx11::false_type)
Definition: common.hpp:91
void rng_array_left_zero(Array< T, K > &, cxx11::false_type)
Definition: common.hpp:60
void rng_array_left_shift(Array< T, K > &state)
Definition: common.hpp:71