mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-30 17:51:18 +08:00
Added halfvec_cmp_internal function [skip ci]
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user