random_fill.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_ALGORITHM_DETAIL_RANDOM_FILL_HPP
  11. #define BOOST_COMPUTE_ALGORITHM_DETAIL_RANDOM_FILL_HPP
  12. #include <iterator>
  13. #include <boost/compute/command_queue.hpp>
  14. #include <boost/compute/random/default_random_engine.hpp>
  15. #include <boost/compute/random/uniform_real_distribution.hpp>
  16. namespace boost {
  17. namespace compute {
  18. namespace detail {
  19. template<class OutputIterator, class Generator>
  20. inline void random_fill(OutputIterator first,
  21. OutputIterator last,
  22. Generator &g,
  23. command_queue &queue)
  24. {
  25. g.fill(first, last, queue);
  26. }
  27. template<class OutputIterator>
  28. inline void
  29. random_fill(OutputIterator first,
  30. OutputIterator last,
  31. typename std::iterator_traits<OutputIterator>::value_type lo,
  32. typename std::iterator_traits<OutputIterator>::value_type hi,
  33. command_queue &queue)
  34. {
  35. typedef typename
  36. std::iterator_traits<OutputIterator>::value_type value_type;
  37. typedef typename
  38. boost::compute::default_random_engine engine_type;
  39. typedef typename
  40. boost::compute::uniform_real_distribution<value_type> distribution_type;
  41. engine_type engine(queue);
  42. distribution_type generator(lo, hi);
  43. generator.fill(first, last, engine, queue);
  44. }
  45. } // end detail namespace
  46. } // end compute namespace
  47. } // end boost namespace
  48. #endif // BOOST_COMPUTE_ALGORITHM_DETAIL_RANDOM_FILL_HPP