Skip to content

Commit

Permalink
Update reduction machinery for 0.7
Browse files Browse the repository at this point in the history
The promotion machinery for reduction in sum/prod was changed in JuliaLang/julia#25051. This updates the use.
  • Loading branch information
simonbyrne committed Jan 16, 2018
1 parent 6a8aee8 commit 94ae245
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/FixedPointNumbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Base: ==, <, <=, -, +, *, /, ~, isapprox,
zero, oneunit, one, typemin, typemax, realmin, realmax, eps, sizeof, reinterpret,
float, trunc, round, floor, ceil, bswap,
div, fld, rem, mod, mod1, fld1, min, max, minmax,
start, next, done, reducedim_init, rand
start, next, done, rand
if isdefined(Base, :rem1)
import Base: rem1
end
Expand Down Expand Up @@ -134,20 +134,27 @@ sizeof(::Type{T}) where {T <: FixedPoint} = sizeof(rawtype(T))
# Promotions for reductions
const Treduce = Float64
if isdefined(Base, :r_promote)
# Julia v0.6
Base.r_promote(::typeof(+), x::FixedPoint{T}) where {T} = Treduce(x)
Base.r_promote(::typeof(*), x::FixedPoint{T}) where {T} = Treduce(x)
Base.reducedim_init(f::typeof(identity),
op::typeof(+),
A::AbstractArray{T}, region) where {T <: FixedPoint} =
Base.reducedim_initarray(A, region, zero(Treduce))
Base.reducedim_init(f::typeof(identity),
op::typeof(*),
A::AbstractArray{T}, region) where {T <: FixedPoint} =
Base.reducedim_initarray(A, region, oneunit(Treduce))
else
Base.promote_sys_size(::Type{<:FixedPoint}) = Treduce
# Julia v0.7
Base.add_sum(x::FixedPoint, y::FixedPoint) = Treduce(x) + Treduce(y)
Base.reduce_empty(::typeof(Base.add_sum), ::Type{F}) where {F<:FixedPoint} = zero(Treduce)
Base.reduce_first(::typeof(Base.add_sum), x::FixedPoint) = Treduce(x)
Base.mul_prod(x::FixedPoint, y::FixedPoint) = Treduce(x) * Treduce(y)
Base.reduce_empty(::typeof(Base.mul_prod), ::Type{F}) where {F<:FixedPoint} = one(Treduce)
Base.reduce_first(::typeof(Base.mul_prod), x::FixedPoint) = Treduce(x)
end

reducedim_init(f::typeof(identity),
op::typeof(+),
A::AbstractArray{T}, region) where {T <: FixedPoint} =
reducedim_initarray(A, region, zero(Treduce))
reducedim_init(f::typeof(identity),
op::typeof(*),
A::AbstractArray{T}, region) where {T <: FixedPoint} =
reducedim_initarray(A, region, oneunit(Treduce))

for f in (:div, :fld, :fld1)
@eval begin
Expand Down

0 comments on commit 94ae245

Please sign in to comment.