slice

GC-Allocates an n-dimensional slice.

  1. template slice(Args...)
  2. Slice!(T*, N) slice(size_t[N] lengths, T init)
  3. auto slice(Slice!(Iterator, N, kind) slice)
  4. auto slice(Concatenation!(dim, Slices) concatenation)
    @optmath
    slice
    (
    size_t dim
    Slices...
    )

Return Value

Type: auto

initialzed n-dimensional slice

Examples

auto tensor = slice([2, 3], 5);
assert(tensor.elementCount == 2 * 3);
assert(tensor[1, 1] == 5);

// creates duplicate using `slice`
auto dup = tensor.slice;
assert(dup == tensor);
import mir.ndslice.slice: Slice;
import mir.ndslice.topology : iota;
import mir.ndslice.concatenation;
auto tensor = concatenation([2, 3].iota, [3].iota(6)).slice;
assert(tensor == [3, 3].iota);

static assert(is(typeof(tensor) == Slice!(ptrdiff_t*, 2)));

Meta