aboutsummaryrefslogtreecommitdiff
path: root/km-init-rand.c
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2019-02-05 00:22:15 -0500
committerPaul Duncan <pabs@pablotron.org>2019-02-05 00:22:15 -0500
commitf557d1f49a2914c6084dd18efc783395228d8ce0 (patch)
tree51111fc899f01956cbab948b87c241478576870d /km-init-rand.c
parentb5065ea43cb13c0b553874305b53963176c70f59 (diff)
downloadkmeans-f557d1f49a2914c6084dd18efc783395228d8ce0.tar.bz2
kmeans-f557d1f49a2914c6084dd18efc783395228d8ce0.zip
mv *.[hc] src/
Diffstat (limited to 'km-init-rand.c')
-rw-r--r--km-init-rand.c43
1 files changed, 0 insertions, 43 deletions
diff --git a/km-init-rand.c b/km-init-rand.c
deleted file mode 100644
index 1f59da8..0000000
--- a/km-init-rand.c
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <stdbool.h> // bool
-#include <string.h> // memset()
-#include "util.h"
-#include "km.h"
-
-// init a set with num_clusters clusters of shape num_floats by picking
-// random cluster centers
-bool
-km_init_rand(
- km_set_t * const cs,
- const size_t num_clusters,
- const km_set_t * const set,
- km_rand_t * const rs
-) {
- // get number of floats from data set
- const size_t num_floats = set->shape.num_floats;
-
- // init cluster shape
- const km_shape_t shape = {
- .num_floats = num_floats,
- .num_ints = 1,
- };
-
- // generate random cluster centers
- float floats[num_floats * num_clusters];
- if (!km_rand_get_floats(rs, num_floats * num_clusters, floats)) {
- // return failure
- return false;
- }
-
- // FIXME: should probably be heap-allocated
- int ints[num_clusters];
- memset(ints, 0, sizeof(ints));
-
- // init cluster set
- if (!km_set_init(cs, &shape, num_clusters)) {
- // return failure
- return false;
- }
-
- // add data, return result
- return km_set_push(cs, num_clusters, floats, ints);
-}