The latter seems ok actually but gcc doesn't know ereport never returns. Better to fix anyway. Reported and patch by Josh Kupershmidt.
The previous method was to assign input vectors to centroids from head. It is of course important that each initial centroid is correspond to either of input vector, so that the result will be balanced. So, the new method is to split the vector space made by all the inputs into k pieaces and assign nearest input to the centroid.