https://github.com/InteractiveComputerGraphics/cuNSearch/blob/master/src/cuNSearchDeviceData.cu#L160-#L167
These lines seem to be redundant. Since tempSequence.begin is a unique sequence that starts from 0 and d_SortIndices is also a unique sequence that starts from 0, d_ReversedSortIndices is guaranteed to be exactly the same as d_SortIndices after gather. They why not directly copy d_SortIndices to d_ReversedSortIndices? I validated this on a few examples, but maybe there are cases where this is not the case?