diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2020-05-25 20:55:06 +0200 |
---|---|---|
committer | Marc Glisse <marc.glisse@inria.fr> | 2020-05-25 20:55:06 +0200 |
commit | c6f519abe3d2fe424d9982ad8139ff2a86119bca (patch) | |
tree | 6cf4de5466cedf30d7b1d8f6e01f111a22075206 /src/python/gudhi/clustering/_tomato.cc | |
parent | 9a7fba8b3dcfbd838ce2ea571fd4e8f06cd8a7bd (diff) |
Make specifying an impossible number of clusters a warning
Diffstat (limited to 'src/python/gudhi/clustering/_tomato.cc')
-rw-r--r-- | src/python/gudhi/clustering/_tomato.cc | 18 |
1 files changed, 8 insertions, 10 deletions
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<Cluster_index, py::array::c_style> 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; |