forked from NVIDIA/thrust
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmin_and_max.cu
69 lines (54 loc) · 3.29 KB
/
min_and_max.cu
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
#include <unittest/unittest.h>
#include <thrust/extrema.h>
template<typename T>
struct TestMin
{
void operator()(void)
{
// 2 < 3
T two(2), three(3);
ASSERT_EQUAL(two, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (two,three));
ASSERT_EQUAL(two, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (two,three,thrust::less<T>()));
ASSERT_EQUAL(two, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (three,two));
ASSERT_EQUAL(two, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (three,two,thrust::less<T>()));
ASSERT_EQUAL(three, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (two,three,thrust::greater<T>()));
ASSERT_EQUAL(three, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (three,two,thrust::greater<T>()));
typedef key_value<T,T> KV;
KV two_and_two(two,two);
KV two_and_three(two,three);
// the first element breaks ties
ASSERT_EQUAL_QUIET(two_and_two, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_two, two_and_three));
ASSERT_EQUAL_QUIET(two_and_three, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_three, two_and_two));
ASSERT_EQUAL_QUIET(two_and_two, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_two, two_and_three, thrust::less<KV>()));
ASSERT_EQUAL_QUIET(two_and_three, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_three, two_and_two, thrust::less<KV>()));
ASSERT_EQUAL_QUIET(two_and_two, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_two, two_and_three, thrust::greater<KV>()));
ASSERT_EQUAL_QUIET(two_and_three, thrust::min THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_three, two_and_two, thrust::greater<KV>()));
}
};
SimpleUnitTest<TestMin, NumericTypes> TestMinInstance;
template<typename T>
struct TestMax
{
void operator()(void)
{
// 2 < 3
T two(2), three(3);
ASSERT_EQUAL(three, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (two,three));
ASSERT_EQUAL(three, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (two,three,thrust::less<T>()));
ASSERT_EQUAL(three, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (three,two));
ASSERT_EQUAL(three, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (three,two,thrust::less<T>()));
ASSERT_EQUAL(two, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (two,three,thrust::greater<T>()));
ASSERT_EQUAL(two, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (three,two,thrust::greater<T>()));
typedef key_value<T,T> KV;
KV two_and_two(two,two);
KV two_and_three(two,three);
// the first element breaks ties
ASSERT_EQUAL_QUIET(two_and_two, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_two, two_and_three));
ASSERT_EQUAL_QUIET(two_and_three, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_three, two_and_two));
ASSERT_EQUAL_QUIET(two_and_two, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_two, two_and_three, thrust::less<KV>()));
ASSERT_EQUAL_QUIET(two_and_three, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_three, two_and_two, thrust::less<KV>()));
ASSERT_EQUAL_QUIET(two_and_two, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_two, two_and_three, thrust::greater<KV>()));
ASSERT_EQUAL_QUIET(two_and_three, thrust::max THRUST_PREVENT_MACRO_SUBSTITUTION (two_and_three, two_and_two, thrust::greater<KV>()));
}
};
SimpleUnitTest<TestMax, NumericTypes> TestMaxInstance;