mirror of
https://github.com/pgvector/pgvector.git
synced 2026-06-06 05:51:21 +08:00
Add autovectorized implementation of binary quantize
This commit is contained in:
committed by
Andrew Kane
parent
30382418da
commit
0c9070ba82
12
src/vector.c
12
src/vector.c
@@ -946,8 +946,18 @@ binary_quantize(PG_FUNCTION_ARGS)
|
||||
float *ax = a->x;
|
||||
VarBit *result = InitBitVector(a->dim);
|
||||
unsigned char *rx = VARBITS(result);
|
||||
int i;
|
||||
int count = (a->dim / 8) * 8;
|
||||
unsigned char result_byte;
|
||||
|
||||
for (int i = 0; i < a->dim; i++)
|
||||
for (i = 0; i < count; i += 8)
|
||||
{
|
||||
result_byte = 0;
|
||||
for (int j = 0; j < 8; j++)
|
||||
result_byte |= (ax[i + j] > 0) << (7 - j);
|
||||
rx[i / 8] = result_byte;
|
||||
}
|
||||
for (; i < a->dim; i++)
|
||||
rx[i / 8] |= (ax[i] > 0) << (7 - (i % 8));
|
||||
|
||||
PG_RETURN_VARBIT_P(result);
|
||||
|
||||
Reference in New Issue
Block a user