More uniform binding of Numpy arrays (#381)
Build on RHEL9 / build (push) Successful in 2m54s
Build on RHEL8 / build (push) Successful in 3m31s
Run tests using data on local RHEL8 / build (push) Failing after 4m28s
Build on local RHEL8 / build (push) Successful in 3m6s

- Introduce a standard way to bind numpy arrays: py::array_t<T> and
.noconvert() on the argument
- Take py::array_t by value since it's just a small wrapper
- Update bindings
This commit is contained in:
Erik Fröjdh authored and GitHub committed 2026-09-25 14:40:33 +02:00
1 parent 8579a140f7
commit 941325ea15
26 files changed
+597 -280

No files matched your search

+30 -28
View File
@@ -21,40 +21,42 @@ void define_var_cluster_finder_bindings(py::module &m) {
auto *ptr = new NDArray<int, 2>(self.labeled());
return return_image_data(ptr);
})
.def("set_noiseMap",
[](VarClusterFinder<double> &self,
py::array_t<double, py::array::c_style | py::array::forcecast>
noise_map) {
auto noise_map_span = make_view_2d(noise_map);
self.set_noiseMap(noise_map_span);
})
.def(
"set_noiseMap", // conversions ok
[](VarClusterFinder<double> &self,
py::array_t<double, py::array::c_style | py::array::forcecast>
noise_map) {
auto noise_map_span = make_view_2d(noise_map);
self.set_noiseMap(noise_map_span);
},
py::arg("noise_map"))
.def("set_numberOfNeighbours",
&VarClusterFinder<double>::set_numberOfNeighbours)
.def("set_empty_surroundingPixels",
&VarClusterFinder<double>::set_empty_surroundingPixels)
.def("set_peripheralThresholdFactor",
&VarClusterFinder<double>::set_peripheralThresholdFactor)
.def("find_clusters",
[](VarClusterFinder<double> &self,
py::array_t<double, py::array::c_style | py::array::forcecast>
img) {
auto view = make_view_2d(img);
self.find_clusters(view);
})
.def("find_clusters_X",
[](VarClusterFinder<double> &self,
py::array_t<double, py::array::c_style | py::array::forcecast>
img) {
auto img_span = make_view_2d(img);
self.find_clusters_X(img_span);
})
.def("single_pass",
[](VarClusterFinder<double> &self,
py::array_t<double, py::array::c_style | py::array::forcecast>
img) {
auto img_span = make_view_2d(img);
self.single_pass(img_span);
})
.def(
"find_clusters",
[](VarClusterFinder<double> &self, py::array_t<double> img) {
auto view = make_view_2d(img);
self.find_clusters(view);
},
py::arg("img").noconvert())
.def(
"find_clusters_X",
[](VarClusterFinder<double> &self, py::array_t<double> img) {
auto img_span = make_view_2d(img);
self.find_clusters_X(img_span);
},
py::arg("img").noconvert())
.def(
"single_pass",
[](VarClusterFinder<double> &self, py::array_t<double> img) {
auto img_span = make_view_2d(img);
self.single_pass(img_span);
},
py::arg("img").noconvert())
.def("hits",
[](VarClusterFinder<double> &self) {
auto ptr = new std::vector<VarClusterFinder<double>::Hit>(