code: protected static double subtractedMagnitudeSqrd(DoubleVector c,
                                                     DoubleVector v) {
          if (v instanceof SparseDoubleVector) {
              SparseDoubleVector sv = (SparseDoubleVector) v;
              int[] nonZeros = sv.getNonZeroIndices();
  
              double magnitude = Math.pow(c.magnitude(), 2);
              for (int i : nonZeros) {
                  double value = c.get(i);
                  magnitude -= Math.pow(value, 2);
                  magnitude += Math.pow(value - v.get(i), 2);
              }
              return magnitude;
          } else {
              double magnitude = 0;
              for (int i = 0; i < c.length(); ++i)
                  magnitude += Math.pow(c.get(i) - v.get(i), 2);
              return magnitude;
          }
      }
docs: Returns the magnitude squared of {@code c} as if {@code v} was added to
  the vector.  We do this because it would be more costly, garbage
  collection wise, to create a new vector for each alternate cluster and
  then throw away all but one of them.