This commit is contained in:
@@ -224,8 +224,8 @@ private:
|
||||
float totalCost;
|
||||
};
|
||||
|
||||
typedef pair<CostData, KDTreeIndexParams> KDTreeCostData;
|
||||
typedef pair<CostData, KMeansIndexParams> KMeansCostData;
|
||||
typedef std::pair<CostData, KDTreeIndexParams> KDTreeCostData;
|
||||
typedef std::pair<CostData, KMeansIndexParams> KMeansCostData;
|
||||
|
||||
|
||||
void evaluate_kmeans(CostData& cost, const KMeansIndexParams& kmeans_params)
|
||||
@@ -338,7 +338,7 @@ private:
|
||||
|
||||
int kmeansParamSpaceSize = ARRAY_LEN(maxIterations)*ARRAY_LEN(branchingFactors);
|
||||
|
||||
vector<KMeansCostData> kmeansCosts(kmeansParamSpaceSize);
|
||||
std::vector<KMeansCostData> kmeansCosts(kmeansParamSpaceSize);
|
||||
|
||||
// CostData* kmeansCosts = new CostData[kmeansParamSpaceSize];
|
||||
|
||||
@@ -417,7 +417,7 @@ private:
|
||||
int testTrees[] = { 1, 4, 8, 16, 32 };
|
||||
|
||||
size_t kdtreeParamSpaceSize = ARRAY_LEN(testTrees);
|
||||
vector<KDTreeCostData> kdtreeCosts(kdtreeParamSpaceSize);
|
||||
std::vector<KDTreeCostData> kdtreeCosts(kdtreeParamSpaceSize);
|
||||
|
||||
// evaluate kdtree for all parameter combinations
|
||||
int cnt = 0;
|
||||
@@ -484,7 +484,7 @@ private:
|
||||
IndexParams* estimateBuildParams()
|
||||
{
|
||||
int sampleSize = int(index_params.sample_fraction*dataset.rows);
|
||||
int testSampleSize = min(sampleSize/10, 1000);
|
||||
int testSampleSize = std::min(sampleSize/10, 1000);
|
||||
|
||||
logger().info("Entering autotuning, dataset size: %d, sampleSize: %d, testSampleSize: %d\n",dataset.rows, sampleSize, testSampleSize);
|
||||
|
||||
@@ -550,7 +550,7 @@ private:
|
||||
|
||||
float speedup = 0;
|
||||
|
||||
int samples = (int)min(dataset.rows/10, SAMPLE_COUNT);
|
||||
int samples = (int)std::min(dataset.rows/10, SAMPLE_COUNT);
|
||||
if (samples>0) {
|
||||
Matrix<ELEM_TYPE> testDataset = random_sample(dataset,samples);
|
||||
|
||||
|
@@ -32,7 +32,6 @@
|
||||
#define _OPENCV_DIST_H_
|
||||
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
|
||||
#include "opencv2/flann/general.h"
|
||||
|
||||
|
@@ -109,7 +109,7 @@ public:
|
||||
|
||||
|
||||
template<typename T>
|
||||
NNIndex<T>* load_saved_index(const Matrix<T>& dataset, const string& filename)
|
||||
NNIndex<T>* load_saved_index(const Matrix<T>& dataset, const std::string& filename)
|
||||
{
|
||||
FILE* fin = fopen(filename.c_str(), "rb");
|
||||
if (fin==NULL) {
|
||||
@@ -208,7 +208,7 @@ int Index<T>::radiusSearch(const Matrix<T>& query, Matrix<int>& indices, Matrix<
|
||||
// TODO: optimise here
|
||||
int* neighbors = resultSet.getNeighbors();
|
||||
float* distances = resultSet.getDistances();
|
||||
size_t count_nn = min(resultSet.size(), indices.cols);
|
||||
size_t count_nn = std::min(resultSet.size(), indices.cols);
|
||||
|
||||
assert (dists.cols>=count_nn);
|
||||
|
||||
@@ -222,7 +222,7 @@ int Index<T>::radiusSearch(const Matrix<T>& query, Matrix<int>& indices, Matrix<
|
||||
|
||||
|
||||
template<typename T>
|
||||
void Index<T>::save(string filename)
|
||||
void Index<T>::save(std::string filename)
|
||||
{
|
||||
FILE* fout = fopen(filename.c_str(), "wb");
|
||||
if (fout==NULL) {
|
||||
|
@@ -66,8 +66,8 @@ void find_nearest(const Matrix<T>& dataset, T* query, int* matches, int nn, int
|
||||
int j = dcnt-1;
|
||||
// bubble up
|
||||
while (j>=1 && dists[j]<dists[j-1]) {
|
||||
swap(dists[j],dists[j-1]);
|
||||
swap(match[j],match[j-1]);
|
||||
std::swap(dists[j],dists[j-1]);
|
||||
std::swap(match[j],match[j-1]);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,6 @@
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
@@ -162,7 +161,7 @@ public:
|
||||
}
|
||||
|
||||
/* Switch first node with last. */
|
||||
swap(heap[1],heap[count]);
|
||||
std::swap(heap[1],heap[count]);
|
||||
|
||||
count -= 1;
|
||||
heapify(1); /* Move new node 1 to right position. */
|
||||
@@ -197,7 +196,7 @@ public:
|
||||
|
||||
/* If a child was smaller, than swap parent with it and Heapify. */
|
||||
if (minloc != parent) {
|
||||
swap(heap[parent],heap[minloc]);
|
||||
std::swap(heap[parent],heap[minloc]);
|
||||
heapify(minloc);
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,6 @@
|
||||
#include "opencv2/flann/timer.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
@@ -207,7 +206,7 @@ float test_index_precisions(NNIndex<ELEM_TYPE>& index, const Matrix<ELEM_TYPE>&
|
||||
const float SEARCH_EPS = 0.001;
|
||||
|
||||
// make sure precisions array is sorted
|
||||
sort(precisions, precisions+precisions_length);
|
||||
std::sort(precisions, precisions+precisions_length);
|
||||
|
||||
int pindex = 0;
|
||||
float precision = precisions[pindex];
|
||||
|
@@ -45,8 +45,6 @@
|
||||
#include "opencv2/flann/random.h"
|
||||
#include "opencv2/flann/saving.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
@@ -232,7 +230,7 @@ public:
|
||||
/* Randomize the order of vectors to allow for unbiased sampling. */
|
||||
for (int j = (int)size_; j > 0; --j) {
|
||||
int rnd = rand_int(j);
|
||||
swap(vind[j-1], vind[rnd]);
|
||||
std::swap(vind[j-1], vind[rnd]);
|
||||
}
|
||||
trees[i] = divideTree(0, (int)size_ - 1);
|
||||
}
|
||||
@@ -384,7 +382,7 @@ private:
|
||||
/* Compute mean values. Only the first SAMPLE_MEAN values need to be
|
||||
sampled to get a good estimate.
|
||||
*/
|
||||
int end = min(first + SAMPLE_MEAN, last);
|
||||
int end = std::min(first + SAMPLE_MEAN, last);
|
||||
for (int j = first; j <= end; ++j) {
|
||||
ELEM_TYPE* v = dataset[vind[j]];
|
||||
for (size_t k=0; k<veclen_; ++k) {
|
||||
@@ -432,7 +430,7 @@ private:
|
||||
/* Bubble end value down to right location by repeated swapping. */
|
||||
int j = num - 1;
|
||||
while (j > 0 && v[topind[j]] > v[topind[j-1]]) {
|
||||
swap(topind[j], topind[j-1]);
|
||||
std::swap(topind[j], topind[j-1]);
|
||||
--j;
|
||||
}
|
||||
}
|
||||
@@ -459,7 +457,7 @@ private:
|
||||
++i;
|
||||
} else {
|
||||
/* Move to end of list by swapping vind i and j. */
|
||||
swap(vind[i], vind[j]);
|
||||
std::swap(vind[i], vind[j]);
|
||||
--j;
|
||||
}
|
||||
}
|
||||
@@ -506,7 +504,7 @@ private:
|
||||
|
||||
int checkCount = 0;
|
||||
Heap<BranchSt>* heap = new Heap<BranchSt>((int)size_);
|
||||
vector<bool> checked(size_,false);
|
||||
std::vector<bool> checked(size_,false);
|
||||
|
||||
/* Search once through each tree down to root. */
|
||||
for (i = 0; i < numTrees; ++i) {
|
||||
@@ -530,7 +528,7 @@ private:
|
||||
* at least "mindistsq".
|
||||
*/
|
||||
void searchLevel(ResultSet<ELEM_TYPE>& result, const ELEM_TYPE* vec, Tree node, float mindistsq, int& checkCount, int maxCheck,
|
||||
Heap<BranchSt>* heap, vector<bool>& checked)
|
||||
Heap<BranchSt>* heap, std::vector<bool>& checked)
|
||||
{
|
||||
if (result.worstDist()<mindistsq) {
|
||||
// printf("Ignoring branch, too far\n");
|
||||
|
@@ -46,12 +46,10 @@
|
||||
#include "opencv2/flann/allocator.h"
|
||||
#include "opencv2/flann/random.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
|
||||
|
||||
struct CV_EXPORTS KMeansIndexParams : public IndexParams {
|
||||
KMeansIndexParams(int branching_ = 32, int iterations_ = 11,
|
||||
flann_centers_init_t centers_init_ = CENTERS_RANDOM, float cb_index_ = 0.2 ) :
|
||||
@@ -353,7 +351,7 @@ class KMeansIndex : public NNIndex<ELEM_TYPE>
|
||||
// Compute the new potential
|
||||
double newPot = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
newPot += min( flann_dist(dataset[indices[i]], dataset[indices[i]] + dataset.cols, dataset[indices[index]]), closestDistSq[i] );
|
||||
newPot += std::min( flann_dist(dataset[indices[i]], dataset[indices[i]] + dataset.cols, dataset[indices[index]]), closestDistSq[i] );
|
||||
|
||||
// Store the best result
|
||||
if (bestNewPot < 0 || newPot < bestNewPot) {
|
||||
@@ -366,7 +364,7 @@ class KMeansIndex : public NNIndex<ELEM_TYPE>
|
||||
centers[centerCount] = indices[bestNewIndex];
|
||||
currentPot = bestNewPot;
|
||||
for (int i = 0; i < n; i++)
|
||||
closestDistSq[i] = min( flann_dist(dataset[indices[i]], dataset[indices[i]]+dataset.cols, dataset[indices[bestNewIndex]]), closestDistSq[i] );
|
||||
closestDistSq[i] = std::min( flann_dist(dataset[indices[i]], dataset[indices[i]]+dataset.cols, dataset[indices[bestNewIndex]]), closestDistSq[i] );
|
||||
}
|
||||
|
||||
centers_length = centerCount;
|
||||
@@ -402,7 +400,7 @@ public:
|
||||
branching = params.branching;
|
||||
max_iter = params.iterations;
|
||||
if (max_iter<0) {
|
||||
max_iter = numeric_limits<int>::max();
|
||||
max_iter = (std::numeric_limits<int>::max)();
|
||||
}
|
||||
flann_centers_init_t centersInit = params.centers_init;
|
||||
|
||||
@@ -711,7 +709,7 @@ private:
|
||||
|
||||
if (indices_length < branching) {
|
||||
node->indices = indices;
|
||||
sort(node->indices,node->indices+indices_length);
|
||||
std::sort(node->indices,node->indices+indices_length);
|
||||
node->childs = NULL;
|
||||
return;
|
||||
}
|
||||
@@ -722,7 +720,7 @@ private:
|
||||
|
||||
if (centers_length<branching) {
|
||||
node->indices = indices;
|
||||
sort(node->indices,node->indices+indices_length);
|
||||
std::sort(node->indices,node->indices+indices_length);
|
||||
node->childs = NULL;
|
||||
return;
|
||||
}
|
||||
@@ -859,8 +857,8 @@ private:
|
||||
double d = flann_dist(dataset[indices[i]],dataset[indices[i]]+veclen_,zero());
|
||||
variance += d;
|
||||
mean_radius += sqrt(d);
|
||||
swap(indices[i],indices[end]);
|
||||
swap(belongs_to[i],belongs_to[end]);
|
||||
std::swap(indices[i],indices[end]);
|
||||
std::swap(belongs_to[i],belongs_to[end]);
|
||||
end++;
|
||||
}
|
||||
}
|
||||
@@ -1072,7 +1070,7 @@ private:
|
||||
float meanVariance = root->variance*root->size;
|
||||
|
||||
while (clusterCount<clusters_length) {
|
||||
float minVariance = numeric_limits<float>::max();
|
||||
float minVariance = (std::numeric_limits<float>::max)();
|
||||
int splitIndex = -1;
|
||||
|
||||
for (int i=0;i<clusterCount;++i) {
|
||||
|
@@ -36,7 +36,6 @@
|
||||
#include <stdarg.h>
|
||||
#include "opencv2/flann/general.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
|
@@ -36,8 +36,6 @@
|
||||
#include "opencv2/flann/general.h"
|
||||
#include "opencv2/flann/matrix.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
|
||||
|
@@ -35,7 +35,6 @@
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
@@ -109,7 +108,7 @@ public:
|
||||
// int rand = cast(int) (drand48() * n);
|
||||
int rnd = rand_int(i);
|
||||
assert(rnd >=0 && rnd < i);
|
||||
swap(vals[i-1], vals[rnd]);
|
||||
std::swap(vals[i-1], vals[rnd]);
|
||||
}
|
||||
|
||||
counter = 0;
|
||||
|
@@ -37,8 +37,6 @@
|
||||
#include <vector>
|
||||
#include "opencv2/flann/dist.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
@@ -181,8 +179,8 @@ public:
|
||||
// bubble up
|
||||
while (i>=1 && (dists[i]<dists[i-1] || (dists[i]==dists[i-1] && indices[i]<indices[i-1]) ) ) {
|
||||
// while (i>=1 && (dists[i]<dists[i-1]) ) {
|
||||
swap(indices[i],indices[i-1]);
|
||||
swap(dists[i],dists[i-1]);
|
||||
std::swap(indices[i],indices[i-1]);
|
||||
std::swap(dists[i],dists[i-1]);
|
||||
i--;
|
||||
}
|
||||
|
||||
@@ -191,7 +189,7 @@ public:
|
||||
|
||||
float worstDist() const
|
||||
{
|
||||
return (count<capacity) ? numeric_limits<float>::max() : dists[count-1];
|
||||
return (count<capacity) ? (std::numeric_limits<float>::max)() : dists[count-1];
|
||||
}
|
||||
};
|
||||
|
||||
@@ -215,7 +213,7 @@ class RadiusResultSet : public ResultSet<ELEM_TYPE>
|
||||
}
|
||||
};
|
||||
|
||||
vector<Item> items;
|
||||
std::vector<Item> items;
|
||||
float radius;
|
||||
|
||||
bool sorted;
|
||||
|
@@ -56,7 +56,7 @@ Matrix<T> random_sample(Matrix<T>& srcMatrix, long size, bool remove = false)
|
||||
dest = srcMatrix[srcMatrix.rows-i-1];
|
||||
src = srcMatrix[r];
|
||||
for (size_t j=0;j<srcMatrix.cols;++j) {
|
||||
swap(*src,*dest);
|
||||
std::swap(*src,*dest);
|
||||
src++;
|
||||
dest++;
|
||||
}
|
||||
|
Reference in New Issue
Block a user