mirror of
https://github.com/pgvector/pgvector.git
synced 2026-12-04 08:18:46 +00:00
Merge branch 'master' into e-means
This commit is contained in:
commit
39004e72ac
3 files changed
+27
-13
No files matched your search
+1
-4
@@ -68,10 +68,7 @@ AddSample(Datum *values, IvfflatBuildState * buildstate)
|
||||
}
|
||||
|
||||
if (samples->length < targsamples)
|
||||
{
|
||||
VectorArraySet(samples, samples->length, DatumGetPointer(value));
|
||||
samples->length++;
|
||||
}
|
||||
VectorArrayAdd(samples, DatumGetPointer(value));
|
||||
else
|
||||
{
|
||||
if (buildstate->rowstoskip < 0)
|
||||
|
||||
+24
-3
@@ -324,22 +324,43 @@ static inline Pointer
|
||||
VectorArrayGet(VectorArray arr, int offset)
|
||||
{
|
||||
/* Safety check */
|
||||
if (offset < 0 || offset >= arr->maxlen)
|
||||
if (offset < 0 || offset >= arr->length)
|
||||
elog(ERROR, "index out of bounds");
|
||||
|
||||
return ((char *) arr->items) + (offset * arr->itemsize);
|
||||
}
|
||||
|
||||
static inline void
|
||||
VectorArraySet(VectorArray arr, int offset, Pointer val)
|
||||
VectorArraySetUncheckedLength(VectorArray arr, int offset, Pointer val)
|
||||
{
|
||||
Size size = VARSIZE_ANY(val);
|
||||
|
||||
/* Safety check */
|
||||
if (offset < 0 || offset >= arr->maxlen)
|
||||
elog(ERROR, "index out of bounds");
|
||||
|
||||
/* Safety check */
|
||||
if (size > arr->itemsize)
|
||||
elog(ERROR, "item too large");
|
||||
|
||||
memcpy(VectorArrayGet(arr, offset), val, size);
|
||||
memcpy(((char *) arr->items) + (offset * arr->itemsize), val, size);
|
||||
}
|
||||
|
||||
static inline void
|
||||
VectorArraySet(VectorArray arr, int offset, Pointer val)
|
||||
{
|
||||
/* Safety check */
|
||||
if (offset >= arr->length)
|
||||
elog(ERROR, "index out of bounds");
|
||||
|
||||
VectorArraySetUncheckedLength(arr, offset, val);
|
||||
}
|
||||
|
||||
static inline void
|
||||
VectorArrayAdd(VectorArray arr, Pointer val)
|
||||
{
|
||||
VectorArraySetUncheckedLength(arr, arr->length, val);
|
||||
arr->length++;
|
||||
}
|
||||
|
||||
/* Methods */
|
||||
|
||||
+2
-6
@@ -42,14 +42,12 @@ RandomCenters(Relation index, VectorArray centers, int dimensions, const Ivfflat
|
||||
/* Fill with random data */
|
||||
while (centers->length < centers->maxlen)
|
||||
{
|
||||
Pointer center = VectorArrayGet(centers, centers->length);
|
||||
Pointer center = VectorArrayGet(centers, centers->length++);
|
||||
|
||||
for (int i = 0; i < dimensions; i++)
|
||||
x[i] = (float) RandomDouble();
|
||||
|
||||
typeInfo->updateCenter(center, dimensions, x);
|
||||
|
||||
centers->length++;
|
||||
}
|
||||
|
||||
if (normprocinfo != NULL)
|
||||
@@ -100,9 +98,7 @@ RandomChoice(VectorArray samples, VectorArray centers)
|
||||
|
||||
/* TODO Handle less samples than centers */
|
||||
for (int i = 0; i < centers->maxlen; i++)
|
||||
VectorArraySet(centers, i, VectorArrayGet(samples, i < samples->length ? i : 0));
|
||||
|
||||
centers->length = centers->maxlen;
|
||||
VectorArrayAdd(centers, VectorArrayGet(samples, i < samples->length ? i : 0));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in new issue
Block a user