30void compute_wcss(
const Matrix_& data, Cluster_ ncenters,
const Float_* centers,
const Cluster_* clusters, Float_* wcss) {
31 auto nobs = data.num_observations();
32 auto ndim = data.num_dimensions();
33 size_t long_ndim = ndim;
34 std::fill_n(wcss, ncenters, 0);
36 auto work = data.create_workspace(
static_cast<decltype(nobs)
>(0), nobs);
37 for (
decltype(nobs) obs = 0; obs < nobs; ++obs) {
38 auto cen = clusters[obs];
39 auto curcenter = centers +
static_cast<size_t>(cen) * long_ndim;
40 auto& curwcss = wcss[cen];
42 auto curdata = data.get_observation(work);
43 for (
decltype(ndim) dim = 0; dim < ndim; ++dim, ++curcenter, ++curdata) {
44 Float_ delta =
static_cast<Float_
>(*curdata) - *curcenter;
45 curwcss += delta * delta;