diff --git a/std/experimental/ndslice/selection.d b/std/experimental/ndslice/selection.d index de9277313..3bdccf682 100644 --- a/std/experimental/ndslice/selection.d +++ b/std/experimental/ndslice/selection.d @@ -1724,7 +1724,8 @@ For a multidimensional index, see $(LREF indexSlice). Params: N = dimension count lengths = list of dimension lengths - shift = value of the first element in a slice + shift = value of the first element in a slice (optional) + step = value of the step between elements (optional) Returns: `N`-dimensional slice composed of indexes See_also: $(LREF IotaSlice), $(LREF indexSlice) @@ -1742,6 +1743,15 @@ IotaSlice!N iotaSlice(size_t N)(auto ref size_t[N] lengths, size_t shift = 0) with (typeof(return)) return Range.init.sliced(lengths, shift); } +///ditto +IotaSlice!N iotaSlice(size_t N)(auto ref size_t[N] lengths, size_t shift, size_t step) +{ + auto iota = iotaSlice(lengths, shift); + foreach (i; Iota!(0, N)) + iota._strides[i] *= step; + return iota; +} + /// @safe pure nothrow @nogc unittest { @@ -1759,7 +1769,7 @@ IotaSlice!N iotaSlice(size_t N)(auto ref size_t[N] lengths, size_t shift = 0) } /// -@safe pure nothrow unittest +@safe pure nothrow @nogc unittest { auto im = iotaSlice([10, 5], 100); @@ -1770,6 +1780,15 @@ IotaSlice!N iotaSlice(size_t N)(auto ref size_t[N] lengths, size_t shift = 0) assert(cm[2, 1] == 119); // 119 = 100 + (1 + 2) * 5 + (3 + 1) } +/// `iotaSlice` with step +@safe pure nothrow unittest +{ + auto sl = iotaSlice([2, 3], 10, 10); + + assert(sl == [[10, 20, 30], + [40, 50, 60]]); +} + /++ Slice composed of flattened indexes. See_also: $(LREF iotaSlice)