diff options
author | Vincent Rouvreau <10407034+VincentRouvreau@users.noreply.github.com> | 2020-10-28 09:24:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-28 09:24:37 +0100 |
commit | 6b995c03793096459a333c907b606770113b96d7 (patch) | |
tree | 02f1b230464b01a135e00d5c368f984084b0e3ec /src/Subsampling/include/gudhi | |
parent | 3cfbb32adf1725afe3a1a9d270f520788de5c5a1 (diff) | |
parent | 705aa3b7ddc0a2bbbcc31c4b45e19792bd4ce9a5 (diff) |
Merge pull request #406 from mglisse/far
Handle duplicated points in choose_n_farthest_points
Diffstat (limited to 'src/Subsampling/include/gudhi')
-rw-r--r-- | src/Subsampling/include/gudhi/choose_n_farthest_points.h | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index 66421a69..b70af8a0 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -48,7 +48,8 @@ enum : std::size_t { * \tparam PointOutputIterator Output iterator whose value type is Kernel::Point_d. * \tparam DistanceOutputIterator Output iterator for distances. * \details It chooses `final_size` points from a random access range - * `input_pts` and outputs them in the output iterator `output_it`. It also + * `input_pts` (or the number of distinct points if `final_size` is larger) + * and outputs them in the output iterator `output_it`. It also * outputs the distance from each of those points to the set of previous * points in `dist_it`. * @param[in] k A kernel object. @@ -99,7 +100,7 @@ void choose_n_farthest_points(Kernel const &k, *dist_it++ = dist_to_L[curr_max_w]; std::size_t i = 0; for (auto&& p : input_pts) { - double curr_dist = sqdist(p, *(std::begin(input_pts) + curr_max_w)); + double curr_dist = sqdist(p, input_pts[curr_max_w]); if (curr_dist < dist_to_L[i]) dist_to_L[i] = curr_dist; ++i; @@ -111,6 +112,8 @@ void choose_n_farthest_points(Kernel const &k, curr_max_dist = dist_to_L[i]; curr_max_w = i; } + // If all that remains are duplicates of points already taken, stop. + if (curr_max_dist == 0) break; } } |