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.

  1. Slice!(StairsIterator!(Iterator, type)) stairs(Slice!Iterator slice, size_t n)
    @optmath
    Slice!(StairsIterator!(Iterator, type))
    stairs
    (
    string type
    Iterator
    )
    (
    Slice!Iterator slice
    ,
    size_t n
    )
    if (
    type == "+" ||
    type == "-"
    )
  2. Slice!(StairsIterator!(S*, type)) stairs(S[] slice, size_t n)
  3. auto stairs(S slice, size_t n)
  4. auto stairs(Slice!(Iterator, 2, kind) slice)

Parameters

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

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

n size_t

stairs count

Return Value

Type: Slice!(StairsIterator!(Iterator, type))

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