That is exactly the case with the matlab behavior, which causes an obscure bug the one time your data has one row. Maybe the dimension argument should be required for matrices.
--
In the interest of readability, could we allow something like one of these to work for matrices?
sort(mat, "row")
sort(mat, :row)
sort(mat, ROW)
The 1/2/x indexes are not easy to read quickly.
Harlan
--
--
--
--
--
--
--
--
--
--
--
--
--
--
Giving some rational as to why defining these constants is good or bad is a lot more useful than saying "yuck" and "I kind of agree". I think we should also keep in mind that how this is handled really matters for more than just sort since there are numerous other general functions that already exist and which either have row/col versions already or take a dimension argument (e.g. size, stride, vec (rowvec, colvec), cat (vcat, hcat). An attempt to keep the API small and uniform would make code more maintainable and require users to memorize less. I see defining two constants as being better than creating two additional functions for every function that takes a dimension argument.
Just my 2 cents:
sort(a,1) and sort(a,2) with a compulsory second argument are fine.
--
Giving some rational as to why defining these constants is good or bad
is a lot more useful than saying "yuck" and "I kind of agree".
--
Yes, there’s a functional way to do this. But how about parametrically? I’d prefer a single sort() call rather than one or more lines of code.
But isn’t sort() a special case? Is it worthy of having special matrix dissection parameter syntax? Should sort() be special? Is the split-apply-combine (SAC) strategy actually best overall? Should sort be made simple and dumb, with only data parameters, and no special parameters? Not even for sort order? (Which can easily be done as part of the reassembly procedure.)
I dunno. Generic vs. convenient. SAC is a knife that can cut anything, but it takes more code. By comparison, sort() is short and sweet, but fixing it to be as clear and unambiguous as SAC seems quite difficult.
It seems sort() will always have a limit on its wisdom: What if I want to sort matrix tiles by their determinant and reassemble the matrix accordingly? So we’ll need a simple sort() anyway.
Why not make that the only sort()?
The only reason I can think of to have a “smart” sort() would be to support in-place sorting, to obtain either or both of speed and space benefits. But if LLVM optimizes across function calls, that explicit optimization may be a red herring, and may not be worth the time needed to implement it. Or the time needed to fix the parameters to sort().
-BobC
--
Hi all
I find this puzzling:
julia> sort([11 3 4 2])
11 3 4 2-
julia> sort([11, 3, 4, 2])
2
3
4
11
Same issue with "sortr!".
I am working with the latest Windows build.
Thanks for any comment.