]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/test_invoke.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / compute / test / test_invoke.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2015 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://kylelutz.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #define BOOST_TEST_MODULE TestInvoke
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/compute/function.hpp>
15 #include <boost/compute/lambda.hpp>
16 #include <boost/compute/functional/integer.hpp>
17 #include <boost/compute/functional/math.hpp>
18 #include <boost/compute/utility/invoke.hpp>
19
20 #include "context_setup.hpp"
21
22 namespace compute = boost::compute;
23
24 BOOST_AUTO_TEST_CASE(invoke_builtin)
25 {
26 BOOST_CHECK_EQUAL(compute::invoke(compute::abs<int>(), queue, -3), 3);
27 BOOST_CHECK_CLOSE(compute::invoke(compute::pow<float>(), queue, 2.f, 8.f), 256.f, 1e-4);
28 }
29
30 BOOST_AUTO_TEST_CASE(invoke_function)
31 {
32 BOOST_COMPUTE_FUNCTION(int, plus_two, (int x),
33 {
34 return x + 2;
35 });
36
37 BOOST_CHECK_EQUAL(compute::invoke(plus_two, queue, 2), 4);
38
39 BOOST_COMPUTE_FUNCTION(float, get_max, (float x, float y),
40 {
41 if(x > y)
42 return x;
43 else
44 return y;
45 });
46
47 BOOST_CHECK_EQUAL(compute::invoke(get_max, queue, 10.f, 20.f), 20.f);
48 }
49
50 BOOST_AUTO_TEST_CASE(invoke_lambda)
51 {
52 using boost::compute::lambda::_1;
53 using boost::compute::lambda::_2;
54
55 BOOST_CHECK_EQUAL(compute::invoke(_1 / 2, queue, 4), 2);
56 BOOST_CHECK_EQUAL(compute::invoke(_1 * _2 + 1, queue, 3, 3), 10);
57 }
58
59 BOOST_AUTO_TEST_SUITE_END()