From 7942a4e28f65775aa5da36d70c4e2779be80bc6b Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 3 Nov 2015 05:10:09 -0600 Subject: [PATCH 1/4] Test type-stability of `similar` Tests that the fix in #393 covers #356 --- test/core.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/core.jl b/test/core.jl index e97ea256..d4de7cd7 100644 --- a/test/core.jl +++ b/test/core.jl @@ -133,10 +133,10 @@ facts("Core") do @fact imgc.data --> img.data imgc = copyproperties(imgd, A) @fact imgc.data --> A - img2 = similar(img) + img2 = @inferred(similar(img)) @fact isa(img2, ImageCmap) --> true @fact (img2.data == img.data) --> false - img2 = similar(imgd) + img2 = @inferred(similar(imgd)) @fact isa(img2, Image) --> true img2 = similar(img, (4,4)) @fact isa(img2, ImageCmap) --> true From 77dfa16061672f46dca833c380ed193d0d1c98bb Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 3 Nov 2015 05:11:13 -0600 Subject: [PATCH 2/4] Reduce spurious fail-to-fail errors with test_approx_eq_sigma_eps Sometimes a blurred rand(5,5) will happen to match a different blurred rand(5,5). This should be less likely for larger arrays, and with higher stringency. --- test/algorithms.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/algorithms.jl b/test/algorithms.jl index 3841ea67..b383133a 100644 --- a/test/algorithms.jl +++ b/test/algorithms.jl @@ -88,15 +88,15 @@ facts("Algorithms") do @fact Images.sad(ag, bg) --> roughly(387f0/255) @fact Images.ssd(ag, bg) --> roughly(80699f0/255^2) - a = rand(5,5) - @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(3,5) [1,1] 0.1) - @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(5,5) [1,1] 0.1) - @fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.1) --> nothing + a = rand(15,15) + @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(13,15) [1,1] 0.01) + @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a rand(15,15) [1,1] 0.01) + @fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.01) --> nothing @fact (Images.@test_approx_eq_sigma_eps a a+0.01*rand(size(a)) [1,1] 0.1) --> nothing @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a a+0.5*rand(size(a)) [1,1] 0.1) - a = colorim(rand(3,5,5)) - @fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.1) --> nothing - @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a colorim(rand(3,5,5)) [1,1] 0.1) + a = colorim(rand(3,15,15)) + @fact (Images.@test_approx_eq_sigma_eps a a [1,1] 0.01) --> nothing + @fact_throws ErrorException (Images.@test_approx_eq_sigma_eps a colorim(rand(3,15,15)) [1,1] 0.01) end context("fft and ifft") do From e7d627b8765be1c00283e3b696efa8200a70bbd6 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 3 Nov 2015 06:12:39 -0600 Subject: [PATCH 3/4] Loosen one test due to rounding issues & order of floating-point operations --- test/map.jl | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/map.jl b/test/map.jl index bd431c8b..705239d9 100644 --- a/test/map.jl +++ b/test/map.jl @@ -198,10 +198,12 @@ facts("Map") do res1 = raw(map(mi1, imgr)) mi2 = ScaleAutoMinMax(UFixed16) res2 = raw(map(mi2, raw(imgr))) - if res1 != res2 - @show A - end - @fact res1 --> res2 + # @fact res1 --> res2 + # Note: this fails occassionally. Reproduce it with + # s = 1.1269798f0 + # val = 0xdeb5 + # UFixed16(s*UFixed16(val,0)) == UFixed16((s/typemax(UInt16))*val) + @fact maxabs(convert(Array{Int32}, res1) - convert(Array{Int32}, res2)) --> less_than_or_equal(1) end context("Scaling and ssd") do From 531e3ce66c5d261391142ce6fc069d7f5906cd32 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 3 Nov 2015 06:23:12 -0600 Subject: [PATCH 4/4] Whitespace changes. --- src/map.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/map.jl b/src/map.jl index cdd6b193..47a54ee8 100644 --- a/src/map.jl +++ b/src/map.jl @@ -164,18 +164,18 @@ similar{T,F,To,From,S}(mapi::ScaleMinMax{To,From,S}, ::Type{T}, ::Type{F}) = Sca # Implementation function map{To<:Union{Real,AbstractGray},From<:Union{Real,AbstractGray}}(mapi::ScaleMinMax{To,From}, val::From) g = gray(val) - t = ifelse(g < mapi.min, zero(From), ifelse(g > mapi.max, mapi.max-mapi.min, g-mapi.min)) + t = ifelse(g < mapi.min, zero(From), ifelse(g > mapi.max, mapi.max-mapi.min, g-mapi.min)) convert(To, mapi.s*t) end function map{To<:Union{Real,AbstractGray},From<:Union{Real,AbstractGray}}(mapi::ScaleMinMax{To,From}, val::Union{Real,Colorant}) map(mapi, convert(From, val)) end function map1{To<:Union{RGB24,ARGB32},From<:Real}(mapi::ScaleMinMax{To,From}, val::From) - t = ifelse(val < mapi.min, zero(From), ifelse(val > mapi.max, mapi.max-mapi.min, val -mapi.min)) + t = ifelse(val < mapi.min, zero(From), ifelse(val > mapi.max, mapi.max-mapi.min, val-mapi.min)) convert(UFixed8, mapi.s*t) end function map1{To<:Colorant,From<:Real}(mapi::ScaleMinMax{To,From}, val::From) - t = ifelse(val < mapi.min, zero(From), ifelse(val > mapi.max, mapi.max-mapi.min, val -mapi.min)) + t = ifelse(val < mapi.min, zero(From), ifelse(val > mapi.max, mapi.max-mapi.min, val-mapi.min)) convert(eltype(To), mapi.s*t) end function map1{To<:Union{RGB24,ARGB32},From<:Real}(mapi::ScaleMinMax{To,From}, val::Union{Real,Colorant})