faiss/tests/test_util.h
John Mazanec 12b92e9fa5 Skip HNSWPQ sdc init with new io flag (#3250)
Summary:
## Description

Related issue: https://github.com/facebookresearch/faiss/issues/3246

When reading HNSWPQ from disk, if index ~read only~ new `IO_FLAG_PQ_SKIP_SDC_TABLE` flag is set, skip initializing the sdc_table.

In addition, adds cpp test case verifying functionality and build test util header file to share creation of temporary files amongst tests.

Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3250

Test Plan: buck test //faiss/tests/:test_disable_pq_sdc_tables

Reviewed By: junjieqi

Differential Revision: D53844075

Pulled By: mdouze

fbshipit-source-id: e9a83c0e5243867edbca8f80e3b1242b38ef6a42
2024-03-01 04:27:49 -08:00

40 lines
877 B
C++

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#ifndef FAISS_TEST_UTIL_H
#define FAISS_TEST_UTIL_H
#include <faiss/IndexIVFPQ.h>
#include <unistd.h>
#include <cstdlib>
struct Tempfilename {
pthread_mutex_t* mutex;
std::string filename;
Tempfilename(pthread_mutex_t* mutex, std::string filename) {
this->mutex = mutex;
this->filename = filename;
pthread_mutex_lock(mutex);
int fd = mkstemp(&filename[0]);
close(fd);
pthread_mutex_unlock(mutex);
}
~Tempfilename() {
if (access(filename.c_str(), F_OK)) {
unlink(filename.c_str());
}
}
const char* c_str() {
return filename.c_str();
}
};
#endif // FAISS_TEST_UTIL_H