I’m sorting the columns of each matrix in long vector of matrices (having the matrix columns in a canonical order makes it easy to identify approximately equal matrices). Here’s a minimal working example:
There are functions associated with each column of each matrix as well, and I need to permute these polynomials in the same way when the columns are sorted. But sortperm does not accept the same arguments that sort does. It seems the dims keyword is unsupported.
Am I missing something? Anyone have ideas for a simple workaround?
I would assume (naively?) that sort and sortperm are the same function under the hood and just return different parts of the sort results (sorted items vs. order of sort). EDIT: for the first time ever, I looked at the source code in Base. It seems that sortperm and sort are separate functions…still, I really need a work around for this…
julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin19.5.0)
CPU: Apple M1 Pro
If you are wondering why sortperm does not have a dims parameter, the answer is that Julia will have a dims parameter in Julia version 1.9 since @pjentsch0 just implemented it:
Something I didn’t understand at first—a fundamental misunderstanding—sort(t,dims=2) does not preserve the columns necessarily. It sorts the columns of each row separately. What I really wanted was to sort the entire columns (preserving their contents).
Super helpful! Thanks. I wasn’t aware of sortslices. That makes my sorting syntax simpler (though I still need the sortperm too but @mkitti shared above that a perm version is coming).