The OpenD Programming Language

pack

Creates a packed slice, i.e. slice of slices. Packs the last P dimensions. The function does not allocate any data.

Slice!(SliceIterator!(Iterator, P,
P == 1 &&
kind == Canonical
? Contiguous : kind), N - P, Universal)
pack
(
size_t P
Iterator
size_t N
SliceKind kind
)
(
Slice!(Iterator, N, kind) slice
)
if (
P &&
P < N
)

Parameters

P

size of dimension pack

slice Slice!(Iterator, N, kind)

a slice to pack

Return Value

Type: Slice!(SliceIterator!(Iterator, P,
P == 1 &&
kind == Canonical
? Contiguous : kind), N - P, Universal)

slice.pack!p returns Slice!(kind, [N - p, p], Iterator)

Examples

import mir.ndslice.slice: sliced, Slice;

auto a = iota(3, 4, 5, 6);
auto b = a.pack!2;

static immutable res1 = [3, 4];
static immutable res2 = [5, 6];
assert(b.shape == res1);
assert(b[0, 0].shape == res2);
assert(a == b.unpack);
assert(a.pack!2 == b);
static assert(is(typeof(b) == typeof(a.pack!2)));

See Also

Meta