The OpenD Programming Language

iota

Returns a slice, the elements of which are equal to the initial flattened index value.

Members

Functions

iota
Slice!(IotaIterator!I, N) iota(size_t[N] lengths, I start)
Slice!(StrideIterator!(IotaIterator!I), N) iota(size_t[N] lengths, I start, size_t stride)

Parameters

N

dimension count

lengths

list of dimension lengths

start

value of the first element in a slice (optional for integer I)

Return Value

n-dimensional slice composed of indices

Examples

import mir.primitives: DeepElementType;
auto slice = iota(2, 3);
static immutable array =
    [[0, 1, 2],
     [3, 4, 5]];

assert(slice == array);

static assert(is(DeepElementType!(typeof(slice)) == sizediff_t));
int[6] data;
auto slice = iota([2, 3], data.ptr);
assert(slice[0, 0] == data.ptr);
assert(slice[0, 1] == data.ptr + 1);
assert(slice[1, 0] == data.ptr + 3);
auto im = iota([10, 5], 100);
assert(im[2, 1] == 111); // 100 + 2 * 5 + 1

//slicing works correctly
auto cm = im[1 .. $, 3 .. $];
assert(cm[2, 1] == 119); // 119 = 100 + (1 + 2) * 5 + (3 + 1)

iota with step

auto sl = iota([2, 3], 10, 10);

assert(sl == [[10, 20, 30],
              [40, 50, 60]]);

See Also

Meta