文件 TestUtils.h

namespace faiss

实现了具有多种变体的 k-means 聚类。

版权所有 (c) Facebook, Inc. 及其附属公司。

此源代码根据本源代码树的根目录中的 LICENSE 文件中的 MIT 许可证获得许可。

IDSelector 旨在定义要处理的向量子集(用于删除或作为搜索的子集)

PQ4 SIMD 打包和累积函数

基本内核使用 bbs = nb * 2 * 16 个向量累积 nq 个查询向量,并生成一个用于此的输出矩阵。 对于 nq * nb <= 4 来说很有用,否则寄存器溢出太大。

这些函数的实现分布在 3 个 cpp 文件中,以减少并行编译时间。 模板是显式实例化的。

此文件包含用于计算距离的内核的回调。

在整个库中,向量以 float * 指针的形式提供。 当批量处理(添加/搜索)多个向量时,大多数算法都可以得到优化。 在这种情况下,它们作为矩阵传入。 当大小为 d 的 n 个向量以 float * x 的形式提供时,向量 i 的分量 j 是

x[ i * d + j ]

其中 0 <= i < n 且 0 <= j < d。 换句话说,矩阵始终是紧凑的。 指定矩阵大小时,我们称之为 n*d 矩阵,这意味着行优先存储。

I/O 函数可以读取/写入到文件名、文件句柄或抽象介质的对象。

读取函数返回应使用 delete 释放的对象。 这些对象中的所有引用都归该对象所有。

倒排列表的定义 + 一些实现该接口的常见类。

由于 IVF(倒排文件)索引对于大规模用例非常有用,因此我们将与它们相关的几个函数分组到这个小库中。 大多数函数都适用于 IndexIVF 和嵌入在 IndexPreTransform 中的 IndexIVF。

在此文件中,实现了 L2 和内积之外的额外度量

实现了一些神经网络层,主要为了支持 QINCo

定义了一些对向量集应用转换的对象,通常这些是预处理步骤。

namespace gpu

函数

void newTestSeed()

生成并显示测试的新种子。

void setTestSeed(long seed)

使用显式种子进行测试。

float relativeError(float a, float b)

返回 a 和 b 之间差异的相对误差 (|a - b| / (0.5 * (|a| + |b|))

int randVal(int a, int b)

生成范围 [a, b] 内的随机整数。

bool randBool()

生成一个随机布尔值。

template<typename T>
T randSelect(std::initializer_list<T> vals)

从作为 initializer_list 提供的给定值列表中选择一个随机值

std::vector<float> randVecs(size_t num, size_t dim)

生成范围 [0, 1] 内的随机向量集合。

std::vector<unsigned char> randBinaryVecs(size_t num, size_t dim)

生成随机位向量的集合。

std::vector<float> roundToHalf(const std::vector<float> &v)
void compareIndices(const std::vector<float> &queryVecs, faiss::Index &refIndex, faiss::Index &testIndex, int numQuery, int dim, int k, const std::string &configMsg, float maxRelativeError = 6e-5f, float pctMaxDiff1 = 0.1f, float pctMaxDiffN = 0.005f)

通过查询相似度来比较两个索引,使用用户指定的查询向量集

void compareIndices(faiss::Index &refIndex, faiss::Index &testIndex, int numQuery, int dim, int k, const std::string &configMsg, float maxRelativeError = 6e-5f, float pctMaxDiff1 = 0.1f, float pctMaxDiffN = 0.005f)

通过查询相似度来比较两个索引,生成随机查询向量

void compareLists(const float *refDist, const faiss::idx_t *refInd, const float *testDist, const faiss::idx_t *testInd, int dim1, int dim2, const std::string &configMsg, bool printBasicStats, bool printDiffs, bool assertOnErr, float maxRelativeError = 6e-5f, float pctMaxDiff1 = 0.1f, float pctMaxDiffN = 0.005f)

显示两个(距离,索引)列表中的特定差异。

template<typename A, typename B>
void testIVFEquality(A &cpuIndex, B &gpuIndex)

比较CPU和GPU索引之间的IVF列表。