mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 07:06:57 +08:00
Switched to Datum for ApplyNorm [skip ci]
This commit is contained in:
@@ -87,15 +87,22 @@ InitCenters(Relation index, VectorArray samples, VectorArray centers, float *low
|
|||||||
* Apply norm to vector
|
* Apply norm to vector
|
||||||
*/
|
*/
|
||||||
static inline void
|
static inline void
|
||||||
ApplyNorm(FmgrInfo *normprocinfo, Oid collation, Vector * vec)
|
ApplyNorm(FmgrInfo *normprocinfo, Oid collation, Datum value, IvfflatType type)
|
||||||
{
|
{
|
||||||
double norm = DatumGetFloat8(FunctionCall1Coll(normprocinfo, collation, PointerGetDatum(vec)));
|
double norm = DatumGetFloat8(FunctionCall1Coll(normprocinfo, collation, value));
|
||||||
|
|
||||||
/* TODO Handle zero norm */
|
/* TODO Handle zero norm */
|
||||||
if (norm > 0)
|
if (norm > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < vec->dim; i++)
|
if (type == IVFFLAT_TYPE_VECTOR)
|
||||||
vec->x[i] /= norm;
|
{
|
||||||
|
Vector *vec = DatumGetVector(value);
|
||||||
|
|
||||||
|
for (int i = 0; i < vec->dim; i++)
|
||||||
|
vec->x[i] /= norm;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
elog(ERROR, "Unsupported type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +135,7 @@ QuickCenters(Relation index, VectorArray samples, VectorArray centers, IvfflatTy
|
|||||||
|
|
||||||
for (int i = 0; i < samples->length; i++)
|
for (int i = 0; i < samples->length; i++)
|
||||||
{
|
{
|
||||||
Datum vec = PointerGetDatum(VectorArrayGet(samples, i));
|
Datum vec = PointerGetDatum(VectorArrayGet(samples, i));
|
||||||
|
|
||||||
if (i == 0 || !datumIsEqual(vec, PointerGetDatum(VectorArrayGet(samples, i - 1)), false, -1))
|
if (i == 0 || !datumIsEqual(vec, PointerGetDatum(VectorArrayGet(samples, i - 1)), false, -1))
|
||||||
{
|
{
|
||||||
@@ -153,7 +160,7 @@ QuickCenters(Relation index, VectorArray samples, VectorArray centers, IvfflatTy
|
|||||||
|
|
||||||
/* Normalize if needed (only needed for random centers) */
|
/* Normalize if needed (only needed for random centers) */
|
||||||
if (normprocinfo != NULL)
|
if (normprocinfo != NULL)
|
||||||
ApplyNorm(normprocinfo, collation, vec);
|
ApplyNorm(normprocinfo, collation, PointerGetDatum(vec), type);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
elog(ERROR, "Unsupported type");
|
elog(ERROR, "Unsupported type");
|
||||||
@@ -451,7 +458,7 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers, IvfflatTyp
|
|||||||
|
|
||||||
/* Normalize if needed */
|
/* Normalize if needed */
|
||||||
if (normprocinfo != NULL)
|
if (normprocinfo != NULL)
|
||||||
ApplyNorm(normprocinfo, collation, vec);
|
ApplyNorm(normprocinfo, collation, PointerGetDatum(vec), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 5 */
|
/* Step 5 */
|
||||||
|
|||||||
Reference in New Issue
Block a user