Replies: 2 comments
-
Why not encode this information using some kind of nd-array with shape |
Beta Was this translation helpful? Give feedback.
0 replies
-
Since inside cpp code, there are lots of func based on std::vector operators. But I looked again this problem again recently and found a way to do similarly according to nanobind document Eigen convenience type aliases. It did speed up the run, from 0.1s to 0.01s around. NB_MODULE(linefit, m) {
nb::class_<GroundSegmentation>(m, "ground_seg")
.def(nb::init<>(), "linefit ground segmentation constructor, param: ")
.def(nb::init<const std::string &>(), "linefit ground segmentation constructor, with toml file as param file input.")
.def("run", [](GroundSegmentation& self, const nb::ndarray<double>& array) {
if (array.ndim() != 2 || array.shape(1) != 3) {
throw std::runtime_error("Input array must have shape (N, 3)");
}
std::vector<Eigen::Vector3d> points_vec(array.shape(0));
std::memcpy(points_vec.data(), array.data(), array.size() * sizeof(double));
return self.segment(points_vec);
}, "points"_a, nb::rv_policy::reference);
} Thanks for your reply still. Hope this could help people afterward. Some old reference issues from pytbind I attached here: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Now what I do is here, the full code can be found in this repo: linefit point cloud ground segmentation:
As you can see, every time:
onst std::vector<std::vector<float>> points
to C++std::vector<Eigen::Vector3d>
in C++.When the N (the number of points) is large, then speed could be slow here.
In pybind11, a popular open3d library they also did kind of thing from
stl_vector_eigen
full file link: cpp/pybind/utility/eigen.cppI'm wondering if nanobind has a better way of processing or I need to rewrite a py_array_to_vectors_double in nanobind also?
Thanks in advance. @wjakob 😊
Beta Was this translation helpful? Give feedback.
All reactions