mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-03 03:00:56 +08:00
Added concatenate operator for vectors
This commit is contained in:
25
src/vector.c
25
src/vector.c
@@ -1160,3 +1160,28 @@ vector_avg(PG_FUNCTION_ARGS)
|
||||
|
||||
PG_RETURN_POINTER(result);
|
||||
}
|
||||
|
||||
/*
|
||||
* Concat 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user