From 6fed8f1e7842347de0e3f9366ee9558453c79b7f Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Tue, 12 Sep 2023 18:37:56 -0700 Subject: [PATCH] Improved types and scoping for k-means [skip ci] --- src/ivfkmeans.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ivfkmeans.c b/src/ivfkmeans.c index 6073635..7d02b3f 100644 --- a/src/ivfkmeans.c +++ b/src/ivfkmeans.c @@ -181,8 +181,6 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers) float *halfcdist; float *newcdist; int closestCenter; - double dxcx; - double dxc; /* Calculate allocation sizes */ Size samplesSize = VECTOR_ARRAY_SIZE(samples->maxlen, samples->dim); @@ -318,6 +316,8 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers) for (k = 0; k < numCenters; k++) { + float dxcx; + /* Step 3: For all remaining points x and centers c */ if (k == closestCenters[j]) continue; @@ -347,7 +347,7 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers) /* Step 3b */ if (dxcx > lowerBound[j * numCenters + k] || dxcx > halfcdist[closestCenters[j] * numCenters + k]) { - dxc = DatumGetFloat8(FunctionCall2Coll(procinfo, collation, PointerGetDatum(vec), PointerGetDatum(VectorArrayGet(centers, k)))); + float dxc = DatumGetFloat8(FunctionCall2Coll(procinfo, collation, PointerGetDatum(vec), PointerGetDatum(VectorArrayGet(centers, k)))); /* d(x,c) calculated */ lowerBound[j * numCenters + k] = dxc; @@ -361,7 +361,6 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers) changes++; } - } } }