Added halfvec_cmp_internal function [skip ci]

This commit is contained in:
Andrew Kane
2024-04-11 18:33:54 -07:00
parent 7fddd296ee
commit e6a591275a
2 changed files with 28 additions and 0 deletions

View File

@@ -998,3 +998,30 @@ halfvec_subvector(PG_FUNCTION_ARGS)
PG_RETURN_POINTER(result);
}
/*
* Internal helper to compare half vectors
*/
int
halfvec_cmp_internal(HalfVector * a, HalfVector * b)
{
int dim = Min(a->dim, b->dim);
/* Check values before dimensions to be consistent with Postgres arrays */
for (int i = 0; i < dim; i++)
{
if (a->x[i] < b->x[i])
return -1;
if (a->x[i] > b->x[i])
return 1;
}
if (a->dim < b->dim)
return -1;
if (a->dim > b->dim)
return 1;
return 0;
}

View File

@@ -45,5 +45,6 @@ HalfVector *InitHalfVector(int dim);
float HalfToFloat4(half num);
half Float4ToHalf(float num);
half Float4ToHalfUnchecked(float num);
int halfvec_cmp_internal(HalfVector * a, HalfVector * b);
#endif