pad

Pads with a constant value.

  1. auto pad(S s, T value, size_t[N] lengths)
    @optmath
    pad
    (
    string direction = "both"
    S
    T
    size_t N
    )
    (
    S s
    ,,
    size_t[N] lengths...
    )
    if (
    hasShape!S &&
    N == typeof(S.shape).length
    )
  2. template pad(size_t[] dimensions, string[] directions)

Parameters

direction

padding direction. Direction can be one of the following values: "both", "pre", and "post".

s S

Slice or ndField

value T

initial value for padding

lengths size_t[N]

list of lengths

Return Value

Type: auto

Examples

import mir.ndslice.allocation: slice;
import mir.ndslice.topology: iota;

auto pad = iota([3], 1)
    .pad(0, [2])
    .slice;

assert(pad == [0, 0,  1, 2, 3,  0, 0]);
import mir.ndslice.allocation: slice;
import mir.ndslice.topology: iota;

auto pad = iota([2, 2], 1)
    .pad(0, [2, 1])
    .slice;

assert(pad == [
    [0,  0, 0,  0],
    [0,  0, 0,  0],

    [0,  1, 2,  0],
    [0,  3, 4,  0],

    [0,  0, 0,  0],
    [0,  0, 0,  0]]);

See Also

._concatenation examples.

Meta