{"id":4064,"date":"2017-05-05T07:42:42","date_gmt":"2017-05-05T07:42:42","guid":{"rendered":"http:\/\/www.dyalog.com\/blog\/?p=4064"},"modified":"2017-05-05T08:05:03","modified_gmt":"2017-05-05T08:05:03","slug":"stencil-maneuvers","status":"publish","type":"post","link":"https:\/\/www.dyalog.com\/blog\/2017\/05\/stencil-maneuvers\/","title":{"rendered":"Stencil Maneuvers"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>The e-mail arrived in the early afternoon from Morten, in Finland attending the FinnAPL Forest Seminar.<\/p>\n<div style=\"margin: 15px 50px 15px 50px;\">How do I speed this up and impress the Finns?<\/p>\n<p><code class=\" language-apl\">   0 cmpx 'e\u2190\u2283\u2228\/0.2 edges\u00a8r g b'<br \/>\n6.4E\u00af1<br \/>\n   edges<br \/>\n{\u237a\u21900.7 \u22c4 1 1\u2193\u00af1 \u00af1\u2193\u237a&lt;(|EdgeDetect apply \u2375)\u00f71\u2308(+\u233f\u00f7\u2262),\u2375}<br \/>\n   apply<br \/>\n{stencil\u2190\u237a \u22c4 {+\/,\u2375\u00d7stencil}\u233a(\u2374stencil)\u22a2\u2375}<br \/>\n   EdgeDetect<br \/>\n\u00af1 \u00af1 \u00af1<br \/>\n\u00af1  8 \u00af1<br \/>\n\u00af1 \u00af1 \u00af1<br \/>\n<\/code><br \/>\n(<code class=\" language-apl\">r g b<\/code> in the attached ws)<\/div>\n<h2>Background<\/h2>\n<p><code class=\" language-apl\">\u233a<\/code> is <em>stencil<\/em>, a new dyadic operator which will be available in version 16.0. In brief, <code class=\" language-apl\">f\u233as<\/code> applies the operand function <code class=\" language-apl\">f<\/code> to windows of size <code class=\" language-apl\">s<\/code>. The window is moved over the argument centered over every possible position. The size is commonly odd and the movement commonly 1. For example:<\/p>\n<pre><code class=\" language-apl\">   {\u2282\u2375}\u233a5 3\u22a26 5\u2374\u237330\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u25020  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0 0\u2502\r\n\u25020  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0 0\u2502\r\n\u25020  1  2\u2502 1  2  3\u2502 2  3  4\u2502 3  4  5\u2502 4  5 0\u2502\r\n\u25020  6  7\u2502 6  7  8\u2502 7  8  9\u2502 8  9 10\u2502 9 10 0\u2502\r\n\u25020 11 12\u250211 12 13\u250212 13 14\u250213 14 15\u250214 15 0\u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u25020  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0 0\u2502\r\n\u25020  1  2\u2502 1  2  3\u2502 2  3  4\u2502 3  4  5\u2502 4  5 0\u2502\r\n\u25020  6  7\u2502 6  7  8\u2502 7  8  9\u2502 8  9 10\u2502 9 10 0\u2502\r\n\u25020 11 12\u250211 12 13\u250212 13 14\u250213 14 15\u250214 15 0\u2502\r\n\u25020 16 17\u250216 17 18\u250217 18 19\u250218 19 20\u250219 20 0\u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u25020  1  2\u2502 1  2  3\u2502 2  3  4\u2502 3  4  5\u2502 4  5 0\u2502\r\n\u25020  6  7\u2502 6  7  8\u2502 7  8  9\u2502 8  9 10\u2502 9 10 0\u2502\r\n\u25020 11 12\u250211 12 13\u250212 13 14\u250213 14 15\u250214 15 0\u2502\r\n\u25020 16 17\u250216 17 18\u250217 18 19\u250218 19 20\u250219 20 0\u2502\r\n\u25020 21 22\u250221 22 23\u250222 23 24\u250223 24 25\u250224 25 0\u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u25020  6  7\u2502 6  7  8\u2502 7  8  9\u2502 8  9 10\u2502 9 10 0\u2502\r\n\u25020 11 12\u250211 12 13\u250212 13 14\u250213 14 15\u250214 15 0\u2502\r\n\u25020 16 17\u250216 17 18\u250217 18 19\u250218 19 20\u250219 20 0\u2502\r\n\u25020 21 22\u250221 22 23\u250222 23 24\u250223 24 25\u250224 25 0\u2502\r\n\u25020 26 27\u250226 27 28\u250227 28 29\u250228 29 30\u250229 30 0\u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u25020 11 12\u250211 12 13\u250212 13 14\u250213 14 15\u250214 15 0\u2502\r\n\u25020 16 17\u250216 17 18\u250217 18 19\u250218 19 20\u250219 20 0\u2502\r\n\u25020 21 22\u250221 22 23\u250222 23 24\u250223 24 25\u250224 25 0\u2502\r\n\u25020 26 27\u250226 27 28\u250227 28 29\u250228 29 30\u250229 30 0\u2502\r\n\u25020  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0 0\u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u25020 16 17\u250216 17 18\u250217 18 19\u250218 19 20\u250219 20 0\u2502\r\n\u25020 21 22\u250221 22 23\u250222 23 24\u250223 24 25\u250224 25 0\u2502\r\n\u25020 26 27\u250226 27 28\u250227 28 29\u250228 29 30\u250229 30 0\u2502\r\n\u25020  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0 0\u2502\r\n\u25020  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0  0\u2502 0  0 0\u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\r\n   {+\/,\u2375}\u233a5 3\u22a26 5\u2374\u237330\r\n 39  63  72  81  57\r\n 72 114 126 138  96\r\n115 180 195 210 145\r\n165 255 270 285 195\r\n152 234 246 258 176\r\n129 198 207 216 147\r\n<\/code><\/pre>\n<p>In addition, for matrix right arguments with movement 1, special code is provided for the following operand functions:<\/p>\n<pre><code class=\" language-apl\">{\u2227\/,\u2375}   {\u2228\/,\u2375}   {=\/,\u2375}   {\u2260\/,\u2375} \r\n\r\n{\u2375}      {,\u2375}     {\u2282\u2375}     {+\/,\u2375}\r\n\r\n{+\/,A\u00d7\u2375}     {E&lt;+\/,A\u00d7\u2375}       \r\n{+\/\u236aA\u00d7\u23642\u22a2\u2375}  {E&lt;+\/\u236aA\u00d7\u23642\u22a2\u2375}\r\n<\/code><\/pre>\n<p>The comparison <code class=\" language-apl\">&lt;<\/code> can be one of <code class=\" language-apl\">&lt; \u2264 = \u2260 \u2265 &gt;<\/code>.<\/p>\n<p>The variables <code class=\" language-apl\">r g b<\/code> in the problem are integer matrices with shape <code class=\" language-apl\">227 316<\/code> having values between <code class=\" language-apl\">0<\/code> and <code class=\" language-apl\">255<\/code>. For present purposes we can initialize them to random values:<\/p>\n<pre><code class=\" language-apl\">   r\u2190\u00af1+?227 316\u2374256\r\n   g\u2190\u00af1+?227 316\u2374256\r\n   b\u2190\u00af1+?227 316\u2374256\r\n<\/code><\/pre>\n<h2>Opening Moves<\/h2>\n<p>I had other obligations and did not attend to the problem until 7 PM. A low-hanging fruit was immediately apparent: <code class=\" language-apl\">{+\/,\u2375\u00d7A}\u233as<\/code> is not implemented by special code but <code class=\" language-apl\">{+\/,A\u00d7\u2375}\u233as<\/code> is. The difference in performance is significant:<\/p>\n<pre><code class=\" language-apl\">   edges1\u2190{\u237a\u21900.7 \u22c4 1 1\u2193\u00af1 \u00af1\u2193\u237a&lt;(|EdgeDetect apply1 \u2375)\u00f71\u2308(+\u233f\u00f7\u2262),\u2375}\r\n   apply1\u2190{stencil\u2190\u237a \u22c4 {+\/,stencil\u00d7\u2375}\u233a(\u2374stencil)\u22a2\u2375}\r\n\r\n   cmpx 'e\u2190\u2283\u2228\/0.2 edges1\u00a8r g b' 'e\u2190\u2283\u2228\/0.2 edges \u00a8r g b'\r\n  e\u2190\u2283\u2228\/0.2 edges1\u00a8r g b \u2192 8.0E\u00af3 |     0% \u2395\r\n  e\u2190\u2283\u2228\/0.2 edges \u00a8r g b \u2192 6.1E\u00af1 | +7559% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>I fired off an e-mail reporting this good result, then turned to other more urgent matters. An example of the good being an enemy of the better, I suppose.<\/p>\n<p>When I returned to the problem at 11 PM, the smug good feelings have largely dissipated:<\/p>\n<ul>\n<li>Why should <code class=\" language-apl\">{+\/,A\u00d7\u2375}\u233as<\/code> be so much faster than <code class=\" language-apl\">{+\/,\u2375\u00d7A}\u233as<\/code>? That is, why is there special code for the former but not the latter? (Answer: all the special codes end with <code class=\" language-apl\">\u2026 \u2375}<\/code>.)<\/li>\n<li>I can not win: If the factor is small, then why isn\u2019t it larger; if it is large, it\u2019s only because the original code wasn\u2019t very good.<\/li>\n<li>The large factor is because, for this problem, C (special code) is still so much faster than APL (<a href=\"https:\/\/www.dyalog.com\/blog\/2015\/06\/in-praise-of-magic-functions-part-one\/\">magic function<\/a>).<\/li>\n<li>If the absolute value can somehow be replaced, the operand function can then be in the form <code class=\" language-apl\">{E&lt;+\/,A\u00d7\u2375}\u233as<\/code>, already implemented by special code. Alternatively, <code class=\" language-apl\">{E&lt;|+\/,A\u00d7\u2375}\u233as<\/code> can be implemented by new special code.<\/li>\n<\/ul>\n<p>Regarding the last point, the performance improvement potentially can be:<\/p>\n<pre><code class=\" language-apl\">   edges2\u2190{\u237a\u21900.7 \u22c4 1 1\u2193\u00af1 \u00af1\u2193(\u237a EdgeDetect)apply2 \u2375}\r\n   apply2\u2190{threshold stencil\u2190\u237a \u22c4 \r\n                    {threshold&lt;+\/,stencil\u00d7\u2375}\u233a(\u2374stencil)\u22a2\u2375}\r\n\r\n   cmpx (\u2282'e\u2190\u2283\u2228\/0.2 edges'),\u00a8'21 ',\u00a8\u2282'\u00a8r g b'\r\n  e\u2190\u2283\u2228\/0.2 edges2\u00a8r g b \u2192 4.8E\u00af3 |      0%\r\n* e\u2190\u2283\u2228\/0.2 edges1\u00a8r g b \u2192 7.5E\u00af3 |    +57%\r\n* e\u2190\u2283\u2228\/0.2 edges \u00a8r g b \u2192 7.4E\u00af1 | +15489% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>The <code class=\" language-apl\">*<\/code> in the result of <code class=\" language-apl\">cmpx<\/code> indicates that the expressions don&#8217;t give the same results. That is expected; <code class=\" language-apl\">edges2<\/code> is not meant to give the same results but is to get a sense of the performance difference. (Here, an additional factor of <code class=\" language-apl\">1.57<\/code>.)<\/p>\n<p><code class=\" language-apl\">edges1<\/code> has the expression <code class=\" language-apl\">\u237a&lt;matrix\u00f71\u2308(+\u233f\u00f7\u2262),\u2375<\/code> where <code class=\" language-apl\">\u237a<\/code> and the divisor are both scalars. Reordering the expression eliminates one matrix operation: <code class=\" language-apl\">(\u237a\u00d71\u2308(+\u233f\u00f7\u2262),\u2375)&lt;matrix<\/code>. Thus:<\/p>\n<pre><code class=\" language-apl\">   edges1a\u2190{\u237a\u21900.7 \u22c4 1 1\u2193\u00af1 \u00af1\u2193(\u237a\u00d71\u2308(+\u233f\u00f7\u2262),\u2375)&lt;|EdgeDetect apply1 \u2375}\r\n\r\n   cmpx (\u2282'e\u2190\u2283\u2228\/0.2 edges'),\u00a8('1a' '1 ' '  '),\u00a8\u2282'\u00a8r g b'\r\n  e\u2190\u2283\u2228\/0.2 edges1a\u00a8r g b \u2192 6.3E\u00af3 |      0%\r\n  e\u2190\u2283\u2228\/0.2 edges1 \u00a8r g b \u2192 7.6E\u00af3 |    +22%\r\n  e\u2190\u2283\u2228\/0.2 edges  \u00a8r g b \u2192 6.5E\u00af1 | +10232% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>The time was almost 1 AM. To bed.<\/p>\n<h2>Further Maneuvers<\/h2>\n<p>Fresh and promising ideas came with the morning. The following discussion applies to the operand function <code class=\" language-apl\">{+\/,A\u00d7\u2375}<\/code>.<\/p>\n<p><strong>(0)<\/strong> Scalar multiple: If all the elements of <code class=\" language-apl\">A<\/code> are equal, then <code class=\" language-apl\">{+\/,A\u00d7\u2375}\u233a(\u2374A)\u22a2r \u2190\u2192 (\u2283A)\u00d7{+\/,\u2375}\u233a(\u2374A)\u22a2r<\/code>.<\/p>\n<pre><code class=\" language-apl\">   A\u21903 3\u2374?17\r\n   ({+\/,A\u00d7\u2375}\u233a(\u2374A)\u22a2r) \u2261 (\u2283A)\u00d7{+\/,\u2375}\u233a(\u2374A)\u22a2r\r\n1\r\n<\/code><\/pre>\n<p><strong>(1)<\/strong> Sum <i>v<\/i> inner product: <code class=\" language-apl\">{+\/,\u2375}\u233a(\u2374A)\u22a2r<\/code> is significantly faster than <code class=\" language-apl\">{+\/,A\u00d7\u2375}\u233a(\u2374A)\u22a2r<\/code> because the former exploits mathematical properties absent from the latter.<\/p>\n<pre><code class=\" language-apl\">   A\u2190?3 3\u237417\r\n   cmpx '{+\/,\u2375}\u233a(\u2374A)\u22a2r' '{+\/,A\u00d7\u2375}\u233a(\u2374A)\u22a2r'\r\n  {+\/,\u2375}\u233a(\u2374A)\u22a2r   \u2192 1.4E\u00af4 |    0% \u2395\u2395\u2395\r\n* {+\/,A\u00d7\u2375}\u233a(\u2374A)\u22a2r \u2192 1.3E\u00af3 | +828% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<p>(The <code class=\" language-apl\">*<\/code> in the result of <code class=\" language-apl\">cmpx<\/code> is expected.)<\/p>\n<p><strong>(2)<\/strong> Linearity: the stencil of the sum equals the sum of the stencils.<\/p>\n<pre><code class=\" language-apl\">   A\u2190?3 3\u237417\r\n   B\u2190?3 3\u237417\r\n   ({+\/,(A+B)\u00d7\u2375}\u233a(\u2374A)\u22a2r) \u2261 ({+\/,A\u00d7\u2375}\u233a(\u2374A)\u22a2r) + {+\/,B\u00d7\u2375}\u233a(\u2374A)\u22a2r \r\n1\r\n<\/code><\/pre>\n<p><strong>(3)<\/strong> Middle: If <code class=\" language-apl\">B<\/code> is zero everywhere except the middle, then <code class=\" language-apl\">{+\/,B\u00d7\u2375}\u233a(\u2374B)\u22a2r \u2190\u2192 mid\u00d7r<\/code> where <code class=\" language-apl\">mid<\/code> is the middle value.<\/p>\n<pre><code class=\" language-apl\">   B\u2190(\u2374A)\u23740 0 0 0 9\r\n   B\r\n0 0 0\r\n0 9 0\r\n0 0 0\r\n   ({+\/,B\u00d7\u2375}\u233a(\u2374B)\u22a2r) \u2261 9\u00d7r\r\n1\r\n<\/code><\/pre>\n<p><strong>(4)<\/strong> A faster solution.<\/p>\n<pre><code class=\" language-apl\">   A\u2190EdgeDetect\r\n   B\u2190(\u2374A)\u23740 0 0 0 9\r\n   C\u2190(\u2374A)\u2374\u00af1\r\n   A B C\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u2502\u00af1 \u00af1 \u00af1\u25020 0 0\u2502\u00af1 \u00af1 \u00af1\u2502\r\n\u2502\u00af1  8 \u00af1\u25020 9 0\u2502\u00af1 \u00af1 \u00af1\u2502\r\n\u2502\u00af1 \u00af1 \u00af1\u25020 0 0\u2502\u00af1 \u00af1 \u00af1\u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\r\n   A \u2261 B+C\r\n1\r\n<\/code><\/pre>\n<p>Whence:<\/p>\n<pre><code class=\" language-apl\">   ({+\/,A\u00d7\u2375}\u233a(\u2374A)\u22a2r) \u2261 ({+\/,B\u00d7\u2375}\u233a(\u2374A)\u22a2r) + {+\/,C\u00d7\u2375}\u233a(\u2374A)\u22a2r \u235d (2)\r\n1\r\n   ({+\/,A\u00d7\u2375}\u233a(\u2374A)\u22a2r) \u2261 ({+\/,B\u00d7\u2375}\u233a(\u2374A)\u22a2r) - {+\/,\u2375}\u233a(\u2374A)\u22a2r   \u235d (0)\r\n1\r\n   ({+\/,A\u00d7\u2375}\u233a(\u2374A)\u22a2r) \u2261 (9\u00d7r) - {+\/,\u2375}\u233a(\u2374A)\u22a2r                \u235d (3)\r\n1\r\n<\/code><\/pre>\n<p>Putting it all together:<\/p>\n<pre><code class=\" language-apl\">edges3\u2190{\r\n  \u237a\u21900.7\r\n  mid\u2190\u2283EdgeDetect\u2193\u2368\u230a2\u00f7\u2368\u2374EdgeDetect\r\n  1 1\u2193\u00af1 \u00af1\u2193(\u237a\u00d71\u2308(+\u233f\u00f7\u2262),\u2375)&lt;|(\u2375\u00d71+mid)-{+\/,\u2375}\u233a(\u2374EdgeDetect)\u22a2\u2375\r\n}\r\n<\/code><\/pre>\n<p>Comparing the various <code class=\" language-apl\">edges<\/code>:<\/p>\n<pre><code class=\" language-apl\">   x\u2190(\u2282'e\u2190\u2283\u2228\/0.2 edges'),\u00a8('3 ' '2 ' '1a' '1 ' '  '),\u00a8\u2282'\u00a8r g b'\r\n   cmpx x\r\n  e\u2190\u2283\u2228\/0.2 edges3 \u00a8r g b \u2192 3.4E\u00af3 |      0%\r\n* e\u2190\u2283\u2228\/0.2 edges2 \u00a8r g b \u2192 4.3E\u00af3 |    +25%\r\n  e\u2190\u2283\u2228\/0.2 edges1a\u00a8r g b \u2192 6.4E\u00af3 |    +88%\r\n  e\u2190\u2283\u2228\/0.2 edges1 \u00a8r g b \u2192 7.5E\u00af3 |   +122%\r\n  e\u2190\u2283\u2228\/0.2 edges  \u00a8r g b \u2192 6.5E\u00af1 | +19022% \u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\u2395\r\n<\/code><\/pre>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><code class=\" language-apl\">edges<\/code><\/td>\n<td style=\"text-align: left;\">original<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><code class=\" language-apl\">edges1<\/code><\/td>\n<td style=\"text-align: left;\">uses <code class=\" language-apl\">{+\/,stencil\u00d7\u2375}<\/code> instead of <code class=\" language-apl\">{+\/,\u2375\u00d7stencil}<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><code class=\" language-apl\">edges1a<\/code><\/td>\n<td style=\"text-align: left;\">uses <code class=\" language-apl\">(\u237a\u00d7mean,\u2375)&lt;matrix<\/code> instead of <code class=\" language-apl\">\u237a&lt;matrix\u00f7mean,\u2375<\/code> <\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><code class=\" language-apl\">edges2<\/code><\/td>\n<td style=\"text-align: left;\">uses <code class=\" language-apl\">{threshold&lt;+\/,stencil\u00d7\u2375}<\/code><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\"><code class=\" language-apl\">edges3<\/code><\/td>\n<td style=\"text-align: left;\">uses the faster <code class=\" language-apl\">{+\/,\u2375}<\/code> instead of <code class=\" language-apl\">{+\/,stencil\u00d7\u2375}<\/code>  and other maneuvers<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Fin<\/h2>\n<p>I don&#8217;t know if the Finns would be impressed. The exercise has been amusing in any case.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction The e-mail arrived in the early afternoon from Morten, in Finland attending the FinnAPL Forest Seminar. How do I speed this up and impress the Finns? 0 cmpx &#8216;e\u2190\u2283\u2228\/0.2 edges\u00a8r g b&#8217; 6.4E\u00af1 edges {\u237a\u21900.7 \u22c4 1 1\u2193\u00af1 \u00af1\u2193\u237a&lt;(|EdgeDetect &hellip; <a href=\"https:\/\/www.dyalog.com\/blog\/2017\/05\/stencil-maneuvers\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-4064","post","type-post","status-publish","format-standard","hentry","category-apl-language"],"_links":{"self":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/4064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/comments?post=4064"}],"version-history":[{"count":5,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/4064\/revisions"}],"predecessor-version":[{"id":4901,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/posts\/4064\/revisions\/4901"}],"wp:attachment":[{"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/media?parent=4064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/categories?post=4064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dyalog.com\/blog\/wp-json\/wp\/v2\/tags?post=4064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}