Skip to content

Commit a77ad49

Browse files
committed
Remove unnecessary double loop of centroids in hkmeans
1 parent 8f0c3eb commit a77ad49

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/cluster/HierarchicalKMeans.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,11 @@ KMeansIntermediate clusterAndSplit(final FloatVectorValues vectors, final int ta
9595
// TODO: consider adding cluster size counts to the kmeans algo
9696
// handle assignment here so we can track distance and cluster size
9797
int[] centroidVectorCount = new int[centroids.length];
98+
int effectiveK = 0;
9899
for (int assigment : assignments) {
99100
centroidVectorCount[assigment]++;
100-
}
101-
102-
int effectiveK = 0;
103-
for (int j : centroidVectorCount) {
104-
if (j > 0) {
101+
// this cluster has received an assignment, its now effective, but only count it once
102+
if (centroidVectorCount[assigment] == 1) {
105103
effectiveK++;
106104
}
107105
}

0 commit comments

Comments
 (0)