提交 9cf1f47d 编写于 作者: M Marius Muja

Speedups for radius search. Cleanups (removed using namespace std)

上级 9c8f55b7
......@@ -101,7 +101,9 @@ endif(USE_MPI)
include_directories(${PROJECT_SOURCE_DIR}/src/cpp)
# require proper c++
add_definitions( "-Wall -ansi -pedantic" )
#add_definitions( "-Wall -ansi -pedantic" )
# HDF5 uses long long which is not ansi
add_definitions( "-Wall" )
add_subdirectory( cmake )
add_subdirectory( src )
......
......@@ -290,8 +290,8 @@ private:
IndexParams* params;
};
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)
......@@ -396,7 +396,7 @@ private:
void optimizeKMeans( vector<CostData>& costs )
void optimizeKMeans( std::vector<CostData>& costs )
{
logger.info("KMEANS, Step 1: Exploring parameter space\n");
......@@ -445,7 +445,7 @@ private:
}
void optimizeKDTree(vector<CostData>& costs)
void optimizeKDTree( std::vector<CostData>& costs)
{
logger.info("KD-TREE, Step 1: Exploring parameter space\n");
......@@ -492,10 +492,10 @@ private:
*/
IndexParams* estimateBuildParams()
{
vector<CostData> costs;
std::vector<CostData> costs;
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, target precision: %g\n",dataset.rows, sampleSize, testSampleSize, index_params.target_precision);
......@@ -583,7 +583,7 @@ private:
float speedup = 0;
int samples = min(dataset.rows/10, SAMPLE_COUNT);
int samples = std::min(dataset.rows/10, SAMPLE_COUNT);
if (samples>0) {
Matrix<ElementType> testDataset = random_sample(dataset,samples);
......
......@@ -33,7 +33,6 @@
#include <cmath>
#include <cstdlib>
using namespace std;
#include "flann/general.h"
......
......@@ -45,8 +45,6 @@
#include "flann/util/random.h"
#include "flann/util/saving.h"
using namespace std;
namespace flann
{
......@@ -225,7 +223,7 @@ public:
{
for (int j = vec_size; j > 0; --j) {
int rnd = rand_int(j);
swap(vec[j-1], vec[rnd]);
std::swap(vec[j-1], vec[rnd]);
}
}
......@@ -390,7 +388,7 @@ private:
/* Compute mean values. Only the first SAMPLE_MEAN values need to be
sampled to get a good estimate.
*/
int cnt = min((int)SAMPLE_MEAN+1, count);
int cnt = std::min((int)SAMPLE_MEAN+1, count);
for (int j = 0; j < cnt; ++j) {
ElementType* v = dataset[ind[j]];
for (size_t k=0; k<veclen_; ++k) {
......@@ -447,7 +445,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;
}
}
......@@ -476,7 +474,7 @@ private:
while (left<=right && dataset[ind[left]][cutfeat]<cutval) ++left;
while (left<=right && dataset[ind[right]][cutfeat]>=cutval) --right;
if (left>right) break;
swap(ind[left], ind[right]); ++left; --right;
std::swap(ind[left], ind[right]); ++left; --right;
}
/* If either list is empty, it means that all remaining features
* are identical. Split in the middle to maintain a balanced tree.
......@@ -487,7 +485,7 @@ private:
while (left<=right && dataset[ind[left]][cutfeat]<=cutval) ++left;
while (left<=right && dataset[ind[right]][cutfeat]>cutval) --right;
if (left>right) break;
swap(ind[left], ind[right]); ++left; --right;
std::swap(ind[left], ind[right]); ++left; --right;
}
lim2 = left;
}
......@@ -521,7 +519,7 @@ private:
int checkCount = 0;
Heap<BranchSt>* heap = new Heap<BranchSt>(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) {
......@@ -545,7 +543,7 @@ private:
* at least "mindistsq".
*/
void searchLevel(ResultSet<DistanceType>& result_set, const ElementType* vec, NodePtr node, float mindistsq, int& checkCount, int maxCheck,
float epsError, Heap<BranchSt>* heap, vector<bool>& checked)
float epsError, Heap<BranchSt>* heap, std::vector<bool>& checked)
{
if (result_set.worstDist()<mindistsq) {
// printf("Ignoring branch, too far\n");
......
......@@ -45,9 +45,6 @@
#include "flann/util/random.h"
#include "flann/util/saving.h"
using namespace std;
namespace flann
{
......@@ -240,7 +237,7 @@ public:
{
for (int j = vec_size; j > 0; --j) {
int rnd = rand_int(j);
swap(vec[j-1], vec[rnd]);
std::swap(vec[j-1], vec[rnd]);
}
}
......@@ -462,7 +459,7 @@ private:
while (left<=right && dataset[ind[left]][cutfeat]<cutval) ++left;
while (left<=right && dataset[ind[right]][cutfeat]>=cutval) --right;
if (left>right) break;
swap(ind[left], ind[right]); ++left; --right;
std::swap(ind[left], ind[right]); ++left; --right;
}
/* If either list is empty, it means that all remaining features
* are identical. Split in the middle to maintain a balanced tree.
......@@ -473,7 +470,7 @@ private:
while (left<=right && dataset[ind[left]][cutfeat]<=cutval) ++left;
while (left<=right && dataset[ind[right]][cutfeat]>cutval) --right;
if (left>right) break;
swap(ind[left], ind[right]); ++left; --right;
std::swap(ind[left], ind[right]); ++left; --right;
}
lim2 = left;
}
......
......@@ -48,8 +48,6 @@
#include "flann/util/random.h"
#include "flann/util/saving.h"
using namespace std;
namespace flann
{
......@@ -382,7 +380,7 @@ class KMeansIndex : public NNIndex<Distance>
// Compute the new potential
double newPot = 0;
for (int i = 0; i < n; i++)
newPot += min( distance(dataset[indices[i]], dataset[indices[index]], dataset.cols), closestDistSq[i] );
newPot += std::min( distance(dataset[indices[i]], dataset[indices[index]], dataset.cols), closestDistSq[i] );
// Store the best result
if (bestNewPot < 0 || newPot < bestNewPot) {
......@@ -395,7 +393,7 @@ class KMeansIndex : public NNIndex<Distance>
centers[centerCount] = indices[bestNewIndex];
currentPot = bestNewPot;
for (int i = 0; i < n; i++)
closestDistSq[i] = min( distance(dataset[indices[i]], dataset[indices[bestNewIndex]], dataset.cols), closestDistSq[i] );
closestDistSq[i] = std::min( distance(dataset[indices[i]], dataset[indices[bestNewIndex]], dataset.cols), closestDistSq[i] );
}
centers_length = centerCount;
......@@ -432,7 +430,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;
......@@ -741,7 +739,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;
}
......@@ -752,7 +750,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;
delete [] centers_idx;
return;
......@@ -890,8 +888,8 @@ private:
float d = distance(dataset[indices[i]], ZeroIterator<ElementType>(), veclen_);
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++;
}
}
......@@ -1113,7 +1111,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,8 +36,6 @@
#include "flann/general.h"
#include "flann/util/matrix.h"
using namespace std;
namespace flann
{
......
......@@ -29,7 +29,6 @@
// include flann_cpp stuff
#include "flann_cpp.cpp"
using namespace std;
#ifdef WIN32
#define EXPORTED extern "C" __declspec(dllexport)
......@@ -103,7 +102,7 @@ flann_index_t __flann_build_index(typename Distance::ElementType* dataset, int r
return index;
}
catch (runtime_error& e) {
catch (std::runtime_error& e) {
logger.error("Caught exception: %s\n",e.what());
return NULL;
}
......@@ -177,7 +176,7 @@ int __flann_save_index(flann_index_t index_ptr, char* filename)
return 0;
}
catch(runtime_error& e) {
catch(std::runtime_error& e) {
logger.error("Caught exception: %s\n",e.what());
return -1;
}
......@@ -247,7 +246,7 @@ flann_index_t __flann_load_index(char* filename, typename Distance::ElementType*
Index<Distance>* index = new Index<Distance>(Matrix<typename Distance::ElementType>(dataset,rows,cols), SavedIndexParams(filename), d);
return index;
}
catch(runtime_error& e) {
catch(std::runtime_error& e) {
logger.error("Caught exception: %s\n",e.what());
return NULL;
}
......@@ -332,7 +331,7 @@ int __flann_find_nearest_neighbors(typename Distance::ElementType* dataset, int
delete index;
return 0;
}
catch(runtime_error& e) {
catch(std::runtime_error& e) {
logger.error("Caught exception: %s\n",e.what());
return -1;
}
......@@ -420,7 +419,7 @@ int __flann_find_nearest_neighbors_index(flann_index_t index_ptr, typename Dista
return 0;
}
catch(runtime_error& e) {
catch(std::runtime_error& e) {
logger.error("Caught exception: %s\n",e.what());
return -1;
}
......@@ -514,7 +513,7 @@ int __flann_radius_search(flann_index_t index_ptr,
return count;
}
catch(runtime_error& e) {
catch(std::runtime_error& e) {
logger.error("Caught exception: %s\n",e.what());
return -1;
}
......@@ -625,7 +624,7 @@ int __flann_free_index(flann_index_t index_ptr, FLANNParameters* flann_params)
return 0;
}
catch(runtime_error& e) {
catch(std::runtime_error& e) {
logger.error("Caught exception: %s\n",e.what());
return -1;
}
......@@ -703,7 +702,7 @@ int __flann_compute_cluster_centers(typename Distance::ElementType* dataset, int
int clusterNum = hierarchicalClustering<Distance>(inputData, centers, params, d);
return clusterNum;
} catch (runtime_error& e) {
} catch (std::runtime_error& e) {
logger.error("Caught exception: %s\n",e.what());
return -1;
}
......
......@@ -43,6 +43,7 @@
#include "flann/nn/index_testing.h"
#include "flann/util/object_factory.h"
#include "flann/util/saving.h"
#include "flann/util/pair_iterator.hpp"
#include "flann/algorithms/all_indices.h"
......@@ -85,6 +86,7 @@ struct SavedIndexParams : public IndexParams {
}
};
template<typename Distance>
class Index {
typedef typename Distance::ElementType ElementType;
......@@ -117,7 +119,7 @@ public:
template<typename Distance>
NNIndex<Distance>* load_saved_index(const Matrix<typename Distance::ElementType>& dataset, const string& filename, Distance distance)
NNIndex<Distance>* load_saved_index(const Matrix<typename Distance::ElementType>& dataset, const std::string& filename, Distance distance)
{
typedef typename Distance::ElementType ElementType;
......@@ -204,15 +206,29 @@ int Index<Distance>::radiusSearch(const Matrix<ElementType>& query, Matrix<int>&
assert(query.cols==nnIndex->veclen());
assert(indices.cols==dists.cols);
RadiusResultSet<DistanceType> resultSet(radius, indices[0], dists[0], indices.cols);
nnIndex->findNeighbors(resultSet, query[0] ,searchParams);
int n = 0;
int* indices_ptr = NULL;
DistanceType* dists_ptr = NULL;
if (indices.cols>0) {
n = indices.cols;
indices_ptr = indices[0];
dists_ptr = dists[0];
}
RadiusResultSet<DistanceType> result_set(radius, indices_ptr, dists_ptr, n);
nnIndex->findNeighbors(result_set, query[0], searchParams);
size_t cnt = result_set.size();
if (searchParams.sorted) {
std::sort(make_pair_iterator(dists_ptr, indices_ptr),
make_pair_iterator(dists_ptr+cnt, indices_ptr+cnt),
pair_iterator_compare<DistanceType*, int*>());
}
return resultSet.size();
return cnt;
}
template<typename Distance>
void Index<Distance>::save(string filename)
void Index<Distance>::save(std::string filename)
{
FILE* fout = fopen(filename.c_str(), "wb");
if (fout==NULL) {
......
......@@ -39,7 +39,6 @@
// index types
#include "flann/algorithms/all_indices.h"
using namespace std;
#ifdef WIN32
#define EXPORTED extern "C" __declspec(dllexport)
......
......@@ -155,11 +155,12 @@ typedef ObjectFactory<IndexParams, flann_algorithm_t> ParamsFactory;
struct SearchParams {
SearchParams(int checks_ = 32, float eps_ = 0) :
checks(checks_), eps(eps_) {};
SearchParams(int checks_ = 32, float eps_ = 0, bool sorted_ = true ) :
checks(checks_), eps(eps_), sorted(sorted_) {};
int checks;
float eps;
int checks; // how many leafs to visit when searching for neighbours (-1 for unlimited)
float eps; // search for eps-approximate neighbours (default: 0)
bool sorted; // only for radius search, require neighbours sorted by distance (default: true)
};
}
......
......@@ -67,8 +67,8 @@ void find_nearest(const Matrix<typename Distance::ElementType>& dataset, typenam
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--;
}
}
......
......@@ -42,8 +42,6 @@
#include "flann/util/timer.h"
using namespace std;
namespace flann
{
......@@ -51,13 +49,15 @@ int countCorrectMatches(int* neighbors, int* groundTruth, int n);
template <typename Distance>
float computeDistanceRaport(const Matrix<typename Distance::ElementType>& inputData, typename Distance::ElementType* target,
typename Distance::ResultType computeDistanceRaport(const Matrix<typename Distance::ElementType>& inputData, typename Distance::ElementType* target,
int* neighbors, int* groundTruth, int veclen, int n, const Distance& distance)
{
float ret = 0;
typedef typename Distance::ResultType DistanceType;
DistanceType ret = 0;
for (int i=0;i<n;++i) {
float den = distance(inputData[groundTruth[i]], target, veclen);
float num = distance(inputData[neighbors[i]], target, veclen);
DistanceType den = distance(inputData[groundTruth[i]], target, veclen);
DistanceType num = distance(inputData[neighbors[i]], target, veclen);
if (den==0 && num==0) {
ret += 1;
......@@ -91,7 +91,7 @@ float search_with_ground_truth(NNIndex<Distance>& index, const Matrix<typename D
int* neighbors = indices + skipMatches;
int correct;
float distR;
DistanceType distR;
StartStopTimer t;
int repeats = 0;
while (t.value<0.2) {
......@@ -127,11 +127,13 @@ float test_index_checks(NNIndex<Distance>& index, const Matrix<typename Distance
const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches,
int checks, float& precision, const Distance& distance, int nn = 1, int skipMatches = 0)
{
typedef typename Distance::ResultType DistanceType;
logger.info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
logger.info("---------------------------------------------------------\n");
float time = 0;
float dist = 0;
DistanceType dist = 0;
precision = search_with_ground_truth(index, inputData, testData, matches, nn, checks, time, dist, distance, skipMatches);
return time;
......@@ -142,6 +144,7 @@ float test_index_precision(NNIndex<Distance>& index, const Matrix<typename Dista
const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches,
float precision, int& checks, const Distance& distance, int nn = 1, int skipMatches = 0)
{
typedef typename Distance::ResultType DistanceType;
const float SEARCH_EPS = 0.001;
logger.info(" Nodes Precision(%) Time(s) Time/vec(ms) Mean dist\n");
......@@ -152,7 +155,7 @@ float test_index_precision(NNIndex<Distance>& index, const Matrix<typename Dista
int c1 = 1;
float p1;
float time;
float dist;
DistanceType dist;
p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches);
......@@ -213,10 +216,12 @@ float test_index_precisions(NNIndex<Distance>& index, const Matrix<typename Dist
const Matrix<typename Distance::ElementType>& testData, const Matrix<int>& matches,
float* precisions, int precisions_length, const Distance& distance, int nn = 1, int skipMatches = 0, float maxTime = 0)
{
typedef typename Distance::ResultType DistanceType;
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];
......@@ -231,7 +236,7 @@ float test_index_precisions(NNIndex<Distance>& index, const Matrix<typename Dist
float p1;
float time;
float dist;
DistanceType dist;
p2 = search_with_ground_truth(index, inputData, testData, matches, nn, c2, time, dist, distance, skipMatches);
......
......@@ -31,9 +31,7 @@
#ifndef HEAP_H
#define HEAP_H
#include <algorithm>
using namespace std;
namespace flann
{
......@@ -165,11 +163,11 @@ public:
if (count == 1) {
count = 0; /* For size 1, no need to swap node with itself */
}
else {
swap(heap[1],heap[count]); /* Switch first node with last. */
else {
std::swap(heap[1],heap[count]); /* Switch first node with last. */
count -= 1;
heapify(1); /* Move new node 1 to right position. */
}
}
value = heap[count + 1];
return true; /* Return old last node. */
}
......@@ -200,7 +198,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);
}
}
......
......@@ -34,7 +34,6 @@
#include <cstdarg>
#include <sstream>
using namespace std;
namespace flann
{
......
......@@ -31,11 +31,9 @@
#ifndef LOGGER_H
#define LOGGER_H
#include <cstdio>
#include "flann/general.h"
using namespace std;
namespace flann
{
......
/***********************************************************************
* Software License Agreement (BSD License)
*
* Copyright 2008-2010 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
* Copyright 2008-2010 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*************************************************************************/
#ifndef PAIR_ITERATOR_HPP_
#define PAIR_ITERATOR_HPP_
#include <algorithm>
#include <functional>
/**
* This file contains a pair iterator that can be used to sort in parallel
* two arrays (or iterators), such as it sorts one array and permutes the
* second one accordingly.
*/
namespace flann
{
template<typename First, typename Second>
class pair
{
public:
First first;
Second second;
pair(const First& a, const Second& b) : first(a), second(b) {}
template<typename U, typename V>
pair(const pair<U,V>& x): first(x.first), second(x.second) {}
template<typename U, typename V>
pair& operator=(const pair<U,V>& x) { first = x.first; second = x.second; return *this; }
pair& operator=(const pair& x) { first = x.first; second = x.second; return *this; }
};
template<typename SortIterator, typename PermuteIterator>
struct pair_iterator_traits
{
typedef std::random_access_iterator_tag iterator_category;
typedef pair<
typename std::iterator_traits<SortIterator>::value_type,
typename std::iterator_traits<PermuteIterator>::value_type > value_type;
typedef pair<
typename std::iterator_traits<SortIterator>::value_type&,
typename std::iterator_traits<PermuteIterator>::value_type& > reference;
typedef typename std::iterator_traits<SortIterator>::difference_type difference_type;
typedef value_type* pointer;
};
template<typename SortIterator, typename PermuteIterator>
class pair_iterator
{
public:
// public typedefs
typedef typename pair_iterator_traits<SortIterator, PermuteIterator>::iterator_category iterator_category;
typedef typename pair_iterator_traits<SortIterator, PermuteIterator>::value_type value_type;
typedef typename pair_iterator_traits<SortIterator, PermuteIterator>::reference reference;
typedef typename pair_iterator_traits<SortIterator, PermuteIterator>::difference_type difference_type;
typedef typename pair_iterator_traits<SortIterator, PermuteIterator>::pointer pointer;
typedef pair_iterator self;
// constructors
pair_iterator(){ };
pair_iterator(SortIterator si, PermuteIterator pi) : si_(si), pi_(pi) { }
// operators
self& operator++( ) { ++si_; ++pi_; return *this; }
self operator++(int) { self tmp = *this; si_++; pi_++; return tmp; }
self& operator--( ) { --si_; --pi_; return *this; }
self operator--(int) { self tmp = *this; si_--; pi_--; return tmp; }
self& operator+=(difference_type x) { si_ += x; pi_ += x; return *this; }
self& operator-=(difference_type x) {si_ -= x; pi_ -= x; return *this; }
reference operator[](difference_type n) { return reference(*(si_+n),*(si_+n)); }
reference operator*() const { return reference(*si_,*pi_); }
self operator+(difference_type y) { return self(si_+y, pi_+y); }
self operator-(difference_type y) { return self(si_-y, pi_-y); }
bool operator==(const self& y) { return si_ == y.si_; }
bool operator!=(const self& y) { return si_ != y.si_; }
bool operator<(const self& y) { return si_ < y.si_; }
difference_type operator-(const self& y) { return si_ - y.si_; }
// friend operators
friend self operator+(difference_type x, const self& y) { return y + x; }
friend self operator-(difference_type x, const self& y) { return y - x; }
private:
SortIterator si_;
PermuteIterator pi_;
};
template <class SortIterator, class PermuteIterator>
struct pair_iterator_compare : std::binary_function<
typename pair_iterator_traits<SortIterator, PermuteIterator>::value_type,
typename pair_iterator_traits<SortIterator, PermuteIterator>::value_type,
bool>
{
typedef typename pair_iterator_traits<SortIterator, PermuteIterator>::value_type T;
bool operator()(const T& t1, const T& t2)
{
return (t1.first < t2.first);
}
};
template <class SortIterator, class PermuteIterator>
pair_iterator<SortIterator, PermuteIterator> make_pair_iterator(SortIterator si, PermuteIterator pi)
{
return pair_iterator<SortIterator, PermuteIterator>(si, pi);
}
} // namespace flann
#endif /* PAIR_ITERATOR_HPP_ */
......@@ -35,7 +35,6 @@
#include <cstdlib>
#include <cassert>
using namespace std;
namespace flann
{
......@@ -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;
......
......@@ -36,8 +36,6 @@
#include <limits>
#include <vector>
using namespace std;
namespace flann
{
......@@ -94,7 +92,7 @@ public:
indices = indices_;
dists = dists_;
count = 0;
dists[capacity-1] = (numeric_limits<DistanceType>::max) ();
dists[capacity-1] = (std::numeric_limits<DistanceType>::max) ();
}
size_t size() const
......@@ -175,33 +173,13 @@ public:
void addPoint(DistanceType dist, int index)
{
if (capacity==0) {
count++;
}
else {
if (dist<radius && count<capacity) {
if (dist<radius) {
if (capacity>0 && count < capacity) {
dists[count] = dist;
indices[count] = index;
count++;
}
// int i;
// for (i=count; i>0;--i) {
// // if ( (dists[i-1]>dist) || (dist==dists[i-1] && indices[i-1]>index) ) {
// if (dists[i-1]>dist) {
// if (i<capacity) {
// dists[i] = dists[i-1];
// indices[i] = indices[i-1];
// }
// }
// else break;
// }
// if (i<capacity) {
// dists[i] = dist;
// indices[i] = index;
// }
// if (count<capacity) count++;
count++;
}
}
DistanceType worstDist() const
......
......@@ -55,7 +55,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++;
}
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册