Skip to content

Commit

Permalink
Undo comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jan 19, 2024
1 parent ab8d1f9 commit dbfbbe3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 53 deletions.
92 changes: 46 additions & 46 deletions test/src/sigmoid_approx_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,52 @@

#include <math_approx/math_approx.hpp>

// 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<float> (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<float> (all_floats, f_approx);
//
// const auto error = test_helpers::compute_error<float> (y_exact, y_approx);
// const auto max_error = test_helpers::abs_max<float> (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<float> (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<float> (all_floats, f_approx);

const auto error = test_helpers::compute_error<float> (y_exact, y_approx);
const auto max_error = test_helpers::abs_max<float> (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")
{
Expand Down
14 changes: 7 additions & 7 deletions tools/bench/sigmoid_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down

0 comments on commit dbfbbe3

Please sign in to comment.