Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage: configure Sonarcube exclusions #413

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/restyled.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Restyled

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
restyled:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- uses: restyled-io/actions/setup@v4
- id: restyler
uses: restyled-io/actions/run@v4
with:
fail-on-differences: true

174 changes: 61 additions & 113 deletions algorithm/include/gnuradio-4.0/algorithm/ImChart.hpp

Large diffs are not rendered by default.

343 changes: 144 additions & 199 deletions algorithm/include/gnuradio-4.0/algorithm/filter/FilterTool.hpp

Large diffs are not rendered by default.

53 changes: 21 additions & 32 deletions algorithm/include/gnuradio-4.0/algorithm/fourier/fft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,24 @@
namespace gr::algorithm {

template<typename TInput, typename TOutput = std::conditional<gr::meta::complex_like<TInput>, TInput, std::complex<typename TInput::value_type>>>
requires((gr::meta::complex_like<TInput> || std::floating_point<TInput>) && (gr::meta::complex_like<TOutput>) )
requires((gr::meta::complex_like<TInput> || std::floating_point<TInput>) && (gr::meta::complex_like<TOutput>))
struct FFT {
using Precision = TOutput::value_type;

std::vector<TOutput> twiddleFactors{};
std::size_t fftSize{ 0 };

FFT() = default;
FFT(const FFT &rhs) = delete;
FFT(FFT &&rhs) noexcept = delete;
FFT &
operator=(const FFT &rhs)
= delete;
FFT &
operator=(FFT &&rhs) noexcept
= delete;
std::size_t fftSize{0};

FFT() = default;
FFT(const FFT& rhs) = delete;
FFT(FFT&& rhs) noexcept = delete;
FFT& operator=(const FFT& rhs) = delete;
FFT& operator=(FFT&& rhs) noexcept = delete;

~FFT() = default;

void
initAll() {
precomputeTwiddleFactors();
}
void initAll() { precomputeTwiddleFactors(); }

auto
compute(const std::ranges::input_range auto &in, std::ranges::output_range<TOutput> auto &&out) {
auto compute(const std::ranges::input_range auto& in, std::ranges::output_range<TOutput> auto&& out) {
if constexpr (requires(std::size_t n) { out.resize(n); }) {
if (out.size() != in.size()) {
out.resize(in.size());
Expand Down Expand Up @@ -74,8 +66,8 @@ struct FFT {
const auto half_s = s / 2;
for (std::size_t k = 0; k < fftSize; k += s) {
for (std::size_t j = 0; j < half_s; j++) {
const auto t{ twiddleFactors[omega_kCounter++] * out[k + j + half_s] };
const auto u{ out[k + j] };
const auto t{twiddleFactors[omega_kCounter++] * out[k + j + half_s]};
const auto u{out[k + j]};
out[k + j] = u + t;
out[k + j + half_s] = u - t;
}
Expand All @@ -85,30 +77,27 @@ struct FFT {
return out;
}

auto
compute(const std::ranges::input_range auto &in) {
return compute(in, std::vector<TOutput>(in.size()));
}
auto compute(const std::ranges::input_range auto& in) { return compute(in, std::vector<TOutput>(in.size())); }

private:
void
bitReversalPermutation(std::vector<TOutput> &vec) const noexcept {
void bitReversalPermutation(std::vector<TOutput>& vec) const noexcept {
for (std::size_t j = 0, rev = 0; j < fftSize; j++) {
if (j < rev) std::swap(vec[j], vec[rev]);
if (j < rev) {
std::swap(vec[j], vec[rev]);
}
auto maskLen = static_cast<std::size_t>(std::countr_zero(j + 1) + 1);
rev ^= fftSize - (fftSize >> maskLen);
}
}

void
precomputeTwiddleFactors() {
void precomputeTwiddleFactors() {
twiddleFactors.clear();
const auto minus2Pi = Precision(-2. * std::numbers::pi);
for (std::size_t s = 2; s <= fftSize; s *= 2) {
const std::size_t m{ s / 2 };
const TOutput w{ std::exp(TOutput(0., minus2Pi / static_cast<Precision>(s))) };
const std::size_t m{s / 2};
const TOutput w{std::exp(TOutput(0., minus2Pi / static_cast<Precision>(s)))};
for (std::size_t k = 0; k < fftSize; k += s) {
TOutput wk{ 1., 0. };
TOutput wk{1., 0.};
for (std::size_t j = 0; j < m; j++) {
twiddleFactors.push_back(wk);
wk *= w;
Expand Down
166 changes: 72 additions & 94 deletions algorithm/include/gnuradio-4.0/algorithm/fourier/fftw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,63 @@
namespace gr::algorithm {

namespace detail {
template<typename TData>
struct FFTwImplTypes {
using PlanType = fftwf_plan;
using InAlgoDataType = std::conditional_t<gr::meta::complex_like<TData>, fftwf_complex, float>;
using OutAlgoDataType = fftwf_complex;
};
template<typename TData>
struct FFTwImplTypes {
using PlanType = fftwf_plan;
using InAlgoDataType = std::conditional_t<gr::meta::complex_like<TData>, fftwf_complex, float>;
using OutAlgoDataType = fftwf_complex;
};

template<typename TData>
requires (std::is_same_v<TData, std::complex<double>> || std::is_same_v<TData, double>)
struct FFTwImplTypes<TData> {
using PlanType = fftw_plan;
using InAlgoDataType = std::conditional_t<gr::meta::complex_like<TData>, fftw_complex, double>;
using OutAlgoDataType = fftw_complex;
};
template<typename TData>
requires(std::is_same_v<TData, std::complex<double>> || std::is_same_v<TData, double>)
struct FFTwImplTypes<TData> {
using PlanType = fftw_plan;
using InAlgoDataType = std::conditional_t<gr::meta::complex_like<TData>, fftw_complex, double>;
using OutAlgoDataType = fftw_complex;
};

template<typename TData>
struct FFTwImplFreeIn {
using InAlgoDataType = FFTwImplTypes<TData>::InAlgoDataType;
void operator()(InAlgoDataType *ptr) { fftwf_free(ptr); }
};
template<typename TData>
struct FFTwImplFreeIn {
using InAlgoDataType = FFTwImplTypes<TData>::InAlgoDataType;
void operator()(InAlgoDataType* ptr) { fftwf_free(ptr); }
};

template<typename TData>
requires (std::is_same_v<TData, std::complex<double>> || std::is_same_v<TData, double>)
struct FFTwImplFreeIn<TData> {
using InAlgoDataType = FFTwImplTypes<TData>::InAlgoDataType;
void operator()(InAlgoDataType *ptr) { fftw_free(ptr); }
};
template<typename TData>
requires(std::is_same_v<TData, std::complex<double>> || std::is_same_v<TData, double>)
struct FFTwImplFreeIn<TData> {
using InAlgoDataType = FFTwImplTypes<TData>::InAlgoDataType;
void operator()(InAlgoDataType* ptr) { fftw_free(ptr); }
};

template<typename TData>
struct FFTwImplFreeOut {
using OutAlgoDataType = FFTwImplTypes<TData>::OutAlgoDataType;
void operator()(OutAlgoDataType *ptr) { fftwf_free(ptr); }
};
template<typename TData>
struct FFTwImplFreeOut {
using OutAlgoDataType = FFTwImplTypes<TData>::OutAlgoDataType;
void operator()(OutAlgoDataType* ptr) { fftwf_free(ptr); }
};

template<typename TData>
requires (std::is_same_v<TData, std::complex<double>> || std::is_same_v<TData, double>)
struct FFTwImplFreeOut<TData> {
using OutAlgoDataType = FFTwImplTypes<TData>::OutAlgoDataType;
void operator()(OutAlgoDataType *ptr) { fftw_free(ptr); }
};
template<typename TData>
requires(std::is_same_v<TData, std::complex<double>> || std::is_same_v<TData, double>)
struct FFTwImplFreeOut<TData> {
using OutAlgoDataType = FFTwImplTypes<TData>::OutAlgoDataType;
void operator()(OutAlgoDataType* ptr) { fftw_free(ptr); }
};

template<typename TData>
struct FFTwImplDestroyPlan {
using PlanType = FFTwImplTypes<TData>::PlanType;
void operator()(PlanType ptr) { fftwf_destroy_plan(ptr); }
};
template<typename TData>
struct FFTwImplDestroyPlan {
using PlanType = FFTwImplTypes<TData>::PlanType;
void operator()(PlanType ptr) { fftwf_destroy_plan(ptr); }
};

template<typename TData>
requires (std::is_same_v<TData, std::complex<double>> || std::is_same_v<TData, double>)
struct FFTwImplDestroyPlan<TData> {
using PlanType = FFTwImplTypes<TData>::PlanType;
void operator()(PlanType ptr) { fftw_destroy_plan(ptr); }
};
}
template<typename TData>
requires(std::is_same_v<TData, std::complex<double>> || std::is_same_v<TData, double>)
struct FFTwImplDestroyPlan<TData> {
using PlanType = FFTwImplTypes<TData>::PlanType;
void operator()(PlanType ptr) { fftw_destroy_plan(ptr); }
};
} // namespace detail

template<typename TInput, typename TOutput = std::conditional<gr::meta::complex_like<TInput>, TInput, std::complex<typename TInput::value_type>>>
requires((gr::meta::complex_like<TInput> || std::floating_point<TInput>) && (gr::meta::complex_like<TOutput>) )
requires((gr::meta::complex_like<TInput> || std::floating_point<TInput>) && (gr::meta::complex_like<TOutput>))
struct FFTw {
private:
inline static std::mutex fftw_plan_mutex;
Expand Down Expand Up @@ -149,28 +149,23 @@ struct FFTw {
using OutUniquePtr = typename FFTwImpl<AlgoDataType>::OutUniquePtr;
using PlanUniquePtr = typename FFTwImpl<AlgoDataType>::PlanUniquePtr;

std::size_t fftSize{ 0 };
std::string wisdomPath{ ".gr_fftw_wisdom" };
int sign{ FFTW_FORWARD };
unsigned int flags{ FFTW_ESTIMATE }; // FFTW_EXHAUSTIVE, FFTW_MEASURE, FFTW_ESTIMATE
std::size_t fftSize{0};
std::string wisdomPath{".gr_fftw_wisdom"};
int sign{FFTW_FORWARD};
unsigned int flags{FFTW_ESTIMATE}; // FFTW_EXHAUSTIVE, FFTW_MEASURE, FFTW_ESTIMATE
InUniquePtr fftwIn{};
OutUniquePtr fftwOut{};
PlanUniquePtr fftwPlan{};

FFTw() = default;
FFTw(const FFTw &rhs) = delete;
FFTw(FFTw &&rhs) noexcept = delete;
FFTw &
operator=(const FFTw &rhs)
= delete;
FFTw &
operator=(FFTw &&rhs) noexcept
= delete;
FFTw() = default;
FFTw(const FFTw& rhs) = delete;
FFTw(FFTw&& rhs) noexcept = delete;
FFTw& operator=(const FFTw& rhs) = delete;
FFTw& operator=(FFTw&& rhs) noexcept = delete;

~FFTw() { clearFftw(); }

auto
compute(const std::ranges::input_range auto &in, std::ranges::output_range<TOutput> auto &&out) {
auto compute(const std::ranges::input_range auto& in, std::ranges::output_range<TOutput> auto&& out) {
if constexpr (requires(std::size_t n) { out.resize(n); }) {
if (out.size() != in.size()) {
out.resize(in.size());
Expand All @@ -194,7 +189,7 @@ struct FFTw {

// precision is defined by output type, if needed cast input
if constexpr (!std::is_same_v<TInput, AlgoDataType>) {
std::span<AlgoDataType> inSpan(reinterpret_cast<AlgoDataType *>(fftwIn.get()), in.size());
std::span<AlgoDataType> inSpan(reinterpret_cast<AlgoDataType*>(fftwIn.get()), in.size());
std::ranges::transform(in.begin(), in.end(), inSpan.begin(), [](const auto c) { return static_cast<AlgoDataType>(c); });
} else {
std::memcpy(fftwIn.get(), &(*in.begin()), sizeof(InAlgoDataType) * fftSize);
Expand All @@ -220,67 +215,50 @@ struct FFTw {
return out;
}

auto
compute(const std::ranges::input_range auto &in) {
return compute(in, std::vector<TOutput>());
}
auto compute(const std::ranges::input_range auto& in) { return compute(in, std::vector<TOutput>()); }

[[nodiscard]] inline int
importWisdom() const {
[[nodiscard]] inline int importWisdom() const {
// lock file while importing wisdom?
return FFTwImpl<AlgoDataType>::importWisdomFromFilename(wisdomPath);
}

[[nodiscard]] inline int
exportWisdom() const {
[[nodiscard]] inline int exportWisdom() const {
// lock file while exporting wisdom?
return FFTwImpl<AlgoDataType>::exportWisdomToFilename(wisdomPath);
}

[[nodiscard]] inline int
importWisdomFromString(const std::string &wisdomString) const {
return FFTwImpl<AlgoDataType>::importWisdomFromString(wisdomString);
}
[[nodiscard]] inline int importWisdomFromString(const std::string& wisdomString) const { return FFTwImpl<AlgoDataType>::importWisdomFromString(wisdomString); }

[[nodiscard]] std::string
exportWisdomToString() const {
return FFTwImpl<AlgoDataType>::exportWisdomToString();
}
[[nodiscard]] std::string exportWisdomToString() const { return FFTwImpl<AlgoDataType>::exportWisdomToString(); }

inline void
forgetWisdom() const {
return FFTwImpl<AlgoDataType>::forgetWisdom();
}
inline void forgetWisdom() const { return FFTwImpl<AlgoDataType>::forgetWisdom(); }

private:
[[nodiscard]] constexpr std::size_t
getOutputSize() const {
[[nodiscard]] constexpr std::size_t getOutputSize() const {
if constexpr (gr::meta::complex_like<TInput>) {
return fftSize;
} else {
return 1 + fftSize / 2;
}
}

void
initAll() {
void initAll() {
clearFftw();
fftwIn = InUniquePtr(static_cast<InAlgoDataType *>(FFTwImpl<AlgoDataType>::malloc(sizeof(InAlgoDataType) * fftSize)));
fftwOut = OutUniquePtr(static_cast<OutAlgoDataType *>(FFTwImpl<AlgoDataType>::malloc(sizeof(OutAlgoDataType) * getOutputSize())));
fftwIn = InUniquePtr(static_cast<InAlgoDataType*>(FFTwImpl<AlgoDataType>::malloc(sizeof(InAlgoDataType) * fftSize)));
fftwOut = OutUniquePtr(static_cast<OutAlgoDataType*>(FFTwImpl<AlgoDataType>::malloc(sizeof(OutAlgoDataType) * getOutputSize())));

{
std::lock_guard lg{ fftw_plan_mutex };
std::lock_guard lg{fftw_plan_mutex};
// what to do if error is returned
std::ignore = importWisdom();
fftwPlan = PlanUniquePtr(FFTwImpl<AlgoDataType>::plan(static_cast<int>(fftSize), fftwIn.get(), fftwOut.get(), sign, flags));
std::ignore = exportWisdom();
}
}

void
clearFftw() {
void clearFftw() {
{
std::lock_guard lg{ fftw_plan_mutex };
std::lock_guard lg{fftw_plan_mutex};
fftwPlan.reset();
}
fftwIn.reset();
Expand Down
Loading
Loading