Skip to content

Commit

Permalink
Fix inference of mapreduce (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Aug 24, 2019
1 parent 3718725 commit 48f6fcb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ColorTypes = "≥ 0.7.4"
Colors = "≥ 0.7.1"
FixedPointNumbers = "≥ 0.3.0"
StatsBase = "≥ 0.8.2"
julia = "0.7.0"
julia = "0.7, 1"

[extras]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
11 changes: 5 additions & 6 deletions src/ColorVectorSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,11 @@ _nan(::Type{T}, ::Type{C}) where {T<:AbstractFloat,C<:TransparentRGB} = (x = con
## Generic algorithms
mapreduce(f, op::Union{typeof(&), typeof(|)}, a::MathTypes) = f(a) # ambiguity
mapreduce(f, op, a::MathTypes) = f(a)
if isdefined(Base, :r_promote)
Base.r_promote(::typeof(+), c::MathTypes) = mapc(x->Base.r_promote(+, x), c)
elseif isdefined(Base, :promote_sys_size_add)
Base.promote_sys_size_add(c::MathTypes) = mapc(Base.promote_sys_size_add, c)
else
Base.add_sum(c1::MathTypes,c2::MathTypes) = mapc(Base.add_sum, c1, c2)
Base.add_sum(c1::MathTypes,c2::MathTypes) = mapc(Base.add_sum, c1, c2)
Base.reduce_first(::typeof(Base.add_sum), c::MathTypes) = mapc(x->Base.reduce_first(Base.add_sum, x), c)
function Base.reduce_empty(::typeof(Base.add_sum), ::Type{T}) where {T<:MathTypes}
z = Base.reduce_empty(Base.add_sum, eltype(T))
return zero(base_colorant_type(T){typeof(z)})
end

for f in (:trunc, :floor, :round, :ceil, :eps, :bswap)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,11 @@ end
@test size(A) == (1,3)
end
end

@testset "Colors issue #326" begin
A = rand(RGB{N0f8}, 2, 2)
@test @inferred mean(A) == mean(map(c->mapc(FixedPointNumbers.Treduce, c), A))
end
end

end

0 comments on commit 48f6fcb

Please sign in to comment.