]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/test_generate.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 TestGenerate
12 #include <boost/test/unit_test.hpp>
16 #include <boost/compute/function.hpp>
17 #include <boost/compute/algorithm/generate.hpp>
18 #include <boost/compute/algorithm/generate_n.hpp>
19 #include <boost/compute/container/vector.hpp>
20 #include <boost/compute/types/pair.hpp>
23 #include "check_macros.hpp"
24 #include "context_setup.hpp"
26 namespace bc
= boost::compute
;
28 BOOST_AUTO_TEST_CASE(generate4
)
30 bc::vector
<int> vector(4, context
);
31 bc::fill(vector
.begin(), vector
.end(), 2, queue
);
32 CHECK_RANGE_EQUAL(int, 4, vector
, (2, 2, 2, 2));
34 BOOST_COMPUTE_FUNCTION(int, ret4
, (void),
39 bc::generate(vector
.begin(), vector
.end(), ret4
, queue
);
40 CHECK_RANGE_EQUAL(int, 4, vector
, (4, 4, 4, 4));
43 BOOST_AUTO_TEST_CASE(generate_pair
)
45 if(bug_in_struct_assignment(device
)){
46 std::cerr
<< "skipping generate_pair test" << std::endl
;
50 // in order to use std::pair<T1, T2> with BOOST_COMPUTE_FUNCTION() macro we
51 // need a typedef. otherwise the commas in the type declaration screw it up.
52 typedef std::pair
<int, float> pair_type
;
54 bc::vector
<pair_type
> vector(3, context
);
56 BOOST_COMPUTE_FUNCTION(pair_type
, generate_pair
, (void),
58 return boost_make_pair(int, 2, float, 3.14f
);
61 bc::generate(vector
.begin(), vector
.end(), generate_pair
, queue
);
64 std::vector
<pair_type
> host_vector(3);
65 bc::copy(vector
.begin(), vector
.end(), host_vector
.begin(), queue
);
66 BOOST_CHECK(host_vector
[0] == std::make_pair(2, 3.14f
));
67 BOOST_CHECK(host_vector
[1] == std::make_pair(2, 3.14f
));
68 BOOST_CHECK(host_vector
[2] == std::make_pair(2, 3.14f
));
71 BOOST_AUTO_TEST_SUITE_END()