mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-01 10:11:20 +08:00
Added support for Postgres 15 [skip ci]
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
## 0.3.0 (unreleased)
|
||||
|
||||
- Added support for Postgres 15
|
||||
|
||||
## 0.2.7 (2022-07-31)
|
||||
|
||||
- Fixed `unexpected data beyond EOF` error
|
||||
|
||||
@@ -80,7 +80,11 @@ SampleCallback(Relation index, CALLBACK_ITEM_POINTER, Datum *values,
|
||||
|
||||
if (buildstate->rowstoskip <= 0)
|
||||
{
|
||||
#if PG_VERSION_NUM >= 150000
|
||||
int k = (int) (targsamples * sampler_random_fract(&buildstate->rstate.randstate));
|
||||
#else
|
||||
int k = (int) (targsamples * sampler_random_fract(buildstate->rstate.randstate));
|
||||
#endif
|
||||
|
||||
Assert(k >= 0 && k < targsamples);
|
||||
VectorArraySet(samples, k, DatumGetVector(value));
|
||||
|
||||
@@ -5,6 +5,23 @@
|
||||
#include "ivfflat.h"
|
||||
#include "miscadmin.h"
|
||||
|
||||
#if PG_VERSION_NUM >= 150000
|
||||
#include "common/pg_prng.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Random double
|
||||
*/
|
||||
static inline double
|
||||
RandomDouble()
|
||||
{
|
||||
#if PG_VERSION_NUM >= 150000
|
||||
return pg_prng_double(&pg_global_prng_state);
|
||||
#else
|
||||
return (((double) random()) / MAX_RANDOM_VALUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize with kmeans++
|
||||
*
|
||||
@@ -66,7 +83,7 @@ InitCenters(Relation index, VectorArray samples, VectorArray centers, float *low
|
||||
break;
|
||||
|
||||
/* Choose new center using weighted probability distribution. */
|
||||
choice = sum * (((double) random()) / MAX_RANDOM_VALUE);
|
||||
choice = sum * RandomDouble();
|
||||
for (j = 0; j < numSamples - 1; j++)
|
||||
{
|
||||
choice -= weight[j];
|
||||
@@ -145,7 +162,7 @@ QuickCenters(Relation index, VectorArray samples, VectorArray centers)
|
||||
vec->dim = dimensions;
|
||||
|
||||
for (j = 0; j < dimensions; j++)
|
||||
vec->x[j] = ((double) random()) / MAX_RANDOM_VALUE;
|
||||
vec->x[j] = RandomDouble();
|
||||
|
||||
/* Normalize if needed (only needed for random centers) */
|
||||
if (normprocinfo != NULL)
|
||||
@@ -403,7 +420,7 @@ ElkanKmeans(Relation index, VectorArray samples, VectorArray centers)
|
||||
{
|
||||
/* TODO Handle empty centers properly */
|
||||
for (k = 0; k < dimensions; k++)
|
||||
vec->x[k] = ((double) random()) / MAX_RANDOM_VALUE;
|
||||
vec->x[k] = RandomDouble();
|
||||
}
|
||||
|
||||
/* Normalize if needed */
|
||||
|
||||
Reference in New Issue
Block a user