MCPcopy Create free account
hub / github.com/boostorg/compute / random_shuffle

Function random_shuffle

include/boost/compute/algorithm/random_shuffle.hpp:41–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39/// \see scatter()
40template<class Iterator>
41inline void random_shuffle(Iterator first,
42 Iterator last,
43 command_queue &queue = system::default_queue())
44{
45 BOOST_STATIC_ASSERT(is_device_iterator<Iterator>::value);
46 typedef typename std::iterator_traits<Iterator>::value_type value_type;
47
48 size_t count = detail::iterator_range_size(first, last);
49 if(count == 0){
50 return;
51 }
52
53 // generate shuffled indices on the host
54 std::vector<cl_uint> random_indices(count);
55 boost::iota(random_indices, 0);
56#ifdef BOOST_COMPUTE_USE_CPP11
57 std::random_device nondeterministic_randomness;
58 std::default_random_engine random_engine(nondeterministic_randomness());
59 std::shuffle(random_indices.begin(), random_indices.end(), random_engine);
60#else
61 std::random_shuffle(random_indices.begin(), random_indices.end());
62#endif
63
64 // copy random indices to the device
65 const context &context = queue.get_context();
66 vector<cl_uint> indices(count, context);
67 ::boost::compute::copy(random_indices.begin(),
68 random_indices.end(),
69 indices.begin(),
70 queue);
71
72 // make a copy of the values on the device
73 vector<value_type> tmp(count, context);
74 ::boost::compute::copy(first,
75 last,
76 tmp.begin(),
77 queue);
78
79 // write values to their new locations
80 ::boost::compute::scatter(tmp.begin(),
81 tmp.end(),
82 indices.begin(),
83 first,
84 queue);
85}
86
87} // end compute namespace
88} // end boost namespace

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 7

iterator_range_sizeFunction · 0.85
iotaFunction · 0.85
copyFunction · 0.85
scatterFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
get_contextMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68