From 15d2af26e2921d75f0519ed07ab40d7282801013 Mon Sep 17 00:00:00 2001 From: Maciej Kurc Date: Tue, 23 Jan 2024 14:13:48 +0100 Subject: [PATCH] Update GPL FFT test to accomodate for floating point arithmetic tolerance Internal-tag: [#53960] Signed-off-by: Maciej Kurc --- src/gpl/test/fft_test.cc | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/gpl/test/fft_test.cc b/src/gpl/test/fft_test.cc index 039f814ef92..d8aab4830d6 100644 --- a/src/gpl/test/fft_test.cc +++ b/src/gpl/test/fft_test.cc @@ -134,16 +134,39 @@ TEST(FloatFFTTest, Basic) print_tables(fft); + const float tol = 1.3e-4f; // Tolerance factor + + double eforce1_total = 0.0; + double eforce2_total = 0.0; + double ephi_total = 0.0; + for (int y = 0; y < Y_MAX; y++) { for (int x = 0; x < X_MAX; x++) { auto eForce = fft->getElectroForce(x, y); auto electroPhi = fft->getElectroPhi(x, y); - EXPECT_EQ(eForce.first, output_data_eForce_first[x + y * Y_MAX]); - EXPECT_EQ(eForce.second, output_data_eForce_second[x + y * Y_MAX]); - EXPECT_EQ(electroPhi, output_data_electroPhi[x + y * Y_MAX]); + // Compute error + float eforce1 = fabs(eForce.first - output_data_eForce_first[x + y * Y_MAX]); + float eforce2 = fabs(eForce.second - output_data_eForce_second[x + y * Y_MAX]); + float ephi = fabs(electroPhi - output_data_electroPhi[x + y * Y_MAX]); + + // Check error + EXPECT_LT(eforce1, tol); + EXPECT_LT(eforce2, tol); + EXPECT_LT(ephi, tol); + + // Accumulate error + eforce1_total += eforce1; + eforce2_total += eforce2; + ephi_total += ephi; } } + + // Report total error + std::cout << "FFT output vs. reference error (total sum)\n"; + std::cout << fmt::format(" eForce.first : {:26.20f}\n", eforce1_total); + std::cout << fmt::format(" eForce.second: {:26.20f}\n", eforce2_total); + std::cout << fmt::format(" electroPhi : {:26.20f}\n", ephi_total); } } // namespace