예제 #1
0
파일: test_sort.cpp 프로젝트: 2bbb/compute
{
    // function to compare particles by their x-coordinate
    BOOST_COMPUTE_FUNCTION(bool, sort_by_x, (Particle a, Particle b),
    {
        return a.x < b.x;
    });

    std::vector<Particle> particles;
    particles.push_back(Particle(0.1f, 0.f));
    particles.push_back(Particle(-0.4f, 0.f));
    particles.push_back(Particle(10.0f, 0.f));
    particles.push_back(Particle(0.001f, 0.f));

    boost::compute::vector<Particle> vector(4, context);
    boost::compute::copy(particles.begin(), particles.end(), vector.begin(), queue);
    BOOST_CHECK_EQUAL(vector.size(), size_t(4));
    BOOST_CHECK(
        boost::compute::is_sorted(vector.begin(), vector.end(),
                                  sort_by_x, queue) == false
    );

    boost::compute::sort(vector.begin(), vector.end(), sort_by_x, queue);
    BOOST_CHECK(
        boost::compute::is_sorted(vector.begin(), vector.end(),
                                  sort_by_x, queue) == true
    );
    boost::compute::copy(vector.begin(), vector.end(), particles.begin(), queue);
    BOOST_CHECK_CLOSE(particles[0].x, -0.4f, 0.1);
    BOOST_CHECK_CLOSE(particles[1].x, 0.001f, 0.1);
    BOOST_CHECK_CLOSE(particles[2].x, 0.1f, 0.1);
    BOOST_CHECK_CLOSE(particles[3].x, 10.0f, 0.1);
 static void resize( boost::compute::vector< T, A > &x , const boost::compute::vector< T, A > &y )
 {
     x.resize( y.size() );
 }
예제 #3
0
                     test.begin(), std::multiplies<int>());

    BOOST_CHECK_EQUAL_COLLECTIONS(host_vector.begin(), host_vector.end(),
                                  test.begin(), test.end());
}

BOOST_AUTO_TEST_CASE(inclusive_scan_int_custom_function)
{
    BOOST_COMPUTE_FUNCTION(int, multi, (int x, int y),
    {
        return x * y * 2;
    });

    int data[] = { 1, 2, 1, 2, 3 };
    bc::vector<int> vector(data, data + 5, queue);
    BOOST_CHECK_EQUAL(vector.size(), size_t(5));

    bc::vector<int> result(5, context);
    BOOST_CHECK_EQUAL(result.size(), size_t(5));

    // inclusive scan
    bc::inclusive_scan(vector.begin(), vector.end(), result.begin(),
                       multi, queue);
    CHECK_RANGE_EQUAL(int, 5, result, (1, 4, 8, 32, 192));

    // in-place inclusive scan
    CHECK_RANGE_EQUAL(int, 5, vector, (1, 2, 1, 2, 3));
    bc::inclusive_scan(vector.begin(), vector.end(), vector.begin(),
                       multi, queue);
    CHECK_RANGE_EQUAL(int, 5, vector, (1, 4, 8, 32, 192));
}
 static bool same_size( const boost::compute::vector< T, A > &x , const boost::compute::vector< T, A > &y )
 {
     return x.size() == y.size();
 }