test_scatter.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #define BOOST_TEST_MODULE TestScatter
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/algorithm/scatter.hpp>
  14. #include <boost/compute/container/vector.hpp>
  15. #include <boost/compute/iterator/constant_buffer_iterator.hpp>
  16. #include "check_macros.hpp"
  17. #include "context_setup.hpp"
  18. namespace bc = boost::compute;
  19. BOOST_AUTO_TEST_CASE(scatter_int)
  20. {
  21. int input_data[] = { 1, 2, 3, 4, 5 };
  22. bc::vector<int> input(input_data, input_data + 5, queue);
  23. int map_data[] = { 0, 4, 1, 3, 2 };
  24. bc::vector<int> map(map_data, map_data + 5, queue);
  25. bc::vector<int> output(5, context);
  26. bc::scatter(input.begin(), input.end(), map.begin(), output.begin(), queue);
  27. CHECK_RANGE_EQUAL(int, 5, output, (1, 3, 5, 4, 2));
  28. }
  29. BOOST_AUTO_TEST_CASE(scatter_constant_indices)
  30. {
  31. int input_data[] = { 1, 2, 3, 4, 5 };
  32. bc::vector<int> input(input_data, input_data + 5, queue);
  33. int map_data[] = { 0, 4, 1, 3, 2 };
  34. bc::buffer map_buffer(context,
  35. 5 * sizeof(int),
  36. bc::buffer::read_only | bc::buffer::use_host_ptr,
  37. map_data);
  38. bc::vector<int> output(5, context);
  39. bc::scatter(input.begin(),
  40. input.end(),
  41. bc::make_constant_buffer_iterator<int>(map_buffer, 0),
  42. output.begin(),
  43. queue);
  44. CHECK_RANGE_EQUAL(int, 5, output, (1, 3, 5, 4, 2));
  45. }
  46. BOOST_AUTO_TEST_SUITE_END()