From 9383364eebe29cd3896f72c05b8c459cb8b859b9 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Mon, 30 Jan 2017 21:40:55 -0600 Subject: [PATCH 1/2] Widen all-Integer eltypes. Fixes #17. --- src/imfilter.jl | 3 +++ test/nd.jl | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/imfilter.jl b/src/imfilter.jl index abed7bc..769039a 100644 --- a/src/imfilter.jl +++ b/src/imfilter.jl @@ -972,6 +972,8 @@ end filter_type{S}(img::AbstractArray{S}, kernel) = filter_type(S, kernel) filter_type{S,T}(::Type{S}, kernel::ArrayLike{T}) = typeof(zero(S)*zero(T) + zero(S)*zero(T)) +filter_type{S<:Integer,T<:Integer}(::Type{S}, kernel::ArrayLike{T}) = + typeof(zero(widen(S))*zero(widen(T)) + zero(widen(S))*zero(widen(T))) filter_type{S<:Union{Normed,FixedColorant}}(::Type{S}, ::Laplacian) = float32(S) filter_type{S<:Colorant}(::Type{S}, kernel::Laplacian) = S filter_type{S<:AbstractFloat}(::Type{S}, ::Laplacian) = S @@ -982,6 +984,7 @@ filter_type(::Type{Bool}, ::Laplacian) = Int8 signed_type(::Type{UInt8}) = Int16 signed_type(::Type{UInt16}) = Int32 signed_type(::Type{UInt32}) = Int64 +signed_type{T<:Integer}(::Type{T}) = Int @inline function filter_type{S}(::Type{S}, kernel::Tuple{Any,Vararg{Any}}) T = filter_type(S, kernel[1]) diff --git a/test/nd.jl b/test/nd.jl index 7f25d87..da89dcd 100644 --- a/test/nd.jl +++ b/test/nd.jl @@ -36,6 +36,13 @@ using Base.Test @test imfilter!(r, out, img, (kern,), "replicate") == imgf @test_throws MethodError imfilter!(r, out, img, (kern,), "replicate", Algorithm.FIR()) + # Element-type widening + v = fill(0xff, 10) + kern = centered(fill(0xff, 3)) + vout = imfilter(v, kern) + @test eltype(vout) == UInt32 + @test all(x->x==0x0002fa03, vout) + # Cascades don't result in out-of-bounds values k1 = centered([0.25, 0.5, 0.25]) k2 = OffsetArray([0.5, 0.5], 1:2) @@ -62,6 +69,12 @@ using Base.Test @test out ≈ imfilter(img, kern) end +@testset "2d widening" begin + ret = imfilter(fill(typemax(Int16), 10, 10), centered(Int16[1 2 2 2 1])) # issue #17 + @test eltype(ret) == Int32 + @test all(x->x==262136, ret) +end + @testset "3d" begin img = trues(10,10,10) kernel = centered(trues(3,3,3)/27) From 09082b6bf31f0b765498bb1bf9be4f1cfe655c26 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 31 Jan 2017 04:30:32 -0600 Subject: [PATCH 2/2] Eliminate .travis.yml hacks for unregistered packages --- .travis.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 76822aa..94dc1be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,11 +9,9 @@ julia: notifications: email: false # uncomment the following lines to override the default test script -script: - - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - # For the time being, clone unregistered packages - - julia -e 'Pkg.clone("https://github.com/JuliaImages/ImageCore.jl")' - - julia -e 'Pkg.clone(pwd()); Pkg.build("ImageFiltering"); Pkg.test("ImageFiltering"; coverage=true)' +# script: +# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi +# - julia -e 'Pkg.clone(pwd()); Pkg.build("ImageFiltering"); Pkg.test("ImageFiltering"; coverage=true)' after_success: # push coverage results to Codecov - julia -e 'cd(Pkg.dir("ImageFiltering")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'