I'm actually a bit surprised that this is faster than `argsort`, because the expected number of swaps is around 2 *n* lg *n* whereas sorting indices and then using those to sort distances would take 2 *n* lg *n* + *n*.

But no, I can't think of a good alternative -- there's the C++ `std::sort`, which is practically always implemented as the extremely fast [introsort](https://en.wikipedia.org/wiki/Introsort) algorithm, but we also have good reasons not to use C++ code if it's not needed.

Is this called at prediction time?