xpqz / learnapl

Introduction to Dyalog APL: https://xpqz.github.io/learnapl
Other
126 stars 11 forks source link

"The Stencil operator: `⌺`" revision #11

Closed rodrigogiraoserrao closed 3 years ago

rodrigogiraoserrao commented 3 years ago

Revision

Here I include all of the things that, to the best of my knowledge and experience, should be changed/corrected.

To consider

In here I include things that, from my point of view, would be nice additions/modifications. Tick them as you ponder on them, feel free to disregard.

You could very well only have runs of length 3 with elements from the vector:

      3 ,/ ⍳10
┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┐
│0 1 2│1 2 3│2 3 4│3 4 5│4 5 6│5 6 7│6 7 8│7 8 9│
└─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘

What's happening here is that stencil goes farther than just the argument. Stencil goes up to the point where the original array ends at the centre of the window, regardless of that window size dividing the original vector length or not. For example, with windows of size 7, the final window will be 6 7 8 9 0 0 0:

      ⊂⍤⊢⌺7⊢⍳10
┌─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┬─────────────┐
│0 0 0 0 1 2 3│0 0 0 1 2 3 4│0 0 1 2 3 4 5│0 1 2 3 4 5 6│1 2 3 4 5 6 7│2 3 4 5 6 7 8│3 4 5 6 7 8 9│4 5 6 7 8 9 0│5 6 7 8 9 0 0│6 7 8 9 0 0 0│
└─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┴─────────────┘

For even lengths, stencil goes up until the element to the right of the centre, and that's why there's no padding on windows of size 2.

xpqz commented 3 years ago

Fixed in b35e668ab30e60e8ccd54d2ac6bd6328c00ff450 (deployed)