forked from boostorg/compute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_partition.cpp
82 lines (70 loc) · 2.92 KB
/
test_partition.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#define BOOST_TEST_MODULE TestPartition
#include <boost/test/unit_test.hpp>
#include <boost/compute/system.hpp>
#include <boost/compute/functional.hpp>
#include <boost/compute/command_queue.hpp>
#include <boost/compute/algorithm/partition.hpp>
#include <boost/compute/algorithm/partition_copy.hpp>
#include <boost/compute/algorithm/is_partitioned.hpp>
#include <boost/compute/container/vector.hpp>
#include "check_macros.hpp"
#include "context_setup.hpp"
namespace bc = boost::compute;
BOOST_AUTO_TEST_CASE(partition_float_vector)
{
bc::vector<float> vector(context);
vector.push_back(1.0f, queue);
vector.push_back(2.0f, queue);
vector.push_back(-1.0f, queue);
vector.push_back(-2.0f, queue);
vector.push_back(3.0f, queue);
vector.push_back(4.0f, queue);
vector.push_back(-3.0f, queue);
vector.push_back(-4.0f, queue);
// verify is_partitioned()
BOOST_VERIFY(bc::is_partitioned(vector.begin(),
vector.end(),
bc::signbit_<float>(),
queue) == false);
// partition by signbit
bc::vector<float>::iterator iter = bc::partition(vector.begin(),
vector.end(),
bc::signbit_<float>(),
queue);
queue.finish();
BOOST_VERIFY(iter == vector.begin() + 4);
BOOST_CHECK_LT(vector[0], 0.0f);
BOOST_CHECK_LT(vector[1], 0.0f);
BOOST_CHECK_LT(vector[2], 0.0f);
BOOST_CHECK_LT(vector[3], 0.0f);
BOOST_CHECK_GT(vector[4], 0.0f);
BOOST_CHECK_GT(vector[5], 0.0f);
BOOST_CHECK_GT(vector[6], 0.0f);
BOOST_CHECK_GT(vector[7], 0.0f);
// verify is_partitioned()
BOOST_VERIFY(bc::is_partitioned(vector.begin(),
vector.end(),
bc::signbit_<float>(),
queue) == true);
}
BOOST_AUTO_TEST_CASE(partition_small_vector)
{
bc::vector<float> vector(context);
bc::partition(vector.begin(), vector.end(), bc::signbit_<float>(), queue);
vector.push_back(1.0f, queue);
bc::partition(vector.begin(), vector.end(), bc::signbit_<float>(), queue);
CHECK_RANGE_EQUAL(float, 1, vector, (1.0f));
vector.push_back(-1.0f, queue);
bc::partition(vector.begin(), vector.end(), bc::signbit_<float>(), queue);
CHECK_RANGE_EQUAL(float, 2, vector, (-1.0f, 1.0f));
}
BOOST_AUTO_TEST_SUITE_END()