diff --git a/source/dstats/alloc.d b/source/dstats/alloc.d index 905e8d7..5bb70cc 100644 --- a/source/dstats/alloc.d +++ b/source/dstats/alloc.d @@ -118,7 +118,7 @@ public: void popFront() in { assert(!empty); - } body { + } do { this._length--; if(next is null) { do { @@ -149,14 +149,14 @@ public: @property ref Unqual!(K) front() in { assert(!empty); - } body { + } do { return *frontElem; } } else { @property Unqual!(K) front() in { assert(!empty); - } body { + } do { return *frontElem; } } @@ -911,7 +911,7 @@ struct AVLNodeBitwise(T) { void left(typeof(this)* newLeft) nothrow @property in { assert((cast(size_t) newLeft & mask) == 0); - } body { + } do { _left &= mask; _left |= cast(size_t) newLeft; assert(left is newLeft); @@ -928,7 +928,7 @@ struct AVLNodeBitwise(T) { void right(typeof(this)* newRight) nothrow @property in { assert((cast(size_t) newRight & mask) == 0); - } body { + } do { _right &= mask; _right |= cast(size_t) newRight; assert(right is newRight); @@ -1054,7 +1054,7 @@ private: assert(node.left !is null); assert( abs(node.balance) <= 2); - } body { + } do { Node* newHead = node.left; node.left = newHead.right; newHead.right = node; @@ -1070,7 +1070,7 @@ private: in { assert(node.right !is null); assert( abs(node.balance) <= 2); - } body { + } do { Node* newHead = node.right; node.right = newHead.left; newHead.left = node; @@ -1087,7 +1087,7 @@ private: assert(node is null || abs(node.balance) <= 2); } out(ret) { assert( abs(ret.balance) < 2); - } body { + } do { if(node is null) { return null; } @@ -1144,7 +1144,7 @@ private: in { assert(freeList); assert(*freeList); - } body { + } do { auto ret = *freeList; *freeList = ret.right; return ret; @@ -1153,7 +1153,7 @@ private: Node* newNode(T payload) in { assert(freeList, "Uninitialized StackTree!(" ~ T.stringof ~ ")"); - } body { + } do { Node* ret; if(*freeList !is null) { ret = popFreeList(); diff --git a/source/dstats/base.d b/source/dstats/base.d index edfe6a8..783771a 100644 --- a/source/dstats/base.d +++ b/source/dstats/base.d @@ -530,7 +530,7 @@ private void averageTies(T, U)(T sortedInput, U[] ranks, size_t[] perms) in { assert(sortedInput.length == ranks.length); assert(ranks.length == perms.length); -} body { +} do { size_t tieCount = 1; foreach(i; 1..ranks.length) { if(sortedInput[i] == sortedInput[i - 1]) { @@ -856,7 +856,7 @@ unittest { double logNcomb(ulong n, ulong k) in { assert(k <= n); -} body { +} do { if(n < k) return -double.infinity; //Extra parentheses increase numerical accuracy. return logFactorial(n) - (logFactorial(k) + logFactorial(n - k)); @@ -1220,7 +1220,7 @@ public: this(uint n, uint r) in { assert(n >= r); - } body { + } do { if(r > 0) { pos = (seq(0U, r)).ptr; pos[r - 1]--; diff --git a/source/dstats/cor.d b/source/dstats/cor.d index 75b1d10..4d599ae 100644 --- a/source/dstats/cor.d +++ b/source/dstats/cor.d @@ -589,7 +589,7 @@ package KendallLowLevel kendallCorDestructiveLowLevelImpl (R1, R2)(R1 input1, R2 input2, bool needTies) in { assert(input1.length == input2.length); -} body { +} do { static ulong getMs(V)(V data) { //Assumes data is sorted. ulong Ms = 0, tieCount = 0; foreach(i; 1..data.length) { @@ -707,7 +707,7 @@ in { // implementation exists in this module for large N, but when N gets this // large it's not even correct due to overflow errors. assert(input1.length < 1 << 15); -} body { +} do { int m1 = 0, m2 = 0; int s = 0; @@ -1259,7 +1259,7 @@ private void dotMatrix(Matrix)( } assert(ret.rows == rows.length); -} body { +} do { // HACK: Before the multithreaded portion of this algorithm // starts, make sure that there's no need to unshare ret if it's // using ref-counted COW semantics. diff --git a/source/dstats/distrib.d b/source/dstats/distrib.d index ef51a86..d240841 100644 --- a/source/dstats/distrib.d +++ b/source/dstats/distrib.d @@ -228,7 +228,7 @@ enum POISSON_NORMAL = 1UL << 12; // Where to switch to normal approx. private double normApproxPoisCDF(ulong k, double lambda) in { assert(lambda > 0); -} body { +} do { double sd = sqrt(lambda); // mean == lambda. return normalCDF(k + 0.5L, lambda, sd); @@ -278,7 +278,7 @@ unittest { private double normApproxPoisCDFR(ulong k, double lambda) in { assert(lambda > 0); -} body { +} do { double sd = sqrt(lambda); // mean == lambda. return normalCDFR(k - 0.5L, lambda, sd); @@ -403,7 +403,7 @@ private double normApproxBinomCDF(double k, double n, double p) in { assert(k <= n); assert(p >= 0 && p <= 1); -} body { +} do { double mu = p * n; double sd = sqrt( to!double(n) ) * sqrt(p) * sqrt(1 - p); double xCC = k + 0.5L; @@ -482,7 +482,7 @@ private double normApproxBinomCDFR(ulong k, ulong n, double p) in { assert(k <= n); assert(p >= 0 && p <= 1); -} body { +} do { double mu = p * n; double sd = sqrt( to!double(n) ) * sqrt(p) * sqrt(1 - p); double xCC = k - 0.5L; @@ -622,7 +622,7 @@ unittest { double hypergeometricPMF(long x, long n1, long n2, long n) in { assert(x <= n); -} body { +} do { if(x > n1 || x < (n - n2)) { return 0; } diff --git a/source/dstats/regress.d b/source/dstats/regress.d index 0c21d63..f17f889 100644 --- a/source/dstats/regress.d +++ b/source/dstats/regress.d @@ -1304,7 +1304,7 @@ private void shermanMorrisonRidge( assert(lambda > 0); foreach(col; x) assert(col.length == x[0].length); if(x.length) assert(y.length == x[0].length); -} body { +} do { auto alloc = newRegionAllocator(); immutable p = x.length; if(p == 0) return; @@ -2800,7 +2800,7 @@ private double threeDot( ) in { assert(x1.length == x2.length); assert(x2.length == x3.length); -} body { +} do { immutable n = x1.length; auto avec = x1.ptr, bvec = x2.ptr, cvec = x3.ptr; typeof(return) sum0 = 0, sum1 = 0; diff --git a/source/dstats/sort.d b/source/dstats/sort.d index 7ac1bb1..af2011c 100644 --- a/source/dstats/sort.d +++ b/source/dstats/sort.d @@ -344,7 +344,7 @@ in { foreach(array; data[1..$]) { assert(array.length == len); } -} body { +} do { if(data[0].length < 25) { // Skip computing logarithm rather than waiting until qsortImpl to // do this. @@ -481,7 +481,7 @@ in { static if(!is(typeof(array) == ulong*)) assert(array.length == len); } -} body { +} do { if(data[0].length < 65) { //Avoid mem allocation. return insertionSortImpl!(compFun)(data); } @@ -602,7 +602,7 @@ in { static if(!is(typeof(array) == ulong*)) assert(array.length == len); } -} body { +} do { static if(is(T[$ - 1] == ulong*)) { enum dl = data.length - 1; } else { @@ -737,7 +737,7 @@ in { foreach(array; data[1..$]) { assert(array.length == len); } -} body { +} do { auto toSort = prepareForSorting!compFun(data[0]); mergeSortInPlaceImpl!compFun(toSort, data[1..$]); postProcess!compFun(data[0]); @@ -854,7 +854,7 @@ in { foreach(array; data[1..$]) { assert(array.length == len); } -} body { +} do { auto toSort = prepareForSorting!compFun(data[0]); heapSortImpl!compFun(toSort, data[1..$]); postProcess!compFun(data[0]); @@ -944,7 +944,7 @@ in { static if(!is(typeof(array) == ulong*)) assert(array.length == len); } -} body { +} do { auto toSort = prepareForSorting!compFun(data[0]); insertionSortImpl!compFun(toSort, data[1..$]); postProcess!compFun(data[0]); @@ -1111,7 +1111,7 @@ in { foreach(array; data[1..$]) { assert(array.length == len); } -} body { +} do { // Don't use the float-to-int trick because it's actually slower here // because the main part of the algorithm is O(N), not O(N log N). return partitionKImpl!compFun(data, k); @@ -1293,4 +1293,3 @@ unittest { assert(more.getSorted == qsort!("a > b")(nums[0..5])); } } - diff --git a/source/dstats/tests.d b/source/dstats/tests.d index c00af79..5c0528b 100644 --- a/source/dstats/tests.d +++ b/source/dstats/tests.d @@ -1730,7 +1730,7 @@ private double wilcoxonSignedRankPval(double W, ulong N, Alt alt = Alt.twoSided, in { assert(N > 0); assert(tieSum >= 0 || isNaN(tieSum)); -} body { +} do { if(alt == Alt.none) { return double.nan; } @@ -3146,7 +3146,7 @@ private double ksPval(ulong N, ulong Nprime, double D) in { assert(D >= -1); assert(D <= 1); -} body { +} do { return 1 - kolmogorovDistrib(sqrt(cast(double) (N * Nprime) / (N + Nprime)) * abs(D)); } @@ -3154,7 +3154,7 @@ private double ksPval(ulong N, double D) in { assert(D >= -1); assert(D <= 1); -} body { +} do { return 1 - kolmogorovDistrib(abs(D) * sqrt(cast(double) N)); }