JuliaImages / ImageFiltering.jl

Julia implementations of multidimensional array convolution and nonlinear stencil operations
Other
99 stars 49 forks source link

imfilter inaccuracy problem #80

Closed johnnychen94 closed 5 years ago

johnnychen94 commented 5 years ago
julia> using ImageFiltering

julia> x = ones(5,5);

julia> ∇x = [1 -1];

julia> imfilter(x,reflect(∇x),"circular") ≈ zeros(5,5) # expected to be true
false
timholy commented 5 years ago

Comparing anything to all-zeros with is fraught, because the default is atol=0 and rtol yields 0 when the rhs is all-zeros:

help?> ≈
"≈" can be typed by \approx<tab>

search: ≈

  isapprox(x, y; rtol::Real=atol>0 ? 0 : √eps, atol::Real=0, nans::Bool=false, norm::Function)

  Inexact equality comparison: true if norm(x-y) <= max(atol, rtol*max(norm(x), norm(y))). The default atol is zero and the default rtol depends on the types of x and y.
  The keyword argument nans determines whether or not NaN values are considered equal (defaults to false).

...

You can use

julia> @test imfilter(x,reflect(∇x),"circular") ≈ zeros(5,5) atol=1e-12
Test Passed
Evizero commented 5 years ago

oh, good to know. thanks