• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
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
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10 
11 #define BOOST_TEST_MODULE TestIota
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/context.hpp>
16 #include <boost/compute/algorithm/iota.hpp>
17 #include <boost/compute/container/vector.hpp>
18 #include <boost/compute/iterator/permutation_iterator.hpp>
19 
20 #include "check_macros.hpp"
21 #include "context_setup.hpp"
22 
23 namespace bc = boost::compute;
24 
BOOST_AUTO_TEST_CASE(iota_int)25 BOOST_AUTO_TEST_CASE(iota_int)
26 {
27     bc::vector<int> vector(4, context);
28     bc::iota(vector.begin(), vector.end(), 0, queue);
29     CHECK_RANGE_EQUAL(int, 4, vector, (0, 1, 2, 3));
30 
31     bc::iota(vector.begin(), vector.end(), 10, queue);
32     CHECK_RANGE_EQUAL(int, 4, vector, (10, 11, 12, 13));
33 
34     bc::iota(vector.begin() + 2, vector.end(), -5, queue);
35     CHECK_RANGE_EQUAL(int, 4, vector, (10, 11, -5, -4));
36 
37     bc::iota(vector.begin(), vector.end() - 2, 4, queue);
38     CHECK_RANGE_EQUAL(int, 4, vector, (4, 5, -5, -4));
39 }
40 
BOOST_AUTO_TEST_CASE(iota_doctest)41 BOOST_AUTO_TEST_CASE(iota_doctest)
42 {
43     boost::compute::vector<int> vec(3, context);
44 
45 //! [iota]
46 boost::compute::iota(vec.begin(), vec.end(), 0, queue);
47 //! [iota]
48 
49     CHECK_RANGE_EQUAL(int, 3, vec, (0, 1, 2));
50 }
51 
BOOST_AUTO_TEST_CASE(iota_permutation_iterator)52 BOOST_AUTO_TEST_CASE(iota_permutation_iterator)
53 {
54     bc::vector<int> output(5, context);
55     bc::fill(output.begin(), output.end(), 0, queue);
56 
57     int map_data[] = { 2, 0, 1, 4, 3 };
58     bc::vector<int> map(map_data, map_data + 5, queue);
59 
60     bc::iota(
61         bc::make_permutation_iterator(output.begin(), map.begin()),
62         bc::make_permutation_iterator(output.end(), map.end()),
63         1,
64         queue
65     );
66     CHECK_RANGE_EQUAL(int, 5, output, (2, 3, 1, 5, 4));
67 }
68 
BOOST_AUTO_TEST_CASE(iota_uint)69 BOOST_AUTO_TEST_CASE(iota_uint)
70 {
71     bc::vector<bc::uint_> vector(4, context);
72     bc::iota(vector.begin(), vector.end(), bc::uint_(0), queue);
73     CHECK_RANGE_EQUAL(bc::uint_, 4, vector, (0, 1, 2, 3));
74 }
75 
BOOST_AUTO_TEST_CASE(iota_char)76 BOOST_AUTO_TEST_CASE(iota_char)
77 {
78     bc::vector<bc::char_> vector(4, context);
79     bc::iota(vector.begin(), vector.end(), bc::uint_(0), queue);
80     CHECK_RANGE_EQUAL(bc::char_, 4, vector, (0, 1, 2, 3));
81 }
82 
BOOST_AUTO_TEST_CASE(iota_uchar)83 BOOST_AUTO_TEST_CASE(iota_uchar)
84 {
85     bc::vector<bc::uchar_> vector(4, context);
86     bc::iota(vector.begin(), vector.end(), bc::uint_(0), queue);
87     CHECK_RANGE_EQUAL(bc::uchar_, 4, vector, (0, 1, 2, 3));
88 }
89 
90 BOOST_AUTO_TEST_SUITE_END()
91