@@ -19,12 +19,12 @@ T4=$(TR $(TDNW $(LREF $1)) $(TD $2) $(TD $3) $(TD $4))
19
19
module mir.math.stat ;
20
20
21
21
import core.lifetime : move;
22
- import mir.ndslice.slice: Slice, SliceKind ;
22
+ import mir.internal.utility: isFloatingPoint ;
23
23
import mir.math.common: fmamath;
24
24
import mir.math.sum;
25
+ import mir.ndslice.slice: Slice, SliceKind;
25
26
import mir.primitives;
26
- import std.traits : isArray, isMutable, isIterable, isIntegral, CommonType;
27
- import mir.internal.utility: isFloatingPoint;
27
+ import std.traits : Unqual, isArray, isMutable, isIterable, isIntegral, CommonType;
28
28
29
29
// /
30
30
package (mir)
@@ -1259,23 +1259,24 @@ template median(F, bool allowModify = false)
1259
1259
Params:
1260
1260
slice = slice
1261
1261
+/
1262
- meanType! F median (Iterator, size_t N, SliceKind kind)(Slice! (Iterator, N, kind) slice)
1262
+ meanType! F median (Iterator, size_t N, SliceKind kind)(Slice! (Iterator, N, kind) slice) @nogc
1263
1263
{
1264
1264
static assert (! allowModify ||
1265
- isMutable! (DeepElementType ! (Slice ! (Iterator, N, kind)) ),
1265
+ isMutable! (slice.DeepElement ),
1266
1266
" allowModify must be false or the input must be mutable" );
1267
1267
alias G = typeof (return );
1268
1268
size_t len = slice.elementCount;
1269
1269
assert (len > 0 , " median: slice must have length greater than zero" );
1270
1270
1271
- import mir.ndslice.topology: flattened;
1271
+ import mir.ndslice.topology: as, flattened;
1272
1272
1273
1273
static if (! allowModify) {
1274
1274
import mir.ndslice.allocation: rcslice;
1275
1275
1276
1276
if (len > 2 ) {
1277
- auto val = slice.rcslice.flattened;
1278
- auto temp = val.lightScope;
1277
+ auto view = slice.lightScope;
1278
+ auto val = view.as! (Unqual! (slice.DeepElement)).rcslice;
1279
+ auto temp = val.lightScope.flattened;
1279
1280
return .median! (G, true )(temp);
1280
1281
} else {
1281
1282
return mean! G(slice);
@@ -1383,6 +1384,15 @@ unittest
1383
1384
assert (x1.median! (float , true ) == 5 );
1384
1385
}
1385
1386
1387
+ version (mir_test)
1388
+ @safe pure nothrow @nogc
1389
+ unittest
1390
+ {
1391
+ import mir.ndslice.slice: sliced;
1392
+ static immutable x = [9.0 , 1 , 0 , 2 , 3 ];
1393
+ assert (x.sliced.median == 2 );
1394
+ }
1395
+
1386
1396
/+ +
1387
1397
For integral slices, can pass output type as template parameter to ensure output
1388
1398
type is correct
0 commit comments