From 8226f645e01c11ccfc7919327bb281b6f805bfa4 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Sat, 10 Dec 2022 20:40:24 +0100 Subject: Use std::optional for possibly None argument. --- src/python/gudhi/bottleneck.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/python/gudhi/bottleneck.cc b/src/python/gudhi/bottleneck.cc index 3a0fe473..1cf3283c 100644 --- a/src/python/gudhi/bottleneck.cc +++ b/src/python/gudhi/bottleneck.cc @@ -9,18 +9,17 @@ */ #include - +#include #include +#include // Indices are added internally in bottleneck_distance, they are not needed in the input. static auto make_point(double x, double y, py::ssize_t) { return std::pair(x, y); }; // For compatibility with older versions, we want to support e=None. -// In C++17, the recommended way is std::optional. -double bottleneck(Dgm d1, Dgm d2, py::object epsilon) +double bottleneck(Dgm d1, Dgm d2, std::optional epsilon) { - double e = (std::numeric_limits::min)(); - if (!epsilon.is_none()) e = epsilon.cast(); + double e = epsilon.value_or((std::numeric_limits::min)()); // I *think* the call to request() has to be before releasing the GIL. auto diag1 = numpy_to_range_of_pairs(d1, make_point); auto diag2 = numpy_to_range_of_pairs(d2, make_point); -- cgit v1.2.3