canonical

Converts a slice to canonical kind.

@optmath
Slice!(Iterator, N, N == 1 ? Contiguous : Canonical, Labels)
canonical
(
Iterator
size_t N
SliceKind kind
Labels...
)
(
Slice!(Iterator, N, kind, Labels) slice
)
if (
kind == Contiguous ||
kind == Canonical
)

Parameters

slice Slice!(Iterator, N, kind, Labels)

contiguous or canonical slice

Return Value

Type: Slice!(Iterator, N, N == 1 ? Contiguous : Canonical, Labels)

canonical slice

Examples

auto slice = iota(2, 3).canonical;
assert(slice == [[0, 1, 2], [3, 4, 5]]);
assert(slice._lengths == [2, 3]);
assert(slice._strides == [3]);
import mir.ndslice.slice;
import mir.ndslice.allocation: slice;

auto dataframe = slice!(double, int, string)(2, 3);
dataframe.label[] = [1, 2];
dataframe.label!1[] = ["Label1", "Label2", "Label3"];

auto canonicaldf = dataframe.canonical;
assert(canonicaldf._lengths == [2, 3]);
assert(canonicaldf._strides == [3]);

assert(is(typeof(canonicaldf) ==
    Slice!(double*, 2, Canonical, int*, string*)));
assert(canonicaldf.label!0[0] == 1);
assert(canonicaldf.label!1[1] == "Label2");

See Also

Meta