input slice with length equal to n * (n + 1) / 2
1D slice composed of 1D contiguous slices.
import mir.ndslice.topology: iota, as, stairs; auto gen = [3, 3].iota.as!double; auto inc = gen.stairs!"+"; auto dec = gen.stairs!"-"; assert(inc == [ [0], [3, 4], [6, 7, 8]]); assert(dec == [ [0, 1, 2], [4, 5], [8]]); static assert(is(typeof(inc.front) == typeof(gen.front))); static assert(is(typeof(dec.front) == typeof(gen.front))); ///////////////////////////////////////// // Pack lower and upper matrix parts auto n = gen.length; auto m = n * (n + 1) / 2; // allocate memory import mir.ndslice.allocation: uninitSlice; auto lowerData = m.uninitSlice!double; auto upperData = m.uninitSlice!double; // construct packed stairs auto lower = lowerData.stairs!"+"(n); auto upper = upperData.stairs!"-"(n); // copy data import mir.algorithm.iteration: each; each!"a[] = b"(lower, inc); each!"a[] = b"(upper, dec); assert(&lower[0][0] is &lowerData[0]); assert(&upper[0][0] is &upperData[0]); assert(lowerData == [0, 3, 4, 6, 7, 8]); assert(upperData == [0, 1, 2, 4, 5, 8]);
Slice composed of rows of lower or upper triangular matrix.
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 2D input.