File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -1535,7 +1535,7 @@ end
1535
1535
# allocated by the time this gets called.
1536
1536
function filter_algorithm (out, img, kernel:: Union{ArrayType,Tuple{Vararg{ArrayType}}} )
1537
1537
L = maxlen (kernel)
1538
- if L > 30 && eltype (img) <: Union{Number,Colorant} && ! any (isnan, img)
1538
+ if L > 30 && eltype (img) <: Union{Number,Colorant} && all (isfinite, img)
1539
1539
return FFT ()
1540
1540
end
1541
1541
sz = map (length, calculate_padding (kernel))
Original file line number Diff line number Diff line change @@ -92,9 +92,22 @@ Base.zero(::Type{WrappedFloat}) = WrappedFloat(0.0)
92
92
@test all (x-> x== 0 , imgf[first (inds): - 2 ]) && all (x-> x== 0 , imgf[2 : last (inds)])
93
93
end
94
94
95
- # Input with NaN
96
- @test isnan .(imfilter ([NaN ;1 : 100 ],centered (ones (31 )))) == ((0 : 100 ) .<= 15 )
97
-
95
+ # Non-finite input
96
+ for x in (NaN , Inf , - Inf )
97
+ v = rand (100 )
98
+ i = rand (eachindex (v))
99
+ w = [j == i ? x : v[j] for j in eachindex (v)]
100
+ kern = centered (ones (31 ))
101
+ # verify that non-finite values prevent use of FFT
102
+ @test ImageFiltering. filter_algorithm (v, v, kern) == ImageFiltering. FFT ()
103
+ @test ImageFiltering. filter_algorithm (w, w, kern) == ImageFiltering. FIR ()
104
+ vf = imfilter (v, kern)
105
+ wf = imfilter (w, kern)
106
+ around_i = [abs (i- j) <= 15 for j in eachindex (v)]
107
+ @test all (isequal (x), wf[around_i])
108
+ @test wf[.! around_i] ≈ vf[.! around_i]
109
+ end
110
+
98
111
# Issue #110
99
112
img = reinterpret (WrappedFloat, rand (128 ))
100
113
kern = centered (rand (31 ))
You can’t perform that action at this time.
0 commit comments