# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1421631745 18000 # Node ID 2e277129e81bbeb1b78aa000c712207c80709782 # Parent cf8c8c825c6d8e67c2ac75974c9de1ec9e9ac807 jmedcouple: whitespace fixes diff --git a/jmedcouple.c++ b/jmedcouple.c++ --- a/jmedcouple.c++ +++ b/jmedcouple.c++ @@ -9,15 +9,15 @@ using namespace std; -template +template int signum(T val) { - return (T(0) < val) - (val < T(0)); + return (T(0) < val) - (val < T(0)); } template Out sum(const Container& C) { return accumulate(C.begin(), C.end(), Out()); -} +} /* This computes the weighted median of array A with corresponding @@ -60,16 +60,16 @@ else return trial; } - + return 0; } double medcouple(const std::vector& X, - double eps1 = numeric_limits::epsilon(), + double eps1 = numeric_limits::epsilon(), double eps2 = numeric_limits::min()) { long n = X.size(), n2 = (n - 1)/2; - + if (n < 3) return 0; @@ -77,7 +77,7 @@ sort(Z.begin(), Z.end(), std::greater()); double Zmed; - if (n % 2 == 1) + if (n % 2 == 1) Zmed = Z[n2]; else Zmed = (Z[n2] + Z[n2 + 1])/2; @@ -87,7 +87,7 @@ return -1.0; if (abs(Z[n - 1] - Zmed) < eps1*(eps1 + abs(Zmed))) return 1.0; - + // Centre Z wrt median, so that median(Z) = 0. for_each(Z.begin(), Z.end(), [&](double& z){ z -= Zmed;}); @@ -100,13 +100,13 @@ // These overlap on the entries that are tied with the median vector Zplus, Zminus; - copy_if(Z.begin(), Z.end(), back_inserter(Zplus), + copy_if(Z.begin(), Z.end(), back_inserter(Zplus), [=](double z){return z >= -Zeps;}); - copy_if(Z.begin(), Z.end(), back_inserter(Zminus), + copy_if(Z.begin(), Z.end(), back_inserter(Zminus), [=](double z){return Zeps >= z;}); long - n_plus = Zplus.size(), + n_plus = Zplus.size(), n_minus = Zminus.size(); /* @@ -128,7 +128,7 @@ return h; }; - + // Init left and right borders vector L(n_plus, 0); vector R(n_plus, n_minus - 1); @@ -153,8 +153,8 @@ double Am_eps = eps1*(eps1 + abs(Am)); - //Compute new left and right boundaries, based on the weighted - //median + // Compute new left and right boundaries, based on the weighted + // median vector P(n_plus), Q(n_plus); { @@ -178,7 +178,7 @@ long sumP = sum(P) + n_plus, sumQ = sum(Q); - + if (medc_idx <= sumP - 1) { R = P; Rtot = sumP; @@ -209,7 +209,6 @@ } - int main(int argc, char** argv) { double eps1 = numeric_limits::epsilon(), @@ -241,4 +240,3 @@ return 0; } -