From dbfbbe3a0a597c38d4e8ccb1f975504aae9eb323 Mon Sep 17 00:00:00 2001 From: jatin Date: Thu, 18 Jan 2024 23:40:09 -0800 Subject: [PATCH] Undo comments --- test/src/sigmoid_approx_test.cpp | 92 ++++++++++++++++---------------- tools/bench/sigmoid_bench.cpp | 14 ++--- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/test/src/sigmoid_approx_test.cpp b/test/src/sigmoid_approx_test.cpp index c0dce6f..66a6192 100644 --- a/test/src/sigmoid_approx_test.cpp +++ b/test/src/sigmoid_approx_test.cpp @@ -4,52 +4,52 @@ #include -// TEST_CASE ("Sigmoid Approx Test") -// { -// #if ! defined(WIN32) -// const auto all_floats = test_helpers::all_32_bit_floats (-10.0f, 10.0f, 1.0e-3f); -// #else -// const auto all_floats = test_helpers::all_32_bit_floats (-10.0f, 10.0f, 1.0e-1f); -// #endif -// const auto y_exact = test_helpers::compute_all (all_floats, [] (auto x) -// { return 1.0f / (1.0f + std::exp (-x)); }); -// -// const auto test_approx = [&all_floats, &y_exact] (auto&& f_approx, float err_bound) -// { -// const auto y_approx = test_helpers::compute_all (all_floats, f_approx); -// -// const auto error = test_helpers::compute_error (y_exact, y_approx); -// const auto max_error = test_helpers::abs_max (error); -// -// std::cout << max_error << std::endl; -// REQUIRE (std::abs (max_error) < err_bound); -// }; -// -// SECTION ("9th-Order") -// { -// test_approx ([] (auto x) -// { return math_approx::sigmoid<9> (x); }, -// 6.5e-7f); -// } -// SECTION ("7th-Order") -// { -// test_approx ([] (auto x) -// { return math_approx::sigmoid<7> (x); }, -// 7.0e-6f); -// } -// SECTION ("5th-Order") -// { -// test_approx ([] (auto x) -// { return math_approx::sigmoid<5> (x); }, -// 1.0e-4f); -// } -// SECTION ("3th-Order") -// { -// test_approx ([] (auto x) -// { return math_approx::sigmoid<3> (x); }, -// 2.0e-3f); -// } -// } +TEST_CASE ("Sigmoid Approx Test") +{ +#if ! defined(WIN32) + const auto all_floats = test_helpers::all_32_bit_floats (-10.0f, 10.0f, 1.0e-3f); +#else + const auto all_floats = test_helpers::all_32_bit_floats (-10.0f, 10.0f, 1.0e-1f); +#endif + const auto y_exact = test_helpers::compute_all (all_floats, [] (auto x) + { return 1.0f / (1.0f + std::exp (-x)); }); + + const auto test_approx = [&all_floats, &y_exact] (auto&& f_approx, float err_bound) + { + const auto y_approx = test_helpers::compute_all (all_floats, f_approx); + + const auto error = test_helpers::compute_error (y_exact, y_approx); + const auto max_error = test_helpers::abs_max (error); + + std::cout << max_error << std::endl; + REQUIRE (std::abs (max_error) < err_bound); + }; + + SECTION ("9th-Order") + { + test_approx ([] (auto x) + { return math_approx::sigmoid<9> (x); }, + 6.5e-7f); + } + SECTION ("7th-Order") + { + test_approx ([] (auto x) + { return math_approx::sigmoid<7> (x); }, + 7.0e-6f); + } + SECTION ("5th-Order") + { + test_approx ([] (auto x) + { return math_approx::sigmoid<5> (x); }, + 1.0e-4f); + } + SECTION ("3th-Order") + { + test_approx ([] (auto x) + { return math_approx::sigmoid<3> (x); }, + 2.0e-3f); + } +} TEST_CASE ("Sigmoid (Exp) Approx Test") { diff --git a/tools/bench/sigmoid_bench.cpp b/tools/bench/sigmoid_bench.cpp index d3e1aba..606321e 100644 --- a/tools/bench/sigmoid_bench.cpp +++ b/tools/bench/sigmoid_bench.cpp @@ -24,13 +24,13 @@ benchmark::DoNotOptimize (y); \ } \ } \ BENCHMARK (name); -// SIGMOID_BENCH (sigmoid_std, [] (auto x) { return 1.0f / (1.0f + std::exp (-x)); }) -// SIGMOID_BENCH (sigmoid_approx9, math_approx::sigmoid<9>) -// SIGMOID_BENCH (sigmoid_approx7, math_approx::sigmoid<7>) -// SIGMOID_BENCH (sigmoid_approx5, math_approx::sigmoid<5>) -// SIGMOID_BENCH (sigmoid_exp_approx6, math_approx::sigmoid_exp<6>) -// SIGMOID_BENCH (sigmoid_exp_approx5, math_approx::sigmoid_exp<5>) -// SIGMOID_BENCH (sigmoid_exp_approx4, math_approx::sigmoid_exp<4>) +SIGMOID_BENCH (sigmoid_std, [] (auto x) { return 1.0f / (1.0f + std::exp (-x)); }) +SIGMOID_BENCH (sigmoid_approx9, math_approx::sigmoid<9>) +SIGMOID_BENCH (sigmoid_approx7, math_approx::sigmoid<7>) +SIGMOID_BENCH (sigmoid_approx5, math_approx::sigmoid<5>) +SIGMOID_BENCH (sigmoid_exp_approx6, math_approx::sigmoid_exp<6>) +SIGMOID_BENCH (sigmoid_exp_approx5, math_approx::sigmoid_exp<5>) +SIGMOID_BENCH (sigmoid_exp_approx4, math_approx::sigmoid_exp<4>) #define SIGMOID_SIMD_BENCH(name, func) \ void name (benchmark::State& state) \