Mercurial > hg > medcouple
diff jmedcouple.c++ @ 30:2e277129e81b
jmedcouple: whitespace fixes
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Sun, 18 Jan 2015 20:42:25 -0500 |
parents | cf8c8c825c6d |
children | 6c264f2053bc |
line wrap: on
line diff
--- a/jmedcouple.c++ +++ b/jmedcouple.c++ @@ -9,15 +9,15 @@ using namespace std; -template <typename T> +template <typename T> int signum(T val) { - return (T(0) < val) - (val < T(0)); + return (T(0) < val) - (val < T(0)); } template <typename Container, typename Out = typename Container::value_type> 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<double>& X, - double eps1 = numeric_limits<double>::epsilon(), + double eps1 = numeric_limits<double>::epsilon(), double eps2 = numeric_limits<double>::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>()); 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<double> 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<long> L(n_plus, 0); vector<long> 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<long> 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<double>::epsilon(), @@ -241,4 +240,3 @@ return 0; } -