Skip to content

Commit

Permalink
#24 Added (missing) namespaces to the morphology C++ implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
carljohnsen committed May 14, 2024
1 parent 67d0ba4 commit 6819bc5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/lib/cpp/cpu/morphology.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "morphology.hh"
#include "datatypes.hh"

namespace cpu_par {

template <typename Op, bool neutral>
void morphology_3d_sphere(
const mask_type *voxels,
Expand Down Expand Up @@ -43,4 +45,5 @@ void morphology_3d_sphere(
}
}
}
}
}
} // namespace cpu_par
6 changes: 5 additions & 1 deletion src/lib/cpp/cpu_seq/morphology.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "morphology.hh"
#include "datatypes.hh"

namespace cpu_seq {

template <typename Op, bool neutral>
void morphology_3d_sphere(
const mask_type *voxels,
Expand Down Expand Up @@ -41,4 +43,6 @@ void morphology_3d_sphere(
}
}
}
}
}

} // namespace cpu_seq
6 changes: 5 additions & 1 deletion src/lib/cpp/gpu/morphology.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "morphology.hh"
#include "datatypes.hh"

namespace gpu {

template <typename Op, bool neutral>
void morphology_3d_sphere(
const mask_type *voxels,
Expand Down Expand Up @@ -107,4 +109,6 @@ void morphology_3d_sphere_r16(
#else
throw runtime_error("Library wasn't compiled with OpenACC.");
#endif
}
}

} // namespace gpu
4 changes: 4 additions & 0 deletions src/lib/cpp/include/morphology.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "datatypes.hh"

namespace NS {

template <typename Op, bool neutral>
void morphology_3d_sphere(
const mask_type *voxels,
Expand All @@ -11,4 +13,6 @@ void morphology_3d_sphere(
const int64_t strides[3],
mask_type *result);


} // namespace NS
#endif
32 changes: 28 additions & 4 deletions src/pybind/morphology-pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace py = pybind11;
#include "morphology.cc"
#include "datatypes.hh"

namespace python_api {

template <typename Op, bool neutral>
void morphology_3d_sphere_wrapper(
const py::array_t<mask_type> &np_voxels,
Expand All @@ -24,15 +26,37 @@ void morphology_3d_sphere_wrapper(
mask_type *result = static_cast<mask_type*>(result_info.ptr);

if (radius == (int64_t) 16) {
morphology_3d_sphere_r16<Op, neutral>(voxels, N, strides, result);
NS::morphology_3d_sphere_r16<Op, neutral>(voxels, N, strides, result);
} else {
morphology_3d_sphere<Op, neutral>(voxels, radius, N, strides, result);
NS::morphology_3d_sphere<Op, neutral>(voxels, radius, N, strides, result);
}
}

template <typename Op, bool neutral>
void morphology_3d_sphere_wrapper_alt(
const py::array_t<mask_type> &np_voxels,
const int64_t radius,
py::array_t<mask_type> np_result) {
auto
voxels_info = np_voxels.request(),
result_info = np_result.request();

int64_t Nz = voxels_info.shape[0], Ny = voxels_info.shape[1], Nx = voxels_info.shape[2];
int64_t N[3] = {Nz, Ny, Nx};
int64_t strides[3] = {Ny*Nx, Nx, 1};

const mask_type *voxels = static_cast<const mask_type*>(voxels_info.ptr);
mask_type *result = static_cast<mask_type*>(result_info.ptr);

NS::morphology_3d_sphere_alt(voxels, radius, N, strides, result);
}

} // namespace python_api

PYBIND11_MODULE(morphology, m) {
m.doc() = "Morphology operations."; // optional module docstring
m.def("dilate_3d_sphere", &morphology_3d_sphere_wrapper<std::bit_or<mask_type>, false>, py::arg("np_voxels"), py::arg("radius"), py::arg("np_result").noconvert());
m.def("erode_3d_sphere", &morphology_3d_sphere_wrapper<std::bit_and<mask_type>, true>, py::arg("np_voxels"), py::arg("radius"), py::arg("np_result").noconvert());
m.def("dilate_3d_sphere", &python_api::morphology_3d_sphere_wrapper<std::bit_or<mask_type>, false>, py::arg("np_voxels"), py::arg("radius"), py::arg("np_result").noconvert());
m.def("dilate_3d_sphere_alt", &python_api::morphology_3d_sphere_wrapper_alt<std::bit_or<mask_type>, false>, py::arg("np_voxels"), py::arg("radius"), py::arg("np_result").noconvert());
m.def("erode_3d_sphere", &python_api::morphology_3d_sphere_wrapper<std::bit_and<mask_type>, true>, py::arg("np_voxels"), py::arg("radius"), py::arg("np_result").noconvert());
m.def("erode_3d_sphere_alt", &python_api::morphology_3d_sphere_wrapper_alt<std::bit_and<mask_type>, true>, py::arg("np_voxels"), py::arg("radius"), py::arg("np_result").noconvert());
}

0 comments on commit 6819bc5

Please sign in to comment.