Skip to content

Commit

Permalink
mr_empty specialization for promote_sys_size
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb committed Aug 27, 2017
1 parent 2135990 commit 8592dba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ mr_empty(::typeof(abs2), op::typeof(max), T) = mr_empty(abs2, scalarmax, T)
mr_empty(f, op::typeof(&), T) = true
mr_empty(f, op::typeof(|), T) = false

# Allow mr_empty to “see through” promote_sys_size
let ComposedFunction = typename(typeof(identity identity)).wrapper
global mr_empty(f::ComposedFunction{typeof(promote_sys_size)}, op, T) =
promote_sys_size(mr_empty(f.g, op, T))
end

mr_empty_iter(f, op, itr, ::HasEltype) = mr_empty(f, op, eltype(itr))
mr_empty_iter(f, op::typeof(&), itr, ::EltypeUnknown) = true
mr_empty_iter(f, op::typeof(|), itr, ::EltypeUnknown) = false
Expand Down
8 changes: 8 additions & 0 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ end
@test sum_kbn([-0.0]) === -0.0
@test sum_kbn([-0.0,-0.0]) === -0.0

# check sum(abs, ...) for support of empty collections
@testset "sum(abs, [])" begin
@test @inferred(sum(abs, Float64[])) === 0.0
@test @inferred(sum(abs, Int[])) === 0
@test @inferred(sum(abs, Set{Int}())) === 0
@test_throws MethodError sum(abs, Any[])
end

# prod

@test prod(Int[]) === 1
Expand Down

0 comments on commit 8592dba

Please sign in to comment.