slice

GC-Allocates an n-dimensional slice.

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

Parameters

lengths size_t[N]

List of lengths for each dimension.

init T

Value to initialize with (optional).

Return Value

Type: Slice!(T*, N)

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