pgvector.git / summary / log / commit / refs
commit c9c6b96eede7d78758ca7ca5db98bf8b24021d0f
Author: Andrew Kane <andrew@ankane.org>
Date: Wed Oct 05 23:11:37 2022 +0000
Added support for Postgres 15 [skip ci]
CHANGELOG.md | 4 ++++
src/ivfbuild.c | 4 ++++
src/ivfkmeans.c | 23 ++++++++++++++++++++---
3 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 88d4adcb..2d7edb97 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/src/ivfbuild.c b/src/ivfbuild.c
index 791cb0b8..6875d229 100644
--- a/src/ivfbuild.c
+++ b/src/ivfbuild.c
@@ -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));
diff --git a/src/ivfkmeans.c b/src/ivfkmeans.c
index 60a07f74..9b13691e 100644
--- a/src/ivfkmeans.c
+++ b/src/ivfkmeans.c
@@ -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 */
[parent: 48e9a6830bae]