Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Mar 11, 2024
1 parent 2399ba4 commit 5087d8f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/imfilter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ function buffered_planned_irfft(a::AbstractArray{T}) where {T}
end

function planned_fft(A::AbstractArray{T,N},
kernel::Tuple{AbstractArray,Vararg{AbstractArray}},
kernel::ProcessedKernel,
border::BorderSpecAny=Pad(:replicate)
) where {T,N}
bord = border(kernel, A, Algorithm.FFT())
Expand All @@ -870,6 +870,8 @@ function planned_fft(A::AbstractArray{T,N},
bfp3 = buffered_planned_irfft(_A)
return Algorithm.FFT(bfp1, bfp2, bfp3)
end
planned_fft(A::AbstractArray, kernel, border::AbstractString) = planned_fft(A, kernel, borderinstance(border))
planned_fft(A::AbstractArray, kernel::Union{ArrayLike,Laplacian}, border::BorderSpecAny) = planned_fft(A, factorkernel(kernel), border)

function filtfft(A, krn, planned_rfft1::Function, planned_rfft2::Function, planned_irfft::Function)
B = complex(planned_rfft1(A))
Expand Down
11 changes: 6 additions & 5 deletions test/2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ end
# Dense inseparable kernel
kern = [0.1 0.2; 0.4 0.5]
kernel = OffsetArray(kern, -1:0, 1:2)
border = Inner()
for img in (imgf, imgi, imgg, imgc)
targetimg = zeros(typeof(img[1]*kern[1]), size(img))
targetimg[3:4,2:3] = rot180(kern) .* img[3,4]
Expand All @@ -76,12 +77,12 @@ end
@test_throws MethodError imfilter!(CPU1(Algorithm.FIR()), ret, img, kernel, border, Algorithm.FFT())
end
targetimg_inner = OffsetArray(targetimg[2:end, 1:end-2], 2:5, 1:5)
@test @inferred(imfilter(img, kernel, Inner())) targetimg_inner
@test @inferred(imfilter(f32type(img), img, kernel, Inner())) float32.(targetimg_inner)
@test @inferred(imfilter(img, kernel, border)) targetimg_inner
@test @inferred(imfilter(f32type(img), img, kernel, border)) float32.(targetimg_inner)
for alg in (Algorithm.FIR(), Algorithm.FIRTiled(), Algorithm.FFT(), planned_fft(img, kernel, border))
@test @inferred(imfilter(img, kernel, Inner(), alg)) targetimg_inner
@test @inferred(imfilter(f32type(img), img, kernel, Inner(), alg)) float32.(targetimg_inner)
@test @inferred(imfilter(CPU1(alg), img, kernel, Inner())) targetimg_inner
@test @inferred(imfilter(img, kernel, border, alg)) targetimg_inner
@test @inferred(imfilter(f32type(img), img, kernel, border, alg)) float32.(targetimg_inner)
@test @inferred(imfilter(CPU1(alg), img, kernel, border)) targetimg_inner
end
end
# Factored kernel
Expand Down
3 changes: 2 additions & 1 deletion test/nd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ end
img = trues(10,10,10)
kernel = centered(trues(3,3,3)/27)
for border in ("replicate", "circular", "symmetric", "reflect", Fill(true))
for alg in (Algorithm.FIR(), Algorithm.FIRTiled(), Algorithm.FFT(), planned_fft(img, kernel, border))
# TODO: add support for boolean images in planned_fft
for alg in (Algorithm.FIR(), Algorithm.FIRTiled(), Algorithm.FFT())
@test imfilter(img, kernel, border) img
end
end
Expand Down
13 changes: 6 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ using ImageQualityIndexes
import StaticArrays
using Random

function typestring(::Type{T}) where T # from https://github.com/JuliaImages/ImageCore.jl/pull/133
buf = IOBuffer()
show(buf, T)
String(take!(buf))
end

@testset "ImageFiltering" verbose=true begin
@testset "Project meta quality checks" begin
# Ambiguity test
Expand All @@ -27,12 +33,6 @@ using Random
end
end

function typestring(::Type{T}) where T # from https://github.com/JuliaImages/ImageCore.jl/pull/133
buf = IOBuffer()
show(buf, T)
String(take!(buf))
end

include("compat.jl")
include("border.jl")
include("nd.jl")
Expand All @@ -50,7 +50,6 @@ include("models.jl")

CUDA_INSTALLED = false
try
global CUDA_INSTALLED
# This errors with `IOError` when nvidia driver is not available,
# in which case we don't even need to try `using CUDA`
run(pipeline(`nvidia-smi`, stdout=devnull, stderr=devnull))
Expand Down

0 comments on commit 5087d8f

Please sign in to comment.