未验证 提交 ad352b7f 编写于 作者: M Marius Muja 提交者: GitHub

Merge pull request #392 from greenbrettmichael/greenbrettmichael/fix_for_c17_support

support c++17
......@@ -37,6 +37,7 @@
#include <cstring>
#include <stdarg.h>
#include <cmath>
#include <random>
#include "flann/general.h"
#include "flann/algorithms/nn_index.h"
......@@ -265,7 +266,9 @@ protected:
/* Construct the randomized trees. */
for (int i = 0; i < trees_; i++) {
/* Randomize the order of vectors to allow for unbiased sampling. */
std::random_shuffle(ind.begin(), ind.end());
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(ind.begin(), ind.end(), g);
tree_roots_[i] = divideTree(&ind[0], int(size_) );
}
delete[] mean_;
......
......@@ -105,8 +105,11 @@ public:
count = 0;
}
struct CompareT : public std::binary_function<T,T,bool>
struct CompareT
{
typedef T first_argument_type;
typedef T second_argument_type;
typedef bool result_type;
bool operator()(const T& t_1, const T& t_2) const
{
return t_2 < t_1;
......
......@@ -39,6 +39,7 @@
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <random>
// TODO as soon as we use C++0x, use the code in USE_UNORDERED_MAP
#if USE_UNORDERED_MAP
#include <unordered_map>
......@@ -363,7 +364,9 @@ inline LshTable<unsigned char>::LshTable(unsigned int feature_size, unsigned int
// A bit brutal but fast to code
std::vector<size_t> indices(feature_size * CHAR_BIT);
for (size_t i = 0; i < feature_size * CHAR_BIT; ++i) indices[i] = i;
std::random_shuffle(indices.begin(), indices.end());
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(indices.begin(), indices.end(),g);
// Generate a random set of order of subsignature_size_ bits
for (unsigned int i = 0; i < key_size_; ++i) {
......
......@@ -34,6 +34,7 @@
#include <algorithm>
#include <cstdlib>
#include <cstddef>
#include <random>
#include <vector>
#include "flann/general.h"
......@@ -50,9 +51,6 @@ inline void seed_random(unsigned int seed)
srand(seed);
}
/*
* Generates a random double value.
*/
/**
* Generates a random double value.
* @param high Upper limit
......@@ -61,7 +59,7 @@ inline void seed_random(unsigned int seed)
*/
inline double rand_double(double high = 1.0, double low = 0)
{
return low + ((high-low) * (std::rand() / (RAND_MAX + 1.0)));
return low + ((high - low) * (std::rand() / (RAND_MAX + 1.0)));
}
/**
......@@ -72,17 +70,10 @@ inline double rand_double(double high = 1.0, double low = 0)
*/
inline int rand_int(int high = RAND_MAX, int low = 0)
{
return low + (int) ( double(high-low) * (std::rand() / (RAND_MAX + 1.0)));
return low + (int)(double(high - low) * (std::rand() / (RAND_MAX + 1.0)));
}
class RandomGenerator
{
public:
ptrdiff_t operator() (ptrdiff_t i) { return rand_int(i); }
};
/**
* Random number generator that returns a distinct number from
* the [0,n) interval each time.
......@@ -110,14 +101,14 @@ public:
*/
void init(int n)
{
static RandomGenerator generator;
// create and initialize an array of size n
vals_.resize(n);
size_ = n;
for (int i = 0; i < size_; ++i) vals_[i] = i;
// shuffle the elements in the array
std::random_shuffle(vals_.begin(), vals_.end(), generator);
std::random_device rd;
std::mt19937 g(rd());
std::shuffle(vals_.begin(), vals_.end(), g);
counter_ = 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册