pgvector.git / summary / log / commit / refs
commit 2913c9f0b68efdafdf697f5e72a0d23fa21373fa
Author: Andrew Kane <andrew@ankane.org>
Date: Mon Apr 15 17:35:16 2024 +0000
Moved vector L1 distance to separate function [skip ci]
src/vector.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/src/vector.c b/src/vector.c
index b0f6e69f..73ae2780 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -728,6 +728,18 @@ vector_spherical_distance(PG_FUNCTION_ARGS)
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
*/
@@ -737,17 +749,10 @@ l1_distance(PG_FUNCTION_ARGS)
{
Vector *a = PG_GETARG_VECTOR_P(0);
Vector *b = PG_GETARG_VECTOR_P(1);
- float *ax = a->x;
- float *bx = b->x;
- float distance = 0.0;
CheckDims(a, b);
- /* Auto-vectorized */
- for (int i = 0; i < a->dim; i++)
- distance += fabsf(ax[i] - bx[i]);
-
- PG_RETURN_FLOAT8((double) distance);
+ PG_RETURN_FLOAT8((double) VectorL1Distance(a->dim, a->x, b->x));
}
/*
[parent: fac88d0fd4e9]