The OpenD Programming Language

rcslice

Allocates an n-dimensional reference-counted (thread-safe) slice.

Parameters

lengths size_t[N]

List of lengths for each dimension.

init T

Value to initialize with (optional).

Return Value

Type: Slice!(RCI!T, N)

n-dimensional slice

Examples

import mir.ndslice.slice: Slice;
import mir.rc.array: RCI;
auto tensor = rcslice!int(5, 6, 7);
assert(tensor.length == 5);
assert(tensor.elementCount == 5 * 6 * 7);
static assert(is(typeof(tensor) == Slice!(RCI!int, 3)));

// creates duplicate using `rcslice`
auto dup = tensor.rcslice;
assert(dup == tensor);
import mir.ndslice.slice: Slice;
import mir.rc.array: RCI;
auto tensor = rcslice([2, 3], 5);
assert(tensor.elementCount == 2 * 3);
assert(tensor[1, 1] == 5);

import mir.rc.array;
static assert(is(typeof(tensor) == Slice!(RCI!int, 2)));
import mir.rc.array: RCI;
import mir.ndslice.slice: Slice;
import mir.ndslice.topology : iota;
import mir.ndslice.concatenation;
auto tensor = concatenation([2, 3].iota, [3].iota(6)).rcslice;
assert(tensor == [3, 3].iota);

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

Meta