Skip to content

Commit 303a2d1

Browse files
committed
add example with sum
1 parent 08a4bd9 commit 303a2d1

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

source/mir/ndslice/chunks.d

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a submodule of $(MREF mir,ndslice).
44
The module contains $(LREF _chunks) routine.
55
$(LREF Chunks) structure is multidimensional random access range with slicing.
66
7-
$(SUBREF slice, slicedNdField) can be used to construct ndslice view on top of $(LREF Chunks).
7+
$(SUBREF slice, slicedField), $(SUBREF slice, slicedNdField) can be used to construct ndslice view on top of $(LREF Chunks).
88
99
License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).
1010
Copyright: Copyright © 2016-, Ilya Yaroshenko
@@ -174,7 +174,6 @@ unittest
174174
static assert(isRandomAccessRange!(typeof(ch)));
175175
}
176176

177-
178177
/// 1Dx2D
179178
unittest
180179
{
@@ -205,6 +204,23 @@ unittest
205204
static assert(isRandomAccessRange!(typeof(ch)));
206205
}
207206

207+
// conversion to ndslice
208+
unittest
209+
{
210+
import mir.ndslice.slice : slicedField;
211+
import mir.ndslice.chunks: chunks;
212+
import mir.ndslice.topology: iota, map;
213+
import mir.math.sum: sum;
214+
215+
// 0 1 2 3 4 5 6 7 8 9 10
216+
auto sl = iota(11);
217+
// 0 1 2 | 3 4 5 | 6 7 8 | 9 10
218+
auto ch = sl.chunks(3);
219+
// 3 | 12 | 21 | 19
220+
auto s = ch.slicedField.map!sum;
221+
assert(s == [3, 12, 21, 19]);
222+
}
223+
208224
/++
209225
+/
210226
struct Chunks(size_t[] dimensions, SliceKind kind, size_t[] packs, Iterator)

0 commit comments

Comments
 (0)