|
1 |
| -/** |
| 1 | +/** |
2 | 2 | Module for various utilities used throughout the library.
|
3 | 3 |
|
4 | 4 | Copyright: Copyright Relja Ljubobratovic 2016.
|
@@ -52,42 +52,21 @@ package(dcv) @nogc pure nothrow
|
52 | 52 | }
|
53 | 53 | body
|
54 | 54 | {
|
55 |
| - import std.typecons : Tuple; |
56 | 55 | import std.algorithm.comparison : max;
|
57 |
| - import std.range : iota; |
58 |
| - import std.traits : ReturnType; |
59 |
| - |
60 |
| - struct Range(Iota) |
61 |
| - { |
62 |
| - Iota rows; |
63 |
| - Iota cols; |
64 |
| - @disable this(); |
65 |
| - this(Iota rows, Iota cols) |
66 |
| - { |
67 |
| - this.rows = rows; |
68 |
| - this.cols = cols; |
69 |
| - } |
70 |
| - } |
71 |
| - |
72 |
| - auto range(Iota)(Iota rows, Iota cols) |
73 |
| - { |
74 |
| - return Range!Iota(rows, cols); |
75 |
| - } |
76 | 56 |
|
77 |
| - // forced size_t cast... |
78 |
| - auto _iota(B, E, S)(B begin, E end, S step = 1) |
| 57 | + static struct Range |
79 | 58 | {
|
80 |
| - return iota(size_t(begin), size_t(end), size_t(step)); |
| 59 | + IotaSlice!1 rows; |
| 60 | + IotaSlice!1 cols; |
81 | 61 | }
|
82 | 62 |
|
83 |
| - size_t kh = max(1, ks / 2); |
84 |
| - alias Iota = ReturnType!(iota!(size_t, size_t, size_t)); |
| 63 | + size_t kh = max(size_t(1), ks / 2); |
85 | 64 |
|
86 |
| - Range!(Iota)[4] borders = [ |
87 |
| - range(_iota(0, shape[0]), _iota(0, kh)), |
88 |
| - range(_iota(0, shape[0]), _iota(shape[1] - kh, shape[1])), |
89 |
| - range(_iota(0, kh), _iota(0, shape[1])), |
90 |
| - range(_iota(shape[0] - kh, shape[0]), _iota(0, shape[1])) |
| 65 | + Range[4] borders = [ |
| 66 | + Range(iotaSlice(shape[0]), iotaSlice(kh)), |
| 67 | + Range(iotaSlice(shape[0]), iotaSlice([kh], shape[1] - kh)), |
| 68 | + Range(iotaSlice(kh), iotaSlice(shape[1])), |
| 69 | + Range(iotaSlice([kh], shape[0] - kh), iotaSlice(shape[1])), |
91 | 70 | ];
|
92 | 71 |
|
93 | 72 | return borders;
|
@@ -122,10 +101,7 @@ static Slice!(N, O*) asType(O, V, size_t N)(Slice!(N, V*) inslice)
|
122 | 101 |
|
123 | 102 | unittest
|
124 | 103 | {
|
125 |
| - import std.range : iota; |
126 |
| - import std.array : array; |
127 |
| - |
128 |
| - auto slice = 6.iota.array.sliced(2, 3); |
| 104 | + auto slice = iotaSlice(2, 3).slice; |
129 | 105 | auto fslice = slice.asType!float;
|
130 | 106 | assert(slice == fslice);
|
131 | 107 | }
|
@@ -230,12 +206,6 @@ static if (__VERSION__ >= 2071)
|
230 | 206 | return data.sliced(newShape);
|
231 | 207 | }
|
232 | 208 |
|
233 |
| - version (unittest) |
234 |
| - { |
235 |
| - import std.algorithm.comparison : equal; |
236 |
| - import std.array : array; |
237 |
| - } |
238 |
| - |
239 | 209 | unittest
|
240 | 210 | {
|
241 | 211 | auto s1 = [1, 2, 3].sliced(3);
|
@@ -299,19 +269,16 @@ template BoundaryConditionTest(size_t N, T, Indices...)
|
299 | 269 |
|
300 | 270 | unittest
|
301 | 271 | {
|
302 |
| - import std.range : iota; |
303 |
| - import std.array : array; |
304 |
| - |
305 |
| - assert(isBoundaryCondition!neumann); |
306 |
| - assert(isBoundaryCondition!periodic); |
307 |
| - assert(isBoundaryCondition!symmetric); |
| 272 | + static assert(isBoundaryCondition!neumann); |
| 273 | + static assert(isBoundaryCondition!periodic); |
| 274 | + static assert(isBoundaryCondition!symmetric); |
308 | 275 |
|
309 | 276 | /*
|
310 | 277 | * [0, 1, 2,
|
311 | 278 | * 3, 4, 5,
|
312 | 279 | * 6, 7, 8]
|
313 | 280 | */
|
314 |
| - auto s = iota(9).array.sliced(3, 3); |
| 281 | + auto s = iotaSlice(3, 3).slice; |
315 | 282 |
|
316 | 283 | assert(s.neumann(-1, -1) == s[0, 0]);
|
317 | 284 | assert(s.neumann(0, -1) == s[0, 0]);
|
|
0 commit comments