Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
TestUtils.h
1
2 /**
3 * Copyright (c) 2015-present, Facebook, Inc.
4 * All rights reserved.
5 *
6 * This source code is licensed under the CC-by-NC license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10 // Copyright 2004-present Facebook. All Rights Reserved.
11
12 #pragma once
13
14 #include "../../FaissAssert.h"
15 #include "../../Index.h"
16 #include <initializer_list>
17 #include <memory>
18 #include <string>
19 #include <vector>
20
21 namespace faiss { namespace gpu {
22
23 /// Generates and displays a new seed for the test
24 void newTestSeed();
25
26 /// Uses an explicit seed for the test
27 void setTestSeed(long seed);
28
29 /// Returns the relative error in difference between a and b
30 /// (|a - b| / (0.5 * (|a| + |b|))
31 float relativeError(float a, float b);
32
33 /// Generates a random integer in the range [a, b]
34 int randVal(int a, int b);
35
36 /// Generates a random bool
37 bool randBool();
38
39 /// Select a random value from the given list of values provided as an
40 /// initializer_list
41 template <typename T>
42 T randSelect(std::initializer_list<T> vals) {
43 FAISS_ASSERT(vals.size() > 0);
44 int sel = randVal(0, vals.size());
45
46 int i = 0;
47 for (auto v : vals) {
48 if (i++ == sel) {
49 return v;
50 }
51 }
52
53 // should not get here
54 return *vals.begin();
55 }
56
57 /// Generates a collection of random vectors in the range [0, 1]
58 std::vector<float> randVecs(int num, int dim);
59
60 /// Compare two indices via query for similarity
61 void compareIndices(faiss::Index& refIndex,
62 faiss::Index& testIndex,
63 int numQuery, int dim, int k,
64 const std::string& configMsg,
65 float maxRelativeError = 6e-5f,
66 float pctMaxDiff1 = 0.1f,
67 float pctMaxDiffN = 0.005f);
68
69 /// Display specific differences in the two (distance, index) lists
70 void compareLists(const float* refDist,
71 const faiss::Index::idx_t* refInd,
72 const float* testDist,
73 const faiss::Index::idx_t* testInd,
74 int dim1, int dim2,
75 const std::string& configMsg,
76 bool printBasicStats, bool printDiffs, bool assertOnErr,
77 float maxRelativeError = 6e-5f,
78 float pctMaxDiff1 = 0.1f,
79 float pctMaxDiffN = 0.005f);
80
81 } }
faiss::Index::idx_t
long idx_t
all indices are this type
Definition: Index.h:64
faiss::Index
Definition: Index.h:61