From bea81f2d7bc53876a6f071c919663261314965ab Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Thu, 4 Jun 2020 17:21:05 +0200 Subject: Use ssize_t from pybind11 --- src/python/gudhi/hera/bottleneck.cc | 10 ++++------ src/python/include/pybind11_diagram_utils.h | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src/python') diff --git a/src/python/gudhi/hera/bottleneck.cc b/src/python/gudhi/hera/bottleneck.cc index f543613e..846a3525 100644 --- a/src/python/gudhi/hera/bottleneck.cc +++ b/src/python/gudhi/hera/bottleneck.cc @@ -8,18 +8,16 @@ * - YYYY/MM Author: Description of the modification */ +#include + +#ifdef _MSC_VER // https://github.com/grey-narn/hera/issues/3 // ssize_t is a non-standard type (well, posix) -// BaseTsd.h provides SSIZE_T on windows, this one should be the same there. -#ifdef _MSC_VER -#include -typedef std::ptrdiff_t ssize_t; +using py::ssize_t; #endif #include // Hera -#include - double bottleneck_distance(Dgm d1, Dgm d2, double delta) { // I *think* the call to request() has to be before releasing the GIL. diff --git a/src/python/include/pybind11_diagram_utils.h b/src/python/include/pybind11_diagram_utils.h index d9627258..2d5194f4 100644 --- a/src/python/include/pybind11_diagram_utils.h +++ b/src/python/include/pybind11_diagram_utils.h @@ -18,8 +18,8 @@ namespace py = pybind11; typedef py::array_t Dgm; // Get m[i,0] and m[i,1] as a pair -static auto pairify(void* p, ssize_t h, ssize_t w) { - return [=](ssize_t i){ +static auto pairify(void* p, py::ssize_t h, py::ssize_t w) { + return [=](py::ssize_t i){ char* birth = (char*)p + i * h; char* death = birth + w; return std::make_pair(*(double*)birth, *(double*)death); @@ -32,8 +32,8 @@ inline auto numpy_to_range_of_pairs(py::array_t dgm) { if((buf.ndim!=2 || buf.shape[1]!=2) && (buf.ndim!=1 || buf.shape[0]!=0)) throw std::runtime_error("Diagram must be an array of size n x 2"); // In the case of shape (0), avoid reading non-existing strides[1] even if we won't use it. - ssize_t stride1 = buf.ndim == 2 ? buf.strides[1] : 0; - auto cnt = boost::counting_range(0, buf.shape[0]); + py::ssize_t stride1 = buf.ndim == 2 ? buf.strides[1] : 0; + auto cnt = boost::counting_range(0, buf.shape[0]); return boost::adaptors::transform(cnt, pairify(buf.ptr, buf.strides[0], stride1)); // Be careful that the returned range cannot contain references to dead temporaries. } -- cgit v1.2.3