99 size_t clusters_sz =
sizeof(int) * n;
102 weights =
lwalloc(
sizeof(
int) * k);
105 clusters_last =
lwalloc(clusters_sz);
112 memcpy(clusters_last, clusters, clusters_sz);
114 update_r(objs, clusters, n, centers, k);
118 converged = memcmp(clusters_last, clusters, clusters_sz) == 0;
124 lwerror(
"%s did not converge after %d iterations", __func__, i);
void * lwalloc(size_t size)
#define LW_ON_INTERRUPT(x)
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
#define KMEANS_MAX_ITERATIONS
static void update_r(POINT2D **objs, int *clusters, uint32_t n, POINT2D **centers, uint32_t k)
static void update_means(POINT2D **objs, int *clusters, uint32_t n, POINT2D **centers, uint32_t *weights, uint32_t k)