Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think that you can use <code>thrust::unique</code> with a predicate as it's shown in <a href="https://stackoverflow.com/questions/5521091/thrust-removing-duplicates-in-key-value-arrays">Thrust: Removing duplicates in key-value arrays</a>. Actually, we can do it because of the following characteristic of <code>unique</code>:</p> <blockquote> <p>For each group of consecutive elements in the range [first, last) with the same value, <code>unique</code> removes <strong>all but the first</strong> element of the group.</p> </blockquote> <p>So, you should define a predicate to test for <em>pseudo</em>-equality that will return <code>true</code> for tuples that have the same key and all values are smaller in the first tuple:</p> <pre><code> typedef thrust::tuple&lt;int, int, int, int&gt; tuple_t; // a functor which defines your *uniqueness* condition struct tupleEqual { __host__ __device__ bool operator()(tuple_t x, tuple_t y) { return ( (x.get&lt;0&gt;() == y.get&lt;0&gt;()) // same key &amp;&amp; (x.get&lt;1&gt;() &lt;= y.get&lt;1&gt;()) // all values are smaller &amp;&amp; (x.get&lt;2&gt;() &lt;= y.get&lt;2&gt;()) &amp;&amp; (x.get&lt;3&gt;() &lt;= y.get&lt;3&gt;())); } }; </code></pre> <p>And you have to apply it to a <strong>sorted</strong> collection. In this way, only the first tuple (the smallest) will not be removed. A tuple with the same key and a bigger value in V1, V2 or V3 will yield <code>false</code> so it won't be removed.</p> <pre><code> typedef thrust::device_vector&lt; int &gt; IntVector; typedef IntVector::iterator IntIterator; typedef thrust::tuple&lt; IntIterator, IntIterator, IntIterator, IntIterator &gt; IntIteratorTuple; typedef thrust::zip_iterator&lt; IntIteratorTuple &gt; ZipIterator; IntVector keyVector; IntVector valVector1, valVector2, valVector3; tupleEqual predicate; ZipIterator newEnd = thrust::unique( thrust::make_zip_iterator( thrust::make_tuple( keyVector.begin(), valVector1.begin(), valVector2.begin(), valVector3.begin() ) ), thrust::make_zip_iterator( thrust::make_tuple( keyVector.end(), valVector1.end(), valVector2.end(), valVector3.end() ) ), predicate ); IntIteratorTuple endTuple = newEnd.get_iterator_tuple(); keyVector.erase( thrust::get&lt;0&gt;( endTuple ), keyVector.end() ); valVector1.erase( thrust::get&lt;1&gt;( endTuple ), valVector1.end() ); valVector2.erase( thrust::get&lt;2&gt;( endTuple ), valVector2.end() ); valVector3.erase( thrust::get&lt;3&gt;( endTuple ), valVector3.end() ); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload