From c6f519abe3d2fe424d9982ad8139ff2a86119bca Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Mon, 25 May 2020 20:55:06 +0200 Subject: Make specifying an impossible number of clusters a warning --- src/python/gudhi/clustering/_tomato.cc | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/python/gudhi/clustering/_tomato.cc') diff --git a/src/python/gudhi/clustering/_tomato.cc b/src/python/gudhi/clustering/_tomato.cc index 87bd62e9..638e1259 100644 --- a/src/python/gudhi/clustering/_tomato.cc +++ b/src/python/gudhi/clustering/_tomato.cc @@ -195,21 +195,19 @@ auto tomato(Point_index num_points, Neighbors const& neighbors, Density const& d } auto merge(py::array_t children, Cluster_index n_leaves, Cluster_index n_final) { - // Should this really be an error? - if (n_final > n_leaves) - throw std::runtime_error("The number of clusters required is larger than the number of mini-clusters"); + if (n_final > n_leaves) { + std::cerr << "The number of clusters required " << n_final << " is larger than the number of mini-clusters " << n_leaves << '\n'; + n_final = n_leaves; // or return something special and let Tomato use leaf_labels_? + } py::buffer_info cbuf = children.request(); if ((cbuf.ndim != 2 || cbuf.shape[1] != 2) && (cbuf.ndim != 1 || cbuf.shape[0] != 0)) throw std::runtime_error("internal error: children have to be (n,2) or empty"); const int n_merges = cbuf.shape[0]; Cluster_index* d = (Cluster_index*)cbuf.ptr; - // Should this really be an error? - // std::cerr << "n_merges: " << n_merges << ", n_final: " << n_final << ", n_leaves: " << n_leaves << '\n'; - if (n_merges + n_final < n_leaves) - throw std::runtime_error(std::string("The number of clusters required ") + std::to_string(n_final) + - " is smaller than the number of connected components " + - std::to_string(n_leaves - n_merges)); - + if (n_merges + n_final < n_leaves) { + std::cerr << "The number of clusters required " << n_final << " is smaller than the number of connected components " << n_leaves - n_merges << '\n'; + n_final = n_leaves - n_merges; + } struct Dat { Cluster_index parent; int rank; -- cgit v1.2.3