-
-
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
support sorting tuples #56425
support sorting tuples #56425
Conversation
6b10e70
to
d573756
Compare
6f49f4c
to
8d3fe04
Compare
The complexity of this code makes me kind of uncomfortable, especially the typed natural number stuff. How about copy pasting the SortedNetwork implementations up to length 16 and then allocate above that? |
FTR the type domain numbers are applicable to other places, too, I'll be putting up more PRs relying on that code. Also, it's not like there's any complex logic there, it's mostly just unconvential, I think. That reminds me though, I didn't add any tests for type domain numbers here.
|
8d3fe04
to
8e2b350
Compare
it kind of feels like the sorting stuff here is just a facade to sneak in the (previously rejected) type domain number stuff |
Are you trying to be inflammatory or something? Do you really have to do that here, in the PR discussion? |
given that you closed #55571 with the comment
I guess the adjective I would use is "observant" |
I'll bite, what's your point? |
I agree this seems like a lot of code, compared to these 20 lines which handle NTuples in #54494 . What exactly is gained, in what use cases? It seems you claim better inference, can you show examples where this matters?
I assume this refers to https://github.com/JeffreySarnoff/SortingNetworks.jl , which writes out the steps for each length. That also seems attractively simple. |
The benefit is that this supports
As I said above, that can't be the default sort because it's not stable. |
c75f73d
to
06a822d
Compare
It would be trivial (though IMO a bad idea) to make #54494 support non-homogenous tuples. |
Of course, but not with good inference. |
06a822d
to
eff3421
Compare
Uses merge sort, as an obvious choice for a stable sort of tuples. A recursive data structure of singleton type, representing Peano natural numbers, is used to help with splitting a tuple into two halves in the merge sort. An alternative design would use a reference tuple, but this would require relying on `tail`, which seems more harsh on the compiler. With the recursive datastructure the predecessor operation and the successor operation are both trivial. Allows inference to preserve inferred element type even when tuple length is not known. Follow-up PRs may add further improvements, such as the ability to select an unstable sorting algorithm. The added file, typedomainnumbers.jl is not specific to sorting, thus making it a separate file. Xref JuliaLang#55571. Fixes JuliaLang#54489
eff3421
to
59a5c2d
Compare
This replaces `Fix` (xref JuliaLang#54653) with `fix`. The usage is similar: use `fix(i)(f, x)` instead of `Fix{i}(f, x)`. Benefits: * Improved type safety: creating an invalid type such as `Fix{:some_symbol}` or `Fix{-7}` is not possible. * The design should be friendlier to future extensions. E.g., suppose that publicly-facing functionality for fixing a keyword (instead of positional) argument was desired, it could be achieved by adding a new method to `fix` taking a `Symbol`, instead of adding new public names. Lots of changes are shared with PR JuliaLang#56425, if one of them gets merged the other will be greatly simplified.
This replaces `Fix` (xref JuliaLang#54653) with `fix`. The usage is similar: use `fix(i)(f, x)` instead of `Fix{i}(f, x)`. Benefits: * Improved type safety: creating an invalid type such as `Fix{:some_symbol}` or `Fix{-7}` is not possible. * The design should be friendlier to future extensions. E.g., suppose that publicly-facing functionality for fixing a keyword (instead of positional) argument was desired, it could be achieved by adding a new method to `fix` taking a `Symbol`, instead of adding new public names. Lots of changes are shared with PR JuliaLang#56425, if one of them gets merged the other will be greatly simplified.
This replaces `Fix` (xref JuliaLang#54653) with `fix`. The usage is similar: use `fix(i)(f, x)` instead of `Fix{i}(f, x)`. Benefits: * Improved type safety: creating an invalid type such as `Fix{:some_symbol}` or `Fix{-7}` is not possible. * The design should be friendlier to future extensions. E.g., suppose that publicly-facing functionality for fixing a keyword (instead of positional) argument was desired, it could be achieved by adding a new method to `fix` taking a `Symbol`, instead of adding new public names. Lots of changes are shared with PR JuliaLang#56425, if one of them gets merged the other will be greatly simplified.
This replaces `Fix` (xref JuliaLang#54653) with `fix`. The usage is similar: use `fix(i)(f, x)` instead of `Fix{i}(f, x)`. Benefits: * Improved type safety: creating an invalid type such as `Fix{:some_symbol}` or `Fix{-7}` is not possible. * The design should be friendlier to future extensions. E.g., suppose that publicly-facing functionality for fixing a keyword (instead of positional) argument was desired, it could be achieved by adding a new method to `fix` taking a `Symbol`, instead of adding new public names. Lots of changes are shared with PR JuliaLang#56425, if one of them gets merged the other will be greatly simplified.
This replaces `Fix` (xref JuliaLang#54653) with `fix`. The usage is similar: use `fix(i)(f, x)` instead of `Fix{i}(f, x)`. Benefits: * Improved type safety: creating an invalid type such as `Fix{:some_symbol}` or `Fix{-7}` is not possible. * The design should be friendlier to future extensions. E.g., suppose that publicly-facing functionality for fixing a keyword (instead of positional) argument was desired, it could be achieved by adding a new method to `fix` taking a `Symbol`, instead of adding new public names. Lots of changes are shared with PR JuliaLang#56425, if one of them gets merged the other will be greatly simplified.
This replaces `Fix` (xref JuliaLang#54653) with `fix`. The usage is similar: use `fix(i)(f, x)` instead of `Fix{i}(f, x)`. Benefits: * Improved type safety: creating an invalid type such as `Fix{:some_symbol}` or `Fix{-7}` is not possible. * The design should be friendlier to future extensions. E.g., suppose that publicly-facing functionality for fixing a keyword (instead of positional) argument was desired, it could be achieved by adding a new method to `fix` taking a `Symbol`, instead of adding new public names. Lots of changes are shared with PR JuliaLang#56425, if one of them gets merged the other will be greatly simplified.
Do we even want to be able to sort tuples? It makes me a little uncomfortable that it's wildly type unstable to sort e.g. |
Indeed, I think sorting of non-homogenous tuples has very little practical use. |
I would support bringing back the PR that made it easy to sort arbitrary iterables, since in this example it would give the ability to be type stable (eltype of that Tuple is type stable), so the resulting sorted object would be both fast and reliable |
That feature has already been discussed, tuple sorting can clearly be made withiut the requirement that arbitrary iterators can be sorted. |
See also #31818, which points to the static sorting algorithm in TupleTools.jl |
Uses merge sort, as an obvious choice for a stable sort of tuples.
A recursive data structure of singleton type, representing Peano natural numbers, is used to help with splitting a tuple into two halves in the merge sort. An alternative design would use a reference tuple, but this would require relying on
tail
more, which seems more harsh on the compiler. With the recursive datastructure the predecessor operation and the successor operation are both trivial.Allows inference to preserve inferred element type even when tuple length is not known.
Follow-up PRs may add further improvements, such as the ability to select an unstable sorting algorithm.
The added file, typedomainnumbers.jl is not specific to sorting, thus making it a separate file. Xref #55571.
Fixes #54489