-
Notifications
You must be signed in to change notification settings - Fork 69
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
sort! rules #1000
sort! rules #1000
Conversation
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #1000 +/- ##
==========================================
- Coverage 76.07% 75.79% -0.28%
==========================================
Files 35 35
Lines 9926 9962 +36
==========================================
Hits 7551 7551
- Misses 2375 2411 +36 ☔ View full report in Codecov by Sentry. |
kwargs... | ||
) | ||
inds = sortperm(xs.val; kwargs...) | ||
xs.val .= xs.val[inds] |
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 sortperm itself just makes a list of 1:N, then sorts that in place using the original data as the order: https://github.com/JuliaLang/julia/blob/750df9fb5bede16f321f5d5405943d12aec7b83e/base/sort.jl#L1756
Could we change this to first sort the derivative array in place using the primal array as the order, then do the actual sort on the primal? That way we don't have that temporary
Added tests and changed the augmented primal. I will address the other points later. |
Added a rule for batched mode. I had a look at sorting without allocating the index array but couldn't get it to work. The |
882b2c0
to
7de6433
Compare
Is this ready for merge? Test failures look unrelated. |
@jgreener64 will this rule also cover out-of-place |
In general
|
This is what I'm getting on Enzyme Master right now:
I was hoping this PR would fix this issue, but if not maybe I can help add something new to the rule to cover the |
Does that error occur with this PR as well? |
It seems like it. I just swapped Enzyme#master with your |
It looks like a specific rule needs to be written for this path: https://github.com/JuliaLang/julia/blob/750df9fb5bede16f321f5d5405943d12aec7b83e/base/sort.jl#L1817. Though as a short-term fix you can copy the array and call |
@jgreener64 I will do that (I don't care about the unsorted array). I thought the rules would apply to the |
The rules in this PR will always apply to |
I made Enzyme rules for
sort!
as suggested in #880. These are my first Enzyme rules so will need some checking.I put them in
src/internal_rules.jl
for now, let me know if they should go somewhere else. I have tests too which I can add later.