Skip to content

Commit 65b0c0d

Browse files
authored
Merge pull request #73 from JuliaGraphics/teh/reduce
Use mapreducec for implementation of isfinite, isnan, isinf
2 parents 7f5a67b + 70a1c11 commit 65b0c0d

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
julia 0.5
22
Colors 0.7.1
3-
ColorTypes 0.3.3
3+
ColorTypes 0.4
44
FixedPointNumbers 0.3.0
55
StatsBase 0.8.2
66
Compat 0.18.0

src/ColorVectorSpace.jl

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,11 @@ end
149149
(/)(c::TransparentRGB, f::Integer) = (one(eltype(c))/f)*c
150150

151151
isfinite{T<:Normed}(c::Colorant{T}) = true
152-
isfinite{T<:AbstractFloat}(c::AbstractRGB{T}) = isfinite(red(c)) && isfinite(green(c)) && isfinite(blue(c))
153-
isfinite(c::TransparentRGBFloat) = isfinite(red(c)) && isfinite(green(c)) && isfinite(blue(c)) && isfinite(alpha(c))
152+
isfinite(c::Colorant) = mapreducec(isfinite, &, true, c)
154153
isnan{T<:Normed}(c::Colorant{T}) = false
155-
isnan{T<:AbstractFloat}(c::AbstractRGB{T}) = isnan(red(c)) || isnan(green(c)) || isnan(blue(c))
156-
isnan(c::TransparentRGBFloat) = isnan(red(c)) || isnan(green(c)) || isnan(blue(c)) || isnan(alpha(c))
154+
isnan(c::Colorant) = mapreducec(isnan, |, false, c)
157155
isinf{T<:Normed}(c::Colorant{T}) = false
158-
isinf{T<:AbstractFloat}(c::AbstractRGB{T}) = isinf(red(c)) || isinf(green(c)) || isinf(blue(c))
159-
isinf(c::TransparentRGBFloat) = isinf(red(c)) || isinf(green(c)) || isinf(blue(c)) || isinf(alpha(c))
156+
isinf(c::Colorant) = mapreducec(isinf, |, false, c)
160157
abs(c::AbstractRGB) = abs(red(c))+abs(green(c))+abs(blue(c)) # should this have a different name?
161158
abs{T<:Normed}(c::AbstractRGB{T}) = Float32(red(c))+Float32(green(c))+Float32(blue(c)) # should this have a different name?
162159
abs(c::TransparentRGB) = abs(red(c))+abs(green(c))+abs(blue(c))+abs(alpha(c)) # should this have a different name?
@@ -238,12 +235,6 @@ min(a::AbstractGray, b::AbstractGray) = min(promote(a,b)...)
238235
min(a::Number, b::AbstractGray) = min(promote(a,b)...)
239236
min(a::AbstractGray, b::Number) = min(promote(a,b)...)
240237

241-
isfinite{T<:AbstractFloat}(c::AbstractGray{T}) = isfinite(gray(c))
242-
isfinite(c::TransparentGrayFloat) = isfinite(gray(c)) && isfinite(alpha(c))
243-
isnan{T<:AbstractFloat}(c::AbstractGray{T}) = isnan(gray(c))
244-
isnan(c::TransparentGrayFloat) = isnan(gray(c)) && isnan(alpha(c))
245-
isinf{T<:AbstractFloat}(c::AbstractGray{T}) = isinf(gray(c))
246-
isinf(c::TransparentGrayFloat) = isinf(gray(c)) && isnan(alpha(c))
247238
norm(c::AbstractGray) = abs(gray(c))
248239
abs(c::TransparentGray) = abs(gray(c))+abs(alpha(c)) # should this have a different name?
249240
abs(c::TransparentGrayNormed) = Float32(gray(c)) + Float32(alpha(c)) # should this have a different name?
@@ -357,6 +348,10 @@ histrange{T}(v::AbstractArray{Gray{T}}, n::Integer) = histrange(convert(Array{Fl
357348
promote_array_type{T<:Real,C<:MathTypes}(F, ::Type{T}, ::Type{C}) = base_colorant_type(C){Base.promote_array_type(F, T, eltype(C))}
358349
promote_rule{T<:Real,C<:AbstractGray}(::Type{T}, ::Type{C}) = promote_type(T, eltype(C))
359350

360-
typemin{T<:ColorTypes.AbstractGray}(::Union{T,Type{T}}) = T(typemin(eltype(T)))
361-
typemax{T<:ColorTypes.AbstractGray}(::Union{T,Type{T}}) = T(typemax(eltype(T)))
351+
typemin{T<:ColorTypes.AbstractGray}(::Type{T}) = T(typemin(eltype(T)))
352+
typemax{T<:ColorTypes.AbstractGray}(::Type{T}) = T(typemax(eltype(T)))
353+
354+
typemin{T<:ColorTypes.AbstractGray}(::T) = T(typemin(eltype(T)))
355+
typemax{T<:ColorTypes.AbstractGray}(::T) = T(typemax(eltype(T)))
356+
362357
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ end
6666
@test cu/0.5f0 == Gray(cu.val/0.5f0)
6767
@test cf+cf == ccmp
6868
@test isfinite(cf)
69+
@test isfinite(Gray(true))
6970
@test !isinf(cf)
7071
@test !isnan(cf)
7172
@test !isfinite(Gray(NaN))

0 commit comments

Comments
 (0)