mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-06 12:40:56 +08:00
Moved vector L1 distance to separate function [skip ci]
This commit is contained in:
21
src/vector.c
21
src/vector.c
@@ -728,6 +728,18 @@ vector_spherical_distance(PG_FUNCTION_ARGS)
|
|||||||
PG_RETURN_FLOAT8(acos(distance) / M_PI);
|
PG_RETURN_FLOAT8(acos(distance) / M_PI);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float
|
||||||
|
VectorL1Distance(int dim, float *ax, float *bx)
|
||||||
|
{
|
||||||
|
float distance = 0.0;
|
||||||
|
|
||||||
|
/* Auto-vectorized */
|
||||||
|
for (int i = 0; i < dim; i++)
|
||||||
|
distance += fabsf(ax[i] - bx[i]);
|
||||||
|
|
||||||
|
return distance;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the L1 distance between two vectors
|
* Get the L1 distance between two vectors
|
||||||
*/
|
*/
|
||||||
@@ -737,17 +749,10 @@ l1_distance(PG_FUNCTION_ARGS)
|
|||||||
{
|
{
|
||||||
Vector *a = PG_GETARG_VECTOR_P(0);
|
Vector *a = PG_GETARG_VECTOR_P(0);
|
||||||
Vector *b = PG_GETARG_VECTOR_P(1);
|
Vector *b = PG_GETARG_VECTOR_P(1);
|
||||||
float *ax = a->x;
|
|
||||||
float *bx = b->x;
|
|
||||||
float distance = 0.0;
|
|
||||||
|
|
||||||
CheckDims(a, b);
|
CheckDims(a, b);
|
||||||
|
|
||||||
/* Auto-vectorized */
|
PG_RETURN_FLOAT8((double) VectorL1Distance(a->dim, a->x, b->x));
|
||||||
for (int i = 0; i < a->dim; i++)
|
|
||||||
distance += fabsf(ax[i] - bx[i]);
|
|
||||||
|
|
||||||
PG_RETURN_FLOAT8((double) distance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user