Skip to content

Commit 8592dba

Browse files
committed
mr_empty specialization for promote_sys_size
1 parent 2135990 commit 8592dba

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

base/reduce.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ mr_empty(::typeof(abs2), op::typeof(max), T) = mr_empty(abs2, scalarmax, T)
242242
mr_empty(f, op::typeof(&), T) = true
243243
mr_empty(f, op::typeof(|), T) = false
244244

245+
# Allow mr_empty to “see through” promote_sys_size
246+
let ComposedFunction = typename(typeof(identity identity)).wrapper
247+
global mr_empty(f::ComposedFunction{typeof(promote_sys_size)}, op, T) =
248+
promote_sys_size(mr_empty(f.g, op, T))
249+
end
250+
245251
mr_empty_iter(f, op, itr, ::HasEltype) = mr_empty(f, op, eltype(itr))
246252
mr_empty_iter(f, op::typeof(&), itr, ::EltypeUnknown) = true
247253
mr_empty_iter(f, op::typeof(|), itr, ::EltypeUnknown) = false

test/reduce.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ end
144144
@test sum_kbn([-0.0]) === -0.0
145145
@test sum_kbn([-0.0,-0.0]) === -0.0
146146

147+
# check sum(abs, ...) for support of empty collections
148+
@testset "sum(abs, [])" begin
149+
@test @inferred(sum(abs, Float64[])) === 0.0
150+
@test @inferred(sum(abs, Int[])) === 0
151+
@test @inferred(sum(abs, Set{Int}())) === 0
152+
@test_throws MethodError sum(abs, Any[])
153+
end
154+
147155
# prod
148156

149157
@test prod(Int[]) === 1

0 commit comments

Comments
 (0)