| 22 | #include "context_setup.hpp" |
| 23 | |
| 24 | BOOST_AUTO_TEST_CASE(simple_merge_int) |
| 25 | { |
| 26 | int data1[] = { 1, 3, 5, 7 }; |
| 27 | int data2[] = { 2, 4, 6, 8 }; |
| 28 | |
| 29 | boost::compute::vector<int> v1(4, context); |
| 30 | boost::compute::vector<int> v2(4, context); |
| 31 | boost::compute::vector<int> v3(8, context); |
| 32 | |
| 33 | boost::compute::copy_n(data1, 4, v1.begin(), queue); |
| 34 | boost::compute::copy_n(data2, 4, v2.begin(), queue); |
| 35 | boost::compute::fill(v3.begin(), v3.end(), 0, queue); |
| 36 | |
| 37 | // merge v1 with v2 into v3 |
| 38 | boost::compute::merge( |
| 39 | v1.begin(), v1.end(), |
| 40 | v2.begin(), v2.end(), |
| 41 | v3.begin(), |
| 42 | queue |
| 43 | ); |
| 44 | CHECK_RANGE_EQUAL(int, 8, v3, (1, 2, 3, 4, 5, 6, 7, 8)); |
| 45 | |
| 46 | // merge v2 with v1 into v3 |
| 47 | boost::compute::merge( |
| 48 | v2.begin(), v2.end(), |
| 49 | v1.begin(), v1.end(), |
| 50 | v3.begin(), |
| 51 | queue |
| 52 | ); |
| 53 | CHECK_RANGE_EQUAL(int, 8, v3, (1, 2, 3, 4, 5, 6, 7, 8)); |
| 54 | |
| 55 | // merge v1 with v1 into v3 |
| 56 | boost::compute::merge( |
| 57 | v1.begin(), v1.end(), |
| 58 | v1.begin(), v1.end(), |
| 59 | v3.begin(), |
| 60 | queue |
| 61 | ); |
| 62 | CHECK_RANGE_EQUAL(int, 8, v3, (1, 1, 3, 3, 5, 5, 7, 7)); |
| 63 | |
| 64 | // merge v2 with v2 into v3 |
| 65 | boost::compute::merge( |
| 66 | v2.begin(), v2.end(), |
| 67 | v2.begin(), v2.end(), |
| 68 | v3.begin(), |
| 69 | queue |
| 70 | ); |
| 71 | CHECK_RANGE_EQUAL(int, 8, v3, (2, 2, 4, 4, 6, 6, 8, 8)); |
| 72 | |
| 73 | // merge v1 with empty range into v3 |
| 74 | boost::compute::merge( |
| 75 | v1.begin(), v1.end(), |
| 76 | v1.begin(), v1.begin(), |
| 77 | v3.begin(), |
| 78 | queue |
| 79 | ); |
| 80 | CHECK_RANGE_EQUAL(int, 4, v3, (1, 3, 5, 7)); |
| 81 | |