Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Multiway count_if/copy_if #799

Open
upsj opened this issue Mar 18, 2022 · 1 comment
Open

Feature Request: Multiway count_if/copy_if #799

upsj opened this issue Mar 18, 2022 · 1 comment
Assignees
Labels
thrust For all items related to Thrust.

Comments

@upsj
Copy link

upsj commented Mar 18, 2022

I frequently run across the need for an algorithm that can copy multiple disjoint subsets from a vector to another vector (or set of vectors?) based on some kind of classification function that tells me for each element which subset it belongs to, if any. For now, let's just imagine it as a lambda returning a non-negative integer, or -1 if it's not part of any subset.

For a small number of subsets, this could be implemented as a number of copy_ifs, for a larger number of subsets, it could be implemented via stable_sort by subset ID followed by finding the end of the -1 subset. But both of those approaches are far from a single-pass or at worst two-pass approach that a hand-written implementation would require.

I believe a count_if/copy_if pair like this could be really useful for many applications, e.g.

  • histogram calculation
  • element classification
  • generalized partition_copy (if we don't have -1 values)

This could even be used to implement a badly tuned version of Radixsort or Samplesort by yourself.

Interface considerations for this include

  • How to represent the classification? Lambda returning an integer would be straightforward, but that leaves us open to somebody returning out-of-bounds subset IDs (just discard all of the elements?)
  • How to represent the output ranges? If the number of classes is known statically, a variadic templated parameter/tuple matching the number of output ranges would work, otherwise this would be related to the RangeOfRanges approach discussed in Consider support for segmented reductions and sorts specified by count-value representation #676, or everything is just being written to a single contiguous output range (like partition_copy), together with an offset array specifying their sizes.
  • How to return the output sizes/iterators from the multiway copy_if? This could be a tuple of individual iterators for the statically known size, or a range of ranges for the dynamic case
@alliepiper
Copy link
Collaborator

This sounds somewhat related to NVIDIA/cub#297.

@jrhemstad jrhemstad added the thrust For all items related to Thrust. label Feb 22, 2023
@jarmak-nv jarmak-nv transferred this issue from NVIDIA/thrust Nov 8, 2023
@github-project-automation github-project-automation bot moved this to Todo in CCCL Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
thrust For all items related to Thrust.
Projects
Status: Todo
Development

No branches or pull requests

4 participants