# HG changeset patch # User Tuomo Valkonen # Date 1577491806 -7200 # Node ID 41d13bf7d6374615967892e204e7dc340d3da2fa # Parent 62645d05985aa9eec71e5b292d0f40d2c6cb36ad Use @threadsif from AlgTools diff -r 62645d05985a -r 41d13bf7d637 src/ImFilter.jl --- 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) diff -r 62645d05985a -r 41d13bf7d637 src/Translate.jl --- 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