#include #include #include #include using namespace unittest; struct MakeTupleFunctor { template __host__ __device__ thrust::tuple operator()(T1 &lhs, T2 &rhs) { return thrust::make_tuple(lhs, rhs); } }; template struct GetFunctor { template __host__ __device__ typename thrust::access_traits< typename thrust::tuple_element::type >::const_type operator()(const Tuple &t) { return thrust::get(t); } }; template struct TestTupleStableSort { void operator()(const size_t n) { using namespace thrust; host_vector h_keys = random_integers(n); host_vector h_values = random_integers(n); // zip up the data host_vector< tuple > h_tuples(n); transform(h_keys.begin(), h_keys.end(), h_values.begin(), h_tuples.begin(), MakeTupleFunctor()); // copy to device device_vector< tuple > d_tuples = h_tuples; // sort on host stable_sort(h_tuples.begin(), h_tuples.end()); // sort on device stable_sort(d_tuples.begin(), d_tuples.end()); ASSERT_EQUAL(true, is_sorted(d_tuples.begin(), d_tuples.end())); // select keys transform(h_tuples.begin(), h_tuples.end(), h_keys.begin(), GetFunctor<0>()); device_vector d_keys(h_keys.size()); transform(d_tuples.begin(), d_tuples.end(), d_keys.begin(), GetFunctor<0>()); // select values transform(h_tuples.begin(), h_tuples.end(), h_values.begin(), GetFunctor<1>()); device_vector d_values(h_values.size()); transform(d_tuples.begin(), d_tuples.end(), d_values.begin(), GetFunctor<1>()); ASSERT_ALMOST_EQUAL(h_keys, d_keys); ASSERT_ALMOST_EQUAL(h_values, d_values); } }; VariableUnitTest > TestTupleStableSortInstance;