The OpenD Programming Language

repeat

Returns a slice with identical elements. RepeatSlice stores only single value.

  1. Slice!(FieldIterator!(RepeatField!T), M, Universal) repeat(T value, size_t[M] lengths)
    @trusted
    repeat
    (
    T
    size_t M
    )
    (,
    size_t[M] lengths...
    )
    if (
    M &&
    )
  2. Slice!(SliceIterator!(Iterator, N, kind), M, Universal) repeat(Slice!(Iterator, N, kind) slice, size_t[M] lengths)

Parameters

lengths size_t[M]

list of dimension lengths

Return Value

Type: Slice!(FieldIterator!(RepeatField!T), M, Universal)

n-dimensional slice composed of identical values, where n is dimension count.

Examples

auto sl = iota(3).repeat(4);
assert(sl == [[0, 1, 2],
              [0, 1, 2],
              [0, 1, 2],
              [0, 1, 2]]);
import mir.ndslice.dynamic : transposed;

auto sl = iota(3)
    .repeat(4)
    .unpack
    .universal
    .transposed;

assert(sl == [[0, 0, 0, 0],
              [1, 1, 1, 1],
              [2, 2, 2, 2]]);
import mir.ndslice.allocation;

auto sl = iota([3], 6).slice;
auto slC = sl.repeat(2, 3);
sl[1] = 4;
assert(slC == [[[6, 4, 8],
                [6, 4, 8],
                [6, 4, 8]],
               [[6, 4, 8],
                [6, 4, 8],
                [6, 4, 8]]]);
import mir.primitives: DeepElementType;

auto sl = repeat(4.0, 2, 3);
assert(sl == [[4.0, 4.0, 4.0],
              [4.0, 4.0, 4.0]]);

static assert(is(DeepElementType!(typeof(sl)) == double));

sl[1, 1] = 3;
assert(sl == [[3.0, 3.0, 3.0],
              [3.0, 3.0, 3.0]]);

Meta