plaidml / openvino

OpenVINO™ Toolkit - Deep Learning Deployment Toolkit repository
https://docs.openvinotoolkit.org/latest/index.html
Apache License 2.0
0 stars 1 forks source link

use stable sort to sort values and indices in topk #139

Closed haoyouab closed 3 years ago

haoyouab commented 3 years ago

In the reference implementation of TopK std::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.