#include #include #include #include #include #include #include template void TestTransformOutputIterator(void) { typedef typename Vector::value_type T; typedef thrust::square UnaryFunction; typedef typename Vector::iterator Iterator; Vector input(4); Vector output(4); // initialize input thrust::sequence(input.begin(), input.end(), T{1}); // construct transform_iterator thrust::transform_output_iterator output_iter(output.begin(), UnaryFunction()); thrust::copy(input.begin(), input.end(), output_iter); Vector gold_output(4); gold_output[0] = 1; gold_output[1] = 4; gold_output[2] = 9; gold_output[3] = 16; ASSERT_EQUAL(output, gold_output); } DECLARE_VECTOR_UNITTEST(TestTransformOutputIterator); template void TestMakeTransformOutputIterator(void) { typedef typename Vector::value_type T; typedef thrust::square UnaryFunction; Vector input(4); Vector output(4); // initialize input thrust::sequence(input.begin(), input.end(), 1); thrust::copy(input.begin(), input.end(), thrust::make_transform_output_iterator(output.begin(), UnaryFunction())); Vector gold_output(4); gold_output[0] = 1; gold_output[1] = 4; gold_output[2] = 9; gold_output[3] = 16; ASSERT_EQUAL(output, gold_output); } DECLARE_VECTOR_UNITTEST(TestMakeTransformOutputIterator); template struct TestTransformOutputIteratorScan { void operator()(const size_t n) { thrust::host_vector h_data = unittest::random_samples(n); thrust::device_vector d_data = h_data; thrust::host_vector h_result(n); thrust::device_vector d_result(n); // run on host thrust::inclusive_scan(thrust::make_transform_iterator(h_data.begin(), thrust::negate()), thrust::make_transform_iterator(h_data.end(), thrust::negate()), h_result.begin()); // run on device thrust::inclusive_scan(d_data.begin(), d_data.end(), thrust::make_transform_output_iterator( d_result.begin(), thrust::negate())); ASSERT_EQUAL(h_result, d_result); } }; VariableUnitTest TestTransformOutputIteratorScanInstance;