stairs

Chops 1D input slice into n chunks with ascending or descending lengths.

stairs can be used to pack and unpack symmetric and triangular matrix storage.

Note: stairs is defined for 1D (packet) input and 2D (general) input. This part of documentation is for 1D input.

Parameters

type
  • "-" for stairs with lengths n, n-1, ..., 1.
  • "+" for stairs with lengths 1, 2, ..., n;
slice S

input slice with length equal to n * (n + 1) / 2

n size_t

stairs count

Return Value

Type: auto

1D contiguous slice composed of 1D contiguous slices.

Examples

import mir.ndslice.topology: iota, stairs;

auto pck = 15.iota;
auto inc = pck.stairs!"+"(5);
auto dec = pck.stairs!"-"(5);

assert(inc == [
    [0],
    [1, 2],
    [3, 4, 5],
    [6, 7, 8, 9],
    [10, 11, 12, 13, 14]]);
assert(inc[1 .. $][2] == [6, 7, 8, 9]);

assert(dec == [
    [0, 1, 2, 3, 4],
       [5, 6, 7, 8],
        [9, 10, 11],
           [12, 13],
               [14]]);
assert(dec[1 .. $][2] == [12, 13]);

static assert(is(typeof(inc.front) == typeof(pck)));
static assert(is(typeof(dec.front) == typeof(pck)));

See Also

Meta