In the reference implementation of TopKstd::sort(not std::stable_sort) is used, which does not guarantee to be stable. This is OK when sorting the values but when obtaining indices based on values, the indices of two equivalent values could be re-ordered. In my local env (OS & compiler) std::sort is stable and the TopK tests pass, but I suspect the tests may fail on some other OS/compilers due to possible unstable std::sort in ref implementation.
This PR changes std::sort to std::stable_sort in reference implementations so that we can make sure both ref implementation and our implementation of TopK are using stable sort/argsort. Please advice.
In the reference implementation of
TopK
std::sort
(notstd::stable_sort
) is used, which does not guarantee to be stable. This is OK when sorting thevalues
but when obtainingindices
based onvalues
, theindices
of two equivalentvalues
could be re-ordered. In my local env (OS & compiler)std::sort
is stable and the TopK tests pass, but I suspect the tests may fail on some other OS/compilers due to possible unstablestd::sort
in ref implementation.This PR changes
std::sort
tostd::stable_sort
in reference implementations so that we can make sure both ref implementation and our implementation of TopK are using stable sort/argsort. Please advice.