Skip to content

Commit 037ac37

Browse files
add error methods for unsupported NA borders
1 parent e4cfafb commit 037ac37

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/imfilter.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,21 @@ end
955955
planned_fft(A::AbstractArray, kernel, border::AbstractString) = planned_fft(A, kernel, borderinstance(border))
956956
planned_fft(A::AbstractArray, kernel::Union{ArrayLike,Laplacian}, border::BorderSpecAny) = planned_fft(A, factorkernel(kernel), border)
957957

958+
# Error methods for NA borders - these should not be used with planned FFT
959+
function planned_fft(A::AbstractArray{T,N},
960+
kernel::ProcessedKernel,
961+
border::NA) where {T,N}
962+
throw(ArgumentError("NA borders are not supported with planned FFT algorithms."))
963+
end
964+
965+
function planned_fft(A::AbstractArray,
966+
kernel::Union{ArrayLike,Laplacian},
967+
border::NA)
968+
throw(ArgumentError("NA borders are not supported with planned FFT algorithms."))
969+
end
970+
971+
planned_fft(A::AbstractArray, kernel, border::NA) = throw(ArgumentError("NA borders are not supported with planned FFT algorithms."))
972+
958973
# Unified filtfft function for planned FFT operations
959974
function filtfft(A::AbstractArray{T}, krn, planned_rfft1::Function, planned_rfft2::Function, planned_irfft::Function) where {T}
960975
if T <: Colorant

test/2d.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,18 @@ end
449449
@test filtfft(C, D) filtfft(C, ComplexF32.(D))
450450
@test filtfft(C, D) filtfft(ComplexF32.(C), ComplexF32.(D))
451451
end
452+
453+
@testset "Planned FFT with NA borders should error" begin
454+
imgf = zeros(Float64, 5, 7); imgf[3,4] = 1.0
455+
imgi = zeros(Int, 5, 7); imgi[3,4] = 1
456+
imgc = fill(RGB{Float64}(0,0,0), 5, 7); imgc[3,4] = RGB{Float64}(1,0,0)
457+
kernel = OffsetArray([0.1 0.2; 0.4 0.5], -1:0, 1:2)
458+
na_border = NA()
459+
460+
@test_throws ArgumentError planned_fft(imgf, kernel, na_border)
461+
@test_throws ArgumentError planned_fft(imgi, kernel, na_border)
462+
@test_throws ArgumentError planned_fft(imgc, kernel, na_border)
463+
kern_tuple = (OffsetArray([0.2, 0.8], -1:0), OffsetArray([0.3 0.6], 0:0, 1:2))
464+
@test_throws ArgumentError planned_fft(imgf, kern_tuple, na_border)
465+
@test_throws ArgumentError planned_fft(imgf, Kernel.Laplacian(), na_border)
466+
end

0 commit comments

Comments
 (0)