-
-
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
Define extrema
using mapreduce
; support init
#36265
Conversation
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 a few superficial comments.
extrema(x::Real) = (x, x) | ||
extrema(f, x::Real) = (y = f(x); (y, y)) |
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.
Aren't these still useful?
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.
mapreduce
has a specialization for Number
:
Line 419 in 5142abf
mapreduce(f, op, a::Number) = mapreduce_first(f, op, a) |
So, I think the compiler will generate the equivalent machine code.
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.
Cool. Maybe worth checking just in case?
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
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 great! Needing a special version in compiler isn't so bad, IMO.
Bump. Looks like this just needs to be rebased. |
bump, hitting |
Co-authored-by: Tim Holy <tim.holy@gmail.com>
@tkf The CI failures seem related to the contents of the PR. |
This passed the tests for SparseArrays locally but I noticed that it's not hitting the right method. Unfortunately, the build process ignores missing name on import and happy define
We need some fix in SparseArrays to make it reasonably correct and practically OK. (100% correctness is impossible with the current facility in Base because SparseArrays seem to want to assume |
#43604 took care of this |
Like #36188, but now for
extrema
.This patch also switches the implementation of
extrema
to usemapreduce
. It improves the performance even for simple arrays:The improvement is much more drastic when mixing it with iterator transforms because it hits the transducer path.
Of course, for arrays, we might want to use the same unrolling trick as in
minimum
/maximum
. But that's tracked by #31442 and can be done later. I think this PR would be a good generic fallback that is useful as a baseline for #31442.One thing not so great about this PR is that I had to copy the old
iterate
-onlyextrema
implementation to compiler.jl as apparently it is required for bootstrap. I think it might be nice to separate out a very minimal portion ofreduce.jl
so that it can beinclude
d from the compiler. But that's a bit too large refactoring to do in this PR.