// Special case sparse double vectors so that we don't incure a possibly
// log n get operation for each zero value, as that's the common case
// for CompactSparseVector.
if (v instanceof SparseDoubleVector) {
SparseDoubleVector sv = (SparseDoubleVector) v;
int[] nonZeros = sv.getNonZeroIndices();
int sparseIndex = 0;
for (int i = 0; i < c.length(); ++i) {
double value = c.get(i);
if (sparseIndex < nonZeros.length &&
i == nonZeros[sparseIndex])
value -= sv.get(nonZeros[sparseIndex++]);
newCentroid.set(i, value);
}
} else
for (int i = 0; i < c.length(); ++i)