diff options
author | Marc Glisse <marc.glisse@inria.fr> | 2020-06-05 19:44:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-05 19:44:22 +0200 |
commit | d1df63c72af9a239b5dad44d0f8545d24a4a292b (patch) | |
tree | 3cd7f3fbca6d08cf4394bf4469b421d2eab3d316 | |
parent | 26b93249f907305c70323ed2e5ac855fa91de9a3 (diff) | |
parent | 4a437177cb2b10b6462380c39739a923c08dc121 (diff) |
Merge pull request #344 from mglisse/bottlenone
Support e=None for bottleneck_distance
-rw-r--r-- | src/python/gudhi/bottleneck.cc | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/python/gudhi/bottleneck.cc b/src/python/gudhi/bottleneck.cc index 732cb9a8..838bf9eb 100644 --- a/src/python/gudhi/bottleneck.cc +++ b/src/python/gudhi/bottleneck.cc @@ -12,22 +12,26 @@ #include <pybind11_diagram_utils.h> -double bottleneck(Dgm d1, Dgm d2, double epsilon) +// For compatibility with older versions, we want to support e=None. +// In C++17, the recommended way is std::optional<double>. +double bottleneck(Dgm d1, Dgm d2, py::object epsilon) { + double e = (std::numeric_limits<double>::min)(); + if (!epsilon.is_none()) e = epsilon.cast<double>(); // I *think* the call to request() has to be before releasing the GIL. auto diag1 = numpy_to_range_of_pairs(d1); auto diag2 = numpy_to_range_of_pairs(d2); py::gil_scoped_release release; - return Gudhi::persistence_diagram::bottleneck_distance(diag1, diag2, epsilon); + return Gudhi::persistence_diagram::bottleneck_distance(diag1, diag2, e); } PYBIND11_MODULE(bottleneck, m) { m.attr("__license__") = "GPL v3"; m.def("bottleneck_distance", &bottleneck, py::arg("diagram_1"), py::arg("diagram_2"), - py::arg("e") = (std::numeric_limits<double>::min)(), + py::arg("e") = py::none(), R"pbdoc( This function returns the point corresponding to a given vertex. @@ -42,7 +46,7 @@ PYBIND11_MODULE(bottleneck, m) { bits of the mantissa may be wrong). This version of the algorithm takes advantage of the limited precision of `double` and is usually a lot faster to compute, whatever the value of `e`. - Thus, by default, `e` is the smallest positive double. + Thus, by default (`e=None`), `e` is the smallest positive double. :type e: float :rtype: float :returns: the bottleneck distance. |