•edge — Edge modes
For an axis of n items, n•edge p gives the position to read for each position in p, under the fill mode. •edge mode gives the function for another mode, "clamp", "wrap", "reflect" or "symmetric", which takes n and p the same way. •edge maps over a list of mode names, as •element maps over tags. Like an element function, a mode function is displayed as the call that made it, such as •edge"clamp". Positions inside the axis stay as they are in every mode.
p←¯2+ι8ₓ
[clamp wrap reflect symmetric]←•edge "clamp" "wrap" "reflect" "symmetric"
4•edge p ⍝ $n $n 0 1 2 3 $n $n
4 clamp p ⍝ [0 0 0 1 2 3 3 3]ₓ
4 wrap p ⍝ [2 3 0 1 2 3 0 1]ₓ
4 reflect p ⍝ [2 1 0 1 2 3 2 1]ₓ
4 symmetric p ⍝ [1 0 0 1 2 3 3 2]ₓFill gives 64-bit floats whatever the float setting of •prefs, with NaN for a position outside the axis. The other modes give exact integers. "reflect" leaves out the edge item, as NumPy’s and PyTorch’s reflect do. "symmetric" repeats it, as NumPy’s symmetric does. An axis of length 0 gives NaN in every mode. A NaN in p stays NaN.
A selection reads the positions that •edge gives. Because NaN isn’t a whole number, selecting at NaN gives the fill, and a write there writes nothing, as Indexing describes. ⌷⍠["fill":v] reads v there instead. Put a position that has spaces in it in parentheses inside the brackets:
x←10 20 30 40 ◇ i←ι4ₓ ◇ clamp←•edge "clamp"
x.[(4•edge i-1)] ⍝ 0 10 20 30
x.[(4 clamp i-1)] ⍝ 10 10 20 30
[(4•edge i-1)]⌷⍠["fill":¯1] x ⍝ ¯1 10 20 30Each mode is arithmetic on positions. Wrap is n|p, and clamp is 0⌈(n-1)⌊p. •edge treats a negative position as outside the axis. A negative position given straight to a selection counts back from the end, as in every selection: x.[¯1] is 40, whereas x.[(4•edge ¯1)] is the fill, 0.
Windows and Stencil take a mode’s name as the edge of an options record, and use that mode for window positions past the ends of an axis, as in ["size":3 "edge":"wrap"]↕v.
Errors: DOMAIN for a mode name that isn’t one of the five, a length that isn’t a nonnegative whole number, or a position that isn’t whole.