Skip to content

Commit

Permalink
fixed cpp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-urban committed Oct 15, 2024
1 parent ef1036f commit 69f1541
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 36 deletions.
33 changes: 14 additions & 19 deletions src/tests/algorithms/functions/wcicorrection.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ using namespace themachinethatgoesping::algorithms::amplitudecorrection::functio

template<themachinethatgoesping::tools::helper::c_xtensor t_xtensor_2d,
themachinethatgoesping::tools::helper::c_xtensor t_xtensor_1d>
void check_wci(std::string name,
const t_xtensor_2d& result,
const t_xtensor_2d& wci,
const t_xtensor_1d& per_beam_offset,
const t_xtensor_1d& per_sample_offset,
std::optional<size_t> min_beam_index = std::nullopt,
std::optional<size_t> max_beam_index = std::nullopt)
void check_wci([[maybe_unused]] std::string name,
const t_xtensor_2d& result,
const t_xtensor_2d& wci,
const t_xtensor_1d& per_beam_offset,
const t_xtensor_1d& per_sample_offset,
std::optional<size_t> min_beam_index = std::nullopt,
std::optional<size_t> max_beam_index = std::nullopt)
{
using Catch::Approx;

Expand Down Expand Up @@ -57,15 +57,9 @@ void check_wci(std::string name,
for (size_t sn = 0; sn < nsamples; ++sn)
{
// std::string msg = fmt::format(
// "ERROR[{}]: per_beam_offset({}) = {}, per_sample_offset({}) = {}, wci({},{}) = {}",
// name,
// bn,
// per_beam_offset(bn),
// sn,
// per_sample_offset(sn),
// bn,
// sn,
// wci(bn, sn));
// "ERROR[{}]: per_beam_offset({}) = {}, per_sample_offset({}) = {}, wci({},{}) =
// {}", name, bn, per_beam_offset(bn), sn, per_sample_offset(sn), bn, sn, wci(bn,
// sn));

// if (min_beam_index.has_value())
// msg += fmt::format(", min_beam_index = {}", min_beam_index.value());
Expand All @@ -92,7 +86,8 @@ void check_wci(std::string name,
for (size_t sn = 0; sn < nsamples; ++sn)
{
// INFO(
// fmt::format("ERROR[{}]: Value should be untouchted (1)! bn = {}/min {}, sn = {}"
// fmt::format("ERROR[{}]: Value should be untouchted (1)! bn = {}/min {}, sn =
// {}"
// "wci({},{}) = {}",
// name,
// bn,
Expand Down Expand Up @@ -286,9 +281,9 @@ TEST_CASE("WCICorrection functions should reproduce previously computed results"

for (size_t mp_cores : { 1, 0, 4 })
for (std::optional<size_t> min_bn :
std::vector<std::optional<size_t>>{ std::nullopt, 0, 3, 7, 9, 10, 11, 999999 })
std::vector<std::optional<size_t>>{ std::nullopt, 0, 7, 10, 999999 })
for (std::optional<size_t> max_bn :
std::vector<std::optional<size_t>>{ std::nullopt, 0, 3, 7, 9, 10, 11, 999999 })
std::vector<std::optional<size_t>>{ std::nullopt, 0, 3, 10, 999999 })
{

// --- inplace_beam_sample_correction ---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//sourcehash: 3d75623baa823bce891424d7bf0f91b17a13bbec95afccb52c15f153793e8f99

/*
This file contains docstrings for use in the Python bindings.
Do not edit! They were automatically extracted by pybind11_mkdoc.
This is a modified version which allows for more than 8 arguments and includes def-guard
*/

#pragma once

#ifndef __DOCSTRINGS_HPP__

#define __EXPAND(x) x
#define __COUNT(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, COUNT, ...) COUNT
#define __VA_SIZE(...) __EXPAND(__COUNT(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1))
#define __CAT1(a, b) a##b
#define __CAT2(a, b) __CAT1(a, b)
#define __DOC1(n1) __doc_##n1
#define __DOC2(n1, n2) __doc_##n1##_##n2
#define __DOC3(n1, n2, n3) __doc_##n1##_##n2##_##n3
#define __DOC4(n1, n2, n3, n4) __doc_##n1##_##n2##_##n3##_##n4
#define __DOC5(n1, n2, n3, n4, n5) __doc_##n1##_##n2##_##n3##_##n4##_##n5
#define __DOC6(n1, n2, n3, n4, n5, n6) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6
#define __DOC7(n1, n2, n3, n4, n5, n6, n7) __doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7
#define __DOC8(n1, n2, n3, n4, n5, n6, n7, n8) \
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7##_##n8
#define __DOC9(n1, n2, n3, n4, n5, n6, n7, n8, n9) \
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7##_##n8##_##n9
#define __DOC10(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10) \
__doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7##_##n8##_##n9##_##n10
#define DOC(...) __EXPAND(__EXPAND(__CAT2(__DOC, __VA_SIZE(__VA_ARGS__)))(__VA_ARGS__))

#endif // NEW_DOC_HEADER_HPP
#if defined(__GNUG__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif


static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_assert_wci_axis_shape = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_assert_wci_beam_sample_shape = R"doc()doc";

#if defined(__GNUG__)
#pragma GCC diagnostic pop
#endif


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: 50c3a9bed6dffaec83b931b6cf30653eaca9ebfdce0e73ee940aea068eac54b6
//sourcehash: 19d855f4b32912e8d1bcf4f095813225f4cff8d1cadf936071d75c435684376c

/*
This file contains docstrings for use in the Python bindings.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: ac07a37fcf08e556461524a3ee96694d20786614afa37e2f9d34b5e4be76c671
//sourcehash: 95a453fd6a55fe697a7d06e626b3f2e6f49a5bddac04c4b9d51319dbb7e753b1

/*
This file contains docstrings for use in the Python bindings.
Expand Down Expand Up @@ -38,15 +38,147 @@
#endif


static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_approximate_range_factor = R"doc()doc";
static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_approximate_range_factor =
R"doc(Approximates the range factor based on the sample interval and a
single sound velocity.
static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_approximate_ranges = R"doc()doc";
This function calculates the range factor using the given sample
interval and sound velocity. The formula used is: range_factor =
sample_interval_s * sound_velocity_m_s * 0.5
static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_approximate_ranges_2 = R"doc()doc";
Template parameter ``t_float``:
The floating-point type used for the calculations.
static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_compute_cw_range_correction = R"doc()doc";
Parameter ``sample_interval_s``:
The sample interval in seconds.
static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_get_sample_numbers_plus_half = R"doc()doc";
Parameter ``sound_velocity_m_s``:
The sound velocity in meters per second.
Returns:
The approximated range factor.)doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_approximate_ranges =
R"doc(Approximates the ranges based on the provided sample interval and a
single sound velocity.
This function calculates the approximate ranges for a given set of
sample numbers by multiplying the sample numbers (plus half) with the
approximate range factor.
Template parameter ``t_xtensor_1d``:
A 1D tensor type that satisfies the c_xtensor_1d concept.
Template parameter ``t_int``:
An integer type for sample numbers.
Parameter ``sample_interval_s``:
The sample interval in seconds.
Parameter ``sound_velocity_m_s``:
The sound velocity in meters per second.
Parameter ``first_sample_nr``:
The first sample number.
Parameter ``last_sample_nr``:
The last sample number.
Parameter ``step``:
The step size between sample numbers (default is 1).
Returns:
A 1D tensor containing the approximated ranges.)doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_approximate_ranges_2 =
R"doc(Approximates the ranges based on sample interval, a single sound
velocity, and sample numbers.
This function calculates the approximate ranges by using the provided
sample interval, sound velocity, and sample numbers. The calculation
is performed by adding 0.5 to each sample number and then multiplying
by the approximate range factor.
Template parameter ``t_xtensor_1d``:
A 1D tensor type that satisfies the tools::helper::c_xtensor
concept.
Template parameter ``t_xtensor_1d_int``:
A 1D tensor type for integers that satisfies the
tools::helper::c_xtensor concept.
Parameter ``sample_interval_s``:
The interval between samples in seconds.
Parameter ``sound_velocity_m_s``:
The velocity of sound in meters per second.
Parameter ``sample_numbers``:
A 1D tensor containing the sample numbers.
Returns:
A 1D tensor containing the approximated ranges.)doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_compute_cw_range_correction =
R"doc(Computes the continuous wave (CW) range correction.
This function calculates the range correction based on the provided
ranges, absorption coefficient, and time-varying gain (TVG) factor.
The range correction is computed using the formula:
\f[ \text{range correction} = 2 \cdot \text{absorption\_db\_m} \cdot
\text{ranges\_m} + \text{tvg\_factor} \cdot
\log_{10}(\text{ranges\_m}) \f]
If the absorption coefficient is finite and non-zero, it is used in
the calculation. If the TVG factor is finite and non-zero, it is also
included in the calculation. If neither the absorption coefficient nor
the TVG factor are finite and non-zero, the function returns a tensor
of zeros with the same shape as the input ranges.
Template parameter ``t_xtensor_1d``:
A 1D tensor type that satisfies the tools::helper::c_xtensor_1d
concept.
Parameter ``ranges_m``:
A 1D tensor representing the ranges in meters.
Parameter ``absorption_db_m``:
The absorption coefficient in decibels per meter.
Parameter ``tvg_factor``:
The time-varying gain factor.
Returns:
A 1D tensor representing the computed range correction.)doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_get_sample_numbers_plus_half =
R"doc(Generates a 1D tensor of sample numbers incremented by half. (used for
range compuation)
This function calculates a range of sample numbers starting from
`first_sample_nr + 0.5` to `last_sample_nr + 1.5` with a specified
step.
Template parameter ``t_xtensor_1d``:
A 1D tensor type that satisfies the `tools::helper::c_xtensor`
concept.
Template parameter ``t_int``:
An integer type for the sample numbers.
Parameter ``first_sample_nr``:
The starting sample number.
Parameter ``last_sample_nr``:
The ending sample number.
Parameter ``step``:
The step size for the range (default is 1).
Returns:
A 1D tensor of sample numbers incremented by half. @note The
template parameter must be a 1D tensor.)doc";

#if defined(__GNUG__)
#pragma GCC diagnostic pop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//sourcehash: 74cc20afed09c424822f5f20f0e76ab9dd2d949f43487fcf56bb7ce19d4fc5ab
//sourcehash: 08faf1ecb5292411c6b77cb76116b765edd214e9e57cf2beb259bec1fa3328e4

/*
This file contains docstrings for use in the Python bindings.
Expand Down Expand Up @@ -40,7 +40,33 @@

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_apply_beam_correction = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_apply_beam_sample_correction = R"doc()doc";
static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_apply_beam_sample_correction =
R"doc(Applies beam and sample corrections to the given 2D tensor.
Apply beam and sample corrections to the input 2D tensor. per_beam
correction is applied to each sample in a beam, per_sample correction
to each sample nr for each beam
Template parameter ``t_xtensor_2d``:
Type of the 2D tensor.
Template parameter ``t_xtensor_1d``:
Type of the 1D tensor.
Parameter ``wci``:
The input 2D tensor to which corrections will be applied.
Parameter ``per_beam_offset``:
A 1D tensor containing the per-beam offsets.
Parameter ``per_sample_offset``:
A 1D tensor containing the per-sample offsets.
Parameter ``mp_cores``:
The number of cores to use for parallel processing (default is 1).
Returns:
A 2D tensor with the applied beam and sample corrections.)doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_apply_beam_sample_correction_loop = R"doc()doc";

Expand All @@ -54,18 +80,10 @@ static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_f

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_apply_system_offset = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_assert_wci_axis_shape = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_assert_wci_axis_shape_0 = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_assert_wci_beam_sample_shape = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_inplace_beam_correction = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_inplace_beam_sample_correction = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_inplace_beam_sample_correction2 = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_inplace_sample_correction = R"doc()doc";

static const char *__doc_themachinethatgoesping_algorithms_amplitudecorrection_functions_inplace_system_offset = R"doc()doc";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#pragma once

/* generated doc strings */
#include ".docstrings/_shape_assertations.doc.hpp"

#include <Eigen/Core>
#include <Eigen/Dense>
#include <fmt/core.h>
Expand Down

0 comments on commit 69f1541

Please sign in to comment.