mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 09:00:22 +03:00
add iotaSlice variant with step
This commit is contained in:
parent
69c00bc1a9
commit
945feb73c5
1 changed files with 21 additions and 2 deletions
|
@ -1724,7 +1724,8 @@ For a multidimensional index, see $(LREF indexSlice).
|
||||||
Params:
|
Params:
|
||||||
N = dimension count
|
N = dimension count
|
||||||
lengths = list of dimension lengths
|
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:
|
Returns:
|
||||||
`N`-dimensional slice composed of indexes
|
`N`-dimensional slice composed of indexes
|
||||||
See_also: $(LREF IotaSlice), $(LREF indexSlice)
|
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);
|
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
|
@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);
|
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)
|
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.
|
Slice composed of flattened indexes.
|
||||||
See_also: $(LREF iotaSlice)
|
See_also: $(LREF iotaSlice)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue