Skip to content

Commit 521e138

Browse files
jmh5309il
authored andcommitted
Additional fixes
1 parent ca81c73 commit 521e138

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

source/mir/ndslice/topology.d

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4181,43 +4181,44 @@ See_also:
41814181
$(LREF transposed).
41824182
+/
41834183
template byDim(Dimensions...)
4184-
if (Dimensions.length)
4184+
if (Dimensions.length > 0)
41854185
{
4186-
import mir.ndslice.slice : Slice, SliceKind;
4187-
import mir.ndslice.internal : isSize_t, toSize_t;
4188-
import std.meta : allSatisfy, staticMap;
4189-
4186+
import mir.ndslice.internal : isSize_t;
4187+
import std.meta : allSatisfy;
4188+
41904189
static if (!allSatisfy!(isSize_t, Dimensions))
4190+
{
4191+
import std.meta : staticMap;
4192+
import mir.ndslice.internal : toSize_t;
4193+
41914194
alias byDim = .byDim!(staticMap!(toSize_t, Dimensions));
4195+
}
41924196
else
4193-
///
4194-
@fastmath auto byDim(SliceKind kind, size_t[] packs, Iterator)
4195-
(Slice!(kind, packs, Iterator) slice)
41964197
{
4197-
import mir.ndslice.topology : ipack;
4198-
import mir.ndslice.internal : DimensionsCountCTError, DimensionCTError;
4199-
4200-
mixin DimensionsCountCTError;
4201-
4202-
static if (packs == [1])
4203-
{
4204-
return slice;
4205-
}
4206-
else
4198+
import mir.ndslice.slice : Slice, SliceKind;
4199+
///
4200+
@fastmath auto byDim(SliceKind kind, size_t[] packs, Iterator)
4201+
(Slice!(kind, packs, Iterator) slice)
42074202
{
42084203
import mir.ndslice.topology : ipack;
4209-
return slice.adjTransposed!Dimensions.ipack!1;
4204+
import mir.ndslice.internal : DimensionsCountCTError;
4205+
4206+
mixin DimensionsCountCTError;
4207+
4208+
static if (packs == [1])
4209+
{
4210+
return slice;
4211+
}
4212+
else
4213+
{
4214+
return slice
4215+
.adjTransposed!Dimensions
4216+
.ipack!(Dimensions.length);
4217+
}
42104218
}
42114219
}
42124220
}
42134221

4214-
///
4215-
auto byDim(SliceKind kind, size_t[] packs, Iterator)
4216-
(Slice!(kind, packs, Iterator) slice)
4217-
{
4218-
return slice.byDim!0;
4219-
}
4220-
42214222
/// 2-dimensional slice support
42224223
@safe @nogc pure nothrow
42234224
unittest
@@ -4241,7 +4242,7 @@ unittest
42414242
// | 4 5 6 7 |
42424243
// | 8 9 10 11 |
42434244
// ------------
4244-
auto x = slice.byDim;
4245+
auto x = slice.byDim!0;
42454246
assert(x.shape == shape3);
42464247
assert(x.front.shape == shape4);
42474248
assert(x.front == iota(4));
@@ -4292,7 +4293,7 @@ unittest
42924293
//->
42934294
// | 3 4 |
42944295
//->
4295-
// | 4 3 |
4296+
// | 5 4 |
42964297
//->
42974298
// | 3 |
42984299
//->
@@ -4302,7 +4303,7 @@ unittest
43024303
size_t[2] shape45 = [4, 5];
43034304
size_t[2] shape35 = [3, 5];
43044305
size_t[2] shape34 = [3, 4];
4305-
size_t[2] shape43 = [4, 3];
4306+
size_t[2] shape54 = [5, 4];
43064307
size_t[1] shape3 = [3];
43074308
size_t[1] shape4 = [4];
43084309
size_t[1] shape5 = [5];
@@ -4323,7 +4324,7 @@ unittest
43234324
// | 50 51 52 53 54 |
43244325
// | 55 56 57 58 59 |
43254326
// ----------------
4326-
auto x = slice.byDim;
4327+
auto x = slice.byDim!0;
43274328
assert(x.shape == shape3);
43284329
assert(x.front.shape == shape45);
43294330
assert(x.front == iota([4, 5]));
@@ -4410,8 +4411,8 @@ unittest
44104411
// | 19 39 59 |
44114412
// ----------
44124413
auto a = slice.byDim!(2, 1);
4413-
assert(a.shape == shape5);
4414-
assert(a.front.shape == shape43);
4414+
assert(a.shape == shape54);
4415+
assert(a.front.shape == shape4);
44154416
assert(a.front == iota([3, 4], 0, 5).universal.transposed!1);
44164417
a.popFront;
44174418
assert(a.front.front == iota([3], 1, 20));
@@ -4440,7 +4441,7 @@ unittest
44404441
// | 4 5 6 7 |
44414442
// | 8 9 10 11 |
44424443
// ------------
4443-
auto x = slice.byDim;
4444+
auto x = slice.byDim!0;
44444445
assert(x.shape == shape3);
44454446
assert(x.front.shape == shape4);
44464447
assert(x.front == iota(4));
@@ -4484,7 +4485,7 @@ unittest
44844485
// | 4 5 6 7 |
44854486
// | 8 9 10 11 |
44864487
// ------------
4487-
auto x = slice.byDim;
4488+
auto x = slice.byDim!0;
44884489
assert(x.shape == shape3);
44894490
assert(x.front.shape == shape4);
44904491
assert(x.front == iota(4));
@@ -4514,6 +4515,6 @@ unittest
45144515
// | 0 1 2 |
45154516
// -------
45164517
auto slice = iota(3);
4517-
auto x = slice.byDim;
4518+
auto x = slice.byDim!0;
45184519
assert(x == slice);
45194520
}

0 commit comments

Comments
 (0)