Skip to content

Commit

Permalink
Use an absolute tolerance to test the dot product kernel
Browse files Browse the repository at this point in the history
Signed-off-by: Clayton Smith <argilo@gmail.com>
  • Loading branch information
argilo committed Oct 15, 2023
1 parent 0d65424 commit 43d8980
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/kernel_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ std::vector<volk_test_case_t> init_test_list(volk_test_params_t test_params)
QA(VOLK_INIT_TEST(volk_32fc_deinterleave_real_32f, test_params))
QA(VOLK_INIT_TEST(volk_32fc_deinterleave_real_64f, test_params))
QA(VOLK_INIT_TEST(volk_32fc_x2_dot_prod_32fc, test_params_inacc))
QA(VOLK_INIT_TEST(volk_32fc_32f_dot_prod_32fc, test_params_inacc))
QA(VOLK_INIT_TEST(volk_32fc_32f_dot_prod_32fc, test_params.make_absolute(1e-2)))
QA(VOLK_INIT_TEST(volk_32fc_index_max_16u, test_params))
QA(VOLK_INIT_TEST(volk_32fc_index_max_32u, test_params))
QA(VOLK_INIT_TEST(volk_32fc_index_min_16u, test_params))
Expand Down
40 changes: 24 additions & 16 deletions lib/qa_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,6 @@ bool fcompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode)
template <class t>
bool ccompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode)
{
if (absolute_mode) {
std::cout << "ccompare does not support absolute mode" << std::endl;
return true;
}
bool fail = false;
int print_max_errs = 10;
for (unsigned int i = 0; i < 2 * vlen; i += 2) {
Expand All @@ -423,9 +419,7 @@ bool ccompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode)
t err = std::sqrt(diff[0] * diff[0] + diff[1] * diff[1]);
t norm = std::sqrt(in1[i] * in1[i] + in1[i + 1] * in1[i + 1]);

// for very small numbers we'll see round off errors due to limited
// precision. So a special test case...
if (norm < 1e-30) {
if (absolute_mode) {
if (err > tol) {
fail = true;
if (print_max_errs-- > 0) {
Expand All @@ -435,15 +429,29 @@ bool ccompare(t* in1, t* in2, unsigned int vlen, float tol, bool absolute_mode)
std::cout << " tolerance was: " << tol << std::endl;
}
}
}
// the primary test is the percent different greater than given tol
else if ((err / norm) > tol) {
fail = true;
if (print_max_errs-- > 0) {
std::cout << "offset " << i / 2 << " in1: " << in1[i] << " + "
<< in1[i + 1] << "j in2: " << in2[i] << " + " << in2[i + 1]
<< "j";
std::cout << " tolerance was: " << tol << std::endl;
} else {
// for very small numbers we'll see round off errors due to limited
// precision. So a special test case...
if (norm < 1e-30) {
if (err > tol) {
fail = true;
if (print_max_errs-- > 0) {
std::cout << "offset " << i / 2 << " in1: " << in1[i] << " + "
<< in1[i + 1] << "j in2: " << in2[i] << " + "
<< in2[i + 1] << "j";
std::cout << " tolerance was: " << tol << std::endl;
}
}
}
// the primary test is the percent different greater than given tol
else if ((err / norm) > tol) {
fail = true;
if (print_max_errs-- > 0) {
std::cout << "offset " << i / 2 << " in1: " << in1[i] << " + "
<< in1[i + 1] << "j in2: " << in2[i] << " + " << in2[i + 1]
<< "j";
std::cout << " tolerance was: " << tol << std::endl;
}
}
}
}
Expand Down

0 comments on commit 43d8980

Please sign in to comment.