From 960798e8a44bc937725cb35670747cd6a6d7879a Mon Sep 17 00:00:00 2001 From: Peter Urban Date: Wed, 25 Sep 2024 21:22:58 +0200 Subject: [PATCH] use xtensor concepts to fix clang builds --- .../amplitudecorrection/functions/module.hpp | 10 ++-- .../.docstrings/rangecorrection.doc.hpp | 2 +- .../.docstrings/wcicorrection.doc.hpp | 2 +- .../functions/rangecorrection.hpp | 51 ++++++++++++------- .../functions/wcicorrection.hpp | 18 +++++-- 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/src/pymodule/amplitudecorrection/functions/module.hpp b/src/pymodule/amplitudecorrection/functions/module.hpp index ca54617..35b5a41 100644 --- a/src/pymodule/amplitudecorrection/functions/module.hpp +++ b/src/pymodule/amplitudecorrection/functions/module.hpp @@ -50,20 +50,20 @@ void init_m_functions(pybind11::module& m) // range correction submodule.def("get_sample_numbers_plus_half", - get_sample_numbers_plus_half, + &get_sample_numbers_plus_half, int64_t>, DOC_functions(get_sample_numbers_plus_half), py::arg("first_sample_nr"), py::arg("last_sample_nr"), py::arg("step") = 1); submodule.def("approximate_range_factor", - approximate_range_factor, + &approximate_range_factor, DOC_functions(approximate_range_factor), py::arg("sample_interval_s"), py::arg("sound_velocity_m_s")); submodule.def("approximate_ranges", - approximate_ranges, + &approximate_ranges, int64_t>, DOC_functions(approximate_ranges), py::arg("sample_interval_s"), py::arg("sound_velocity_m_s"), @@ -72,14 +72,14 @@ void init_m_functions(pybind11::module& m) py::arg("step") = 1); submodule.def("compute_cw_range_correction", - compute_cw_range_correction, + &compute_cw_range_correction>, DOC_functions(compute_cw_range_correction), py::arg("ranges_m"), py::arg("absorption_db_m"), py::arg("tvg_factor")); submodule.def("apply_wci_correction", - apply_wci_correction, + &apply_wci_correction, xt::pytensor>, DOC_functions(apply_wci_correction), py::arg("wci"), py::arg("per_beam_offset"), diff --git a/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/.docstrings/rangecorrection.doc.hpp b/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/.docstrings/rangecorrection.doc.hpp index 26c88ea..efe8d27 100644 --- a/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/.docstrings/rangecorrection.doc.hpp +++ b/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/.docstrings/rangecorrection.doc.hpp @@ -1,4 +1,4 @@ -//sourcehash: fd3765d68f5b2a0a54c3a4057bfde38c84b4a141f4eaacb1862ef398989d077a +//sourcehash: 449e2ac24adaedde10a18e765cfb777059a926172151583846f99e67ba681c04 /* This file contains docstrings for use in the Python bindings. diff --git a/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/.docstrings/wcicorrection.doc.hpp b/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/.docstrings/wcicorrection.doc.hpp index 7f10d6f..4d58cd8 100644 --- a/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/.docstrings/wcicorrection.doc.hpp +++ b/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/.docstrings/wcicorrection.doc.hpp @@ -1,4 +1,4 @@ -//sourcehash: 1ae8666ee5111ec85d545eb0598565f91fc501c9641654802e5948d424bae907 +//sourcehash: 9f9b40bf69cc0bc6ec707420219e7f552a786bcfa4cc47a6f78c86291bd384ae /* This file contains docstrings for use in the Python bindings. diff --git a/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/rangecorrection.hpp b/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/rangecorrection.hpp index 03bdc71..38d4a7b 100644 --- a/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/rangecorrection.hpp +++ b/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/rangecorrection.hpp @@ -13,44 +13,61 @@ #include #include +#include + namespace themachinethatgoesping { namespace algorithms { namespace amplitudecorrection { namespace functions { -template typename t_xtensor, typename t_float, typename t_int> -inline t_xtensor get_sample_numbers_plus_half(t_int first_sample_nr, - t_int last_sample_nr, - t_int step = 1) +// template + +template +inline t_xtensor_1d get_sample_numbers_plus_half(t_int first_sample_nr, + t_int last_sample_nr, + t_int step = 1) { + static_assert(tools::helper::c_xtensor_1d, + "Template parameter must be a 1D tensor"); + + using t_float = tools::helper::xtensor_datatype::type; + // calculate the sample numbers - return xt::arange(first_sample_nr + 0.5, last_sample_nr + 0.5 + 1, step); + return xt::arange(first_sample_nr + t_float(0.5), last_sample_nr + t_float(1.5), step); } template inline t_float approximate_range_factor(t_float sample_interval_s, t_float sound_velocity_m_s) { // calculate the ranges - return sample_interval_s * sound_velocity_m_s * 0.5; + return sample_interval_s * sound_velocity_m_s * t_float(0.5); } -template typename t_xtensor, typename t_float, typename t_int> -inline t_xtensor approximate_ranges(t_float sample_interval_s, - t_float sound_velocity_m_s, - t_int first_sample_nr, - t_int last_sample_nr, - t_int step = 1) +template +inline t_xtensor_1d approximate_ranges( + typename tools::helper::xtensor_datatype::type sample_interval_s, + typename tools::helper::xtensor_datatype::type sound_velocity_m_s, + t_int first_sample_nr, + t_int last_sample_nr, + t_int step = 1) { - return get_sample_numbers_plus_half( + static_assert(tools::helper::c_xtensor_1d, + "Template parameter must be a 1D tensor"); + + return get_sample_numbers_plus_half( first_sample_nr, last_sample_nr, step) * approximate_range_factor(sample_interval_s, sound_velocity_m_s); } -template typename t_xtensor, typename t_float> -inline t_xtensor compute_cw_range_correction(const t_xtensor& ranges_m, - t_float absorption_db_m, - t_float tvg_factor) +template +inline t_xtensor_1d compute_cw_range_correction( + const t_xtensor_1d& ranges_m, + typename tools::helper::xtensor_datatype::type absorption_db_m, + typename tools::helper::xtensor_datatype::type tvg_factor) { + static_assert(tools::helper::c_xtensor_1d, + "Template parameter must be a 1D tensor"); + // range correction = absorption*R + tvg_factor*log10(R) return absorption_db_m * ranges_m + tvg_factor * xt::log10(ranges_m); } diff --git a/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/wcicorrection.hpp b/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/wcicorrection.hpp index 204ebe7..338b5c3 100644 --- a/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/wcicorrection.hpp +++ b/src/themachinethatgoesping/algorithms/amplitudecorrection/functions/wcicorrection.hpp @@ -13,9 +13,12 @@ #include #include #include +#include #include #include +#include + #include "rangecorrection.hpp" namespace themachinethatgoesping { @@ -23,12 +26,17 @@ namespace algorithms { namespace amplitudecorrection { namespace functions { -template typename t_xtensor, typename t_float> -inline t_xtensor apply_wci_correction(t_xtensor wci, - const t_xtensor& per_beam_offset, - const t_xtensor& per_sample_offset, - int mp_cores = 1) +template +inline t_xtensor_2d apply_wci_correction(t_xtensor_2d wci, + const t_xtensor_1d& per_beam_offset, + const t_xtensor_1d& per_sample_offset, + int mp_cores = 1) { + static_assert(tools::helper::c_xtensor_2d, + "Template parameter must be a 2D tensor"); + static_assert(tools::helper::c_xtensor_1d, + "Template parameter must be a 1D tensor"); + // assert that beam_offset has the same shape as wci.shape[0] if (wci.shape(0) != per_beam_offset.size()) throw std::invalid_argument(fmt::format("wci.shape(0) [{}] != per_beam_offset.size() [{}]",