6 #include <boost/compute/context.hpp> 7 #include <boost/test/unit_test.hpp> 13 template <
typename precision_t>
14 void check_conjugate_and_multiply_sized(
int asize,
int bsize) {
16 if (std::is_same<double, precision_t>::value) {
17 if (not device.supports_extension(
"cl_khr_fp64")) {
19 "Test disabled, device (" << device.name()
20 <<
") does not support cl_khr_fp64, i.e., " 21 "double precision floating point");
25 boost::compute::context context(device);
26 boost::compute::command_queue queue(context, device);
28 unsigned int seed = std::random_device()();
29 std::mt19937 gen(seed);
30 std::uniform_real_distribution<precision_t> dis(-1000, 1000);
31 auto generator = [&gen, &dis]() {
return dis(gen); };
32 BOOST_TEST_MESSAGE(
"SEED = " << seed);
34 std::vector<std::complex<precision_t>> asrc;
36 std::vector<std::complex<precision_t>> bsrc(bsize);
44 std::fill(bsrc.begin(), bsrc.end(), std::complex<precision_t>(1.0, 1.0));
46 boost::compute::vector<std::complex<precision_t>> a(asize, context);
47 boost::compute::vector<std::complex<precision_t>> b(bsize, context);
48 boost::compute::vector<std::complex<precision_t>> out(asize, context);
49 std::vector<std::complex<precision_t>> actual(asize);
51 boost::compute::copy(asrc.begin(), asrc.end(), a.begin(), queue);
52 boost::compute::copy(bsrc.begin(), bsrc.end(), b.begin(), queue);
53 BOOST_TEST_MESSAGE(
"copied data to device");
56 a.begin(), a.end(), b.begin(), b.end(), out.begin(), queue);
57 if (not future.valid()) {
58 BOOST_CHECK_EQUAL(asize, 0);
61 if (device.platform().name() ==
"Portable Computing Language") {
65 queue.enqueue_barrier(boost::compute::wait_list(future.get_event()));
68 boost::compute::copy_async(out.begin(), out.end(), actual.begin(), queue);
70 std::vector<std::complex<precision_t>> expected(asize);
71 for (
int i = 0; i != asize; ++i) {
72 expected[i] = std::conj(asrc[i]) * bsrc[i];
78 BOOST_CHECK_MESSAGE(res,
"collections are not within tolerance=" << tol);
81 template <
typename precision_t>
82 void check_conjugate_and_multiply() {
83 constexpr std::size_t
size = 32768;
84 check_conjugate_and_multiply_sized<precision_t>(
size,
size);
87 template <
typename precision_t>
88 void check_conjugate_and_multiply_empty() {
89 check_conjugate_and_multiply_sized<precision_t>(0, 0);
92 template <
typename precision_t>
93 void check_conjugate_and_multiply_mismatched() {
94 constexpr std::size_t
size = 32768;
95 check_conjugate_and_multiply_sized<precision_t>(
size, size / 2);
105 check_conjugate_and_multiply<float>();
113 check_conjugate_and_multiply<double>();
121 BOOST_CHECK_NO_THROW(check_conjugate_and_multiply_empty<float>());
129 BOOST_CHECK_NO_THROW(check_conjugate_and_multiply_empty<double>());
138 check_conjugate_and_multiply_mismatched<float>(), std::exception);
void create_random_timeseries(generator &gen, int nsamples, timeseries &ts)
Create a simple timeseries where the values look like a random.
boost::compute::device device_selector(config const &cfg)
Select an OpenCL device matching the current configuration.
BOOST_AUTO_TEST_CASE(conjugate_and_multiply_float)
bool check_collection_close_enough(collection_t const &a, collection_t const &b, int tol=1, int max_differences_printed=JB_TESTING_MAX_DIFFERENCES_PRINTED)
Given two collections of numbers of the same value type, find the differences that are out of a given...
boost::compute::future< OutputIterator > conjugate_and_multiply(InputIterator a_start, InputIterator a_end, InputIterator b_start, InputIterator b_end, OutputIterator output, boost::compute::command_queue &queue, boost::compute::wait_list const &wait=boost::compute::wait_list())