-
Notifications
You must be signed in to change notification settings - Fork 222
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
Allow sorting of tuples of numbers #1196
Conversation
Using What about: julia> f(i, a) = i ? @inbounds(a[]) : Ref{Int}()[]
f (generic function with 2 methods)
julia> f(false, [1])
140526431453856
julia> f(true, [1])
1
julia> @code_llvm f(true, [1])
; @ REPL[11]:1 within `f`
define i64 @julia_f_235(i8 zeroext %0, {}* nonnull align 16 dereferenceable(40) %1) #0 {
top:
%2 = and i8 %0, 1
%.not = icmp eq i8 %2, 0
br i1 %.not, label %L28, label %L23
L23: ; preds = %top
; ┌ @ abstractarray.jl:1218 within `getindex`
; │┌ @ abstractarray.jl:1245 within `_getindex`
; ││┌ @ array.jl:839 within `getindex`
%3 = bitcast {}* %1 to i64**
%4 = load i64*, i64** %3, align 8
%5 = load i64, i64* %4, align 8
; └└└
ret i64 %5
L28: ; preds = %top
ret i64 undef
} Bit ugly, but does result in the expected |
Ok, I did not look closely enough to figure out what the zero was or wasn't being used for. If unused, then a generic |
sortperm
Rebased. Removed the |
Turns out we can just do the naive thing (on 1.7, at least): define a variable conditionally and use it under the same condition so that LLVM can optimize the |
Thanks for picking this up! |
520ca81
to
a264126
Compare
Codecov Report
@@ Coverage Diff @@
## master #1196 +/- ##
=======================================
Coverage 78.94% 78.95%
=======================================
Files 119 119
Lines 8650 8649 -1
=======================================
Hits 6829 6829
+ Misses 1821 1820 -1
Continue to review full report at Codecov.
|
7395aba
to
6504ad4
Compare
12fb49e
to
431d318
Compare
This allows
sort
to work on arrays of tuples, motivated bypartialsortperm(x; dims)
-like things in FluxML/NNlib.jl#353It also adds the simplest implementation of
sortperm
using that. Not sure if this is too crude for the package to want to keep? Needs tests, if it is wanted.