-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement sortslices, deprecate sortrows/sortcols #28332
Conversation
base/sort.jl
Outdated
dims == :cols ? 2 : | ||
error("Only :rows or :cols are allowed as symbolic dimensions") | ||
end | ||
_sortslices(A, Val{dims}(); kws...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this file is include
d in the system image before Val
is defined, which is causing the CI errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not entirely convinced that it should live here. I think it might make more sense to go with multidimensional, esp since we now use this file from the compiler. This code has very little to do with sorting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 That does seem like a more appropriate place for it, IMO.
base/sort.jl
Outdated
Note that the default comparison function on one dimensional slices sorts | ||
lexicographically. | ||
|
||
For convenience, `dims=:rows` and `dims=:cols` are supported as alternative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do this for anything else, why is this function special in that regard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough, it was requested for convenience, but I think the behavior is consistent enough that we can do without.
base/multidimensional.jl
Outdated
Note that the default comparison function on one dimensional slices sorts | ||
lexicographically. | ||
|
||
For convenience, `dims=:rows` and `dims=:cols` are supported as alternative |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get rid of these awkward special cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; this makes supporting named dimensions a breaking change, so we shouldn't have this now.
One thing to note for those looking at this, is that in some ways this is incompatible with
I.e. the dims keyword has opposite meaning here. |
There was some discussion of the meaning of the dims argument to |
base/multidimensional.jl
Outdated
# Higher dimensions | ||
|
||
`sortslices` extends naturally to higher dimensions. E.g., if `A` is a | ||
a 2x2x2 array, `sortslices(A, dims=2)` will slices along the 3rd dimension, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will slices
=> will slice
Did you mean dims=3
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
base/multidimensional.jl
Outdated
|
||
If `dims` is a tuple, the order of the dimensions in `dims` is | ||
relevant and specifies the linear order of the slices. E.g., if `A` is three | ||
dimensional and `dims` is `(1,2)`, we will take slices in the dimension three, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra the
base/multidimensional.jl
Outdated
sortslices(A; dims, alg::Algorithm=DEFAULT_UNSTABLE, lt=isless, by=identity, rev::Bool=false, order::Ordering=Forward) | ||
|
||
Sort slices of an array `A`. The keyword argument `dims` must be either | ||
an integer or a tuple of integers specifies along which dimension to take the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"take the slices" sounds like it's where the colon goes to me. I think a slightly better wording might be:
dims
… specifies the dimension(s) over which the slices are sorted.
base/multidimensional.jl
Outdated
# Higher dimensions | ||
|
||
`sortslices` extends naturally to higher dimensions. E.g., if `A` is a | ||
a 2x2x2 array, `sortslices(A, dims=3)` will slice along the 3rd dimension, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/slice along/sort slices within/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just minor doc comments
With regards to the meaning of I also think that this is aligned with the meaning of |
As discussed on triage, `sortslices` is the higher dimensional extension of `sortrows`/`sortcols`. The dimensions being specified are the dimensions (and for higher dimensions the order of the dimensions) to slice along. See the help text for an example of the higher dimensional behavior. Deprecate sortrows/sortcols in favor of sortslices.
As discussed on triage, `sortslices` is the higher dimensional extension of `sortrows`/`sortcols`. The dimensions being specified are the dimensions (and for higher dimensions the order of the dimensions) to slice along. See the help text for an example of the higher dimensional behavior. Deprecate sortrows/sortcols in favor of sortslices.
As discussed on triage,
sortslices
is the higher dimensional extensionof
sortrows
/sortcols
. The dimensions being specified are the dimensions(and for higher dimensions the order of the dimensions) to slice along. See
the help text for an example of the higher dimensional behavior. Deprecate
sortrows/sortcols in favor of sortslices.