Skip to content
Snippets Groups Projects
Commit afae9316 authored by Arend G. Dijkstra's avatar Arend G. Dijkstra
Browse files

performance improvements

parent a152b2e0
No related branches found
No related tags found
1 merge request!18Add c++ version of mean shift algorithm
...@@ -58,7 +58,7 @@ void Grouper::readCoordinates(py::array_t<cdt> array, py::array_t<cdt> farray){ ...@@ -58,7 +58,7 @@ void Grouper::readCoordinates(py::array_t<cdt> array, py::array_t<cdt> farray){
} }
static double euclid_distance(std::pair<cdt, cdt> coordinate1, std::pair<cdt,cdt> coordinate2){ static double euclid_distance(const std::pair<cdt, cdt> &coordinate1, const std::pair<cdt,cdt> &coordinate2){
// Euclidian distance between two points // Euclidian distance between two points
double result = 0.0; double result = 0.0;
double distx = coordinate1.first - coordinate2.first; double distx = coordinate1.first - coordinate2.first;
...@@ -66,7 +66,7 @@ static double euclid_distance(std::pair<cdt, cdt> coordinate1, std::pair<cdt,cdt ...@@ -66,7 +66,7 @@ static double euclid_distance(std::pair<cdt, cdt> coordinate1, std::pair<cdt,cdt
return sqrt(distx * distx + disty * disty); return sqrt(distx * distx + disty * disty);
} }
static std::vector<unsigned> neighbourhood_points(std::pair<cdt,cdt> centroid, ctype coordinates, double max_distance){ static std::vector<unsigned> neighbourhood_points(const std::pair<cdt,cdt>& centroid, const ctype& coordinates, double max_distance){
std::vector<unsigned> result; std::vector<unsigned> result;
for (unsigned n=0; n<coordinates.size(); ++n){ for (unsigned n=0; n<coordinates.size(); ++n){
double distance = euclid_distance(centroid, coordinates[n]); double distance = euclid_distance(centroid, coordinates[n]);
...@@ -114,7 +114,7 @@ void Grouper::run(){ ...@@ -114,7 +114,7 @@ void Grouper::run(){
} }
double maxdiff = 0.0; double maxdiff = 0.0;
unsigned n=0; unsigned n=0;
for (auto coordinate : _coordinates){ for (auto &coordinate : _coordinates){
double diff = euclid_distance(coordinate, newcoords[n]); double diff = euclid_distance(coordinate, newcoords[n]);
if (diff > maxdiff){ if (diff > maxdiff){
maxdiff = diff; maxdiff = diff;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment