/* * Copyright 2008-2012 NVIDIA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include namespace thrust { namespace random { template discard_block_engine ::discard_block_engine() : m_e(), m_n(0) {} template discard_block_engine ::discard_block_engine(result_type s) : m_e(s), m_n(0) {} template discard_block_engine ::discard_block_engine(const base_type &urng) : m_e(urng), m_n(0) {} template void discard_block_engine ::seed(void) { m_e.seed(); m_n = 0; } template void discard_block_engine ::seed(result_type s) { m_e.seed(s); m_n = 0; } template typename discard_block_engine::result_type discard_block_engine ::operator()(void) { if(m_n >= used_block) { m_e.discard(block_size - m_n); // for(; m_n < block_size; ++m_n) // m_e(); m_n = 0; } ++m_n; return m_e(); } template void discard_block_engine ::discard(unsigned long long z) { // XXX this should be accelerated for(; z > 0; --z) { this->operator()(); } // end for } template const typename discard_block_engine::base_type & discard_block_engine ::base(void) const { return m_e; } template template std::basic_ostream& discard_block_engine ::stream_out(std::basic_ostream &os) const { typedef std::basic_ostream ostream_type; typedef typename ostream_type::ios_base ios_base; // save old flags & fill character const typename ios_base::fmtflags flags = os.flags(); const CharT fill = os.fill(); const CharT space = os.widen(' '); os.flags(ios_base::dec | ios_base::fixed | ios_base::left); os.fill(space); // output the base engine followed by n os << m_e << space << m_n; // restore flags & fill character os.flags(flags); os.fill(fill); return os; } template template std::basic_istream& discard_block_engine ::stream_in(std::basic_istream &is) { typedef std::basic_istream istream_type; typedef typename istream_type::ios_base ios_base; // save old flags const typename ios_base::fmtflags flags = is.flags(); is.flags(ios_base::skipws); // input the base engine and then n is >> m_e >> m_n; // restore old flags is.flags(flags); return is; } template bool discard_block_engine ::equal(const discard_block_engine &rhs) const { return (m_e == rhs.m_e) && (m_n == rhs.m_n); } template std::basic_ostream& operator<<(std::basic_ostream &os, const discard_block_engine &e) { return thrust::random::detail::random_core_access::stream_out(os,e); } template std::basic_istream& operator>>(std::basic_istream &is, discard_block_engine &e) { return thrust::random::detail::random_core_access::stream_in(is,e); } template bool operator==(const discard_block_engine &lhs, const discard_block_engine &rhs) { return thrust::random::detail::random_core_access::equal(lhs,rhs); } template bool operator!=(const discard_block_engine &lhs, const discard_block_engine &rhs) { return !(lhs == rhs); } } // end random } // end thrust