Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing erase after remove_if #966

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Subsampling/benchmark/choose_n_farthest_points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ int main(int argc, char**argv) {
<< " vs metric " << std::chrono::duration_cast<std::chrono::milliseconds>((time_stop2 - time_start2)).count()
<< " (Boost version " << BOOST_VERSION << ")\n";
if (dists != dists2 || results != results2) {
// Note that with many points, it often happens that 2 points with the same distance are swapped in the output.
std::cerr << "Results differ\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it happen that results differ ? I was not able to reach this code.

Copy link
Member Author

@mglisse mglisse Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With 100k points and seed 0, I get 1 swap. With 50k points, I need to try several seeds before I get a swap. (I don't remember if this was dimension 2 or 4)

#ifdef LOG_DIFF
std::ofstream log_gen("log_gen");
std::ofstream log_met("log_met");
for(std::size_t i = 0; i < results.size(); ++i){
log_gen << dists2[i] << '\t' << results2[i] << '\n';
log_met << dists [i] << '\t' << results [i] << '\n';
}
#endif
return -1;
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/Subsampling/include/gudhi/choose_n_farthest_points.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,15 @@ void choose_n_farthest_points_metric(Distance dist_,
auto handle_neighbor_neighbors = [&](std::size_t ngb)
{
auto& ngb_info = landmarks[ngb];
std::remove_if(ngb_info.neighbors.begin(), ngb_info.neighbors.end(), [&](auto near_){
auto it = std::remove_if(ngb_info.neighbors.begin(), ngb_info.neighbors.end(), [&](auto near_){
std::size_t near = near_.first;
FT d = near_.second;
// Conservative 3 * radius: we could use the old radii of ngb and near, but not the new ones.
if (d <= 3 * radius) { l_neighbors.insert(near); }
// Here it is safe to use the new radii.
return d >= max_dist(ngb_info.radius, landmarks[near].radius);
});
ngb_info.neighbors.erase(it, ngb_info.neighbors.end());
};
// First update the Voronoi diagram, so we can compute all the updated
// radii before pruning neighbor lists. The main drawback is that we have
Expand Down