Small possible optimisations

Sat, 14 Dec 2019 23:56:21 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Sat, 14 Dec 2019 23:56:21 +0200
changeset 20
9aef75a9452d
parent 19
b28e4ee6ffc5
child 21
a9ea98043eb9

Small possible optimisations

src/Translate.jl file | annotate | diff | comparison | revisions
--- a/src/Translate.jl	Sat Dec 14 23:51:49 2019 +0200
+++ b/src/Translate.jl	Sat Dec 14 23:56:21 2019 +0200
@@ -110,10 +110,11 @@
 function translate_image!(x, z, u::DisplacementConstant)
     @assert(size(u)==(2,) && size(x)==size(z))
 
+    a, b = u[1], u[2]
+
     @inbounds Threads.@threads for i=1:size(x, 1)
         @simd for j=1:size(x, 2)
-            pt = (i - u[1], j - u[2])
-            x[i, j] = interpolate2d_quadrants(z, pt)
+            x[i, j] = interpolate2d_quadrants(z, (i - a, j - b))
         end
     end
 end
@@ -136,11 +137,16 @@
     qx = floor(Int, min(imx, vxʹ + bx) - vxʹ)
     qy = floor(Int, min(imy, vyʹ + by) - vyʹ)
     
-    b .= 0
+    @inbounds begin
+        b[1:px-1, :] .= 0
+        b[qx+1:end, :] .= 0
 
-    @inbounds Threads.@threads for i=px:qx
-        @simd for j=py:qy
-            b[i, j] = interpolate2d_quadrants(im, (i+vxʹ, j+vyʹ))
+        Threads.@threads for i=px:qx
+            b[i, 1:py-1] .= 0
+            b[i, qy+1:end] .= 0
+            @simd for j=py:qy
+                b[i, j] = interpolate2d_quadrants(im, (i+vxʹ, j+vyʹ))
+            end
         end
     end
 end

mercurial