mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-03 19:20:56 +08:00
Added concatenate operator for vectors
This commit is contained in:
@@ -905,6 +905,30 @@ halfvec_mul(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_POINTER(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Concatenate half vectors
|
||||
*/
|
||||
PGDLLEXPORT PG_FUNCTION_INFO_V1(halfvec_concat);
|
||||
Datum
|
||||
halfvec_concat(PG_FUNCTION_ARGS)
|
||||
{
|
||||
HalfVector *a = PG_GETARG_HALFVEC_P(0);
|
||||
HalfVector *b = PG_GETARG_HALFVEC_P(1);
|
||||
HalfVector *result;
|
||||
int dim = a->dim + b->dim;
|
||||
|
||||
CheckDim(dim);
|
||||
result = InitHalfVector(dim);
|
||||
|
||||
for (int i = 0; i < a->dim; i++)
|
||||
result->x[i] = a->x[i];
|
||||
|
||||
for (int i = 0; i < b->dim; i++)
|
||||
result->x[i + a->dim] = b->x[i];
|
||||
|
||||
PG_RETURN_POINTER(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Quantize a half vector
|
||||
*/
|
||||
|
||||
24
src/vector.c
24
src/vector.c
@@ -916,6 +916,30 @@ vector_mul(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_POINTER(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Concatenate vectors
|
||||
*/
|
||||
PGDLLEXPORT PG_FUNCTION_INFO_V1(vector_concat);
|
||||
Datum
|
||||
vector_concat(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Vector *a = PG_GETARG_VECTOR_P(0);
|
||||
Vector *b = PG_GETARG_VECTOR_P(1);
|
||||
Vector *result;
|
||||
int dim = a->dim + b->dim;
|
||||
|
||||
CheckDim(dim);
|
||||
result = InitVector(dim);
|
||||
|
||||
for (int i = 0; i < a->dim; i++)
|
||||
result->x[i] = a->x[i];
|
||||
|
||||
for (int i = 0; i < b->dim; i++)
|
||||
result->x[i + a->dim] = b->x[i];
|
||||
|
||||
PG_RETURN_POINTER(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Quantize a vector
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user