Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Transform Iterators and Sort By Key #1711

@neoblizz

Description

@neoblizz

I have a use-case for performing a sort by key, where I don't actually care about the key but I'd like to use it to sort the values.
The problem here is that the keys are not stored anywhere, and I would like them to be "generated" using a transform iterator.
So, if I effectively passed the variance lambda into sort_by_key with a transform_iterator, I would get the input sorted based on the return values of the lambda.

auto variance = [=] __device__(std::size_t i) {
    auto x = input_data[i];
    return get_variance(x); // assume this returns an integer.
};
thrust::sort_by_key(
    thrust::cuda::par_nosync.on(stream);
    thrust::make_transform_iterator(
        thrust::make_counting_iterator<std::size_t>(0), variance),                   // keys begin.
    thrust::make_transform_iterator(
        thrust::make_counting_iterator<std::size_t>(num_elements), variance),        // keys end.
    input.begin());                                                                  // values begin.

But it seems like this use is not supported due to:

RandomAccessIterator1 is a model of Random Access Iterator, RandomAccessIterator1 is mutable.

Is my understanding correct? If so, any suggestions on another way to address this problem without actually first generating the keys and storing them separately?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions