Skip to content

Commit

Permalink
fix python binding
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed Oct 15, 2024
1 parent 370375e commit 6ed9099
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 16 additions & 8 deletions bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T>
struct glm_name {};
template <>
Expand Down Expand Up @@ -114,8 +121,7 @@ struct nb::detail::type_caster<glm::mat<C, R, T, Q>> {
}
}
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);
}
};

Expand Down Expand Up @@ -160,8 +166,7 @@ struct nb::detail::type_caster<std::vector<glm::vec<N, T, Q>>> {
}
}
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);
}
};

Expand Down Expand Up @@ -193,8 +198,7 @@ struct nb::detail::type_caster<manifold::VecView<glm::vec<N, T, Q>>> {
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);
}
};

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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."
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 6ed9099

Please sign in to comment.