2 * Copyright 2008-2012 NVIDIA Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <thrust/random/discard_block_engine.h>
26 template<typename Engine, size_t p, size_t r>
27 discard_block_engine<Engine,p,r>
28 ::discard_block_engine()
33 template<typename Engine, size_t p, size_t r>
34 discard_block_engine<Engine,p,r>
35 ::discard_block_engine(result_type s)
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)
47 template<typename Engine, size_t p, size_t r>
48 void discard_block_engine<Engine,p,r>
56 template<typename Engine, size_t p, size_t r>
57 void discard_block_engine<Engine,p,r>
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>
72 m_e.discard(block_size - m_n);
73 // for(; m_n < block_size; ++m_n)
84 template<typename Engine, size_t p, size_t r>
85 void discard_block_engine<Engine,p,r>
86 ::discard(unsigned long long z)
88 // XXX this should be accelerated
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>
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
110 typedef std::basic_ostream<CharT,Traits> ostream_type;
111 typedef typename ostream_type::ios_base ios_base;
113 // save old flags & fill character
114 const typename ios_base::fmtflags flags = os.flags();
115 const CharT fill = os.fill();
117 const CharT space = os.widen(' ');
118 os.flags(ios_base::dec | ios_base::fixed | ios_base::left);
121 // output the base engine followed by n
122 os << m_e << space << m_n;
124 // restore flags & fill character
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)
137 typedef std::basic_istream<CharT,Traits> istream_type;
138 typedef typename istream_type::ios_base ios_base;
141 const typename ios_base::fmtflags flags = is.flags();
143 is.flags(ios_base::skipws);
145 // input the base engine and then n
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
158 return (m_e == rhs.m_e) && (m_n == rhs.m_n);
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)
168 return thrust::random::detail::random_core_access::stream_out(os,e);
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)
178 return thrust::random::detail::random_core_access::stream_in(is,e);
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)
186 return thrust::random::detail::random_core_access::equal(lhs,rhs);
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)
194 return !(lhs == rhs);