Improved HnswNormValue [skip ci]

This commit is contained in:
Andrew Kane
2024-03-27 17:19:58 -07:00
parent e2978d1365
commit 6eedf78c25
3 changed files with 5 additions and 3 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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);
} }