File: zip_iterator_sort.cu

package info (click to toggle)
rocthrust 6.4.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,588 kB
  • sloc: cpp: 66,309; ansic: 34,184; python: 1,519; sh: 331; xml: 212; makefile: 115
file content (31 lines) | stat: -rw-r--r-- 974 bytes parent folder | download | duplicates (5)
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
#include <unittest/unittest.h>
#include <thrust/iterator/zip_iterator.h>
#include <thrust/sort.h>

template <typename T>
  struct TestZipIteratorStableSort
{
  void operator()(const size_t n)
  {
    using namespace thrust;

    host_vector<T>   h1 = unittest::random_integers<T>(n);
    host_vector<T>   h2 = unittest::random_integers<T>(n);
    
    device_vector<T> d1 = h1;
    device_vector<T> d2 = h2;
    
    // sort on host
    stable_sort( make_zip_iterator(make_tuple(h1.begin(), h2.begin())),
                 make_zip_iterator(make_tuple(h1.end(),   h2.end())) );

    // sort on device
    stable_sort( make_zip_iterator(make_tuple(d1.begin(), d2.begin())),
                 make_zip_iterator(make_tuple(d1.end(),   d2.end())) );
  
    ASSERT_EQUAL_QUIET(h1, d1);
    ASSERT_EQUAL_QUIET(h2, d2);
  }
};
VariableUnitTest<TestZipIteratorStableSort, unittest::type_list<unittest::int8_t,unittest::int16_t,unittest::int32_t> > TestZipIteratorStableSortInstance;