From e3354fd95e8dd38d1ccdf601debf40197c55c693 Mon Sep 17 00:00:00 2001 From: "yudong.cai" Date: Thu, 28 Nov 2019 11:15:46 +0800 Subject: [PATCH] #527 update ground truth check --- .../faiss_benchmark/faiss_benchmark_test.cpp | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp b/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp index 0d49004621..9c2a072390 100644 --- a/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp +++ b/core/src/index/unittest/faiss_benchmark/faiss_benchmark_test.cpp @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -#define USE_FAISS_V0_2_1 0 +#define USE_FAISS_V_0_3_0 #include @@ -35,16 +35,20 @@ #include #include -#if USE_FAISS_V0_2_1 +#ifdef USE_FAISS_V_0_3_0 // faiss_0.3.0 + +#include +#include +#include + +#else // faiss_0.2.1 + #include #include #include #include #include -#else -#include -#include -#include + #endif #ifdef CUSTOMIZATION @@ -206,15 +210,11 @@ GetResultHitCount(const faiss::Index::idx_t* ground_index, const faiss::Index::i size_t min_k = std::min(ground_k, k); int hit = 0; for (int i = 0; i < nq; i++) { - // count the num of results exist in ground truth result set - // each result replicates INDEX_ADD_LOOPS times - for (int j_c = 0; j_c < k; j_c++) { - int r_c = index[i * k + j_c]; - for (int j_g = 0; j_g < min_k / index_add_loops; j_g++) { - if (ground_index[i * ground_k + j_g] == r_c) { - hit++; - continue; - } + std::set ground(ground_index + i * ground_k, ground_index + i * ground_k + min_k); + for (int j = 0; j < min_k; j++) { + faiss::Index::idx_t id = index[i * k + j]; + if (ground.count(id) > 0) { + hit++; } } }