-
-
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
RFC: Continuation of #20607, revision of sum, prod, and reduce #22825
Conversation
|
I don't see any need for this. Nor is it inconsistent, in the sense of type-stability. Simpler to just keep |
base/reduce.jl
Outdated
mr_empty(::typeof(identity), op::typeof(+), T) = zero(T)::T | ||
mr_empty(::typeof(abs), op::typeof(+), T) = abs(zero(T)::T) | ||
mr_empty(::typeof(abs2), op::typeof(+), T) = abs2(zero(T)::T) | ||
mr_empty(::typeof(identity), op::typeof(*), T) = one(T)::T |
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.
This is incorrect, since one(T)
may not be of type T
for a dimensionful type. Just get rid of the typeassert here.
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.
Will fix, thanks. Actually it would be nice to see if any of these type annotations are really still necessary, since MethodError
now infers as Union{}
instead of Any
. I will remove them all and we can see if any benchmarks regress.
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.
All these annotations are gone now.
base/reducedim.jl
Outdated
@@ -574,14 +577,22 @@ any!(r, A) | |||
for (fname, op) in [(:sum, :+), (:prod, :*), | |||
(:maximum, :scalarmax), (:minimum, :scalarmin), | |||
(:all, :&), (:any, :|)] | |||
function compose_pss(x) |
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.
only used once, abbreviating the name isn't that helpful
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.
makes sense, wrote it in full
@TotalVerb, I agree it's probably not worth a special case for |
This got stalled out, but it would be great to make some progress here. Anything we can do to help? |
Going to pick this back up now and work through the remaining TODO items. Mostly, it should be just testing and confirming the consistency of the slice-based reductions. |
Another change to add to the unrelated changes list: I restricted the |
The code change is done. I still need to write up a NEWS entry and some doctests. In the meantime, could someone run nanosoldier on the latest revision? |
@@ -228,38 +228,41 @@ pairwise_blocksize(::typeof(abs2), ::typeof(+)) = 4096 | |||
|
|||
# handling empty arrays | |||
_empty_reduce_error() = throw(ArgumentError("reducing over an empty collection is not allowed")) | |||
mr_empty(f, op, T) = _empty_reduce_error() |
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.
RIP Mr. Empty :(
@nanosoldier |
If this is the error, it looks unrelated:
Please excuse me if this is unrelated, as I have not read nanosoldier logs before. |
Unrelated to this PR. Looks like BaseBenchmarks was broken by #22907. |
Could someone please run nanosoldier again? |
@nanosoldier |
1 similar comment
@nanosoldier |
This failure looks related to the mapreduce changes. I'll investigate. |
JuliaLang/julia#22825 will change the behavior of `mapreduce` to never promote, so to retain the previous behavior it must be changed to `sum`.
Could someone please review and merge the associated BaseBenchmarks PR, |
JuliaLang/julia#22825 will change the behavior of `mapreduce` to never promote, so to retain the previous behavior it must be changed to `sum`.
I'm retuning the Nanosoldier benchmarks now that your change has been merged and I'll start a new Nanosoldier run here once that's done. |
base/reduce.jl
Outdated
# reduced over to an appropriate size. | ||
promote_sys_size(x) = x | ||
promote_sys_size(x::SmallSigned) = Int(x) | ||
promote_sys_size(x::SmallUnsigned) = UInt(x) |
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.
This should also include Bool
. I believe that will fix the problem in BaseBenchmarks.
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.
Thanks, I'll fix and test this.
Bump. This is so close! |
Ok, here's a revised approach that I hope should handle |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
Once this passes I'll squash all but the first commit and merge this. |
Squashed version is on master; github might not pick up that this has been merged. |
Thanks! |
Thanks so much @TotalVerb for persisting with this change! |
Use Compat.Test instead of Base.Test, adapt to JuliaLang/julia#22825
Since the demise of `r_promote` in #22825, there is now a type-instability in `mapreduce` if the operator does not give an element of the same type as the input. This arose during my implementation of Kahan summation using a reduction operator, see: JuliaMath/KahanSummation.jl#7 This adds a `mapreduce_single` function which defines what the result should be in these cases.
Since the demise of `r_promote` in #22825, there is now a type-instability in `mapreduce` if the operator does not give an element of the same type as the input. This arose during my implementation of Kahan summation using a reduction operator, see: JuliaMath/KahanSummation.jl#7 This adds a `mapreduce_single` function which defines what the result should be in these cases.
Since the demise of `r_promote` in #22825, there is now a type-instability in `mapreduce` if the operator does not give an element of the same type as the input. This arose during my implementation of Kahan summation using a reduction operator, see: JuliaMath/KahanSummation.jl#7 This adds a `mapreduce_single` function which defines what the result should be in these cases.
Since the demise of `r_promote` in #22825, there is now a type-instability in `mapreduce` if the operator does not give an element of the same type as the input. This arose during my implementation of Kahan summation using a reduction operator, see: JuliaMath/KahanSummation.jl#7 This adds a `mapreduce_single` function which defines what the result should be in these cases.
(Continuation of #20607 by @felixrehren. The intermediate commit should be preserved, but we should run the tests on it.)
This is not done yet. I'm creating this PR to solicit feedback about this approach.
Remaining things to do:
mr_empty
should grow a specialization for compositions ofpromote_sys_size
and something else (avoids regressions in empty case ofsum(abs, ...)
). This empty summation is apparently untested so tests will be needed to.sum
andprod
to ensure things are consistent (and test)Certain design decisions that are in addition to the consensus discussed in #20560, #20607, and #21523, (I'm fairly convinced that they're the right thing to do, but please leave feedback if you disagree):
sum(Int8(1))
is nowInt(1)
instead ofInt8(1)
. The previous behavior was inconsistent with other iterators. While it's true that this case cannot cause any problems, it's preferable in my opinion to always return a consistent result.r_promote
and related things are entirely gone. It's too much effort to properly deprecate them. It's not particularly useful anyway: promotion behavior can be passed in by the caller throughv0
orf
.sum
of integer ranges has always had this behavior by accident... by callinglength()
and using the result of that in the calculation. So I've left them alone.mr_empty
is defined to look more sane.Certain things NOT addressed in this PR:
sum
,prod
ofTuple
s ignores the promotion behavior of arrays and other iterables. TODO items have been added.