@@ -544,7 +544,7 @@ unittest
544
544
}
545
545
546
546
version (mir_test)
547
- @safe pure @nogc nothrow
547
+ @safe pure nothrow @nogc
548
548
unittest
549
549
{
550
550
import mir.ndslice.slice: sliced;
@@ -816,7 +816,7 @@ unittest
816
816
817
817
// / Arbitrary harmonic mean
818
818
version (mir_test)
819
- @safe pure @nogc nothrow
819
+ @safe pure nothrow @nogc
820
820
unittest
821
821
{
822
822
import mir.math.common: approxEqual;
@@ -830,7 +830,7 @@ unittest
830
830
}
831
831
832
832
version (mir_test)
833
- @safe pure @nogc nothrow
833
+ @safe pure nothrow @nogc
834
834
unittest
835
835
{
836
836
import mir.math.common: approxEqual;
@@ -860,7 +860,7 @@ F nthroot(F)(in F x, in size_t n)
860
860
}
861
861
862
862
version (mir_test)
863
- @safe @nogc pure nothrow
863
+ @safe pure nothrow @nogc
864
864
unittest
865
865
{
866
866
import mir.math.common: approxEqual;
@@ -1221,7 +1221,7 @@ unittest
1221
1221
}
1222
1222
1223
1223
version (mir_test)
1224
- @safe pure @nogc nothrow
1224
+ @safe pure nothrow @nogc
1225
1225
unittest
1226
1226
{
1227
1227
import mir.ndslice.slice: sliced;
@@ -1259,7 +1259,8 @@ 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) @nogc
1262
+ @nogc
1263
+ meanType! F median (Iterator, size_t N, SliceKind kind)(Slice! (Iterator, N, kind) slice)
1263
1264
{
1264
1265
static assert (! allowModify ||
1265
1266
isMutable! (slice.DeepElement),
@@ -1436,6 +1437,23 @@ unittest
1436
1437
assert (x.sliced.median == 2 );
1437
1438
}
1438
1439
1440
+ // withAsSlice test
1441
+ version (mir_test)
1442
+ @safe pure nothrow @nogc
1443
+ unittest
1444
+ {
1445
+ import mir.math.common: approxEqual;
1446
+ import mir.rc.array: RCArray;
1447
+
1448
+ static immutable a = [9.0 , 1 , 0 , 2 , 3 , 4 , 6 , 8 , 7 , 10 , 5 ];
1449
+
1450
+ auto x = RCArray! double (11 );
1451
+ foreach (i, ref e; x)
1452
+ e = a[i];
1453
+
1454
+ assert (x.median.approxEqual(5 ));
1455
+ }
1456
+
1439
1457
/+ +
1440
1458
For integral slices, can pass output type as template parameter to ensure output
1441
1459
type is correct
@@ -1775,6 +1793,38 @@ unittest
1775
1793
assert (x.center.standardDeviation! " assumeZeroMean" .approxEqual(x.standardDeviation));
1776
1794
}
1777
1795
1796
+ // dynamic array test
1797
+ version (mir_test)
1798
+ @safe pure nothrow
1799
+ unittest
1800
+ {
1801
+ import mir.algorithm.iteration: all;
1802
+ import mir.math.common: approxEqual;
1803
+
1804
+ double [] x = [1.0 , 2 , 3 , 4 , 5 , 6 ];
1805
+
1806
+ assert (x.center.all! approxEqual([- 2.5 , - 1.5 , - 0.5 , 0.5 , 1.5 , 2.5 ]));
1807
+ }
1808
+
1809
+ // withAsSlice test
1810
+ version (mir_test)
1811
+ @safe pure nothrow @nogc
1812
+ unittest
1813
+ {
1814
+ import mir.algorithm.iteration: all;
1815
+ import mir.math.common: approxEqual;
1816
+ import mir.rc.array: RCArray;
1817
+
1818
+ static immutable a = [1.0 , 2 , 3 , 4 , 5 , 6 ];
1819
+ static immutable result = [- 2.5 , - 1.5 , - 0.5 , 0.5 , 1.5 , 2.5 ];
1820
+
1821
+ auto x = RCArray! double (6 );
1822
+ foreach (i, ref e; x)
1823
+ e = a[i];
1824
+
1825
+ assert (x.center.all! approxEqual(result));
1826
+ }
1827
+
1778
1828
/+ +
1779
1829
Output range that applies function `fun` to each input before summing
1780
1830
+/
@@ -1836,7 +1886,7 @@ unittest
1836
1886
}
1837
1887
1838
1888
version (mir_test)
1839
- @safe pure @nogc nothrow
1889
+ @safe pure nothrow @nogc
1840
1890
unittest
1841
1891
{
1842
1892
import mir.ndslice.slice: sliced;
@@ -2317,6 +2367,40 @@ unittest
2317
2367
assert (v.variance(PopulationFalseCT).approxEqual(54.76562 / 11 ));
2318
2368
}
2319
2369
2370
+ // dynamic array test
2371
+ version (mir_test)
2372
+ @safe pure nothrow
2373
+ unittest
2374
+ {
2375
+ import mir.math.common: approxEqual;
2376
+ import mir.rc.array: RCArray;
2377
+
2378
+ double [] x = [0.0 , 1.0 , 1.5 , 2.0 , 3.5 , 4.25 ,
2379
+ 2.0 , 7.5 , 5.0 , 1.0 , 1.5 , 0.0 ];
2380
+
2381
+ auto v = VarianceAccumulator! (double , VarianceAlgo.twoPass, Summation.naive)(x);
2382
+ assert (v.centeredSumOfSquares.sum.approxEqual(54.76562 ));
2383
+ }
2384
+
2385
+ // withAsSlice test
2386
+ version (mir_test)
2387
+ @safe pure nothrow @nogc
2388
+ unittest
2389
+ {
2390
+ import mir.math.common: approxEqual;
2391
+ import mir.rc.array: RCArray;
2392
+
2393
+ static immutable a = [0.0 , 1.0 , 1.5 , 2.0 , 3.5 , 4.25 ,
2394
+ 2.0 , 7.5 , 5.0 , 1.0 , 1.5 , 0.0 ];
2395
+
2396
+ auto x = RCArray! double (12 );
2397
+ foreach (i, ref e; x)
2398
+ e = a[i];
2399
+
2400
+ auto v = VarianceAccumulator! (double , VarianceAlgo.twoPass, Summation.naive)(x);
2401
+ assert (v.centeredSumOfSquares.sum.approxEqual(54.76562 ));
2402
+ }
2403
+
2320
2404
// /
2321
2405
struct VarianceAccumulator (T, VarianceAlgo varianceAlgo, Summation summation)
2322
2406
if (isMutable! T && varianceAlgo == VarianceAlgo.assumeZeroMean)
@@ -2872,7 +2956,7 @@ unittest
2872
2956
}
2873
2957
2874
2958
version (mir_test)
2875
- @safe pure @nogc nothrow
2959
+ @safe pure nothrow @nogc
2876
2960
unittest
2877
2961
{
2878
2962
import mir.ndslice.slice: sliced;
0 commit comments