Skip to content

Commit 94ae245

Browse files
committed
Update reduction machinery for 0.7
The promotion machinery for reduction in sum/prod was changed in JuliaLang/julia#25051. This updates the use.
1 parent 6a8aee8 commit 94ae245

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/FixedPointNumbers.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Base: ==, <, <=, -, +, *, /, ~, isapprox,
1010
zero, oneunit, one, typemin, typemax, realmin, realmax, eps, sizeof, reinterpret,
1111
float, trunc, round, floor, ceil, bswap,
1212
div, fld, rem, mod, mod1, fld1, min, max, minmax,
13-
start, next, done, reducedim_init, rand
13+
start, next, done, rand
1414
if isdefined(Base, :rem1)
1515
import Base: rem1
1616
end
@@ -134,20 +134,27 @@ sizeof(::Type{T}) where {T <: FixedPoint} = sizeof(rawtype(T))
134134
# Promotions for reductions
135135
const Treduce = Float64
136136
if isdefined(Base, :r_promote)
137+
# Julia v0.6
137138
Base.r_promote(::typeof(+), x::FixedPoint{T}) where {T} = Treduce(x)
138139
Base.r_promote(::typeof(*), x::FixedPoint{T}) where {T} = Treduce(x)
140+
Base.reducedim_init(f::typeof(identity),
141+
op::typeof(+),
142+
A::AbstractArray{T}, region) where {T <: FixedPoint} =
143+
Base.reducedim_initarray(A, region, zero(Treduce))
144+
Base.reducedim_init(f::typeof(identity),
145+
op::typeof(*),
146+
A::AbstractArray{T}, region) where {T <: FixedPoint} =
147+
Base.reducedim_initarray(A, region, oneunit(Treduce))
139148
else
140-
Base.promote_sys_size(::Type{<:FixedPoint}) = Treduce
149+
# Julia v0.7
150+
Base.add_sum(x::FixedPoint, y::FixedPoint) = Treduce(x) + Treduce(y)
151+
Base.reduce_empty(::typeof(Base.add_sum), ::Type{F}) where {F<:FixedPoint} = zero(Treduce)
152+
Base.reduce_first(::typeof(Base.add_sum), x::FixedPoint) = Treduce(x)
153+
Base.mul_prod(x::FixedPoint, y::FixedPoint) = Treduce(x) * Treduce(y)
154+
Base.reduce_empty(::typeof(Base.mul_prod), ::Type{F}) where {F<:FixedPoint} = one(Treduce)
155+
Base.reduce_first(::typeof(Base.mul_prod), x::FixedPoint) = Treduce(x)
141156
end
142157

143-
reducedim_init(f::typeof(identity),
144-
op::typeof(+),
145-
A::AbstractArray{T}, region) where {T <: FixedPoint} =
146-
reducedim_initarray(A, region, zero(Treduce))
147-
reducedim_init(f::typeof(identity),
148-
op::typeof(*),
149-
A::AbstractArray{T}, region) where {T <: FixedPoint} =
150-
reducedim_initarray(A, region, oneunit(Treduce))
151158

152159
for f in (:div, :fld, :fld1)
153160
@eval begin

0 commit comments

Comments
 (0)