]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/test_gather.cpp
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 TestGather
12 #include <boost/test/unit_test.hpp>
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/algorithm/copy_if.hpp>
16 #include <boost/compute/algorithm/gather.hpp>
17 #include <boost/compute/container/vector.hpp>
19 #include "check_macros.hpp"
20 #include "context_setup.hpp"
22 namespace compute
= boost::compute
;
24 BOOST_AUTO_TEST_CASE(gather_int
)
26 int input_data
[] = { 1, 2, 3, 4, 5 };
27 compute::vector
<int> input(input_data
, input_data
+ 5, queue
);
29 int indices_data
[] = { 0, 4, 1, 3, 2 };
30 compute::vector
<int> indices(indices_data
, indices_data
+ 5, queue
);
32 compute::vector
<int> output(5, context
);
34 indices
.begin(), indices
.end(), input
.begin(), output
.begin(), queue
36 CHECK_RANGE_EQUAL(int, 5, output
, (1, 5, 2, 4, 3));
39 indices
.begin() + 1, indices
.end(), input
.begin(), output
.begin(), queue
41 CHECK_RANGE_EQUAL(int, 5, output
, (5, 2, 4, 3, 3));
44 BOOST_AUTO_TEST_CASE(copy_index_then_gather
)
47 int data
[] = { 1, 4, 3, 2, 5, 9, 8, 7 };
48 compute::vector
<int> input(data
, data
+ 8, queue
);
50 // function returning true if the input is odd
51 BOOST_COMPUTE_FUNCTION(bool, is_odd
, (int x
),
56 // copy indices of all odd values
57 compute::vector
<int> odds(5, context
);
58 compute::detail::copy_index_if(
59 input
.begin(), input
.end(), odds
.begin(), is_odd
, queue
61 CHECK_RANGE_EQUAL(int, 5, odds
, (0, 2, 4, 5, 7));
63 // gather all odd values
64 compute::vector
<int> odd_values(5, context
);
66 odds
.begin(), odds
.end(), input
.begin(), odd_values
.begin(), queue
68 CHECK_RANGE_EQUAL(int, 5, odd_values
, (1, 3, 5, 9, 7));
71 BOOST_AUTO_TEST_SUITE_END()