Spaces:
Runtime error
Runtime error
File size: 3,306 Bytes
be11144 |
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
#include <unittest/unittest.h>
#include <thrust/sort.h>
#include <thrust/functional.h>
#include <thrust/iterator/retag.h>
template<typename RandomAccessIterator>
void sort(my_system &system, RandomAccessIterator, RandomAccessIterator)
{
system.validate_dispatch();
}
void TestSortDispatchExplicit()
{
thrust::device_vector<int> vec(1);
my_system sys(0);
thrust::sort(sys, vec.begin(), vec.begin());
ASSERT_EQUAL(true, sys.is_valid());
}
DECLARE_UNITTEST(TestSortDispatchExplicit);
template<typename RandomAccessIterator>
void sort(my_tag, RandomAccessIterator first, RandomAccessIterator)
{
*first = 13;
}
void TestSortDispatchImplicit()
{
thrust::device_vector<int> vec(1);
thrust::sort(thrust::retag<my_tag>(vec.begin()),
thrust::retag<my_tag>(vec.begin()));
ASSERT_EQUAL(13, vec.front());
}
DECLARE_UNITTEST(TestSortDispatchImplicit);
template <class Vector>
void InitializeSimpleKeySortTest(Vector& unsorted_keys, Vector& sorted_keys)
{
unsorted_keys.resize(7);
unsorted_keys[0] = 1;
unsorted_keys[1] = 3;
unsorted_keys[2] = 6;
unsorted_keys[3] = 5;
unsorted_keys[4] = 2;
unsorted_keys[5] = 0;
unsorted_keys[6] = 4;
sorted_keys.resize(7);
sorted_keys[0] = 0;
sorted_keys[1] = 1;
sorted_keys[2] = 2;
sorted_keys[3] = 3;
sorted_keys[4] = 4;
sorted_keys[5] = 5;
sorted_keys[6] = 6;
}
template <class Vector>
void TestSortSimple(void)
{
Vector unsorted_keys;
Vector sorted_keys;
InitializeSimpleKeySortTest(unsorted_keys, sorted_keys);
thrust::sort(unsorted_keys.begin(), unsorted_keys.end());
ASSERT_EQUAL(unsorted_keys, sorted_keys);
}
DECLARE_VECTOR_UNITTEST(TestSortSimple);
template <typename T>
void TestSortAscendingKey(const size_t n)
{
thrust::host_vector<T> h_data = unittest::random_integers<T>(n);
thrust::device_vector<T> d_data = h_data;
thrust::sort(h_data.begin(), h_data.end(), thrust::less<T>());
thrust::sort(d_data.begin(), d_data.end(), thrust::less<T>());
ASSERT_EQUAL(h_data, d_data);
}
DECLARE_VARIABLE_UNITTEST(TestSortAscendingKey);
void TestSortDescendingKey(void)
{
const size_t n = 10027;
thrust::host_vector<int> h_data = unittest::random_integers<int>(n);
thrust::device_vector<int> d_data = h_data;
thrust::sort(h_data.begin(), h_data.end(), thrust::greater<int>());
thrust::sort(d_data.begin(), d_data.end(), thrust::greater<int>());
ASSERT_EQUAL(h_data, d_data);
}
DECLARE_UNITTEST(TestSortDescendingKey);
void TestSortBool(void)
{
const size_t n = 10027;
thrust::host_vector<bool> h_data = unittest::random_integers<bool>(n);
thrust::device_vector<bool> d_data = h_data;
thrust::sort(h_data.begin(), h_data.end());
thrust::sort(d_data.begin(), d_data.end());
ASSERT_EQUAL(h_data, d_data);
}
DECLARE_UNITTEST(TestSortBool);
void TestSortBoolDescending(void)
{
const size_t n = 10027;
thrust::host_vector<bool> h_data = unittest::random_integers<bool>(n);
thrust::device_vector<bool> d_data = h_data;
thrust::sort(h_data.begin(), h_data.end(), thrust::greater<bool>());
thrust::sort(d_data.begin(), d_data.end(), thrust::greater<bool>());
ASSERT_EQUAL(h_data, d_data);
}
DECLARE_UNITTEST(TestSortBoolDescending);
|