test_inner_product.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 TestInnerProduct
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/system.hpp>
  13. #include <boost/compute/algorithm/inner_product.hpp>
  14. #include <boost/compute/container/vector.hpp>
  15. #include <boost/compute/iterator/counting_iterator.hpp>
  16. #include "context_setup.hpp"
  17. namespace bc = boost::compute;
  18. BOOST_AUTO_TEST_CASE(inner_product_int)
  19. {
  20. int data1[] = { 1, 2, 3, 4 };
  21. bc::vector<int> input1(data1, data1 + 4, queue);
  22. int data2[] = { 10, 20, 30, 40 };
  23. bc::vector<int> input2(data2, data2 + 4, queue);
  24. int product = bc::inner_product(input1.begin(),
  25. input1.end(),
  26. input2.begin(),
  27. 0,
  28. queue);
  29. BOOST_CHECK_EQUAL(product, 300);
  30. }
  31. BOOST_AUTO_TEST_CASE(inner_product_counting_iterator)
  32. {
  33. BOOST_CHECK_EQUAL(
  34. boost::compute::inner_product(
  35. boost::compute::make_counting_iterator<int>(0),
  36. boost::compute::make_counting_iterator<int>(100),
  37. boost::compute::make_counting_iterator<int>(0),
  38. 0,
  39. queue
  40. ),
  41. 328350
  42. );
  43. }
  44. BOOST_AUTO_TEST_SUITE_END()