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

Function random_shuffle

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

Source from the content-addressed store, hash-verified

31/// \see scatter()
32template<class Iterator>
33inline void random_shuffle(Iterator first,
34 Iterator last,
35 command_queue &queue = system::default_queue())
36{
37 typedef typename std::iterator_traits<Iterator>::value_type value_type;
38
39 size_t count = detail::iterator_range_size(first, last);
40 if(count == 0){
41 return;
42 }
43
44 // generate shuffled indices on the host
45 std::vector<cl_uint> random_indices(count);
46 boost::iota(random_indices, 0);
47 std::random_shuffle(random_indices.begin(), random_indices.end());
48
49 // copy random indices to the device
50 const context &context = queue.get_context();
51 vector<cl_uint> indices(count, context);
52 ::boost::compute::copy(random_indices.begin(),
53 random_indices.end(),
54 indices.begin(),
55 queue);
56
57 // make a copy of the values on the device
58 vector<value_type> tmp(count, context);
59 ::boost::compute::copy(first,
60 last,
61 tmp.begin(),
62 queue);
63
64 // write values to their new locations
65 ::boost::compute::scatter(tmp.begin(),
66 tmp.end(),
67 indices.begin(),
68 first,
69 queue);
70}
71
72} // end compute namespace
73} // 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