Randomness in built-in .sort

jmh530 john.michael.hall at gmail.com
Tue Mar 23 21:41:00 UTC 2021


On Tuesday, 23 March 2021 at 21:22:25 UTC, mw wrote:
> [snip]
>
> I'm now looking for np.argsort, and found this post.
>
> @bearophile, the doc page above is gone, although the zip file 
> is still there (~10 years old), do you want to create a github 
> repo, and contribute the code to dub (https://code.dlang.org/)?
>
>
> BTW, does anyone know if there is a np.argsort function in some 
> other d libraries?
>
>
> Thanks.

import std.algorithm.sorting: makeIndex;
import std.algorithm.comparison: equal;
import std.range: indexed;

void main() {
     int[] arr0 = [ 2, 3, 1, 5, 0 ];
     int[] arr1 = [ 1, 5, 4, 2, -1 ];

     auto index = new int[arr0.length];
     makeIndex!("a < b")(arr0, index);
     assert(index == [4, 2, 0, 1, 3]);
     auto view = arr1.indexed(index);
     assert(view.equal([-1, 4, 1, 5, 2]));
}


More information about the Digitalmars-d mailing list