Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can try to use Thrust library and thrust::remove_if algorithm (see example). Something like this:

struct is_good_match
{
    template <typename Tuple>
    __device__ bool operator()(const Tuple& tuple) const
    {
        // unpack the tuple
        const int2 trainIdx1 = thrust::get<0>(tuple);
        const float2 distance1 = thrust::get<1>(tuple);

        // check if it is a good match
        return (distance1.x / distance1.y) > 0.7;
    }
};

thrust::device_ptr<int2> trainIdx1_ptr(trainIdx1);
thrust::device_ptr<float2> distance1_ptr(distance1);

size_t new_size = thrust::remove_if(thrust::make_zip_iterator(thrust::make_tuple(trainIdx1_ptr, distance1_ptr)),
                                    thrust::make_zip_iterator(thrust::make_tuple(trainIdx1_ptr + size, distance1_ptr + size)),
                                    is_good_match())
                      - thrust::make_zip_iterator(thrust::make_tuple(trainIdx1_ptr, distance1_ptr));

You can try to use Thrust library and thrust::remove_if algorithm (see example). Something like this:

struct is_good_match
is_bad_match
{
    template <typename Tuple>
    __device__ bool operator()(const Tuple& tuple) const
    {
        // unpack the tuple
        const int2 trainIdx1 = thrust::get<0>(tuple);
        const float2 distance1 = thrust::get<1>(tuple);

        // check if it is a good bad match
        return (distance1.x / distance1.y) > < 0.7;
    }
};

thrust::device_ptr<int2> trainIdx1_ptr(trainIdx1);
thrust::device_ptr<float2> distance1_ptr(distance1);

size_t new_size = thrust::remove_if(thrust::make_zip_iterator(thrust::make_tuple(trainIdx1_ptr, distance1_ptr)),
                                    thrust::make_zip_iterator(thrust::make_tuple(trainIdx1_ptr + size, distance1_ptr + size)),
                                    is_good_match())
is_bad_match())
                      - thrust::make_zip_iterator(thrust::make_tuple(trainIdx1_ptr, distance1_ptr));