Skip to content

Commit 2a84214

Browse files
authored
Revert "add more methods and tests for reductions over empty arrays" (#52003)
Reverts #29919 CI was older than I realized on this, so this needed some updates to tests and docstrings
1 parent 9bc6994 commit 2a84214

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
lines changed

base/reduce.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,6 @@ reduce_empty(::typeof(*), ::Type{<:AbstractChar}) = ""
348348
reduce_empty(::typeof(&), ::Type{Bool}) = true
349349
reduce_empty(::typeof(|), ::Type{Bool}) = false
350350

351-
reduce_empty(::typeof(max), T) = typemin(T)
352-
reduce_empty(::typeof(min), T) = typemax(T)
353-
354351
reduce_empty(::typeof(add_sum), ::Type{Union{}}) = _empty_reduce_error(add_sum, Union{})
355352
reduce_empty(::typeof(add_sum), ::Type{T}) where {T} = reduce_empty(+, T)
356353
reduce_empty(::typeof(add_sum), ::Type{T}) where {T<:SmallSigned} = zero(Int)
@@ -376,10 +373,8 @@ mapreduce_empty(::typeof(identity), op, T) = reduce_empty(op, T)
376373
mapreduce_empty(::typeof(abs), op, T) = abs(reduce_empty(op, T))
377374
mapreduce_empty(::typeof(abs2), op, T) = abs2(reduce_empty(op, T))
378375

379-
mapreduce_empty(::typeof(abs), ::typeof(max), T) = abs(zero(T))
380-
mapreduce_empty(::typeof(abs), ::typeof(min), T) = typemax(abs(zero(T)))
381-
mapreduce_empty(::typeof(abs2), ::typeof(max), T) = abs2(zero(T))
382-
mapreduce_empty(::typeof(abs2), ::typeof(min), T) = typemax(abs2(zero(T)))
376+
mapreduce_empty(f::typeof(abs), ::typeof(max), T) = abs(zero(T))
377+
mapreduce_empty(f::typeof(abs2), ::typeof(max), T) = abs2(zero(T))
383378

384379
# For backward compatibility:
385380
mapreduce_empty_iter(f, op, itr, ItrEltype) =

test/reduce.jl

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ end
9191
@test mapreduce(abs2, *, Float64[]) === 1.0
9292
@test mapreduce(abs2, max, Float64[]) === 0.0
9393
@test mapreduce(abs, max, Float64[]) === 0.0
94-
@test mapreduce(abs2, min, Float64[]) === Inf
95-
@test mapreduce(abs, min, Float64[]) === Inf
96-
@test_throws ArgumentError mapreduce(abs2, &, Float64[])
97-
@test_throws ArgumentError mapreduce(abs2, |, Float64[])
9894
@test_throws ["reducing over an empty collection is not allowed",
9995
"consider supplying `init`"] mapreduce(abs2, &, Float64[])
10096
@test_throws str -> !occursin("Closest candidates are", str) mapreduce(abs2, &, Float64[])
@@ -264,21 +260,6 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr)
264260
@test minimum(sin, []; init=1) == 1
265261
@test extrema(sin, []; init=(1, -1)) == (1, -1)
266262

267-
@test maximum(Float64[]) === -Inf
268-
@test minimum(Float64[]) === +Inf
269-
270-
@test maximum(Float32[]) === -Inf32
271-
@test minimum(Float32[]) === +Inf32
272-
273-
@test maximum(abs, Int[]) === 0
274-
@test_throws ArgumentError minimum(abs, Int[])
275-
276-
@test maximum(abs, Float64[]) === 0.0
277-
@test minimum(abs, Float64[]) === +Inf
278-
279-
@test maximum(abs, Float32[]) === 0.0f0
280-
@test minimum(abs, Float32[]) === +Inf32
281-
282263
@test maximum(5) == 5
283264
@test minimum(5) == 5
284265
@test extrema(5) == (5, 5)

0 commit comments

Comments
 (0)