The OpenD Programming Language

iota

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

Parameters

N

dimension count

lengths size_t[N]

list of dimension lengths

start I

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

Return Value

Type: Slice!(IotaIterator!I, N)

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