You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
For the common count -> allocate -> fill pattern (e.g. count_if/copy_if) there are some fill algorithms without a corresponding count algorithm, mainly unique_copy, unique_by_key_copy and reduce_by_key. So I want to suggest adding a count_unique algorithm with basically the same interface as unique save the return type:
difference_type thrust::count_unique(
Policy exec,
ForwardIterator first,
ForwardIterator last,
BinaryPredicate binary_pred)
The name probably needs a bit of discussion, since it doesn't actually count unique elements, but runs of unique elements, but unique has the same issue, so there is some prior art for it.
@allisonvacanti suggested using cub::DeviceRunLengthEncode::Encode to implement it, so I wanted to check whether there are any other approaches to consider before starting work on a PR. Another simple approach might be
auto zip_it = zip(it, it + 1);
if (size > 0) {
return1 + count_if(zip_it, zip_it + size - 1, [](auto a) { !binary_pred(get<0>(a), get<1>(a)); });
} else {
return0;
}