diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Subsampling/include/gudhi/choose_n_farthest_points.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/Subsampling/include/gudhi/choose_n_farthest_points.h b/src/Subsampling/include/gudhi/choose_n_farthest_points.h index b6b7ace3..ea387bf9 100644 --- a/src/Subsampling/include/gudhi/choose_n_farthest_points.h +++ b/src/Subsampling/include/gudhi/choose_n_farthest_points.h @@ -73,10 +73,15 @@ void choose_n_farthest_points(Kernel const &k, std::size_t final_size, std::size_t starting_point, OutputIterator output_it) { - typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); - std::size_t nb_points = boost::size(input_pts); - assert(nb_points >= final_size); + if (final_size > nb_points) + final_size = nb_points; + + // Tests to the limit + if (final_size < 1) + return; + + typename Kernel::Squared_distance_d sqdist = k.squared_distance_d_object(); std::size_t current_number_of_landmarks = 0; // counter for landmarks const double infty = std::numeric_limits<double>::infinity(); // infinity (see next entry) @@ -132,10 +137,14 @@ void choose_n_farthest_points(Kernel const& k, Point_range const &input_pts, unsigned final_size, OutputIterator output_it) { + // Tests to the limit + if ((final_size < 1) || (input_pts.size() == 0)) + return; + // Choose randomly the first landmark std::random_device rd; std::mt19937 gen(rd()); - std::uniform_int_distribution<> dis(0, final_size); + std::uniform_int_distribution<> dis(0, (input_pts.size() - 1)); int starting_point = dis(gen); choose_n_farthest_points(k, input_pts, final_size, starting_point, output_it); } |