test_iota.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 TestIota
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/context.hpp>
  14. #include <boost/compute/algorithm/iota.hpp>
  15. #include <boost/compute/container/vector.hpp>
  16. #include <boost/compute/iterator/permutation_iterator.hpp>
  17. #include "check_macros.hpp"
  18. #include "context_setup.hpp"
  19. namespace bc = boost::compute;
  20. BOOST_AUTO_TEST_CASE(iota_int)
  21. {
  22. bc::vector<int> vector(4, context);
  23. bc::iota(vector.begin(), vector.end(), 0, queue);
  24. CHECK_RANGE_EQUAL(int, 4, vector, (0, 1, 2, 3));
  25. bc::iota(vector.begin(), vector.end(), 10, queue);
  26. CHECK_RANGE_EQUAL(int, 4, vector, (10, 11, 12, 13));
  27. bc::iota(vector.begin() + 2, vector.end(), -5, queue);
  28. CHECK_RANGE_EQUAL(int, 4, vector, (10, 11, -5, -4));
  29. bc::iota(vector.begin(), vector.end() - 2, 4, queue);
  30. CHECK_RANGE_EQUAL(int, 4, vector, (4, 5, -5, -4));
  31. }
  32. BOOST_AUTO_TEST_CASE(iota_doctest)
  33. {
  34. boost::compute::vector<int> vec(3, context);
  35. //! [iota]
  36. boost::compute::iota(vec.begin(), vec.end(), 0, queue);
  37. //! [iota]
  38. CHECK_RANGE_EQUAL(int, 3, vec, (0, 1, 2));
  39. }
  40. BOOST_AUTO_TEST_CASE(iota_permutation_iterator)
  41. {
  42. bc::vector<int> output(5, context);
  43. bc::fill(output.begin(), output.end(), 0, queue);
  44. int map_data[] = { 2, 0, 1, 4, 3 };
  45. bc::vector<int> map(map_data, map_data + 5, queue);
  46. bc::iota(
  47. bc::make_permutation_iterator(output.begin(), map.begin()),
  48. bc::make_permutation_iterator(output.end(), map.end()),
  49. 1,
  50. queue
  51. );
  52. CHECK_RANGE_EQUAL(int, 5, output, (2, 3, 1, 5, 4));
  53. }
  54. BOOST_AUTO_TEST_CASE(iota_uint)
  55. {
  56. bc::vector<bc::uint_> vector(4, context);
  57. bc::iota(vector.begin(), vector.end(), bc::uint_(0), queue);
  58. CHECK_RANGE_EQUAL(bc::uint_, 4, vector, (0, 1, 2, 3));
  59. }
  60. BOOST_AUTO_TEST_CASE(iota_char)
  61. {
  62. bc::vector<bc::char_> vector(4, context);
  63. bc::iota(vector.begin(), vector.end(), bc::uint_(0), queue);
  64. CHECK_RANGE_EQUAL(bc::char_, 4, vector, (0, 1, 2, 3));
  65. }
  66. BOOST_AUTO_TEST_CASE(iota_uchar)
  67. {
  68. bc::vector<bc::uchar_> vector(4, context);
  69. bc::iota(vector.begin(), vector.end(), bc::uint_(0), queue);
  70. CHECK_RANGE_EQUAL(bc::uchar_, 4, vector, (0, 1, 2, 3));
  71. }
  72. BOOST_AUTO_TEST_SUITE_END()