Skip to content

Commit

Permalink
fix some false positive warnings emitted by msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
HDembinski committed Apr 25, 2024
1 parent 90867e2 commit 44fa5eb
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ project
: requirements
<implicit-dependency>/boost//headers
<include>$(BOOST_ROOT)
<toolset>clang:<cxxflags>"-pedantic -Wextra -Wsign-compare -Wstrict-aliasing -fstrict-aliasing -Wvexing-parse -Wfloat-conversion -fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>clang:<cxxflags>"-pedantic -Wextra -Wsign-compare -Wstrict-aliasing -fstrict-aliasing -Wvexing-parse -Wfloat-conversion -Wimplicit-float-conversion -fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>darwin:<cxxflags>"-pedantic -Wextra -Wsign-compare -Wstrict-aliasing -fstrict-aliasing -Wvexing-parse -Wfloat-conversion -fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>gcc:<cxxflags>"-pedantic -Wextra -Wsign-compare -Wstrict-aliasing -fstrict-aliasing -Wfloat-conversion -fvisibility=hidden -fvisibility-inlines-hidden"
<toolset>msvc:<cxxflags>"/bigobj"
Expand Down
10 changes: 5 additions & 5 deletions include/boost/histogram/utility/clopper_pearson_interval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ class clopper_pearson_interval : public binomial_proportion_interval<ValueType>
@param successes Number of successful trials.
@param failures Number of failed trials.
*/
interval_type operator()(value_type successes, value_type failures) const noexcept {
interval_type operator()(value_type successes, value_type failures) const noexcept override {
// analytical solution when successes or failures are zero
// T. Mans (2014), Electronic Journal of Statistics. 8 (1): 817-840.
// arXiv:1303.1288. doi:10.1214/14-EJS909.
const value_type total = successes + failures;
if (successes == 0) return {0, 1 - std::pow(alpha_half_, 1 / total)};
if (failures == 0) return {std::pow(alpha_half_, 1 / total), 1};
const value_type one{1.0}, zero{0.0}, total{successes + failures};
if (successes == 0) return {zero, one - std::pow(alpha_half_, one / total)};
if (failures == 0) return {std::pow(alpha_half_, one / total), one};

// Source:
// https://en.wikipedia.org/wiki/
// Binomial_proportion_confidence_interval#Clopper%E2%80%93Pearson_interval
math::beta_distribution<value_type> beta_a(successes, failures + 1);
const value_type a = math::quantile(beta_a, alpha_half_);
math::beta_distribution<value_type> beta_b(successes + 1, failures);
const value_type b = math::quantile(beta_b, 1 - alpha_half_);
const value_type b = math::quantile(beta_b, one - alpha_half_);
return {a, b};
}

Expand Down
13 changes: 7 additions & 6 deletions include/boost/histogram/utility/jeffreys_interval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@ class jeffreys_interval : public binomial_proportion_interval<ValueType> {
@param successes Number of successful trials.
@param failures Number of failed trials.
*/
interval_type operator()(value_type successes, value_type failures) const noexcept {
interval_type operator()(value_type successes,
value_type failures) const noexcept override {
// See L.D. Brown, T.T. Cai, A. DasGupta, Statistical Science 16 (2001) 101-133,
// doi:10.1214/ss/1009213286, section 4.1.2.
const value_type half{0.5};
const value_type half{0.5}, one{1.0}, zero{0.0};
const value_type total = successes + failures;

// if successes or failures are 0, modified interval is equal to Clopper-Pearson
if (successes == 0) return {0, 1 - std::pow(alpha_half_, 1 / total)};
if (failures == 0) return {std::pow(alpha_half_, 1 / total), 1};
if (successes == 0) return {zero, one - std::pow(alpha_half_, one / total)};
if (failures == 0) return {std::pow(alpha_half_, one / total), one};

math::beta_distribution<value_type> beta(successes + half, failures + half);
const value_type a = successes == 1 ? 0 : math::quantile(beta, alpha_half_);
const value_type b = failures == 1 ? 1 : math::quantile(beta, 1 - alpha_half_);
const value_type a = successes == 1 ? zero : math::quantile(beta, alpha_half_);
const value_type b = failures == 1 ? one : math::quantile(beta, one - alpha_half_);
return {a, b};
}

Expand Down
3 changes: 2 additions & 1 deletion include/boost/histogram/utility/wald_interval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class wald_interval : public binomial_proportion_interval<ValueType> {
@param successes Number of successful trials.
@param failures Number of failed trials.
*/
interval_type operator()(value_type successes, value_type failures) const noexcept {
interval_type operator()(value_type successes,
value_type failures) const noexcept override {
// See https://en.wikipedia.org/wiki/
// Binomial_proportion_confidence_interval
// #Normal_approximation_interval_or_Wald_interval
Expand Down
3 changes: 2 additions & 1 deletion include/boost/histogram/utility/wilson_interval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class wilson_interval : public binomial_proportion_interval<ValueType> {
@param successes Number of successful trials.
@param failures Number of failed trials.
*/
interval_type operator()(value_type successes, value_type failures) const noexcept {
interval_type operator()(value_type successes,
value_type failures) const noexcept override {
// See https://en.wikipedia.org/wiki/
// Binomial_proportion_confidence_interval
// #Wilson_score_interval
Expand Down
2 changes: 1 addition & 1 deletion test/utility_clopper_pearson_interval_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ template <class T>
void test() {
const T atol = 0.001;

clopper_pearson_interval<T> iv(deviation{1.f});
clopper_pearson_interval<T> iv(deviation{1});

{
const auto x = iv(0.f, 1.f);
Expand Down
68 changes: 34 additions & 34 deletions test/utility_jeffreys_interval_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,78 +25,78 @@ void test() {
jeffreys_interval<T> iv(confidence_level{0.95});

{
auto p = iv(0, 7);
BOOST_TEST_IS_CLOSE(p.first, 0, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.41, atol);
auto p = iv(0.f, 7.f);
BOOST_TEST_IS_CLOSE(p.first, 0.f, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.41f, atol);
}

{
auto p = iv(1, 6);
BOOST_TEST_IS_CLOSE(p.first, 0, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.501, atol);
auto p = iv(1.f, 6.f);
BOOST_TEST_IS_CLOSE(p.first, 0.f, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.501f, atol);
}

{
auto p = iv(2, 5);
BOOST_TEST_IS_CLOSE(p.first, 0.065, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.648, atol);
auto p = iv(2.f, 5.f);
BOOST_TEST_IS_CLOSE(p.first, 0.065f, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.648f, atol);
}

{
auto p = iv(3, 4);
BOOST_TEST_IS_CLOSE(p.first, 0.139, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.766, atol);
auto p = iv(3.f, 4.f);
BOOST_TEST_IS_CLOSE(p.first, 0.139f, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.766f, atol);
}

{
auto p = iv(4, 7 - 4);
BOOST_TEST_IS_CLOSE(p.first, 0.234, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.861, atol);
auto p = iv(4.f, 7.f - 4.f);
BOOST_TEST_IS_CLOSE(p.first, 0.234f, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.861f, atol);
}

// extrapolated from table
{
auto p = iv(5, 2);
BOOST_TEST_IS_CLOSE(p.first, 1 - 0.648, atol);
BOOST_TEST_IS_CLOSE(p.second, 1 - 0.065, atol);
auto p = iv(5.f, 2.f);
BOOST_TEST_IS_CLOSE(p.first, 1.f - 0.648f, atol);
BOOST_TEST_IS_CLOSE(p.second, 1.f - 0.065f, atol);
}

// extrapolated from table
{
auto p = iv(6, 1);
BOOST_TEST_IS_CLOSE(p.first, 1 - 0.501, atol);
BOOST_TEST_IS_CLOSE(p.second, 1, atol);
auto p = iv(6.f, 1.f);
BOOST_TEST_IS_CLOSE(p.first, 1.f - 0.501f, atol);
BOOST_TEST_IS_CLOSE(p.second, 1.f, atol);
}

// extrapolated from table
{
auto p = iv(7, 0);
BOOST_TEST_IS_CLOSE(p.first, 1 - 0.41, atol);
BOOST_TEST_IS_CLOSE(p.second, 1, atol);
auto p = iv(7.f, 0.f);
BOOST_TEST_IS_CLOSE(p.first, 1.f - 0.41f, atol);
BOOST_TEST_IS_CLOSE(p.second, 1.f, atol);
}

// not in table
{
auto p = iv(0, 1);
BOOST_TEST_IS_CLOSE(p.first, 0, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.975, atol);
auto p = iv(0.f, 1.f);
BOOST_TEST_IS_CLOSE(p.first, 0.f, atol);
BOOST_TEST_IS_CLOSE(p.second, 0.975f, atol);

fraction<T> f(0, 1);
fraction<T> f(0.f, 1.f);
const auto y = iv(f);
BOOST_TEST_IS_CLOSE(y.first, 0.0, atol);
BOOST_TEST_IS_CLOSE(y.second, 0.975, atol);
BOOST_TEST_IS_CLOSE(y.first, 0.f, atol);
BOOST_TEST_IS_CLOSE(y.second, 0.975f, atol);
}

// not in table
{
auto p = iv(1, 0);
auto p = iv(1.f, 0.f);
BOOST_TEST_IS_CLOSE(p.first, 0.025, atol);
BOOST_TEST_IS_CLOSE(p.second, 1, atol);

fraction<T> f(1, 0);
fraction<T> f(1.f, 0.f);
const auto y = iv(f);
BOOST_TEST_IS_CLOSE(y.first, 0.025, atol);
BOOST_TEST_IS_CLOSE(y.second, 1, atol);
BOOST_TEST_IS_CLOSE(y.first, 0.025f, atol);
BOOST_TEST_IS_CLOSE(y.second, 1.f, atol);
}
}

Expand Down

0 comments on commit 44fa5eb

Please sign in to comment.