Get rid of non-portable drand48. (#1349)

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

Reviewed By: mdouze

Differential Revision: D23289393

Pulled By: beauby

fbshipit-source-id: a626bbf252ced4ae01abbc3dce4be50d9e628728
This commit is contained in:
Lucas Hosseini
2020-08-24 00:42:21 -07:00
committed by Facebook GitHub Bot
parent 1d4b1571e9
commit c37e71456b
21 changed files with 119 additions and 40 deletions
+8 -2
View File
@@ -9,6 +9,7 @@
#include <cstdlib>
#include <memory>
#include <random>
#include <vector>
#include <gtest/gtest.h>
@@ -19,6 +20,7 @@
#include <faiss/clone_index.h>
#include <faiss/IVFlib.h>
using namespace faiss;
typedef Index::idx_t idx_t;
@@ -47,8 +49,10 @@ int window_size = 10;
std::vector<float> make_data(size_t n)
{
std::vector <float> database (n * d);
std::mt19937 rng;
std::uniform_real_distribution<> distrib;
for (size_t i = 0; i < n * d; i++) {
database[i] = drand48();
database[i] = distrib(rng);
}
return database;
}
@@ -92,8 +96,10 @@ void make_index_slices (const Index* trained_index,
auto xb = make_data(nb * d);
std::vector<faiss::Index::idx_t> ids (nb);
std::mt19937 rng;
std::uniform_int_distribution<> distrib;
for (int j = 0; j < nb; j++) {
ids[j] = lrand48();
ids[j] = distrib(rng);
}
index->add_with_ids (nb, xb.data(), ids.data());
}