OSDN Git Service

modified: utilsrc/src/Admin/Makefile
[eos/others.git] / utiltools / X86MAC64 / cuda / include / thrust / random / detail / discard_block_engine.inl
1 /*
2  *  Copyright 2008-2012 NVIDIA Corporation
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 #include <thrust/random/discard_block_engine.h>
18
19 namespace thrust
20 {
21
22 namespace random
23 {
24
25
26 template<typename Engine, size_t p, size_t r>
27   discard_block_engine<Engine,p,r>
28     ::discard_block_engine()
29       : m_e(), m_n(0)
30 {}
31
32
33 template<typename Engine, size_t p, size_t r>
34   discard_block_engine<Engine,p,r>
35     ::discard_block_engine(result_type s)
36       : m_e(s), m_n(0)
37 {}
38
39
40 template<typename Engine, size_t p, size_t r>
41   discard_block_engine<Engine,p,r>
42     ::discard_block_engine(const base_type &urng)
43       : m_e(urng), m_n(0)
44 {}
45
46
47 template<typename Engine, size_t p, size_t r>
48   void discard_block_engine<Engine,p,r>
49     ::seed(void)
50 {
51   m_e.seed();
52   m_n = 0;
53 }
54
55
56 template<typename Engine, size_t p, size_t r>
57   void discard_block_engine<Engine,p,r>
58     ::seed(result_type s)
59 {
60   m_e.seed(s);
61   m_n = 0;
62 }
63
64
65 template<typename Engine, size_t p, size_t r>
66   typename discard_block_engine<Engine,p,r>::result_type
67     discard_block_engine<Engine,p,r>
68       ::operator()(void)
69 {
70   if(m_n >= used_block)
71   {
72     m_e.discard(block_size - m_n);
73 //    for(; m_n < block_size; ++m_n)
74 //      m_e();
75     m_n = 0;
76   }
77
78   ++m_n;
79
80   return m_e();
81 }
82
83
84 template<typename Engine, size_t p, size_t r>
85   void discard_block_engine<Engine,p,r>
86     ::discard(unsigned long long z)
87 {
88   // XXX this should be accelerated
89   for(; z > 0; --z)
90   {
91     this->operator()();
92   } // end for
93 }
94
95
96 template<typename Engine, size_t p, size_t r>
97   const typename discard_block_engine<Engine,p,r>::base_type &
98     discard_block_engine<Engine,p,r>
99       ::base(void) const
100 {
101   return m_e;
102 }
103
104
105 template<typename Engine, size_t p, size_t r>
106   template<typename CharT, typename Traits>
107     std::basic_ostream<CharT,Traits>& discard_block_engine<Engine,p,r>
108       ::stream_out(std::basic_ostream<CharT,Traits> &os) const
109 {
110   typedef std::basic_ostream<CharT,Traits> ostream_type;
111   typedef typename ostream_type::ios_base  ios_base;
112
113   // save old flags & fill character
114   const typename ios_base::fmtflags flags = os.flags();
115   const CharT fill = os.fill();
116
117   const CharT space = os.widen(' ');
118   os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
119   os.fill(space);
120
121   // output the base engine followed by n
122   os << m_e << space << m_n;
123
124   // restore flags & fill character
125   os.flags(flags);
126   os.fill(fill);
127
128   return os;
129 }
130
131
132 template<typename Engine, size_t p, size_t r>
133   template<typename CharT, typename Traits>
134     std::basic_istream<CharT,Traits>& discard_block_engine<Engine,p,r>
135       ::stream_in(std::basic_istream<CharT,Traits> &is)
136 {
137   typedef std::basic_istream<CharT,Traits> istream_type;
138   typedef typename istream_type::ios_base  ios_base;
139
140   // save old flags
141   const typename ios_base::fmtflags flags = is.flags();
142
143   is.flags(ios_base::skipws);
144
145   // input the base engine and then n
146   is >> m_e >> m_n;
147
148   // restore old flags
149   is.flags(flags);
150   return is;
151 }
152
153
154 template<typename Engine, size_t p, size_t r>
155   bool discard_block_engine<Engine,p,r>
156     ::equal(const discard_block_engine<Engine,p,r> &rhs) const
157 {
158   return (m_e == rhs.m_e) && (m_n == rhs.m_n);
159 }
160
161
162 template<typename Engine, size_t p, size_t r,
163          typename CharT, typename Traits>
164 std::basic_ostream<CharT,Traits>&
165 operator<<(std::basic_ostream<CharT,Traits> &os,
166            const discard_block_engine<Engine,p,r> &e)
167 {
168   return thrust::random::detail::random_core_access::stream_out(os,e);
169 }
170
171
172 template<typename Engine, size_t p, size_t r,
173          typename CharT, typename Traits>
174 std::basic_istream<CharT,Traits>&
175 operator>>(std::basic_istream<CharT,Traits> &is,
176            discard_block_engine<Engine,p,r> &e)
177 {
178   return thrust::random::detail::random_core_access::stream_in(is,e);
179 }
180
181
182 template<typename Engine, size_t p, size_t r>
183 bool operator==(const discard_block_engine<Engine,p,r> &lhs,
184                 const discard_block_engine<Engine,p,r> &rhs)
185 {
186   return thrust::random::detail::random_core_access::equal(lhs,rhs);
187 }
188
189
190 template<typename Engine, size_t p, size_t r>
191 bool operator!=(const discard_block_engine<Engine,p,r> &lhs,
192                 const discard_block_engine<Engine,p,r> &rhs)
193 {
194   return !(lhs == rhs);
195 }
196
197
198 } // end random
199
200 } // end thrust
201