Skip to content

Commit 065a28f

Browse files
N5N3tkf
andcommitted
Remove _extrema_rf optimization for AbstractFloat (follow advise)
Add TODO apply suggestions Update NEWS.md Co-Authored-By: Takafumi Arakaki <takafumi.a@gmail.com> Co-Authored-By: Takafumi Arakaki <29282+tkf@users.noreply.github.com>
1 parent d9fce2a commit 065a28f

File tree

4 files changed

+2
-21
lines changed

4 files changed

+2
-21
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Standard library changes
9696
arithmetic to error if the result may be wrapping. Or use a package such as SaferIntegers.jl when
9797
constructing the range. ([#40382])
9898
* TCP socket objects now expose `closewrite` functionality and support half-open mode usage ([#40783]).
99-
* `extrema` now supports `init` keyword argument ([#36265]).
99+
* `extrema` now supports `init` keyword argument ([#36265], [#43604]).
100100
* Intersect returns a result with the eltype of the type-promoted eltypes of the two inputs ([#41769]).
101101
* `Iterators.countfrom` now accepts any type that defines `+`. ([#37747])
102102

base/mpfr.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -706,17 +706,6 @@ function min(x::BigFloat, y::BigFloat)
706706
return z
707707
end
708708

709-
# We don't want allocations during `extrema`.
710-
# TODO: avoid allocations in `min/max`
711-
function Base._extrema_rf(x::NTuple{2,BigFloat}, y::NTuple{2,BigFloat})
712-
(x1, x2), (y1, y2) = x, y
713-
isnan(x1) && return x
714-
isnan(y1) && return y
715-
z1 = x1 < y1 || signbit(x1) > signbit(y1) ? x1 : y1
716-
z2 = x2 < y2 || signbit(x2) > signbit(y2) ? y2 : x2
717-
z1, z2
718-
end
719-
720709
function modf(x::BigFloat)
721710
zint = BigFloat()
722711
zfloat = BigFloat()

base/reduce.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -847,15 +847,8 @@ end
847847
ExtremaMap(::Type{T}) where {T} = ExtremaMap{Type{T}}(T)
848848
@inline (f::ExtremaMap)(x) = (y = f.f(x); (y, y))
849849

850+
# TODO: optimize for inputs <: AbstractFloat
850851
@inline _extrema_rf((min1, max1), (min2, max2)) = (min(min1, min2), max(max1, max2))
851-
# optimization for AbstractFloat
852-
function _extrema_rf(x::NTuple{2,T}, y::NTuple{2,T}) where {T<:AbstractFloat}
853-
(x1, x2), (y1, y2) = x, y
854-
anynan = isnan(x1)|isnan(y1)
855-
z1 = ifelse(anynan, x1-y1, ifelse(signbit(x1-y1), x1, y1))
856-
z2 = ifelse(anynan, x1-y1, ifelse(signbit(x2-y2), y2, x2))
857-
z1, z2
858-
end
859852

860853
## findmax, findmin, argmax & argmin
861854

base/reducedim.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ for (Op, initfun) in ((:(typeof(add_sum)), :zero), (:(typeof(mul_prod)), :one))
8080
@eval initarray!(a::AbstractArray{T}, ::Any, ::$(Op), init::Bool, src::AbstractArray) where {T} = (init && fill!(a, $(initfun)(T)); a)
8181
end
8282

83-
# for min/max copyfirst is not correct for initialization, use `mapfirst!` instead
8483
initarray!(a::AbstractArray{T}, f, ::Union{typeof(min),typeof(max),typeof(_extrema_rf)},
8584
init::Bool, src::AbstractArray) where {T} = (init && mapfirst!(f, a, src); a)
8685

0 commit comments

Comments
 (0)