Moved overflow check

This commit is contained in:
Andrew Kane
2023-06-04 13:37:31 -07:00
parent 8294a0a562
commit b6430bae62

View File

@@ -398,9 +398,6 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers)
if (centerCounts[j] > 0) if (centerCounts[j] > 0)
{ {
for (k = 0; k < dimensions; k++)
vec->x[k] /= centerCounts[j];
/* Double avoids overflow, but requires more memory */ /* Double avoids overflow, but requires more memory */
/* TODO Update bounds */ /* TODO Update bounds */
for (k = 0; k < dimensions; k++) for (k = 0; k < dimensions; k++)
@@ -408,6 +405,9 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers)
if (isinf(vec->x[k])) if (isinf(vec->x[k]))
vec->x[k] = vec->x[k] > 0 ? FLT_MAX : -FLT_MAX; vec->x[k] = vec->x[k] > 0 ? FLT_MAX : -FLT_MAX;
} }
for (k = 0; k < dimensions; k++)
vec->x[k] /= centerCounts[j];
} }
else else
{ {