Closed
Description
Let's play "guess the result type":
julia> typeof(sum(rand(Bool, 4)))
Int64
julia> typeof(sum(rand(Int8, 4)))
Int32
julia> typeof(sum(rand(UInt8, 4)))
UInt32
julia> typeof(sum(rand(Int16, 4)))
Int32
julia> typeof(sum(rand(UInt16, 4)))
UInt32
julia> typeof(sum(rand(Int32, 4)))
Int64
julia> typeof(sum(rand(UInt32, 4)))
UInt64
julia> typeof(sum(rand(Int64, 4)))
Int64
julia> typeof(sum(rand(UInt64, 4)))
UInt64
julia> typeof(sum(rand(Int128, 4)))
Int128
julia> typeof(sum(rand(UInt128, 4)))
UInt128
This isn't entirely inconsistent, but it's not super simple either. It's not entirely obvious why 32 bits is some kind of special threshold on a 64-bit machine. I propose that we simply return the type that +
would have produced instead and if people want a different result type for their reduction, we should allow them to choose it by specifying a zero element of that type. This applies to prod
and other built-in reductions as well.