Moved type check out of loop [skip ci]

This commit is contained in:
Andrew Kane
2024-04-11 20:31:27 -07:00
parent 1bc6f954f4
commit fea2eb262e

View File

@@ -473,31 +473,35 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers, IvfflatTyp
centerCounts[j] = 0; centerCounts[j] = 0;
} }
for (int64 j = 0; j < numSamples; j++) /* Increment sum of closest center */
if (type == IVFFLAT_TYPE_VECTOR)
{ {
int closestCenter = closestCenters[j]; for (int j = 0; j < numSamples; j++)
Vector *aggCenter = (Vector *) VectorArrayGet(aggCenters, closestCenter);
/* Increment sum and count of closest center */
if (type == IVFFLAT_TYPE_VECTOR)
{ {
Vector *aggCenter = (Vector *) VectorArrayGet(aggCenters, closestCenters[j]);
Vector *vec = (Vector *) VectorArrayGet(samples, j); Vector *vec = (Vector *) VectorArrayGet(samples, j);
for (int k = 0; k < dimensions; k++) for (int k = 0; k < dimensions; k++)
aggCenter->x[k] += vec->x[k]; aggCenter->x[k] += vec->x[k];
} }
else if (type == IVFFLAT_TYPE_HALFVEC) }
else if (type == IVFFLAT_TYPE_HALFVEC)
{
for (int j = 0; j < numSamples; j++)
{ {
Vector *aggCenter = (Vector *) VectorArrayGet(aggCenters, closestCenters[j]);
HalfVector *vec = (HalfVector *) VectorArrayGet(samples, j); HalfVector *vec = (HalfVector *) VectorArrayGet(samples, j);
for (int k = 0; k < dimensions; k++) for (int k = 0; k < dimensions; k++)
aggCenter->x[k] += HalfToFloat4(vec->x[k]); aggCenter->x[k] += HalfToFloat4(vec->x[k]);
} }
else
elog(ERROR, "Unsupported type");
centerCounts[closestCenter] += 1;
} }
else
elog(ERROR, "Unsupported type");
/* Increment count of closest center */
for (int j = 0; j < numSamples; j++)
centerCounts[closestCenters[j]] += 1;
for (int j = 0; j < numCenters; j++) for (int j = 0; j < numCenters; j++)
{ {