2
0
mirror of https://github.com/boostorg/compute.git synced 2026-02-19 02:12:19 +00:00

Merge remote-tracking branch 'compute/develop'

This commit is contained in:
Anees Haider
2015-04-06 09:33:52 +05:00
41 changed files with 1424 additions and 493 deletions

View File

@@ -117,6 +117,7 @@ add_compute_test("algorithm.sort_by_key" test_sort_by_key.cpp)
add_compute_test("algorithm.stable_partition" test_stable_partition.cpp)
add_compute_test("algorithm.stable_sort" test_stable_sort.cpp)
add_compute_test("algorithm.transform" test_transform.cpp)
add_compute_test("algorithm.transform_if" test_transform_if.cpp)
add_compute_test("algorithm.transform_reduce" test_transform_reduce.cpp)
add_compute_test("algorithm.unique" test_unique.cpp)
add_compute_test("algorithm.unique_copy" test_unique_copy.cpp)
@@ -190,7 +191,6 @@ add_compute_test("experimental.clamp_range" test_clamp_range.cpp)
add_compute_test("experimental.malloc" test_malloc.cpp)
add_compute_test("experimental.sort_by_transform" test_sort_by_transform.cpp)
add_compute_test("experimental.tabulate" test_tabulate.cpp)
add_compute_test("experimental.transform_if" test_transform_if.cpp)
# miscellaneous tests
add_compute_test("misc.amd_cpp_kernel_language" test_amd_cpp_kernel_language.cpp)

View File

@@ -68,6 +68,14 @@ BOOST_AUTO_TEST_CASE(reverse_copy_int)
bc::reverse_copy(a.begin(), a.end(), b.begin());
BOOST_CHECK(iter == b.end());
CHECK_RANGE_EQUAL(int, 5, b, (4, 3, 2, 1, 0));
iter = bc::reverse_copy(b.begin() + 1, b.end(), a.begin() + 1);
BOOST_CHECK(iter == a.end());
CHECK_RANGE_EQUAL(int, 5, a, (0, 0, 1, 2, 3));
iter = bc::reverse_copy(a.begin(), a.end() - 1, b.begin());
BOOST_CHECK(iter == (b.end() - 1));
CHECK_RANGE_EQUAL(int, 5, b, (2, 1, 0, 0, 0));
}
BOOST_AUTO_TEST_CASE(reverse_copy_counting_iterator)

View File

@@ -298,4 +298,27 @@ boost::compute::transform(
CHECK_RANGE_EQUAL(int, 4, vec, (1, 2, 3, 4));
}
BOOST_AUTO_TEST_CASE(abs_if_odd)
{
// return absolute value only for odd values
BOOST_COMPUTE_FUNCTION(int, abs_if_odd, (int x),
{
if(x & 1){
return abs(x);
}
else {
return x;
}
});
int data[] = { -2, -3, -4, -5, -6, -7, -8, -9 };
compute::vector<int> vector(data, data + 8, queue);
compute::transform(
vector.begin(), vector.end(), vector.begin(), abs_if_odd, queue
);
CHECK_RANGE_EQUAL(int, 8, vector, (-2, +3, -4, +5, -6, +7, -8, +9));
}
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -12,8 +12,7 @@
#include <boost/test/unit_test.hpp>
#include <boost/compute/lambda.hpp>
#include <boost/compute/functional.hpp>
#include <boost/compute/experimental/transform_if.hpp>
#include <boost/compute/algorithm/transform_if.hpp>
#include <boost/compute/container/vector.hpp>
#include "check_macros.hpp"
@@ -21,26 +20,20 @@
namespace compute = boost::compute;
BOOST_AUTO_TEST_CASE(abs_if_odd)
BOOST_AUTO_TEST_CASE(transform_if_odd)
{
using compute::lambda::_1;
using boost::compute::abs;
using boost::compute::lambda::_1;
// input data
int data[] = { -2, -3, -4, -5, -6, -7, -8, -9 };
compute::vector<int> vector(data, data + 8, queue);
// calculate absolute value only for odd values
compute::experimental::transform_if(
vector.begin(),
vector.end(),
vector.begin(),
compute::abs<int>(),
_1 % 2 != 0,
queue
compute::vector<int>::iterator end = compute::transform_if(
vector.begin(), vector.end(), vector.begin(), abs<int>(), _1 % 2 != 0, queue
);
BOOST_CHECK_EQUAL(std::distance(vector.begin(), end), 4);
// check transformed values
CHECK_RANGE_EQUAL(int, 8, vector, (-2, +3, -4, +5, -6, +7, -8, +9));
CHECK_RANGE_EQUAL(int, 4, vector, (+3, +5, +7, +9));
}
BOOST_AUTO_TEST_SUITE_END()