From 1a9b2b671d6f6e677aba59a48f707bb5d63b8ed0 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Tue, 13 Jan 2026 19:14:34 +0100 Subject: [PATCH] [test] Improve testing logging and accuracy Logging only the number of diff does not help solving or reproducing bug, so log every comparison instead. No functional change intended. --- test/test_complex_exponential.cpp | 56 ++++++++--------- test/test_complex_hyperbolic.cpp | 42 ++++++------- test/test_complex_power.cpp | 46 +++++++------- test/test_complex_trigonometric.cpp | 56 ++++++++--------- test/test_error_gamma.cpp | 54 ++++++++--------- test/test_exponential.cpp | 70 ++++++++++------------ test/test_hyperbolic.cpp | 54 ++++++++--------- test/test_poly_evaluation.cpp | 11 ++-- test/test_power.cpp | 62 +++++++++---------- test/test_rounding.cpp | 93 +++++++++-------------------- test/test_select.cpp | 36 +++++------ test/test_trigonometric.cpp | 81 +++++++++++-------------- test/test_utils.hpp | 27 --------- test/test_xsimd_api.cpp | 8 ++- 14 files changed, 285 insertions(+), 411 deletions(-) diff --git a/test/test_complex_exponential.cpp b/test/test_complex_exponential.cpp index 55490294c..0627ce29a 100644 --- a/test/test_complex_exponential.cpp +++ b/test/test_complex_exponential.cpp @@ -54,15 +54,14 @@ struct complex_exponential_test std::transform(exp_input.cbegin(), exp_input.cend(), expected.begin(), [](const value_type& v) { using std::exp; return exp(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, exp_input, i); out = exp(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_expm1() @@ -71,15 +70,14 @@ struct complex_exponential_test [](const value_type& v) { using xsimd::expm1; return expm1(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, exp_input, i); out = expm1(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_huge_exp() @@ -87,15 +85,14 @@ struct complex_exponential_test std::transform(huge_exp_input.cbegin(), huge_exp_input.cend(), expected.begin(), [](const value_type& v) { using std::exp; return exp(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, huge_exp_input, i); out = exp(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_log() @@ -103,15 +100,14 @@ struct complex_exponential_test std::transform(log_input.cbegin(), log_input.cend(), expected.begin(), [](const value_type& v) { using std::log; return log(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, log_input, i); out = log(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_log2() @@ -119,15 +115,14 @@ struct complex_exponential_test std::transform(log_input.cbegin(), log_input.cend(), expected.begin(), [](const value_type& v) { using xsimd::log2; return log2(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, log_input, i); out = log2(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_log10() @@ -135,15 +130,14 @@ struct complex_exponential_test std::transform(log_input.cbegin(), log_input.cend(), expected.begin(), [](const value_type& v) { using std::log10; return log10(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, log_input, i); out = log10(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_log1p() @@ -151,15 +145,14 @@ struct complex_exponential_test std::transform(log_input.cbegin(), log_input.cend(), expected.begin(), [](const value_type& v) { using xsimd::log1p; return log1p(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, log_input, i); out = log1p(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_sign() @@ -167,15 +160,14 @@ struct complex_exponential_test std::transform(log_input.cbegin(), log_input.cend(), expected.begin(), [](const value_type& v) { using xsimd::sign; return sign(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, log_input, i); out = sign(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } }; diff --git a/test/test_complex_hyperbolic.cpp b/test/test_complex_hyperbolic.cpp index 365f9036a..b1e1cce1c 100644 --- a/test/test_complex_hyperbolic.cpp +++ b/test/test_complex_hyperbolic.cpp @@ -55,15 +55,14 @@ struct complex_hyperbolic_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { using std::sinh; return sinh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = sinh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_cosh() @@ -71,15 +70,14 @@ struct complex_hyperbolic_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { using std::cosh; return cosh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = cosh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_tanh() @@ -87,15 +85,14 @@ struct complex_hyperbolic_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { using std::tanh; return tanh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = tanh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_asinh() @@ -103,15 +100,14 @@ struct complex_hyperbolic_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { using std::asinh; return asinh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = asinh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_acosh() @@ -119,15 +115,14 @@ struct complex_hyperbolic_test std::transform(acosh_input.cbegin(), acosh_input.cend(), expected.begin(), [](const value_type& v) { using std::acosh; return acosh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, acosh_input, i); out = acosh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_atanh() @@ -135,15 +130,14 @@ struct complex_hyperbolic_test std::transform(atanh_input.cbegin(), atanh_input.cend(), expected.begin(), [](const value_type& v) { using std::atanh; return atanh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, atanh_input, i); out = atanh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } }; diff --git a/test/test_complex_power.cpp b/test/test_complex_power.cpp index 118ead6e4..99bb82819 100644 --- a/test/test_complex_power.cpp +++ b/test/test_complex_power.cpp @@ -66,16 +66,15 @@ struct complex_power_test std::transform(lhs_np.cbegin(), lhs_np.cend(), real_expected.begin(), [](const value_type& v) { using std::abs; return abs(v); }); - batch_type in; - real_batch_type out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in; + real_batch_type out, ref; detail::load_batch(in, lhs_np, i); out = abs(in); - detail::store_batch(out, real_res, i); + detail::load_batch(ref, real_expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(real_res, real_expected); - CHECK_EQ(diff, 0); } void test_arg() @@ -84,16 +83,15 @@ struct complex_power_test std::transform(lhs_np.cbegin(), lhs_np.cend(), real_expected.begin(), [](const value_type& v) { using std::arg; return arg(v); }); - batch_type in; - real_batch_type out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in; + real_batch_type out, ref; detail::load_batch(in, lhs_np, i); out = arg(in); - detail::store_batch(out, real_res, i); + detail::load_batch(ref, real_expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(real_res, real_expected); - CHECK_EQ(diff, 0); } void test_pow() @@ -154,15 +152,14 @@ struct complex_power_test std::transform(lhs_nn.cbegin(), lhs_nn.cend(), expected.begin(), [](const value_type& v) { using std::sqrt; return sqrt(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, lhs_nn, i); out = sqrt(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_sqrt_pn() @@ -170,15 +167,14 @@ struct complex_power_test std::transform(lhs_pn.cbegin(), lhs_pn.cend(), expected.begin(), [](const value_type& v) { using std::sqrt; return sqrt(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, lhs_pn, i); out = sqrt(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_sqrt_np() @@ -186,15 +182,14 @@ struct complex_power_test std::transform(lhs_np.cbegin(), lhs_np.cend(), expected.begin(), [](const value_type& v) { using std::sqrt; return sqrt(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, lhs_np, i); out = sqrt(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_sqrt_pp() @@ -202,15 +197,14 @@ struct complex_power_test std::transform(lhs_pp.cbegin(), lhs_pp.cend(), expected.begin(), [](const value_type& v) { using std::sqrt; return sqrt(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, lhs_pp, i); out = sqrt(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } }; diff --git a/test/test_complex_trigonometric.cpp b/test/test_complex_trigonometric.cpp index 87c5a7812..09769b62b 100644 --- a/test/test_complex_trigonometric.cpp +++ b/test/test_complex_trigonometric.cpp @@ -56,15 +56,14 @@ struct complex_trigonometric_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { using std::sin; return sin(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = sin(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_cos() @@ -72,15 +71,14 @@ struct complex_trigonometric_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { using std::cos; return cos(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = cos(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_sincos() @@ -92,18 +90,18 @@ struct complex_trigonometric_test std::transform(input.cbegin(), input.cend(), expected2.begin(), [](const value_type& v) { using std::cos; return cos(v); }); - batch_type in, out1, out2; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out1, out2, ref1, ref2; detail::load_batch(in, input, i); std::tie(out1, out2) = sincos(in); - detail::store_batch(out1, res, i); - detail::store_batch(out2, res2, i); + + detail::load_batch(ref1, expected, i); + CHECK_BATCH_EQ(ref1, out1); + + detail::load_batch(ref2, expected2, i); + CHECK_BATCH_EQ(ref2, out2); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); - diff = detail::get_nb_diff(res2, expected2); - CHECK_EQ(diff, 0); } void test_tan() @@ -116,15 +114,14 @@ struct complex_trigonometric_test std::transform(ainput.cbegin(), ainput.cend(), expected.begin(), [](const value_type& v) { using std::asin; return asin(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, ainput, i); out = asin(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_acos() @@ -132,15 +129,14 @@ struct complex_trigonometric_test std::transform(ainput.cbegin(), ainput.cend(), expected.begin(), [](const value_type& v) { using std::acos; return acos(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, ainput, i); out = acos(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } void test_atan() @@ -148,15 +144,14 @@ struct complex_trigonometric_test std::transform(atan_input.cbegin(), atan_input.cend(), expected.begin(), [](const value_type& v) { using std::atan; return atan(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, atan_input, i); out = atan(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } private: @@ -165,15 +160,14 @@ struct complex_trigonometric_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { using std::tan; return tan(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = tan(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } template ::value, int> = 0> diff --git a/test/test_error_gamma.cpp b/test/test_error_gamma.cpp index 214cbb587..3e0865b65 100644 --- a/test/test_error_gamma.cpp +++ b/test/test_error_gamma.cpp @@ -52,32 +52,30 @@ struct error_gamma_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::erf(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = erf(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("erf"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("erf"); - CHECK_EQ(diff, 0); } // erfc { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::erfc(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = erfc(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("erfc"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("erfc"); - CHECK_EQ(diff, 0); } } @@ -88,48 +86,45 @@ struct error_gamma_test std::transform(gamma_input.cbegin(), gamma_input.cend(), expected.begin(), [](const value_type& v) { return std::tgamma(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, gamma_input, i); out = tgamma(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("tgamma"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("tgamma"); - CHECK_EQ(diff, 0); } // tgamma (negative input) { std::transform(gamma_neg_input.cbegin(), gamma_neg_input.cend(), expected.begin(), [](const value_type& v) { return std::tgamma(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, gamma_neg_input, i); out = tgamma(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("tgamma (negative input)"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("tgamma (negative input)"); - CHECK_EQ(diff, 0); } // lgamma { std::transform(gamma_input.cbegin(), gamma_input.cend(), expected.begin(), [](const value_type& v) { return std::lgamma(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, gamma_input, i); out = lgamma(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("lgamma"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("lgamma"); - CHECK_EQ(diff, 0); } #if !(XSIMD_WITH_AVX && !XSIMD_WITH_AVX2) @@ -138,16 +133,15 @@ struct error_gamma_test std::transform(gamma_neg_input.cbegin(), gamma_neg_input.cend(), expected.begin(), [](const value_type& v) { return std::lgamma(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, gamma_neg_input, i); out = lgamma(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("lgamma (negative input)"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("lgamma (negative input)"); - CHECK_EQ(diff, 0); } #endif } diff --git a/test/test_exponential.cpp b/test/test_exponential.cpp index 9b15674f1..0d0184032 100644 --- a/test/test_exponential.cpp +++ b/test/test_exponential.cpp @@ -49,16 +49,15 @@ struct exponential_test std::transform(exp_input.cbegin(), exp_input.cend(), expected.begin(), [](const value_type& v) { return std::exp(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, exp_input, i); out = exp(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("exp"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("exp"); - CHECK_EQ(diff, 0); } // exp2 @@ -66,16 +65,15 @@ struct exponential_test std::transform(exp_input.cbegin(), exp_input.cend(), expected.begin(), [](const value_type& v) { return std::exp2(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, exp_input, i); out = exp2(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("exp2"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("exp2"); - CHECK_EQ(diff, 0); } // exp10 @@ -84,16 +82,15 @@ struct exponential_test /* imprecise but enough for testing version of exp10 */ [](const value_type& v) { return exp(log(10) * v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, exp_input, i); out = exp10(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("exp10"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("exp10"); - CHECK_EQ(diff, 0); } // expm1 @@ -101,16 +98,15 @@ struct exponential_test std::transform(exp_input.cbegin(), exp_input.cend(), expected.begin(), [](const value_type& v) { return std::expm1(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, exp_input, i); out = expm1(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("expm1"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("expm1"); - CHECK_EQ(diff, 0); } } @@ -121,16 +117,15 @@ struct exponential_test std::transform(log_input.cbegin(), log_input.cend(), expected.begin(), [](const value_type& v) { return std::log(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, log_input, i); out = log(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("log"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("log"); - CHECK_EQ(diff, 0); } // log2 @@ -138,16 +133,15 @@ struct exponential_test std::transform(log_input.cbegin(), log_input.cend(), expected.begin(), [](const value_type& v) { return std::log2(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, log_input, i); out = log2(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("log2"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("log2"); - CHECK_EQ(diff, 0); } // log10 @@ -155,16 +149,15 @@ struct exponential_test std::transform(log_input.cbegin(), log_input.cend(), expected.begin(), [](const value_type& v) { return std::log10(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, log_input, i); out = log10(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("log10"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("log10"); - CHECK_EQ(diff, 0); } // log1p @@ -172,15 +165,14 @@ struct exponential_test std::transform(log_input.cbegin(), log_input.cend(), expected.begin(), [](const value_type& v) { return std::log1p(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, log_input, i); out = log1p(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - CHECK_EQ(diff, 0); } } }; diff --git a/test/test_hyperbolic.cpp b/test/test_hyperbolic.cpp index 6821470b8..a97e68479 100644 --- a/test/test_hyperbolic.cpp +++ b/test/test_hyperbolic.cpp @@ -52,48 +52,45 @@ struct hyperbolic_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::sinh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = sinh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("sinh"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("sinh"); - CHECK_EQ(diff, 0); } // cosh { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::cosh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = cosh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("cosh"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("cosh"); - CHECK_EQ(diff, 0); } // tanh { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::tanh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = tanh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("tanh"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("tanh"); - CHECK_EQ(diff, 0); } } @@ -104,48 +101,45 @@ struct hyperbolic_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::asinh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = asinh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("asinh"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("asinh"); - CHECK_EQ(diff, 0); } // acosh { std::transform(acosh_input.cbegin(), acosh_input.cend(), expected.begin(), [](const value_type& v) { return std::acosh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, acosh_input, i); out = acosh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("acosh"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("acosh"); - CHECK_EQ(diff, 0); } // atanh { std::transform(atanh_input.cbegin(), atanh_input.cend(), expected.begin(), [](const value_type& v) { return std::atanh(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, atanh_input, i); out = atanh(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("atanh"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("atanh"); - CHECK_EQ(diff, 0); } } }; diff --git a/test/test_poly_evaluation.cpp b/test/test_poly_evaluation.cpp index b7b597b7e..2b2fedde5 100644 --- a/test/test_poly_evaluation.cpp +++ b/test/test_poly_evaluation.cpp @@ -41,17 +41,14 @@ struct poly_evaluation_test void test_poly_evaluation() { - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out_horner, out_estrin; detail::load_batch(in, input, i); - out = xsimd::kernel::horner(in); - detail::store_batch(out, horner_res, i); - out = xsimd::kernel::estrin(in); - detail::store_batch(out, estrin_res, i); + out_horner = xsimd::kernel::horner(in); + out_estrin = xsimd::kernel::estrin(in); + CHECK_BATCH_EQ(out_horner, out_estrin); } - size_t diff = detail::get_nb_diff(horner_res, estrin_res); - CHECK_EQ(diff, 0); } }; diff --git a/test/test_power.cpp b/test/test_power.cpp index a2a425c8c..01e01a2de 100644 --- a/test/test_power.cpp +++ b/test/test_power.cpp @@ -57,34 +57,32 @@ struct power_test std::transform(lhs_input.cbegin(), lhs_input.cend(), rhs_input.cbegin(), expected.begin(), [](const value_type& l, const value_type& r) { return std::pow(l, r); }); - batch_type lhs_in, rhs_in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type lhs_in, rhs_in, out, ref; detail::load_batch(lhs_in, lhs_input, i); detail::load_batch(rhs_in, rhs_input, i); out = pow(lhs_in, rhs_in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("pow"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("pow"); - CHECK_EQ(diff, 0); } // pow zero { std::transform(zlhs_input.cbegin(), zlhs_input.cend(), rhs_input.cbegin(), expected.begin(), [](const value_type& l, const value_type& r) { return std::pow(l, r); }); - batch_type zlhs_in, rhs_in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type zlhs_in, rhs_in, out, ref; detail::load_batch(zlhs_in, zlhs_input, i); detail::load_batch(rhs_in, rhs_input, i); out = pow(zlhs_in, rhs_in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("0 ^ x"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("0 ^ x"); - CHECK_EQ(diff, 0); // use of undeclared identifier '_MM_SET_EXCEPTION_MASK for emscripten #if defined(__SSE__) && !defined(EMSCRIPTEN) @@ -93,15 +91,15 @@ struct power_test _MM_SET_EXCEPTION_MASK(mask & ~_MM_MASK_INVALID); for (size_t i = 0; i < nb_input; i += size) { + batch_type zlhs_in, rhs_in, out, ref; detail::load_batch(zlhs_in, zlhs_input, i); detail::load_batch(rhs_in, rhs_input, i); out = pow(zlhs_in, rhs_in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("0 ^ x with exception"); + CHECK_BATCH_EQ(ref, out); } _MM_SET_EXCEPTION_MASK(mask); - diff = detail::get_nb_diff(res, expected); - INFO("0 ^ x with exception"); - CHECK_EQ(diff, 0); #endif } #ifndef __FAST_MATH__ @@ -110,17 +108,16 @@ struct power_test std::transform(zero_input.cbegin(), zero_input.cend(), rhs_input.cbegin(), expected.begin(), [](const value_type& z, const value_type& r) { return std::pow(z, -r); }); - batch_type zero_in, rhs_in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type zero_in, rhs_in, out, ref; detail::load_batch(zero_in, zero_input, i); detail::load_batch(rhs_in, rhs_input, i); out = pow(zero_in, -rhs_in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("pow(0, -x)"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("pow(0, -x)"); - CHECK_EQ(diff, 0); } #endif // ipow @@ -129,49 +126,46 @@ struct power_test std::transform(lhs_input.cbegin(), lhs_input.cend(), expected.begin(), [&k, this](const value_type& l) { auto arg = k / size / 8000 - nb_input / size / 8000 / 2; ++k; return std::pow(l, arg); }); - batch_type lhs_in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type lhs_in, out, ref; detail::load_batch(lhs_in, lhs_input, i); out = pow(lhs_in, i / size / 8000 - nb_input / size / 8000 / 2); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("ipow"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("ipow"); - CHECK_EQ(diff, 0); } // hypot { std::transform(lhs_input.cbegin(), lhs_input.cend(), rhs_input.cbegin(), expected.begin(), [](const value_type& l, const value_type& r) { return std::hypot(l, r); }); - batch_type lhs_in, rhs_in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type lhs_in, rhs_in, out, ref; detail::load_batch(lhs_in, lhs_input, i); detail::load_batch(rhs_in, rhs_input, i); out = hypot(lhs_in, rhs_in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("hypot"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("hypot"); - CHECK_EQ(diff, 0); } // cbrt { std::transform(lhs_input.cbegin(), lhs_input.cend(), expected.begin(), [](const value_type& l) { return std::cbrt(l); }); - batch_type lhs_in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type lhs_in, out, ref; detail::load_batch(lhs_in, lhs_input, i); out = cbrt(lhs_in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("cbrt"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("cbrt"); - CHECK_EQ(diff, 0); } } }; diff --git a/test/test_rounding.cpp b/test/test_rounding.cpp index aa7f2b5a5..1435d4639 100644 --- a/test/test_rounding.cpp +++ b/test/test_rounding.cpp @@ -49,100 +49,75 @@ struct rounding_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::ceil(v); }); - batch_type in, out; for (size_t i = 0; i < nb_batches; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = ceil(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("ceil"); + CHECK_BATCH_EQ(ref, out); } - for (size_t i = nb_batches; i < nb_input; ++i) - { - res[i] = std::ceil(input[i]); - } - size_t diff = detail::get_nb_diff(res, expected); - INFO("ceil"); - CHECK_EQ(diff, 0); } // floor { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::floor(v); }); - batch_type in, out; for (size_t i = 0; i < nb_batches; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = floor(in); - detail::store_batch(out, res, i); - } - for (size_t i = nb_batches; i < nb_input; ++i) - { - res[i] = std::floor(input[i]); + detail::load_batch(ref, expected, i); + INFO("floor"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("floor"); - CHECK_EQ(diff, 0); } // trunc { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::trunc(v); }); - batch_type in, out; for (size_t i = 0; i < nb_batches; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = trunc(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("trunc"); + CHECK_BATCH_EQ(ref, out); } - for (size_t i = nb_batches; i < nb_input; ++i) - { - res[i] = std::trunc(input[i]); - } - size_t diff = detail::get_nb_diff(res, expected); - INFO("trunc"); - CHECK_EQ(diff, 0); } // round { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::round(v); }); - batch_type in, out; for (size_t i = 0; i < nb_batches; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = round(in); - detail::store_batch(out, res, i); - } - for (size_t i = nb_batches; i < nb_input; ++i) - { - res[i] = std::round(input[i]); + detail::load_batch(ref, expected, i); + INFO("round"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("round"); - CHECK_EQ(diff, 0); } // nearbyint { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::nearbyint(v); }); - batch_type in, out; for (size_t i = 0; i < nb_batches; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = nearbyint(in); - detail::store_batch(out, res, i); - } - for (size_t i = nb_batches; i < nb_input; ++i) - { - res[i] = std::nearbyint(input[i]); + detail::load_batch(ref, expected, i); + INFO("nearbyint"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("nearbyint"); - CHECK_EQ(diff, 0); } // nearbyint_as_int { @@ -151,41 +126,31 @@ struct rounding_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return xsimd::nearbyint_as_int(v); }); - batch_type in; - int_batch_type out; for (size_t i = 0; i < nb_batches; i += size) { + batch_type in; + int_batch_type out, ref; detail::load_batch(in, input, i); out = nearbyint_as_int(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("nearbyint_as_int"); + CHECK_BATCH_EQ(ref, out); } - for (size_t i = nb_batches; i < nb_input; ++i) - { - res[i] = xsimd::nearbyint_as_int(input[i]); - } - size_t diff = detail::get_nb_diff(res, expected); - INFO("nearbyint_as_int"); - CHECK_EQ(diff, 0); } // rint { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::rint(v); }); - batch_type in, out; for (size_t i = 0; i < nb_batches; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = rint(in); - detail::store_batch(out, res, i); - } - for (size_t i = nb_batches; i < nb_input; ++i) - { - res[i] = std::rint(input[i]); + detail::load_batch(ref, expected, i); + INFO("rint"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("rint"); - CHECK_EQ(diff, 0); } } }; diff --git a/test/test_select.cpp b/test/test_select.cpp index 837fca314..a70bd63e6 100644 --- a/test/test_select.cpp +++ b/test/test_select.cpp @@ -59,24 +59,22 @@ struct select_test expected_b[i] = lhs_input[i] > value_type(3) ? lhs_input_b[i] : rhs_input_b[i]; } - batch_type lhs_in, rhs_in; - batch_bool_type lhs_in_b, rhs_in_b; for (size_t i = 0; i < nb_input; i += size) { + batch_type lhs_in, rhs_in, out, ref; detail::load_batch(lhs_in, lhs_input, i); detail::load_batch(rhs_in, rhs_input, i); - const auto out = xsimd::select(lhs_in > value_type(3), lhs_in, rhs_in); - detail::store_batch(out, res, i); + out = xsimd::select(lhs_in > value_type(3), lhs_in, rhs_in); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); + batch_bool_type lhs_in_b, rhs_in_b, out_b, ref_b; detail::load_batch(lhs_in_b, lhs_input_b, i); detail::load_batch(rhs_in_b, rhs_input_b, i); - const auto out_b = xsimd::select(lhs_in > value_type(3), lhs_in_b, rhs_in_b); - detail::store_batch(out_b, res_b, i); + out_b = xsimd::select(lhs_in > value_type(3), lhs_in_b, rhs_in_b); + detail::load_batch(ref_b, expected_b, i); + CHECK_BATCH_EQ(ref_b, out_b); } - size_t diff = detail::get_nb_diff(res, expected); - size_t diff_b = detail::get_nb_diff(res_b, expected_b); - CHECK_EQ(diff, 0); - CHECK_EQ(diff_b, 0); } struct pattern { @@ -93,24 +91,22 @@ struct select_test expected_b[i] = mask.get(i % size) ? lhs_input_b[i] : rhs_input_b[i]; } - batch_type lhs_in, rhs_in; - batch_bool_type lhs_in_b, rhs_in_b; for (size_t i = 0; i < nb_input; i += size) { + batch_type lhs_in, rhs_in, out, ref; + batch_bool_type lhs_in_b, rhs_in_b, out_b, ref_b; detail::load_batch(lhs_in, lhs_input, i); detail::load_batch(rhs_in, rhs_input, i); - const auto out = xsimd::select(mask, lhs_in, rhs_in); - detail::store_batch(out, res, i); + out = xsimd::select(mask, lhs_in, rhs_in); + detail::load_batch(ref, expected, i); + CHECK_BATCH_EQ(ref, out); detail::load_batch(lhs_in_b, lhs_input_b, i); detail::load_batch(rhs_in_b, rhs_input_b, i); - const auto out_b = xsimd::select(mask, lhs_in_b, rhs_in_b); - detail::store_batch(out_b, res_b, i); + out_b = xsimd::select(mask, lhs_in_b, rhs_in_b); + detail::load_batch(ref_b, expected_b, i); + CHECK_BATCH_EQ(ref_b, out_b); } - size_t diff = detail::get_nb_diff(res, expected); - size_t diff_b = detail::get_nb_diff(res_b, expected_b); - CHECK_EQ(diff, 0); - CHECK_EQ(diff_b, 0); } }; diff --git a/test/test_trigonometric.cpp b/test/test_trigonometric.cpp index 475ff8e1a..7dd703941 100644 --- a/test/test_trigonometric.cpp +++ b/test/test_trigonometric.cpp @@ -52,72 +52,67 @@ struct trigonometric_test std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::sin(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = sin(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("sin"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("sin"); - CHECK_EQ(diff, 0); } // cos { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::cos(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = cos(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("cos"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("cos"); - CHECK_EQ(diff, 0); } // sincos { - vector_type expected2(nb_input), res2(nb_input); + vector_type expected2(nb_input); std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::sin(v); }); std::transform(input.cbegin(), input.cend(), expected2.begin(), [](const value_type& v) { return std::cos(v); }); - batch_type in, out1, out2; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out1, out2, ref1, ref2; detail::load_batch(in, input, i); std::tie(out1, out2) = sincos(in); - detail::store_batch(out1, res, i); - detail::store_batch(out2, res2, i); + detail::load_batch(ref1, expected, i); + INFO("sincos / sin"); + CHECK_BATCH_EQ(ref1, out1); + detail::load_batch(ref2, expected2, i); + INFO("sincos / cos"); + CHECK_BATCH_EQ(ref2, out2); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("sincos(sin)"); - CHECK_EQ(diff, 0); - diff = detail::get_nb_diff(res2, expected2); - INFO("sincos(cos)"); - CHECK_EQ(diff, 0); } // tan { std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) { return std::tan(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, input, i); out = tan(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("tan"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("tan"); - CHECK_EQ(diff, 0); } } @@ -129,65 +124,61 @@ struct trigonometric_test std::transform(ainput.cbegin(), ainput.cend(), expected.begin(), [](const value_type& v) { return std::asin(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, ainput, i); out = asin(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("asin"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("asin"); - CHECK_EQ(diff, 0); } // acos { std::transform(ainput.cbegin(), ainput.cend(), expected.begin(), [](const value_type& v) { return std::acos(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, ainput, i); out = acos(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("acos"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("acos"); - CHECK_EQ(diff, 0); } // atan { std::transform(atan_input.cbegin(), atan_input.cend(), expected.begin(), [](const value_type& v) { return std::atan(v); }); - batch_type in, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, out, ref; detail::load_batch(in, atan_input, i); out = atan(in); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("atan"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("atan"); - CHECK_EQ(diff, 0); } // atan2 { std::transform(atan_input.cbegin(), atan_input.cend(), input.cbegin(), expected.begin(), [](const value_type& v, const value_type& r) { return std::atan2(v, r); }); - batch_type in, rhs, out; for (size_t i = 0; i < nb_input; i += size) { + batch_type in, rhs, out, ref; detail::load_batch(in, atan_input, i); detail::load_batch(rhs, input, i); out = atan2(in, rhs); - detail::store_batch(out, res, i); + detail::load_batch(ref, expected, i); + INFO("atan2"); + CHECK_BATCH_EQ(ref, out); } - size_t diff = detail::get_nb_diff(res, expected); - INFO("atan2"); - CHECK_EQ(diff, 0); } } }; diff --git a/test/test_utils.hpp b/test/test_utils.hpp index 0da0c6f12..8be9ab6b7 100644 --- a/test/test_utils.hpp +++ b/test/test_utils.hpp @@ -448,33 +448,6 @@ namespace detail return expect_batch_near(tmp, rhs); } - template - size_t get_nb_diff(It lhs_begin, It lhs_end, It rhs_begin) - { - size_t res = 0; - using value_type = typename std::iterator_traits::value_type; - while (lhs_begin != lhs_end) - { - if (!scalar_comparison::run(*lhs_begin++, *rhs_begin++)) - { - ++res; - } - } - return res; - } - - template - size_t get_nb_diff(const std::vector& lhs, const std::vector& rhs) - { - return get_nb_diff(lhs.begin(), lhs.end(), rhs.begin()); - } - - template - size_t get_nb_diff(const std::array& lhs, const std::array& rhs) - { - return get_nb_diff(lhs.begin(), lhs.end(), rhs.begin()); - } - template size_t get_nb_diff_near(const std::vector& lhs, const std::vector& rhs, float precision) { diff --git a/test/test_xsimd_api.cpp b/test/test_xsimd_api.cpp index d39d600d5..8c58543ad 100644 --- a/test/test_xsimd_api.cpp +++ b/test/test_xsimd_api.cpp @@ -740,9 +740,13 @@ struct xsimd_api_float_types_functions { value_type val0(2); value_type val1(2); + value_type nval1(-3); int ival1 = 4; + int nival1 = -5; CHECK_EQ(extract(xsimd::pow(T(val0), T(val1))), std::pow(val0, val1)); CHECK_EQ(extract(xsimd::pow(T(val0), ival1)), std::pow(val0, ival1)); + CHECK_EQ(extract(xsimd::pow(T(val0), T(nval1))), doctest::Approx(std::pow(val0, nval1))); + CHECK_EQ(extract(xsimd::pow(T(val0), nival1)), doctest::Approx(std::pow(val0, nival1))); } void test_reciprocal() { @@ -784,7 +788,7 @@ struct xsimd_api_float_types_functions void test_sqrt() { value_type val(1); - CHECK_EQ(extract(xsimd::sqrt(T(val))), std::sqrt(val)); + CHECK_EQ(extract(xsimd::sqrt(T(val))), doctest::Approx(std::sqrt(val))); } void test_tan() { @@ -1183,7 +1187,7 @@ struct xsimd_api_all_signed_types_functions void test_abs() { value_type val(-1); - CHECK_EQ(extract(xsimd::abs(T(val))), std::abs(val)); + CHECK_EQ(extract(xsimd::abs(T(val))), doctest::Approx(std::abs(val))); } void test_fnms()