Skip to content

Commit

Permalink
Merge pull request #4693 from 9il/iota3
Browse files Browse the repository at this point in the history
add iotaSlice variant with step
  • Loading branch information
DmitryOlshansky authored Aug 9, 2016
2 parents 31ef7f7 + 945feb7 commit 488b399
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions std/experimental/ndslice/selection.d
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,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)
Expand All @@ -1734,6 +1735,15 @@ IotaSlice!N iotaSlice(size_t N)(auto ref size_t[N] lengths, size_t shift = 0)
return IotaMap!().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
{
Expand All @@ -1751,7 +1761,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);

Expand All @@ -1762,6 +1772,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)
Expand Down

0 comments on commit 488b399

Please sign in to comment.