I want to sort a two-dimensional ndslice by its columns according to some predefined predicate.

What I mean is _not_ sorting the contents of each column individually, but instead to reorder the entire columns of the matrix so that they are sorted according to some "greater than" function.

Here's a MWE (the `larger` function is just an example):

```
import std.stdio;

import mir.ndslice.slice;
import mir.ndslice.sorting;

void main() {
    auto a = [[1, -1, 3, 2],
              [0, -2, 3, 1]].sliced;

    writeln(a);
    a.byDim!1.sort!((u, v) => larger(u, v));
    writeln(a);
}

auto larger(C)(C u, C v) {
    import mir.math.sum : sum;
    return sum(u) > sum(v);
}
```

I would have expected this to print:
[[1, -1, 3, 2], [0, -2, 3, 1]]
[[3, 2, 1, -1], [3, 1, 0, -2]]

but instead it prints
[[1, -1, 3, 2], [0, -2, 3, 1]]
[[1, -1, 3, 2], [0, -2, 3, 1]]

i.e, nothing happens!
Any suggestions?

Arredondo.

Reply via email to