]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/test_permutation_iterator.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 TestPermutationIterator
12 #include <boost/test/unit_test.hpp>
16 #include <boost/type_traits.hpp>
17 #include <boost/static_assert.hpp>
19 #include <boost/compute/types.hpp>
20 #include <boost/compute/algorithm/copy.hpp>
21 #include <boost/compute/container/vector.hpp>
22 #include <boost/compute/iterator/buffer_iterator.hpp>
23 #include <boost/compute/iterator/permutation_iterator.hpp>
25 #include "check_macros.hpp"
26 #include "context_setup.hpp"
28 BOOST_AUTO_TEST_CASE(value_type
)
30 using boost::compute::float4_
;
34 boost::compute::permutation_iterator
<
35 boost::compute::buffer_iterator
<float>,
36 boost::compute::buffer_iterator
<int>
43 boost::compute::permutation_iterator
<
44 boost::compute::buffer_iterator
<float4_
>,
45 boost::compute::buffer_iterator
<short>
52 BOOST_AUTO_TEST_CASE(base_type
)
56 boost::compute::permutation_iterator
<
57 boost::compute::buffer_iterator
<int>,
58 boost::compute::buffer_iterator
<int>
60 boost::compute::buffer_iterator
<int>
65 BOOST_AUTO_TEST_CASE(copy
)
67 int input_data
[] = { 3, 4, 2, 1, 5 };
68 boost::compute::vector
<int> input(input_data
, input_data
+ 5, queue
);
70 int map_data
[] = { 3, 2, 0, 1, 4 };
71 boost::compute::vector
<int> map(map_data
, map_data
+ 5, queue
);
73 boost::compute::vector
<int> output(5, context
);
75 boost::compute::make_permutation_iterator(input
.begin(), map
.begin()),
76 boost::compute::make_permutation_iterator(input
.end(), map
.end()),
80 CHECK_RANGE_EQUAL(int, 5, output
, (1, 2, 3, 4, 5));
83 BOOST_AUTO_TEST_CASE(reverse_range_doctest
)
85 int values_data
[] = { 10, 20, 30, 40 };
86 int indices_data
[] = { 3, 2, 1, 0 };
88 boost::compute::vector
<int> values(values_data
, values_data
+ 4, queue
);
89 boost::compute::vector
<int> indices(indices_data
, indices_data
+ 4, queue
);
91 boost::compute::vector
<int> result(4, context
);
94 // values = { 10, 20, 30, 40 }
95 // indices = { 3, 2, 1, 0 }
98 boost::compute::make_permutation_iterator(values
.begin(), indices
.begin()),
99 boost::compute::make_permutation_iterator(values
.end(), indices
.end()),
104 // result == { 40, 30, 20, 10 }
107 CHECK_RANGE_EQUAL(int, 4, result
, (40, 30, 20, 10));
110 BOOST_AUTO_TEST_SUITE_END()