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

Function unique_copy

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

Source from the content-addressed store, hash-verified

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

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