Skip to content
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 reduce promotion: default to system default #20607

Closed
wants to merge 5 commits into from

Conversation

felixrehren
Copy link
Contributor

@felixrehren felixrehren commented Feb 14, 2017

Before this PR, the result type of a map_reduce is erratic on integers.

After this PR, sum(xs) for eltype(xs) = IntX returns IntY, where Y the bit-size of the system, when X <= Y. I.e. on a 32-bit system, sum(Int8[])::Int32 and on a 64-bit system sum(Int8[])::Int64, etc. Types wider than the system size are untouched, as before. The same changes hold for unsigned integers and prod.

This paves the way for sum(T, xs)::T, or sum(zero(T), xs)::T to be type-stable, see #20561

@ararslan ararslan added maths Mathematical functions types and dispatch Types, subtyping and method dispatch labels Feb 14, 2017
@ararslan ararslan added the needs docs Documentation for this change is required label Feb 14, 2017
@tkelman tkelman added the needs news A NEWS entry is required for this change label Feb 14, 2017
base/reduce.jl Outdated
@@ -13,20 +13,23 @@ const SmallUnsigned = Union{UInt8,UInt16,UInt32}
end

const CommonReduceResult = Union{UInt64,UInt128,Int64,Int128,Float32,Float64}
const WidenReduceResult = Union{SmallSigned, SmallUnsigned, Float16}
const SmallReduceResult = Union{SmallSigned, SmallUnsigned, Float16}
Copy link
Member

@stevengj stevengj Feb 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SmallReduceResult seems like a misnomer here. The result is Int, which is not small.

Float16 should still be widened to Float32, presumably, which is not a "system size". Or I guess the widening there could be eliminated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Float16 is a "real computational type" #5942 (comment) it shouldn't be widened, right?

@KristofferC
Copy link
Member

  • Run doctests

@stevengj
Copy link
Member

Bump.

r_promote_type{T<:WidenReduceResult}(op, ::Type{T}) = widen(T)
r_promote_type{T<:WidenReduceResult}(::typeof(+), ::Type{T}) = widen(T)
r_promote_type{T<:WidenReduceResult}(::typeof(*), ::Type{T}) = widen(T)
r_promote_type{T<:WidenReduceResult}(op, ::Type{T}) = promote_sys_size(T)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in #21523, widening is not necessarily appropriate for an arbitrary user-defined operator. Maybe the default should be T.

@felixrehren
Copy link
Contributor Author

Will try and do this in June (changed jobs recently, hence different availability to before). If I understand the consensus correctly, it's to remove any promotion from reduce, but keep it for sum. Confirmation (e.g. 👍/👎) appreciated on this.

With apologies, the thing that held this up in the first place is that I couldn't figure out how to run doctests. @KristofferC

@TotalVerb
Copy link
Contributor

@felixrehren, are you still able to work on this?

cc @StefanKarpinski

@KristofferC
Copy link
Member

Don't let the doctests hold you up then, they can be fixed later.

@TotalVerb
Copy link
Contributor

Hey @felixrehren, I've continued this PR in #22825. Thanks for your work on it!

@KristofferC KristofferC removed needs news A NEWS entry is required for this change needs docs Documentation for this change is required labels Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants