@@ -92,7 +92,7 @@ InitCenters(Relation index, VectorArray samples, VectorArray centers, float *low
9292 * Norm centers
9393 */
9494static void
95- NormCenters (FmgrInfo * normalizeprocinfo , Oid collation , VectorArray centers )
95+ NormCenters (const IvfflatTypeInfo * typeInfo , Oid collation , VectorArray centers )
9696{
9797 MemoryContext normCtx = AllocSetContextCreate (CurrentMemoryContext ,
9898 "Ivfflat norm temporary context" ,
@@ -102,7 +102,7 @@ NormCenters(FmgrInfo *normalizeprocinfo, Oid collation, VectorArray centers)
102102 for (int j = 0 ; j < centers -> length ; j ++ )
103103 {
104104 Datum center = PointerGetDatum (VectorArrayGet (centers , j ));
105- Datum newCenter = IvfflatNormValue (normalizeprocinfo , collation , center );
105+ Datum newCenter = IvfflatNormValue (typeInfo , collation , center );
106106 Size size = VARSIZE_ANY (DatumGetPointer (newCenter ));
107107
108108 if (size > centers -> itemsize )
@@ -123,9 +123,8 @@ static void
123123RandomCenters (Relation index , VectorArray centers , const IvfflatTypeInfo * typeInfo )
124124{
125125 int dimensions = centers -> dim ;
126- Oid collation = index -> rd_indcollation [0 ];
127126 FmgrInfo * normprocinfo = IvfflatOptionalProcInfo (index , IVFFLAT_KMEANS_NORM_PROC );
128- FmgrInfo * normalizeprocinfo = IvfflatOptionalProcInfo ( index , IVFFLAT_NORMALIZE_PROC ) ;
127+ Oid collation = index -> rd_indcollation [ 0 ] ;
129128 float * x = (float * ) palloc (sizeof (float ) * dimensions );
130129
131130 /* Fill with random data */
@@ -142,7 +141,7 @@ RandomCenters(Relation index, VectorArray centers, const IvfflatTypeInfo * typeI
142141 }
143142
144143 if (normprocinfo != NULL )
145- NormCenters (normalizeprocinfo , collation , centers );
144+ NormCenters (typeInfo , collation , centers );
146145
147146 pfree (x );
148147}
@@ -196,7 +195,7 @@ UpdateCenters(float *agg, VectorArray centers, const IvfflatTypeInfo * typeInfo)
196195 * Compute new centers
197196 */
198197static void
199- ComputeNewCenters (VectorArray samples , float * agg , VectorArray newCenters , int * centerCounts , int * closestCenters , FmgrInfo * normprocinfo , FmgrInfo * normalizeprocinfo , Oid collation , const IvfflatTypeInfo * typeInfo )
198+ ComputeNewCenters (VectorArray samples , float * agg , VectorArray newCenters , int * centerCounts , int * closestCenters , FmgrInfo * normprocinfo , Oid collation , const IvfflatTypeInfo * typeInfo )
200199{
201200 int dimensions = newCenters -> dim ;
202201 int numCenters = newCenters -> length ;
@@ -251,7 +250,7 @@ ComputeNewCenters(VectorArray samples, float *agg, VectorArray newCenters, int *
251250
252251 /* Normalize if needed */
253252 if (normprocinfo != NULL )
254- NormCenters (normalizeprocinfo , collation , newCenters );
253+ NormCenters (typeInfo , collation , newCenters );
255254}
256255
257256/*
@@ -267,7 +266,6 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers, const Ivff
267266{
268267 FmgrInfo * procinfo ;
269268 FmgrInfo * normprocinfo ;
270- FmgrInfo * normalizeprocinfo ;
271269 Oid collation ;
272270 int dimensions = centers -> dim ;
273271 int numCenters = centers -> maxlen ;
@@ -315,7 +313,6 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers, const Ivff
315313 /* Set support functions */
316314 procinfo = index_getprocinfo (index , 1 , IVFFLAT_KMEANS_DISTANCE_PROC );
317315 normprocinfo = IvfflatOptionalProcInfo (index , IVFFLAT_KMEANS_NORM_PROC );
318- normalizeprocinfo = IvfflatOptionalProcInfo (index , IVFFLAT_NORMALIZE_PROC );
319316 collation = index -> rd_indcollation [0 ];
320317
321318 /* Use memory context */
@@ -477,7 +474,7 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers, const Ivff
477474 }
478475
479476 /* Step 4: For each center c, let m(c) be mean of all points assigned */
480- ComputeNewCenters (samples , agg , newCenters , centerCounts , closestCenters , normprocinfo , normalizeprocinfo , collation , typeInfo );
477+ ComputeNewCenters (samples , agg , newCenters , centerCounts , closestCenters , normprocinfo , collation , typeInfo );
481478
482479 /* Step 5 */
483480 for (int j = 0 ; j < numCenters ; j ++ )
0 commit comments