Skip to content

Commit

Permalink
Start upols_convolver tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Aug 10, 2023
1 parent bc830f9 commit 85b0b4e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ target_sources(neo_fft_tests
PRIVATE
"neo/fft/math_test.cpp"
"neo/fft/container/sparse_matrix_test.cpp"
"neo/fft/convolution/upols_convolver_test.cpp"
"neo/fft/convolution/uniform_partition_test.cpp"
"neo/fft/fixed_point/fixed_point_test.cpp"
"neo/fft/transform/radix2_test.cpp"
Expand Down
67 changes: 67 additions & 0 deletions src/lib/neo/fft/convolution/upols_convolver_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "upols_convolver.hpp"

#include <neo/fft/algorithm/allclose.hpp>
#include <neo/fft/convolution/uniform_partition.hpp>

#include <catch2/catch_template_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>

#include <concepts>
#include <random>
#include <span>
#include <vector>

template<std::floating_point Float>
[[nodiscard]] auto make_noise_signal(std::size_t length) -> std::vector<Float>
{
auto signal = std::vector<Float>(length, Float(0));
auto rng = std::mt19937{std::random_device{}()};
auto dist = std::uniform_real_distribution<Float>{Float(-1), Float(1)};
std::generate(signal.begin(), signal.end(), [&] { return dist(rng); });
return signal;
}

template<std::floating_point Float>
[[nodiscard]] auto make_identity_impulse(std::size_t blockSize, std::size_t numPartitions)
-> KokkosEx::mdarray<std::complex<Float>, Kokkos::dextents<std::size_t, 2>>
{
auto const windowSize = blockSize * 2;
auto const numBins = windowSize / 2 + 1;

auto impulse = KokkosEx::mdarray<std::complex<Float>, Kokkos::dextents<std::size_t, 2>>{
numPartitions,
numBins,
};

for (auto partition{0U}; partition < impulse.extent(0); ++partition) {
for (auto bin{0U}; bin < impulse.extent(1); ++bin) {
impulse(partition, bin) = std::complex{Float(1), Float(0)};
}
}
return impulse;
}

TEMPLATE_TEST_CASE("neo/fft/convolution: upols_convolver", "", float)
{
using Float = TestType;

auto const blockSize = GENERATE(as<std::size_t>{}, 128, 256, 512);
auto const signal = make_noise_signal<Float>(blockSize * 100UL);
auto const partitions = make_identity_impulse<Float>(blockSize, 10UL);

auto convolver = neo::fft::upols_convolver{};
auto output = signal;
convolver.filter(partitions);

for (auto i{0U}; i < output.size(); i += blockSize) {
auto block = std::span{output}.subspan(i, blockSize);
convolver(block);
}

// TODO: Loop should go to output.size(), curently fails on index 128 i.e. after one block
for (auto i{0ULL}; i < blockSize; ++i) {
CAPTURE(i);
REQUIRE_THAT(output[i], Catch::Matchers::WithinAbs(signal[i], 0.00001));
}
}

0 comments on commit 85b0b4e

Please sign in to comment.