/* * Copyright 2008-2021 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. */ #pragma once #include #if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) # pragma GCC system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) # pragma clang system_header #elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) # pragma system_header #endif // no system header #include THRUST_NAMESPACE_BEGIN namespace random { template _CCCL_HOST_DEVICE discard_block_engine::discard_block_engine() : m_e() , m_n(0) {} template _CCCL_HOST_DEVICE discard_block_engine::discard_block_engine(result_type s) : m_e(s) , m_n(0) {} template _CCCL_HOST_DEVICE discard_block_engine::discard_block_engine(const base_type& urng) : m_e(urng) , m_n(0) {} template _CCCL_HOST_DEVICE void discard_block_engine::seed() { m_e.seed(); m_n = 0; } template _CCCL_HOST_DEVICE void discard_block_engine::seed(result_type s) { m_e.seed(s); m_n = 0; } template _CCCL_HOST_DEVICE 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 _CCCL_HOST_DEVICE void discard_block_engine::discard(unsigned long long z) { // XXX this should be accelerated for (; z > 0; --z) { this->operator()(); } // end for } template _CCCL_HOST_DEVICE const typename discard_block_engine::base_type& discard_block_engine::base() 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 _CCCL_HOST_DEVICE 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 _CCCL_HOST_DEVICE bool operator==(const discard_block_engine& lhs, const discard_block_engine& rhs) { return thrust::random::detail::random_core_access::equal(lhs, rhs); } template _CCCL_HOST_DEVICE bool operator!=(const discard_block_engine& lhs, const discard_block_engine& rhs) { return !(lhs == rhs); } } // namespace random THRUST_NAMESPACE_END