Domanda

I'm trying to figure out how thrust::set_intersection works but from my test results I get even more confused on what this function is doing.

Here is a few examples:

const int size1 = 5;
const int size2 = 5;
int A1[size1] = { 2, 3, 4, 5, 6 };
int A2[size2] = { 1, 2, 3, 4, 5 };
int *result = new int[1000];
int *result_end = thrust::set_intersection(A1, A1 + size1, A2, A2 + size2, result, thrust::less<int>());

returns 2, 3, 4, 5

thrust::equal_to<int>()

returns 2, 3, 4, 5, 6

thrust::greater<int>()

returns nothing

I do understand what the default set_intersection does and I agree with the result, but for any other example I'm totally lost where the result came from? Or how it was calculated?

Is it known how this algorithm works? Can someone explain it?

EDIT:

My goal is given 2 sets of tuples(lets say of size 2):

A={(1, 1), (2, 2), (3, 3)}
B={(0, 2), (2, 2), (3, 3)}

So I want to define on operator on tuples like >< that returns all the element that satisfy the operator:

>< defined like a.first > b.first && a.second < b.second

so the answer is only A[0] and B[0].

So you can't achieve this with set_intersection right?

EDIT answer: Never mind I found the answer here by these rules such operator won't be 'Strict Weak Ordering' operator.

È stato utile?

Soluzione

To two input sets need to be sorted according to the last argument, the comparator.

  • In the first example they are, and the function works correctly.

  • The sets are not sorted according to thrust::greater<int>(). Since the prerequisites are not met, the function cannot do its job.

  • thrust::equal_to<int>() is not even a valid comparator.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top