How to sort 2D Slice along 0 axis in mir.ndslice ?

9il ilyayaroshenko at gmail.com
Wed Mar 11 06:12:55 UTC 2020


On Wednesday, 11 March 2020 at 00:24:13 UTC, jmh530 wrote:
> On Tuesday, 10 March 2020 at 23:31:55 UTC, p.shkadzko wrote:
>> [snip]
>
> Below does the same thing as the numpy version.
>
> /+dub.sdl:
> dependency "mir-algorithm" version="~>3.7.18"
> +/
> import mir.ndslice.sorting : sort;
> import mir.ndslice.topology : byDim;
> import mir.ndslice.slice : sliced;
>
> void main() {
>     auto m = [1, -1, 3, 2, 0, -2, 3, 1].sliced(2, 4);
>     m.byDim!0.each!(a => a.sort);
> }

Almost the same, just fixed import for `each` and a bit polished

/+dub.sdl:
dependency "mir-algorithm" version="~>3.7.18"
+/
import mir.ndslice;
import mir.ndslice.sorting;
import mir.algorithm.iteration: each;

void main() {
     auto m = [[1, -1, 3, 2],
               [0, -2, 3, 1]].fuse;
     m.byDim!0.each!sort;

     import std.stdio;
     m.byDim!0.each!writeln;
}



More information about the Digitalmars-d-learn mailing list