#include // bool #include // 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 size_t num_floats, km_rand_t * const rs ) { // 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_fill(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); }