@@ -4181,43 +4181,44 @@ See_also:
4181
4181
$(LREF transposed).
4182
4182
+/
4183
4183
template byDim (Dimensions... )
4184
- if (Dimensions.length)
4184
+ if (Dimensions.length > 0 )
4185
4185
{
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
+
4190
4189
static if (! allSatisfy! (isSize_t, Dimensions))
4190
+ {
4191
+ import std.meta : staticMap;
4192
+ import mir.ndslice.internal : toSize_t;
4193
+
4191
4194
alias byDim = .byDim! (staticMap! (toSize_t, Dimensions));
4195
+ }
4192
4196
else
4193
- // /
4194
- @fastmath auto byDim(SliceKind kind, size_t [] packs, Iterator)
4195
- (Slice! (kind, packs, Iterator) slice)
4196
4197
{
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)
4207
4202
{
4208
4203
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
+ }
4210
4218
}
4211
4219
}
4212
4220
}
4213
4221
4214
- // /
4215
- auto byDim (SliceKind kind, size_t [] packs, Iterator)
4216
- (Slice! (kind, packs, Iterator) slice)
4217
- {
4218
- return slice.byDim! 0 ;
4219
- }
4220
-
4221
4222
// / 2-dimensional slice support
4222
4223
@safe @nogc pure nothrow
4223
4224
unittest
@@ -4241,7 +4242,7 @@ unittest
4241
4242
// | 4 5 6 7 |
4242
4243
// | 8 9 10 11 |
4243
4244
// ------------
4244
- auto x = slice.byDim;
4245
+ auto x = slice.byDim! 0 ;
4245
4246
assert (x.shape == shape3);
4246
4247
assert (x.front.shape == shape4);
4247
4248
assert (x.front == iota(4 ));
@@ -4292,7 +4293,7 @@ unittest
4292
4293
// ->
4293
4294
// | 3 4 |
4294
4295
// ->
4295
- // | 4 3 |
4296
+ // | 5 4 |
4296
4297
// ->
4297
4298
// | 3 |
4298
4299
// ->
@@ -4302,7 +4303,7 @@ unittest
4302
4303
size_t [2 ] shape45 = [4 , 5 ];
4303
4304
size_t [2 ] shape35 = [3 , 5 ];
4304
4305
size_t [2 ] shape34 = [3 , 4 ];
4305
- size_t [2 ] shape43 = [4 , 3 ];
4306
+ size_t [2 ] shape54 = [5 , 4 ];
4306
4307
size_t [1 ] shape3 = [3 ];
4307
4308
size_t [1 ] shape4 = [4 ];
4308
4309
size_t [1 ] shape5 = [5 ];
@@ -4323,7 +4324,7 @@ unittest
4323
4324
// | 50 51 52 53 54 |
4324
4325
// | 55 56 57 58 59 |
4325
4326
// ----------------
4326
- auto x = slice.byDim;
4327
+ auto x = slice.byDim! 0 ;
4327
4328
assert (x.shape == shape3);
4328
4329
assert (x.front.shape == shape45);
4329
4330
assert (x.front == iota([4 , 5 ]));
@@ -4410,8 +4411,8 @@ unittest
4410
4411
// | 19 39 59 |
4411
4412
// ----------
4412
4413
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 );
4415
4416
assert (a.front == iota([3 , 4 ], 0 , 5 ).universal.transposed! 1 );
4416
4417
a.popFront;
4417
4418
assert (a.front.front == iota([3 ], 1 , 20 ));
@@ -4440,7 +4441,7 @@ unittest
4440
4441
// | 4 5 6 7 |
4441
4442
// | 8 9 10 11 |
4442
4443
// ------------
4443
- auto x = slice.byDim;
4444
+ auto x = slice.byDim! 0 ;
4444
4445
assert (x.shape == shape3);
4445
4446
assert (x.front.shape == shape4);
4446
4447
assert (x.front == iota(4 ));
@@ -4484,7 +4485,7 @@ unittest
4484
4485
// | 4 5 6 7 |
4485
4486
// | 8 9 10 11 |
4486
4487
// ------------
4487
- auto x = slice.byDim;
4488
+ auto x = slice.byDim! 0 ;
4488
4489
assert (x.shape == shape3);
4489
4490
assert (x.front.shape == shape4);
4490
4491
assert (x.front == iota(4 ));
@@ -4514,6 +4515,6 @@ unittest
4514
4515
// | 0 1 2 |
4515
4516
// -------
4516
4517
auto slice = iota(3 );
4517
- auto x = slice.byDim;
4518
+ auto x = slice.byDim! 0 ;
4518
4519
assert (x == slice);
4519
4520
}
0 commit comments