1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #define BOOST_TEST_MODULE TestScatter
12 #include <boost/test/unit_test.hpp>
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/algorithm/scatter.hpp>
16 #include <boost/compute/container/vector.hpp>
17 #include <boost/compute/iterator/constant_buffer_iterator.hpp>
19 #include "check_macros.hpp"
20 #include "context_setup.hpp"
22 namespace bc
= boost::compute
;
24 BOOST_AUTO_TEST_CASE(scatter_int
)
26 int input_data
[] = { 1, 2, 3, 4, 5 };
27 bc::vector
<int> input(input_data
, input_data
+ 5, queue
);
29 int map_data
[] = { 0, 4, 1, 3, 2 };
30 bc::vector
<int> map(map_data
, map_data
+ 5, queue
);
32 bc::vector
<int> output(5, context
);
33 bc::scatter(input
.begin(), input
.end(), map
.begin(), output
.begin(), queue
);
34 CHECK_RANGE_EQUAL(int, 5, output
, (1, 3, 5, 4, 2));
37 BOOST_AUTO_TEST_CASE(scatter_constant_indices
)
39 int input_data
[] = { 1, 2, 3, 4, 5 };
40 bc::vector
<int> input(input_data
, input_data
+ 5, queue
);
42 int map_data
[] = { 0, 4, 1, 3, 2 };
43 bc::buffer
map_buffer(context
,
45 bc::buffer::read_only
| bc::buffer::use_host_ptr
,
48 bc::vector
<int> output(5, context
);
49 bc::scatter(input
.begin(),
51 bc::make_constant_buffer_iterator
<int>(map_buffer
, 0),
54 CHECK_RANGE_EQUAL(int, 5, output
, (1, 3, 5, 4, 2));
57 BOOST_AUTO_TEST_SUITE_END()