Skip to content

Commit

Permalink
Added unittest example demonstrating overlapped blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljubobratovicrelja committed Nov 5, 2016
1 parent 946dce2 commit c312da1
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions std/experimental/ndslice/selection.d
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,41 @@ pure nothrow unittest
[1, 2, 3, 3, 3, 3, 2, 1]]);
}

/// Overlapping blocks using windows
pure nothrow unittest
{
// ----------------
// | 0 1 2 3 4 |
// | 5 6 7 8 9 |
// | 10 11 12 13 14 |
// | 15 16 17 18 19 |
// | 20 21 22 23 24 |
// ----------------
//->
// ---------------------
// | 0 1 2 | 2 3 4 |
// | 5 6 7 | 7 8 9 |
// | 10 11 12 | 12 13 14 |
// | - - - - - - - - - - |
// | 10 11 13 | 12 13 14 |
// | 15 16 17 | 17 18 19 |
// | 20 21 22 | 22 23 24 |
// ---------------------

import std.experimental.ndslice.slice;
import std.experimental.ndslice.iteration : strided;

auto overlappingBlocks = iotaSlice(5, 5)
.windows(3, 3)
.strided!(0, 1)(2, 2);

assert(overlappingBlocks ==
[[[[ 0, 1, 2], [ 5, 6, 7], [10, 11, 12]],
[[ 2, 3, 4], [ 7, 8, 9], [12, 13, 14]]],
[[[10, 11, 12], [15, 16, 17], [20, 21, 22]],
[[12, 13, 14], [17, 18, 19], [22, 23, 24]]]]);
}

/++
Returns a new slice for the same data with different dimensions.
Expand Down

0 comments on commit c312da1

Please sign in to comment.