From 6ed90995960e0d35b99c22a8c370d1dd349ca26d Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 15 Oct 2024 14:34:42 +0800 Subject: [PATCH] fix python binding --- bindings/python/CMakeLists.txt | 2 +- bindings/python/manifold3d.cpp | 24 ++++++++++++++++-------- pyproject.toml | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/bindings/python/CMakeLists.txt b/bindings/python/CMakeLists.txt index ee8c9b6a0..9d4abad2d 100644 --- a/bindings/python/CMakeLists.txt +++ b/bindings/python/CMakeLists.txt @@ -52,7 +52,7 @@ else() nanobind GIT_REPOSITORY https://github.com/wjakob/nanobind.git GIT_TAG - 9641bb7151f04120013b812789b3ebdfa7e7324f # v2.1.0 + 784efa2a0358a4dc5432c74f5685ee026e20f2b6 # v2.2.0 GIT_PROGRESS TRUE ) FetchContent_MakeAvailable(nanobind) diff --git a/bindings/python/manifold3d.cpp b/bindings/python/manifold3d.cpp index 949b66ede..0c71e0b55 100644 --- a/bindings/python/manifold3d.cpp +++ b/bindings/python/manifold3d.cpp @@ -31,6 +31,13 @@ namespace nb = nanobind; using namespace manifold; +#if NB_VERSION_MAJOR < 2 || (NB_VERSION_MAJOR == 2 && NB_VERSION_MINOR < 2) +#define ndarray_export ndarray_wrap +#define numpy_value int(ndarray_framework::numpy) +#else +#define numpy_value numpy::value +#endif + template struct glm_name {}; template <> @@ -114,8 +121,7 @@ struct nb::detail::type_caster> { } } numpy_type arr{buffer, {R, C}, std::move(mem_mgr)}; - return ndarray_wrap(arr.handle(), int(ndarray_framework::numpy), policy, - cleanup); + return ndarray_export(arr.handle(), numpy::value, policy, cleanup); } }; @@ -160,8 +166,7 @@ struct nb::detail::type_caster>> { } } numpy_type arr{buffer, {num_vec, N}, std::move(mem_mgr)}; - return ndarray_wrap(arr.handle(), ndarray_framework::numpy, policy, - cleanup); + return ndarray_export(arr.handle(), numpy_value, policy, cleanup); } }; @@ -193,8 +198,7 @@ struct nb::detail::type_caster>> { static_assert(sizeof(vec[0]) == (N * sizeof(T)), "VecView -> numpy requires packed structs"); numpy_type arr{&vec[0], {num_vec, N}, nb::handle()}; - return ndarray_wrap(arr.handle(), ndarray_framework::numpy, policy, - cleanup); + return ndarray_export(arr.handle(), numpy_value, policy, cleanup); } }; @@ -256,7 +260,9 @@ NB_MODULE(manifold3d, m) { .def("scale", &Manifold::Scale, nb::arg("v"), manifold__scale__v) .def( "scale", - [](const Manifold &self, double s) { self.Scale({s, s, s}); }, + [](const Manifold &self, double s) { + self.Scale({s, s, s}); + }, nb::arg("s"), "Scale this Manifold in space. This operation can be chained. " "Transforms are combined and applied lazily.\n\n" @@ -651,7 +657,9 @@ NB_MODULE(manifold3d, m) { cross_section__scale__scale) .def( "scale", - [](const CrossSection &self, double s) { self.Scale({s, s}); }, + [](const CrossSection &self, double s) { + self.Scale({s, s}); + }, nb::arg("s"), "Scale this CrossSection in space. This operation can be chained. " "Transforms are combined and applied lazily." diff --git a/pyproject.toml b/pyproject.toml index 166753335..cc38ed26b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ dependencies = [ [build-system] requires = [ - "nanobind>=1.8.0", + "nanobind>=1.8.0,<=2.2.0", "scikit-build-core", ] build-backend = "scikit_build_core.build"