Sat, 28 Dec 2019 02:10:06 +0200
Use @threadsif from AlgTools
src/ImFilter.jl | file | annotate | diff | comparison | revisions | |
src/Translate.jl | file | annotate | diff | comparison | revisions |
--- a/src/ImFilter.jl Fri Dec 27 21:41:52 2019 +0200 +++ b/src/ImFilter.jl Sat Dec 28 02:10:06 2019 +0200 @@ -8,6 +8,7 @@ module ImFilter using OffsetArrays +using AlgTools.Util: @threadsif ########## # Exports @@ -25,7 +26,8 @@ end function simple_imfilter(b::Array{Float64,2}, - kernel::OffsetArray{Float64,2,Array{Float64,2}}) + kernel::OffsetArray{Float64,2,Array{Float64,2}}; + threads::Bool=true) n, m = size(b) k, π = size(kernel) @@ -38,7 +40,7 @@ res = similar(b) - Threads.@threads for i=1:n + @threadsif threads for i=1:n @inbounds for j=1:m tmp = 0.0 itβ = inside(i, aβ, bβ, 1, n)
--- a/src/Translate.jl Fri Dec 27 21:41:52 2019 +0200 +++ b/src/Translate.jl Sat Dec 28 02:10:06 2019 +0200 @@ -6,6 +6,8 @@ module Translate +using AlgTools.Util: @threadsif + ########## # Exports ########## @@ -96,23 +98,25 @@ # Translation ############## -function translate_image!(x, z, u::DisplacementFull) +function translate_image!(x, z, u::DisplacementFull; + threads::Bool=false) @assert(size(u, 1)==2 && size(x)==size(u)[2:end] && size(x)==size(z)) - Threads.@threads for i=1:size(x, 1) - @inbounds for j=1:size(x, 2) + @threadsif threads for i=1:size(x, 1) + for j=1:size(x, 2) x[i, j] = interpolate2d_quadrants(z, i - u[1, i, j], j - u[2, i, j]) end end end -function translate_image!(x, z, u::DisplacementConstant) +function translate_image!(x, z, u::DisplacementConstant; + threads::Bool=false) @assert(size(u)==(2,) && size(x)==size(z)) @inbounds a, b = u[1], u[2] - Threads.@threads for i=1:size(x, 1) - @inbounds for j=1:size(x, 2) + @threadsif threads for i=1:size(x, 1) + for j=1:size(x, 2) x[i, j] = interpolate2d_quadrants(z, i - a, j - b) end end @@ -122,7 +126,8 @@ # Subimage extraction ###################### -function extract_subimage!(b, im, v::DisplacementConstant) +function extract_subimage!(b, im, v::DisplacementConstant; + threads::Bool=false) (imx, imy) = size(im) (bx, by) = size(b) @@ -141,7 +146,7 @@ b[qx+1:bx, :] .= 0 end - Threads.@threads for i=px:qx + @threadsif false for i=px:qx @inbounds begin b[i, 1:py-1] .= 0 b[i, qy+1:by] .= 0