MCPcopy Create free account
hub / github.com/boostorg/compute / unique_copy

Function unique_copy

include/boost/compute/algorithm/unique_copy.hpp:80–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78
79template<class InputIterator, class OutputIterator, class BinaryPredicate>
80inline OutputIterator unique_copy(InputIterator first,
81 InputIterator last,
82 OutputIterator result,
83 BinaryPredicate op,
84 command_queue &queue)
85{
86 if(first == last){
87 return result;
88 }
89
90 const context &context = queue.get_context();
91 size_t count = detail::iterator_range_size(first, last);
92
93 // flags marking unique elements
94 vector<uint_> flags(count, context);
95
96 // find each unique element and mark it with a one
97 transform(
98 first, last - 1, first + 1, flags.begin() + 1, not2(op), queue
99 );
100
101 // first element is always unique
102 fill_n(flags.begin(), 1, 1, queue);
103
104 // storage for desination indices
105 vector<uint_> indices(count, context);
106
107 // copy indices for each unique element
108 vector<uint_>::iterator last_index = detail::copy_index_if(
109 flags.begin(), flags.end(), indices.begin(), lambda::_1 == 1, queue
110 );
111
112 // copy unique values from input to output using the computed indices
113 gather(indices.begin(), last_index, first, result, queue);
114
115 // return an iterator to the end of the unique output range
116 return result + std::distance(indices.begin(), last_index);
117}
118
119} // end detail namespace
120

Callers 4

BOOST_AUTO_TEST_CASEFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
uniqueFunction · 0.85

Calls 10

iterator_range_sizeFunction · 0.85
transformFunction · 0.85
not2Function · 0.85
fill_nFunction · 0.85
copy_index_ifFunction · 0.85
gatherFunction · 0.85
serial_unique_copyFunction · 0.85
get_contextMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68