Skip to content

Commit

Permalink
incorporated review proposals
Browse files Browse the repository at this point in the history
Signed-off-by: rstein <r.steinhagen@gsi.de>
  • Loading branch information
RalphSteinhagen committed Jan 13, 2025
1 parent 0e18e1f commit 4ecda2f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ namespace estimators {
template<typename T>
[[nodiscard]] constexpr T computeCentreOfMass(const DataSet<T>& ds, std::size_t minIndex = 0UZ, std::size_t maxIndex = max_size_t, std::size_t signalIndex = 0, std::source_location location = std::source_location::current()) {
maxIndex = detail::checkIndexRange(ds, minIndex, maxIndex, signalIndex, location);
;
T com = T(0);
T mass = T(0);
T com = T(0);
T mass = T(0);

for (std::size_t i = minIndex; i < maxIndex; i++) {
const T x = getIndexValue(ds, dim::X, i);
Expand Down Expand Up @@ -66,10 +65,10 @@ template<std::ranges::random_access_range T, typename TValue = gr::meta::fundame
for (upperLimit = index; upperLimit < data.size() && data[upperLimit] > maxHalf; upperLimit++) {
// done in condition
}
for (lowerLimit = index; lowerLimit >= 0 && data[lowerLimit] > maxHalf; lowerLimit--) {
for (lowerLimit = index; data[lowerLimit] > maxHalf; lowerLimit--) {
// done in condition
}
if (upperLimit >= data.size() || lowerLimit < 0) {
if (upperLimit >= data.size()) {
return std::numeric_limits<TValue>::quiet_NaN();
}
return static_cast<TValue>(upperLimit - lowerLimit);
Expand All @@ -87,10 +86,10 @@ template<std::ranges::random_access_range T, typename TValue = typename T::value
for (upperLimit = index; upperLimit < data.size() && data[upperLimit] > maxHalf; upperLimit++) {
// done in condition
}
for (lowerLimit = index; lowerLimit >= 0 && data[lowerLimit] > maxHalf; lowerLimit--) {
for (lowerLimit = index; data[lowerLimit] > maxHalf; lowerLimit--) {
// done in condition
}
if (upperLimit >= data.size() || lowerLimit < 0) {
if (upperLimit >= data.size()) {
return std::numeric_limits<TValue>::quiet_NaN();
}
TValue lowerRefined = detail::linearInterpolate(value_t(lowerLimit), value_t(lowerLimit + 1), data[lowerLimit], data[lowerLimit + 1], maxHalf);
Expand Down Expand Up @@ -178,7 +177,7 @@ template<typename T, typename TValue = gr::meta::fundamental_base_value_type_t<T
}

std::vector<T> data(values.begin(), values.end()); // temporary mutable copy for in-place partitioning
auto mid = data.begin() + data.size() / 2;
auto mid = data.begin() + static_cast<std::ptrdiff_t>(data.size()) / 2;
std::ranges::nth_element(data, mid);

if ((data.size() & 1UZ) == 0UZ) {
Expand Down Expand Up @@ -520,7 +519,7 @@ std::optional<StepStartDetectionResult<T>> detectStepStart(D& ds, TValue thresho

T thresholdCrossing = isRising ? initial + threshold * (max_val - initial) : initial - threshold * (initial - min_val);
T triggerTime = estimators::getZeroCrossing<MetaInfo::None>(ds, thresholdCrossing, indexMin, indexMax, signalIndex);
if (triggerTime == std::numeric_limits<TValue>::quiet_NaN()) {
if (std::isnan(gr::value(triggerTime))) {
return std::nullopt; // failed to compute trigger time
}

Expand Down Expand Up @@ -588,7 +587,7 @@ template<MetaInfo mode = MetaInfo::Apply, DataSetLike D, typename T = typename s
prevRMS = localRMS;
}
T settlingLevel = estimators::getMean(dataSet, settlingTimeIdx, maxIndex + windowSize, signalIndex);
settlingTime += windowSize / 2UZ;
settlingTime += static_cast<int>(windowSize) / 2;
if (settlingTime < 0) {
return std::nullopt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ constexpr DataSet<T> applyMedian(const DataSet<T>& ds, std::size_t windowSize, s
std::copy(signal.begin() + start, signal.begin() + end, medianWindow.begin());

auto medianWindowView = std::span(medianWindow.data(), size);
auto midIter = medianWindowView.begin() + (size / 2UZ);
auto midIter = medianWindowView.begin() + static_cast<std::ptrdiff_t>(size / 2UZ);
std::ranges::nth_element(medianWindowView, midIter);

if ((size & 1UZ) == 0UZ) { // even-sized window -> take average around mid-point
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ template<typename T, typename TValue = gr::meta::fundamental_base_value_type_t<T
ds.timing_events.resize(1UZ);
ds.extents = {1, static_cast<std::int32_t>(count)};

auto gauss = [](U x, U mu, U sigma) -> TValue { return std::exp(-std::pow((TValue(x) - TValue(mu)) / TValue(sigma), 2) / U(2)) / (TValue(sigma) * std::sqrt(TValue(2) * std::numbers::pi_v<TValue>)); };
auto gauss = [](U x, U mu, U sig) -> TValue { return std::exp(-std::pow((TValue(x) - TValue(mu)) / TValue(sig), 2) / U(2)) / (TValue(sig) * std::sqrt(TValue(2) * std::numbers::pi_v<TValue>)); };

for (std::size_t i = 0; i < count; ++i) {
ds.axis_values[0][i] = static_cast<TValue>(i);
Expand Down
8 changes: 6 additions & 2 deletions algorithm/test/qa_DataSetEstimators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ const boost::ut::suite<"DataSet<T> visual test functions"> _DataSetTestFcuntions

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdouble-promotion"
#pragma GCC diagnostic ignored "-Wfloat-conversion"
#pragma GCC diagnostic ignored "-Wconversion"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wimplicit-float-conversion" // GCC & Clang: Loss or promotion of floating-point precision, disabled only for unit-tests
#endif

const boost::ut::suite<"DataSet<T> element-wise accessor"> _dataSetAccessors = [] {
using namespace boost::ut;
Expand Down Expand Up @@ -495,7 +499,7 @@ const boost::ut::suite<"DataSet<T> math "> _dataSetMath = [] {

auto ds_pulse_proto = generate::stepFunction<T>("pulse", 100, 20);
for (std::size_t i = 50; i < 70; ++i) {
ds_pulse_proto.signal_values[i] = 1.0 - 0.01 * (i - 50); // gradual decrease at end-of-flat top
ds_pulse_proto.signal_values[i] = value_t(1.0) - value_t(0.01) * value_t(i - 50); // gradual decrease at end-of-flat top
}
for (std::size_t i = 70; i < 100; ++i) {
ds_pulse_proto.signal_values[i] = 0.0; // final level
Expand Down Expand Up @@ -568,7 +572,7 @@ const boost::ut::suite<"DataSet<T> filter"> _dataSetFilter = [] {

auto smoothed = filter::applyMovingAverage(ds, 3UZ);

std::vector<T> expected = {0.1, 0.2, 0.4, 0.6, 0.7};
std::vector<T> expected = {value_t(0.1), value_t(0.2), value_t(0.4), value_t(0.6), value_t(0.7)};
for (std::size_t i = 0; i < expected.size(); ++i) {
T val = smoothed.signal_values[i];
expect(approx(val, expected[i], T(1e-3))) << fmt::format("smoothed value at index {}: expected {}, got {}", i, expected[i], val);
Expand Down
3 changes: 3 additions & 0 deletions meta/include/gnuradio-4.0/meta/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@
namespace gr {

#pragma GCC diagnostic push // suppress unavoidable float/int/size_t conversion warnings
#pragma GCC diagnostic ignored "-Wconversion"
#ifdef __clang__
#pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion"
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#pragma GCC diagnostic ignored "-Wimplicit-int-float-conversion"
#pragma GCC diagnostic ignored "-Wimplicit-float-conversion"
#endif

using Size_t = std::uint32_t; // strict type definition in view of cross-platform/cross-compiler/cross-network portability similar to 'std::size_t' (N.B. which is not portable)
inline constexpr Size_t max_Size_t = std::numeric_limits<gr::Size_t>::max();
Expand Down

0 comments on commit 4ecda2f

Please sign in to comment.