#include #include #include #include #include #include #include template void TestTransformIterator(void) { typedef typename Vector::value_type T; typedef thrust::negate UnaryFunction; typedef typename Vector::iterator Iterator; Vector input(4); Vector output(4); // initialize input thrust::sequence(input.begin(), input.end(), 1); // construct transform_iterator thrust::transform_iterator iter(input.begin(), UnaryFunction()); thrust::copy(iter, iter + 4, output.begin()); ASSERT_EQUAL(output[0], -1); ASSERT_EQUAL(output[1], -2); ASSERT_EQUAL(output[2], -3); ASSERT_EQUAL(output[3], -4); } DECLARE_VECTOR_UNITTEST(TestTransformIterator); template void TestMakeTransformIterator(void) { typedef typename Vector::value_type T; typedef thrust::negate UnaryFunction; typedef typename Vector::iterator Iterator; Vector input(4); Vector output(4); // initialize input thrust::sequence(input.begin(), input.end(), 1); // construct transform_iterator thrust::transform_iterator iter(input.begin(), UnaryFunction()); thrust::copy(thrust::make_transform_iterator(input.begin(), UnaryFunction()), thrust::make_transform_iterator(input.end(), UnaryFunction()), output.begin()); ASSERT_EQUAL(output[0], -1); ASSERT_EQUAL(output[1], -2); ASSERT_EQUAL(output[2], -3); ASSERT_EQUAL(output[3], -4); } DECLARE_VECTOR_UNITTEST(TestMakeTransformIterator); template struct TestTransformIteratorReduce { void operator()(const size_t n) { thrust::host_vector h_data = unittest::random_samples(n); thrust::device_vector d_data = h_data; // run on host T h_result = thrust::reduce( thrust::make_transform_iterator(h_data.begin(), thrust::negate()), thrust::make_transform_iterator(h_data.end(), thrust::negate()) ); // run on device T d_result = thrust::reduce( thrust::make_transform_iterator(d_data.begin(), thrust::negate()), thrust::make_transform_iterator(d_data.end(), thrust::negate()) ); ASSERT_EQUAL(h_result, d_result); } }; VariableUnitTest TestTransformIteratorReduceInstance;