-
-
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
Faster multi-arg mapreduce #39053
Faster multi-arg mapreduce #39053
Conversation
Partially addresses JuliaLang#38558
Also does anyone have a good idea for how to test for |
Add is as a benchmark, so nanosoldier will track it? |
I think in this case just adding an explicit |
Co-authored-by: Fredrik Bagge Carlson <baggepinnen@gmail.com>
I'm reverting to the first version of this that I made. It doesn't handle keword arguments, but I think it's probably good to merge as is since it's a strict improvement compared to master. |
Bump? |
good call. I'd forgotten about this PR. |
base/reducedim.jl
Outdated
mapreduce(f, op, A::AbstractArrayOrBroadcasted...; kw...) = | ||
reduce(op, map(f, A...); kw...) | ||
function mapreduce(f, op, A::AbstractArrayOrBroadcasted...; kw...) | ||
isempty(kw) && return mapreduce(A->f(A...), op, zip(A...)) |
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.
Should this allow mapreduce(+, +, -3:3, -3:3, init=1)
to take the zip
path?
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 it should. Is there an easy way to do that?
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 think the only two legal ones are dims, init
, but am not sure if init = _InitialValue()
is understood by all the relevant methods. If not, then this would work:
function mapreduce(f, op, A::AbstractArrayOrBroadcasted...; dims=:, kw...)
dims==(:) && return mapreduce(A->f(A...), op, zip(A...); kw...)
...
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.
Last commit needs ; kw...)
-> ; dims=:, kw...)
, I think.
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
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.
LGTM
As a note, I think in PRs like this it is great if the first post contains a benchmark that shows the before/after performance and can easily be run by someone looking at the PR. |
The failure here is real. Locally, replacing mapreduce_empty(f::typeof(splat(+)).name.wrapper, op, ::Type{T}) where {T<:Tuple} =
reduce_empty(op, Core.Compiler.return_type(op, T)) worked as a quick fix. I think for a proper solution, we should make |
Partially addresses #38558
If there's an easy way to make this handle the kwarkgs, let me know.