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

Revert "add more methods and tests for reductions over empty arrays" #52003

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,6 @@ reduce_empty(::typeof(*), ::Type{<:AbstractChar}) = ""
reduce_empty(::typeof(&), ::Type{Bool}) = true
reduce_empty(::typeof(|), ::Type{Bool}) = false

reduce_empty(::typeof(max), T) = typemin(T)
reduce_empty(::typeof(min), T) = typemax(T)

reduce_empty(::typeof(add_sum), ::Type{Union{}}) = _empty_reduce_error(add_sum, Union{})
reduce_empty(::typeof(add_sum), ::Type{T}) where {T} = reduce_empty(+, T)
reduce_empty(::typeof(add_sum), ::Type{T}) where {T<:SmallSigned} = zero(Int)
Expand All @@ -376,10 +373,8 @@ mapreduce_empty(::typeof(identity), op, T) = reduce_empty(op, T)
mapreduce_empty(::typeof(abs), op, T) = abs(reduce_empty(op, T))
mapreduce_empty(::typeof(abs2), op, T) = abs2(reduce_empty(op, T))

mapreduce_empty(::typeof(abs), ::typeof(max), T) = abs(zero(T))
mapreduce_empty(::typeof(abs), ::typeof(min), T) = typemax(abs(zero(T)))
mapreduce_empty(::typeof(abs2), ::typeof(max), T) = abs2(zero(T))
mapreduce_empty(::typeof(abs2), ::typeof(min), T) = typemax(abs2(zero(T)))
mapreduce_empty(f::typeof(abs), ::typeof(max), T) = abs(zero(T))
mapreduce_empty(f::typeof(abs2), ::typeof(max), T) = abs2(zero(T))

# For backward compatibility:
mapreduce_empty_iter(f, op, itr, ItrEltype) =
Expand Down
19 changes: 0 additions & 19 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ end
@test mapreduce(abs2, *, Float64[]) === 1.0
@test mapreduce(abs2, max, Float64[]) === 0.0
@test mapreduce(abs, max, Float64[]) === 0.0
@test mapreduce(abs2, min, Float64[]) === Inf
@test mapreduce(abs, min, Float64[]) === Inf
@test_throws ArgumentError mapreduce(abs2, &, Float64[])
@test_throws ArgumentError mapreduce(abs2, |, Float64[])
@test_throws ["reducing over an empty collection is not allowed",
"consider supplying `init`"] mapreduce(abs2, &, Float64[])
@test_throws str -> !occursin("Closest candidates are", str) mapreduce(abs2, &, Float64[])
Expand Down Expand Up @@ -264,21 +260,6 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr)
@test minimum(sin, []; init=1) == 1
@test extrema(sin, []; init=(1, -1)) == (1, -1)

@test maximum(Float64[]) === -Inf
@test minimum(Float64[]) === +Inf

@test maximum(Float32[]) === -Inf32
@test minimum(Float32[]) === +Inf32

@test maximum(abs, Int[]) === 0
@test_throws ArgumentError minimum(abs, Int[])

@test maximum(abs, Float64[]) === 0.0
@test minimum(abs, Float64[]) === +Inf

@test maximum(abs, Float32[]) === 0.0f0
@test minimum(abs, Float32[]) === +Inf32

@test maximum(5) == 5
@test minimum(5) == 5
@test extrema(5) == (5, 5)
Expand Down
Loading