Skip to content

Commit abdc9b8

Browse files
authored
Merge pull request #80 from 9il/patch-5
update borders
2 parents 085b04b + d9f2fc9 commit abdc9b8

File tree

1 file changed

+15
-48
lines changed

1 file changed

+15
-48
lines changed

source/dcv/core/utils.d

+15-48
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
Module for various utilities used throughout the library.
33
44
Copyright: Copyright Relja Ljubobratovic 2016.
@@ -52,42 +52,21 @@ package(dcv) @nogc pure nothrow
5252
}
5353
body
5454
{
55-
import std.typecons : Tuple;
5655
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-
}
7656

77-
// forced size_t cast...
78-
auto _iota(B, E, S)(B begin, E end, S step = 1)
57+
static struct Range
7958
{
80-
return iota(size_t(begin), size_t(end), size_t(step));
59+
IotaSlice!1 rows;
60+
IotaSlice!1 cols;
8161
}
8262

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);
8564

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])),
9170
];
9271

9372
return borders;
@@ -122,10 +101,7 @@ static Slice!(N, O*) asType(O, V, size_t N)(Slice!(N, V*) inslice)
122101

123102
unittest
124103
{
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;
129105
auto fslice = slice.asType!float;
130106
assert(slice == fslice);
131107
}
@@ -230,12 +206,6 @@ static if (__VERSION__ >= 2071)
230206
return data.sliced(newShape);
231207
}
232208

233-
version (unittest)
234-
{
235-
import std.algorithm.comparison : equal;
236-
import std.array : array;
237-
}
238-
239209
unittest
240210
{
241211
auto s1 = [1, 2, 3].sliced(3);
@@ -299,19 +269,16 @@ template BoundaryConditionTest(size_t N, T, Indices...)
299269

300270
unittest
301271
{
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);
308275

309276
/*
310277
* [0, 1, 2,
311278
* 3, 4, 5,
312279
* 6, 7, 8]
313280
*/
314-
auto s = iota(9).array.sliced(3, 3);
281+
auto s = iotaSlice(3, 3).slice;
315282

316283
assert(s.neumann(-1, -1) == s[0, 0]);
317284
assert(s.neumann(0, -1) == s[0, 0]);

0 commit comments

Comments
 (0)