Skip to content

Commit

Permalink
Merge pull request #84 from JuliaGraphics/teh/fix0.7
Browse files Browse the repository at this point in the history
Fix on 0.7
  • Loading branch information
timholy authored Oct 25, 2017
2 parents 32835c2 + ac70431 commit 91e3c10
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ColorTypes 0.6.3
FixedPointNumbers 0.3.0
StatsBase 0.8.2
Compat 0.18.0
SpecialFunctions
40 changes: 24 additions & 16 deletions src/ColorVectorSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ __precompile__(true)

module ColorVectorSpace

using Colors, FixedPointNumbers, Compat
using Colors, FixedPointNumbers, SpecialFunctions, Compat
import StatsBase: histrange

import Base: ==, +, -, *, /, ^, <, ~
Expand All @@ -22,13 +22,10 @@ import Base: conj, sin, cos, tan, sinh, cosh, tanh,
sind, tand, acosd, acotd, acscd, asecd,
asind, atand, rad2deg, deg2rad,
log, log2, log10, log1p, exponent, exp,
exp2, expm1, cbrt, sqrt, erf,
erfc, erfcx, erfi, dawson,
exp2, expm1, cbrt, sqrt,
significand, lgamma,
gamma, lfact, frexp, modf, airy, airyai,
airyprime, airyaiprime, airybi, airybiprime,
besselj0, besselj1, bessely0, bessely1,
eta, zeta, digamma, float, middle
gamma, lfact, frexp, modf,
float, middle

export dotc

Expand All @@ -53,7 +50,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)
Base.r_promote(::typeof(+), c::MathTypes) = mapc(x->Base.r_promote(+, x), c)
if isdefined(Base, :r_promote)
Base.r_promote(::typeof(+), c::MathTypes) = mapc(x->Base.r_promote(+, x), c)
else
Base.promote_sys_size_add(c::MathTypes) = mapc(Base.promote_sys_size_add, c)
end

for f in (:trunc, :floor, :round, :ceil, :eps, :bswap)
@eval $f(g::Gray{T}) where {T} = Gray{T}($f(gray(g)))
Expand Down Expand Up @@ -198,13 +199,15 @@ const unaryOps = (:~, :conj, :abs,
:sind, :tand, :acosd, :acotd, :acscd, :asecd,
:asind, :atand, :rad2deg, :deg2rad,
:log, :log2, :log10, :log1p, :exponent, :exp,
:exp2, :expm1, :cbrt, :sqrt, :erf,
:erfc, :erfcx, :erfi, :dawson,
:exp2, :expm1, :cbrt, :sqrt,
:significand, :lgamma,
:gamma, :lfact, :frexp, :modf, :airy, :airyai,
:airyprime, :airyaiprime, :airybi, :airybiprime,
:besselj0, :besselj1, :bessely0, :bessely1,
:eta, :zeta, :digamma)
:gamma, :lfact, :frexp, :modf,
:(SpecialFunctions.erf), :(SpecialFunctions.erfc),
:(SpecialFunctions.erfcx), :(SpecialFunctions.erfi), :(SpecialFunctions.dawson),
:(SpecialFunctions.airy), :(SpecialFunctions.airyai),
:(SpecialFunctions.airyprime), :(SpecialFunctions.airyaiprime), :(SpecialFunctions.airybi), :(SpecialFunctions.airybiprime),
:(SpecialFunctions.besselj0), :(SpecialFunctions.besselj1), :(SpecialFunctions.bessely0), :(SpecialFunctions.bessely1),
:(SpecialFunctions.eta), :(SpecialFunctions.zeta), :(SpecialFunctions.digamma))
for op in unaryOps
@eval ($op)(c::AbstractGray) = $op(gray(c))
end
Expand Down Expand Up @@ -288,8 +291,13 @@ dotc(x::AbstractGray, y::AbstractGray) = dotc(promote(x, y)...)
float(::Type{T}) where {T<:Gray} = typeof(float(zero(T)))

# Mixed types
(+)(a::MathTypes, b::MathTypes) = (+)(Base.promote_noncircular(a, b)...)
(-)(a::MathTypes, b::MathTypes) = (-)(Base.promote_noncircular(a, b)...)
if VERSION < v"0.7.0-DEV.2138"
(+)(a::MathTypes, b::MathTypes) = (+)(Base.promote_noncircular(a, b)...)
(-)(a::MathTypes, b::MathTypes) = (-)(Base.promote_noncircular(a, b)...)
else
(+)(a::MathTypes, b::MathTypes) = (+)(promote(a, b)...)
(-)(a::MathTypes, b::MathTypes) = (-)(promote(a, b)...)
end

Compat.@dep_vectorize_2arg Gray max
Compat.@dep_vectorize_2arg Gray min
Expand Down
8 changes: 4 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end
@test 2.0f0*cu == Gray(2.0f0*cu.val)
f = N0f8(0.5)
@test (f*cu).val f*cu.val
@test 2.*cf == ccmp
@test 2 .* cf == ccmp
@test cf.*2 == ccmp
@test cf/2.0f0 == Gray{Float32}(0.05)
@test cu/2 == Gray(cu.val/2)
Expand Down Expand Up @@ -94,7 +94,7 @@ end
@test typeof(acu.+cf) == Vector{Gray{Float32}}
@test typeof(acu.-cf) == Vector{Gray{Float32}}
@test typeof(2*acf) == Vector{Gray{Float32}}
@test typeof(2.*acf) == Vector{Gray{Float32}}
@test typeof(2 .* acf) == Vector{Gray{Float32}}
@test typeof(0x02*acu) == Vector{Gray{Float32}}
@test typeof(acu/2) == Vector{Gray{typeof(N0f8(0.5)/2)}}
@test typeof(acf.^2) == Vector{Gray{Float32}}
Expand Down Expand Up @@ -225,7 +225,7 @@ end
@test_colortype_approx_eq 2.0f0*cu RGB(2.0f0*cu.r, 2.0f0*cu.g, 2.0f0*cu.b)
f = N0f8(0.5)
@test (f*cu).r f*cu.r
@test 2.*cf == ccmp
@test 2 .* cf == ccmp
@test cf.*2 == ccmp
@test cf/2.0f0 == RGB{Float32}(0.05,0.1,0.15)
@test cu/2 RGB(cu.r/2,cu.g/2,cu.b/2)
Expand Down Expand Up @@ -300,7 +300,7 @@ end
@test_colortype_approx_eq 2.0f0*cu RGBA(2.0f0*cu.r, 2.0f0*cu.g, 2.0f0*cu.b, 2.0f0*cu.alpha)
f = N0f8(0.5)
@test (f*cu).r f*cu.r
@test 2.*cf == ccmp
@test 2 .* cf == ccmp
@test cf.*2 == ccmp
@test cf/2.0f0 == RGBA{Float32}(0.05,0.1,0.15,0.2)
@test cu/2 == RGBA(cu.r/2,cu.g/2,cu.b/2,cu.alpha/2)
Expand Down

0 comments on commit 91e3c10

Please sign in to comment.