Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ os:
- linux
- osx
julia:
- 0.6
- nightly
notifications:
email: false
Expand Down
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
julia 0.6
julia 0.7.0-beta.85
Colors 0.7.1
ColorTypes 0.6.3
FixedPointNumbers 0.3.0
StatsBase 0.8.2
Compat 0.18.0
SpecialFunctions
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

Expand Down
53 changes: 14 additions & 39 deletions src/ColorVectorSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ __precompile__(true)

module ColorVectorSpace

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

import Base: ==, +, -, *, /, ^, <, ~
import Base: abs, abs2, clamp, convert, copy, div, eps, isfinite, isinf,
isnan, isless, length, mapreduce, norm, oneunit, promote_array_type,
isnan, isless, length, mapreduce, oneunit,
promote_op, promote_rule, zero, trunc, floor, round, ceil, bswap,
mod, rem, atan2, hypot, max, min, varm, real, typemin, typemax
mod, rem, atan2, hypot, max, min, real, typemin, typemax
import LinearAlgebra: norm
import StatsBase: histrange, varm
import SpecialFunctions: gamma, lgamma, lfact
import Statistics: middle

export nan

Expand All @@ -23,9 +26,9 @@ import Base: conj, sin, cos, tan, sinh, cosh, tanh,
asind, atand, rad2deg, deg2rad,
log, log2, log10, log1p, exponent, exp,
exp2, expm1, cbrt, sqrt,
significand, lgamma,
gamma, lfact, frexp, modf,
float, middle
significand,
frexp, modf,
float

export dotc

Expand Down Expand Up @@ -60,14 +63,9 @@ end

for f in (:trunc, :floor, :round, :ceil, :eps, :bswap)
@eval $f(g::Gray{T}) where {T} = Gray{T}($f(gray(g)))
@eval Compat.@dep_vectorize_1arg Gray $f
end
eps(::Type{Gray{T}}) where {T} = Gray(eps(T))
Compat.@dep_vectorize_1arg AbstractGray isfinite
Compat.@dep_vectorize_1arg AbstractGray isinf
Compat.@dep_vectorize_1arg AbstractGray isnan
Compat.@dep_vectorize_1arg AbstractGray abs
Compat.@dep_vectorize_1arg AbstractGray abs2

for f in (:trunc, :floor, :round, :ceil)
@eval $f(::Type{T}, g::Gray) where {T<:Integer} = Gray{T}($f(T, gray(g)))
end
Expand Down Expand Up @@ -274,7 +272,7 @@ function Base.isapprox(x::AbstractArray{Cx},
y::AbstractArray{Cy};
rtol::Real=Base.rtoldefault(eltype(Cx),eltype(Cy),0),
atol::Real=0,
norm::Function=vecnorm) where {Cx<:MathTypes,Cy<:MathTypes}
norm::Function=norm) where {Cx<:MathTypes,Cy<:MathTypes}
d = norm(x - y)
if isfinite(d)
return d <= atol + rtol*max(norm(x), norm(y))
Expand All @@ -293,16 +291,8 @@ dotc(x::AbstractGray, y::AbstractGray) = dotc(promote(x, y)...)
float(::Type{T}) where {T<:Gray} = typeof(float(zero(T)))

# Mixed types
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
(+)(a::MathTypes, b::MathTypes) = (+)(promote(a, b)...)
(-)(a::MathTypes, b::MathTypes) = (-)(promote(a, b)...)

# Arrays
+(A::AbstractArray{C}) where {C<:MathTypes} = A
Expand Down Expand Up @@ -345,7 +335,6 @@ real(::Type{C}) where {C<:AbstractGray} = real(eltype(C))
histrange(v::AbstractArray{Gray{T}}, n::Integer) where {T} = histrange(convert(Array{Float32}, map(gray, v)), n, :right)

# To help type inference
promote_array_type(F, ::Type{T}, ::Type{C}) where {T<:Real,C<:MathTypes} = base_colorant_type(C){Base.promote_array_type(F, T, eltype(C))}
promote_rule(::Type{T}, ::Type{C}) where {T<:Real,C<:AbstractGray} = promote_type(T, eltype(C))

typemin(::Type{T}) where {T<:ColorTypes.AbstractGray} = T(typemin(eltype(T)))
Expand All @@ -354,18 +343,4 @@ typemax(::Type{T}) where {T<:ColorTypes.AbstractGray} = T(typemax(eltype(T)))
typemin(::T) where {T<:ColorTypes.AbstractGray} = T(typemin(eltype(T)))
typemax(::T) where {T<:ColorTypes.AbstractGray} = T(typemax(eltype(T)))

# deprecations
function Base.one(::Type{C}) where {C<:Union{TransparentGray,AbstractRGB,TransparentRGB}}
Base.depwarn("one($C) will soon switch to returning 1; you might need to switch to `oneunit`", :one)
C(_onetuple(C)...)
end
_onetuple(::Type{C}) where {C<:Colorant{T,N}} where {T,N} = ntuple(d->1, Val(N))

for f in (:min, :max)
@eval begin
@deprecate($f{T<:Gray}(x::Number, y::AbstractArray{T}), $f.(x, y))
@deprecate($f{T<:Gray}(x::AbstractArray{T}, y::Number), $f.(x, y))
end
end

end
1 change: 0 additions & 1 deletion test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
BaseTestNext
StatsBase
18 changes: 7 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module ColorVectorSpaceTests

using ColorVectorSpace, Colors, FixedPointNumbers, Compat, StatsBase
using LinearAlgebra, Statistics
using ColorVectorSpace, Colors, FixedPointNumbers, StatsBase

using Base.Test
using Test

const var = Statistics.var

macro test_colortype_approx_eq(a, b)
:(test_colortype_approx_eq($(esc(a)), $(esc(b)), $(string(a)), $(string(b))))
Expand Down Expand Up @@ -57,8 +60,6 @@ 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 cf.*2 == ccmp
@test cf/2.0f0 == Gray{Float32}(0.05)
@test cu/2 == Gray(cu.val/2)
@test cu/0.5f0 == Gray(cu.val/0.5f0)
Expand Down Expand Up @@ -89,8 +90,6 @@ end
@test typeof(acu-acf) == Vector{Gray{Float32}}
@test typeof(acu.+acf) == Vector{Gray{Float32}}
@test typeof(acu.-acf) == Vector{Gray{Float32}}
@test typeof(acu+cf) == Vector{Gray{Float32}}
@test typeof(acu-cf) == Vector{Gray{Float32}}
@test typeof(acu.+cf) == Vector{Gray{Float32}}
@test typeof(acu.-cf) == Vector{Gray{Float32}}
@test typeof(2*acf) == Vector{Gray{Float32}}
Expand Down Expand Up @@ -161,6 +160,7 @@ end
v = @eval $op(gray(g)) # if this fails, don't bother
@show op
@test op(g) == v
catch
end
end
end
Expand Down Expand Up @@ -225,8 +225,6 @@ 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 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)
@test cu/0.5f0 == RGB(cu.r/0.5f0, cu.g/0.5f0, cu.b/0.5f0)
Expand Down Expand Up @@ -300,8 +298,6 @@ 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 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)
@test cu/0.5f0 == RGBA(cu.r/0.5f0, cu.g/0.5f0, cu.b/0.5f0, cu.alpha/0.5f0)
Expand Down Expand Up @@ -379,7 +375,7 @@ end
@test typemax(Gray{T}) === Gray{T}(typemax(T))
@test typemin(Gray{T}(0.5)) === Gray{T}(typemin(T))
@test typemax(Gray{T}(0.5)) === Gray{T}(typemax(T))
A = maximum(Gray{T}.([1 0 0; 0 1 0]), 1) # see PR#44 discussion
A = maximum(Gray{T}.([1 0 0; 0 1 0]); dims=1) # see PR#44 discussion
@test isa(A, Matrix{Gray{T}})
@test size(A) == (1,3)
end
Expand Down