From: John Darrington Date: Fri, 13 Nov 2015 12:57:38 +0000 (+0100) Subject: QUICK CLUSTER: Remove sqrt from Euclidean distance calculations X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=654d2360a1dce57033dbf0030d17522d3c797987;p=pspp QUICK CLUSTER: Remove sqrt from Euclidean distance calculations The Euclidean distance is used only for comparison with other Euclidean distances. Since it is invariant that (sqrt(x) < sqrt(y)) === (x < y) for all non-negative x,y it is a waste of effort calculating the sqrt. --- diff --git a/src/language/stats/quick-cluster.c b/src/language/stats/quick-cluster.c index 4f34e4f0a8..0a2b75de25 100644 --- a/src/language/stats/quick-cluster.c +++ b/src/language/stats/quick-cluster.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include @@ -187,7 +186,7 @@ matrix_mindist (const gsl_matrix *m, int *mn, int *mm) } } - return sqrt (mindist); + return mindist; } @@ -220,7 +219,7 @@ dist_from_case (const struct Kmeans *kmeans, const struct ccase *c, const struct dist += pow2 (gsl_matrix_get (kmeans->centers, which, j) - val->f); } - return sqrt (dist); + return dist; } /* Return the minimum distance of the group WHICH and all other groups */ @@ -247,7 +246,7 @@ min_dist_from (const struct Kmeans *kmeans, const struct qc *qc, int which) } } - return sqrt (mindist); + return mindist; } @@ -349,7 +348,6 @@ kmeans_get_nearest_group (const struct Kmeans *kmeans, struct ccase *c, const st dist += pow2 (gsl_matrix_get (kmeans->centers, i, j) - val->f); } - dist = sqrt (dist); if (dist < mindist0) {