mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-16 17:32:17 +08:00
Improved HnswNormValue [skip ci]
This commit is contained in:
@@ -94,7 +94,7 @@ pq_sendhalf(StringInfo buf, half h)
|
|||||||
/*
|
/*
|
||||||
* Convert a half to a float4
|
* Convert a half to a float4
|
||||||
*/
|
*/
|
||||||
static float
|
float
|
||||||
HalfToFloat4(half num)
|
HalfToFloat4(half num)
|
||||||
{
|
{
|
||||||
#ifdef FLT16_SUPPORT
|
#ifdef FLT16_SUPPORT
|
||||||
@@ -245,7 +245,7 @@ Float4ToHalfUnchecked(float num)
|
|||||||
/*
|
/*
|
||||||
* Convert a float4 to a half
|
* Convert a float4 to a half
|
||||||
*/
|
*/
|
||||||
static half
|
half
|
||||||
Float4ToHalf(float num)
|
Float4ToHalf(float num)
|
||||||
{
|
{
|
||||||
half result = Float4ToHalfUnchecked(num);
|
half result = Float4ToHalfUnchecked(num);
|
||||||
|
|||||||
@@ -34,5 +34,7 @@ typedef struct HalfVector
|
|||||||
} HalfVector;
|
} HalfVector;
|
||||||
|
|
||||||
HalfVector *InitHalfVector(int dim);
|
HalfVector *InitHalfVector(int dim);
|
||||||
|
float HalfToFloat4(half num);
|
||||||
|
half Float4ToHalf(float num);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ HnswNormValue(FmgrInfo *procinfo, Oid collation, Datum *value, int type)
|
|||||||
HalfVector *result = InitHalfVector(v->dim);
|
HalfVector *result = InitHalfVector(v->dim);
|
||||||
|
|
||||||
for (int i = 0; i < v->dim; i++)
|
for (int i = 0; i < v->dim; i++)
|
||||||
result->x[i] = v->x[i] / norm;
|
result->x[i] = Float4ToHalf(HalfToFloat4(v->x[i]) / norm);
|
||||||
|
|
||||||
*value = PointerGetDatum(result);
|
*value = PointerGetDatum(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user