aboutsummaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'util.h')
-rw-r--r--util.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/util.h b/util.h
index fa54ce0..821c3e6 100644
--- a/util.h
+++ b/util.h
@@ -21,6 +21,23 @@
exit(EXIT_FAILURE); \
} while (0)
+// calculate squared euclidean distance between two points
+static inline float
+distance_squared(
+ const size_t num_floats,
+ const float * const a,
+ const float * const b
+) {
+ float r = 0.0;
+
+ for (size_t i = 0; i < num_floats; i++) {
+ r += (b[i] - a[i]) * (b[i] - a[i]);
+ }
+
+ // return squared distance
+ return r;
+}
+
static inline float
km_score(
const float mean_distance,