Skip to content

Commit 6684266

Browse files
authored
fix some false positive warnings emitted by msvc (#399)
* fix some false positive warnings emitted by msvc * make find_package for Python3 more specific
1 parent 90867e2 commit 6684266

11 files changed

+102
-97
lines changed

include/boost/histogram/axis/integer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class integer : public iterator_mixin<integer<Value, MetaData, Options>>,
112112
/// Returns index and shift (if axis has grown) for the passed argument.
113113
auto update(value_type x) noexcept {
114114
auto impl = [this](long x) -> std::pair<index_type, index_type> {
115-
const auto i = x - min_;
115+
const auto i = static_cast<value_type>(x) - min_;
116116
if (i >= 0) {
117117
const auto k = static_cast<axis::index_type>(i);
118118
if (k < size()) return {k, 0};

include/boost/histogram/utility/clopper_pearson_interval.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ class clopper_pearson_interval : public binomial_proportion_interval<ValueType>
5454
@param successes Number of successful trials.
5555
@param failures Number of failed trials.
5656
*/
57-
interval_type operator()(value_type successes, value_type failures) const noexcept {
57+
interval_type operator()(value_type successes, value_type failures) const noexcept override {
5858
// analytical solution when successes or failures are zero
5959
// T. Mans (2014), Electronic Journal of Statistics. 8 (1): 817-840.
6060
// arXiv:1303.1288. doi:10.1214/14-EJS909.
61-
const value_type total = successes + failures;
62-
if (successes == 0) return {0, 1 - std::pow(alpha_half_, 1 / total)};
63-
if (failures == 0) return {std::pow(alpha_half_, 1 / total), 1};
61+
const value_type one{1.0}, zero{0.0}, total{successes + failures};
62+
if (successes == 0) return {zero, one - std::pow(alpha_half_, one / total)};
63+
if (failures == 0) return {std::pow(alpha_half_, one / total), one};
6464

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

include/boost/histogram/utility/jeffreys_interval.hpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,20 @@ class jeffreys_interval : public binomial_proportion_interval<ValueType> {
5151
@param successes Number of successful trials.
5252
@param failures Number of failed trials.
5353
*/
54-
interval_type operator()(value_type successes, value_type failures) const noexcept {
54+
interval_type operator()(value_type successes,
55+
value_type failures) const noexcept override {
5556
// See L.D. Brown, T.T. Cai, A. DasGupta, Statistical Science 16 (2001) 101-133,
5657
// doi:10.1214/ss/1009213286, section 4.1.2.
57-
const value_type half{0.5};
58+
const value_type half{0.5}, one{1.0}, zero{0.0};
5859
const value_type total = successes + failures;
5960

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

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

include/boost/histogram/utility/wald_interval.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class wald_interval : public binomial_proportion_interval<ValueType> {
5959
@param successes Number of successful trials.
6060
@param failures Number of failed trials.
6161
*/
62-
interval_type operator()(value_type successes, value_type failures) const noexcept {
62+
interval_type operator()(value_type successes,
63+
value_type failures) const noexcept override {
6364
// See https://en.wikipedia.org/wiki/
6465
// Binomial_proportion_confidence_interval
6566
// #Normal_approximation_interval_or_Wald_interval

include/boost/histogram/utility/wilson_interval.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ class wilson_interval : public binomial_proportion_interval<ValueType> {
5858
@param successes Number of successful trials.
5959
@param failures Number of failed trials.
6060
*/
61-
interval_type operator()(value_type successes, value_type failures) const noexcept {
61+
interval_type operator()(value_type successes,
62+
value_type failures) const noexcept override {
6263
// See https://en.wikipedia.org/wiki/
6364
// Binomial_proportion_confidence_interval
6465
// #Wilson_score_interval

test/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
# Distributed under the Boost Software License, Version 1.0.
33
# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
44

5-
find_package(Python3)
5+
find_package(Python3 COMPONENTS Interpreter)
66
if (Python3_FOUND)
77
# checks that b2 and cmake are in sync
88
add_test(NAME runpy-${PROJECT_NAME}_check_build_system COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/check_build_system.py)
99

1010
# checks that all headers are included in odr test
1111
add_test(NAME runpy-${PROJECT_NAME}_check_odr_test COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/check_odr_test.py)
12+
else()
13+
MESSAGE(WARNING "Python interpreter not found, cannot check for odr violations and build system consistency")
1214
endif()
1315

1416
include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)

test/accumulators_count_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void run_tests() {
2020
{
2121
c_t c;
2222
++c;
23-
BOOST_TEST_EQ(c.value(), 1);
23+
BOOST_TEST_EQ(c.value(), static_cast<T>(1));
2424
BOOST_TEST_EQ(str(c), "1"s);
2525
BOOST_TEST_EQ(str(c, 2, false), " 1"s);
2626
BOOST_TEST_EQ(str(c, 2, true), "1 "s);

test/accumulators_fraction_test.cpp

+18-18
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ void run_tests() {
2525

2626
{
2727
f_t f;
28-
BOOST_TEST_EQ(f.successes(), 0);
29-
BOOST_TEST_EQ(f.failures(), 0);
28+
BOOST_TEST_EQ(f.successes(), static_cast<T>(0));
29+
BOOST_TEST_EQ(f.failures(), static_cast<T>(0));
3030
BOOST_TEST(std::isnan(f.value()));
3131
BOOST_TEST(std::isnan(f.variance()));
3232

@@ -38,22 +38,22 @@ void run_tests() {
3838
{
3939
f_t f;
4040
f(true);
41-
BOOST_TEST_EQ(f.successes(), 1);
42-
BOOST_TEST_EQ(f.failures(), 0);
41+
BOOST_TEST_EQ(f.successes(), static_cast<T>(1));
42+
BOOST_TEST_EQ(f.failures(), static_cast<T>(0));
4343
BOOST_TEST_EQ(str(f), "fraction(1, 0)"s);
4444
f(false);
45-
BOOST_TEST_EQ(f.successes(), 1);
46-
BOOST_TEST_EQ(f.failures(), 1);
45+
BOOST_TEST_EQ(f.successes(), static_cast<T>(1));
46+
BOOST_TEST_EQ(f.failures(), static_cast<T>(1));
4747
BOOST_TEST_EQ(str(f), "fraction(1, 1)"s);
4848
BOOST_TEST_EQ(str(f, 20), "fraction(1, 1) "s);
4949
}
5050

5151
{
5252
f_t f(3, 1);
53-
BOOST_TEST_EQ(f.successes(), 3);
54-
BOOST_TEST_EQ(f.failures(), 1);
55-
BOOST_TEST_EQ(f.value(), 0.75);
56-
BOOST_TEST_IS_CLOSE(f.variance(), 0.75 * (1 - 0.75) / 4, eps);
53+
BOOST_TEST_EQ(f.successes(), static_cast<T>(3));
54+
BOOST_TEST_EQ(f.failures(), static_cast<T>(1));
55+
BOOST_TEST_EQ(f.value(), 0.75f);
56+
BOOST_TEST_IS_CLOSE(f.variance(), 0.75f * (1.0f - 0.75f) / 4.f, eps);
5757

5858
const auto ci = f.confidence_interval();
5959
const auto expected = utility::wilson_interval<double>()(3, 1);
@@ -63,10 +63,10 @@ void run_tests() {
6363

6464
{
6565
f_t f(0, 1);
66-
BOOST_TEST_EQ(f.successes(), 0);
67-
BOOST_TEST_EQ(f.failures(), 1);
68-
BOOST_TEST_EQ(f.value(), 0);
69-
BOOST_TEST_EQ(f.variance(), 0);
66+
BOOST_TEST_EQ(f.successes(), static_cast<T>(0));
67+
BOOST_TEST_EQ(f.failures(), static_cast<T>(1));
68+
BOOST_TEST_EQ(f.value(), 0.f);
69+
BOOST_TEST_EQ(f.variance(), 0.f);
7070

7171
const auto ci = f.confidence_interval();
7272
const auto expected = utility::wilson_interval<double>()(0, 1);
@@ -76,10 +76,10 @@ void run_tests() {
7676

7777
{
7878
f_t f(1, 0);
79-
BOOST_TEST_EQ(f.successes(), 1);
80-
BOOST_TEST_EQ(f.failures(), 0);
81-
BOOST_TEST_EQ(f.value(), 1);
82-
BOOST_TEST_EQ(f.variance(), 0);
79+
BOOST_TEST_EQ(f.successes(), static_cast<T>(1));
80+
BOOST_TEST_EQ(f.failures(), static_cast<T>(0));
81+
BOOST_TEST_EQ(f.value(), 1.f);
82+
BOOST_TEST_EQ(f.variance(), 0.f);
8383

8484
const auto ci = f.confidence_interval();
8585
const auto expected = utility::wilson_interval<double>()(1, 0);

test/algorithm_reduce_test.cpp

+28-28
Original file line numberDiff line numberDiff line change
@@ -75,39 +75,39 @@ void run_tests() {
7575
// - lower edge of shrink: pick bin which contains edge, lower <= x < upper
7676
// - upper edge of shrink: pick bin which contains edge + 1, lower < x <= upper
7777
{
78-
auto h = make(Tag(), ID(0, 3));
78+
auto h = make(Tag(), ID(0.0, 3.0));
7979
const auto& ax = h.axis();
80-
BOOST_TEST_EQ(ax.value(0), 0);
81-
BOOST_TEST_EQ(ax.value(3), 3);
82-
BOOST_TEST_EQ(ax.index(-1), -1);
83-
BOOST_TEST_EQ(ax.index(3), 3);
84-
85-
BOOST_TEST_EQ(reduce(h, shrink(-1, 5)).axis(), ID(0, 3));
86-
BOOST_TEST_EQ(reduce(h, shrink(0, 3)).axis(), ID(0, 3));
87-
BOOST_TEST_EQ(reduce(h, shrink(1, 3)).axis(), ID(1, 3));
88-
BOOST_TEST_EQ(reduce(h, shrink(1.001, 3)).axis(), ID(1, 3));
89-
BOOST_TEST_EQ(reduce(h, shrink(1.999, 3)).axis(), ID(1, 3));
90-
BOOST_TEST_EQ(reduce(h, shrink(2, 3)).axis(), ID(2, 3));
91-
BOOST_TEST_EQ(reduce(h, shrink(0, 2.999)).axis(), ID(0, 3));
92-
BOOST_TEST_EQ(reduce(h, shrink(0, 2.001)).axis(), ID(0, 3));
93-
BOOST_TEST_EQ(reduce(h, shrink(0, 2)).axis(), ID(0, 2));
94-
BOOST_TEST_EQ(reduce(h, shrink(0, 1.999)).axis(), ID(0, 2));
95-
96-
BOOST_TEST_EQ(reduce(h, crop(-1, 5)).axis(), ID(0, 3));
97-
BOOST_TEST_EQ(reduce(h, crop(0, 3)).axis(), ID(0, 3));
98-
BOOST_TEST_EQ(reduce(h, crop(1, 3)).axis(), ID(1, 3));
99-
BOOST_TEST_EQ(reduce(h, crop(1.001, 3)).axis(), ID(1, 3));
100-
BOOST_TEST_EQ(reduce(h, crop(1.999, 3)).axis(), ID(1, 3));
101-
BOOST_TEST_EQ(reduce(h, crop(2, 3)).axis(), ID(2, 3));
102-
BOOST_TEST_EQ(reduce(h, crop(0, 2.999)).axis(), ID(0, 3));
103-
BOOST_TEST_EQ(reduce(h, crop(0, 2.001)).axis(), ID(0, 3));
104-
BOOST_TEST_EQ(reduce(h, crop(0, 2)).axis(), ID(0, 2));
105-
BOOST_TEST_EQ(reduce(h, crop(0, 1.999)).axis(), ID(0, 2));
80+
BOOST_TEST_EQ(ax.value(0), 0.0);
81+
BOOST_TEST_EQ(ax.value(3), 3.0);
82+
BOOST_TEST_EQ(ax.index(-1.0), -1);
83+
BOOST_TEST_EQ(ax.index(3.0), 3);
84+
85+
BOOST_TEST_EQ(reduce(h, shrink(-1, 5)).axis(), ID(0.0, 3.0));
86+
BOOST_TEST_EQ(reduce(h, shrink(0, 3)).axis(), ID(0.0, 3.0));
87+
BOOST_TEST_EQ(reduce(h, shrink(1, 3)).axis(), ID(1.0, 3.0));
88+
BOOST_TEST_EQ(reduce(h, shrink(1.001, 3)).axis(), ID(1.0, 3.0));
89+
BOOST_TEST_EQ(reduce(h, shrink(1.999, 3)).axis(), ID(1.0, 3.0));
90+
BOOST_TEST_EQ(reduce(h, shrink(2, 3)).axis(), ID(2.0, 3.0));
91+
BOOST_TEST_EQ(reduce(h, shrink(0, 2.999)).axis(), ID(0.0, 3.0));
92+
BOOST_TEST_EQ(reduce(h, shrink(0, 2.001)).axis(), ID(0.0, 3.0));
93+
BOOST_TEST_EQ(reduce(h, shrink(0, 2)).axis(), ID(0.0, 2.0));
94+
BOOST_TEST_EQ(reduce(h, shrink(0, 1.999)).axis(), ID(0.0, 2.0));
95+
96+
BOOST_TEST_EQ(reduce(h, crop(-1, 5)).axis(), ID(0.0, 3.0));
97+
BOOST_TEST_EQ(reduce(h, crop(0, 3)).axis(), ID(0.0, 3.0));
98+
BOOST_TEST_EQ(reduce(h, crop(1, 3)).axis(), ID(1.0, 3.0));
99+
BOOST_TEST_EQ(reduce(h, crop(1.001, 3)).axis(), ID(1.0, 3.0));
100+
BOOST_TEST_EQ(reduce(h, crop(1.999, 3)).axis(), ID(1.0, 3.0));
101+
BOOST_TEST_EQ(reduce(h, crop(2, 3)).axis(), ID(2.0, 3.0));
102+
BOOST_TEST_EQ(reduce(h, crop(0, 2.999)).axis(), ID(0.0, 3.0));
103+
BOOST_TEST_EQ(reduce(h, crop(0, 2.001)).axis(), ID(0.0, 3.0));
104+
BOOST_TEST_EQ(reduce(h, crop(0, 2)).axis(), ID(0.0, 2.0));
105+
BOOST_TEST_EQ(reduce(h, crop(0, 1.999)).axis(), ID(0.0, 2.0));
106106
}
107107

108108
// shrink and rebin
109109
{
110-
auto h = make_s(Tag(), std::vector<int>(), R(4, 1, 5, "1"), R(3, -1, 2, "2"));
110+
auto h = make_s(Tag(), std::vector<int>(), R(4, 1.0, 5.0, "1"), R(3, -1.0, 2.0, "2"));
111111

112112
/*
113113
matrix layout:

test/utility_clopper_pearson_interval_test.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ template <class T>
1818
void test() {
1919
const T atol = 0.001;
2020

21-
clopper_pearson_interval<T> iv(deviation{1.f});
21+
clopper_pearson_interval<T> iv(deviation{1});
2222

2323
{
2424
const auto x = iv(0.f, 1.f);

test/utility_jeffreys_interval_test.cpp

+34-34
Original file line numberDiff line numberDiff line change
@@ -25,78 +25,78 @@ void test() {
2525
jeffreys_interval<T> iv(confidence_level{0.95});
2626

2727
{
28-
auto p = iv(0, 7);
29-
BOOST_TEST_IS_CLOSE(p.first, 0, atol);
30-
BOOST_TEST_IS_CLOSE(p.second, 0.41, atol);
28+
auto p = iv(0.f, 7.f);
29+
BOOST_TEST_IS_CLOSE(p.first, 0.f, atol);
30+
BOOST_TEST_IS_CLOSE(p.second, 0.41f, atol);
3131
}
3232

3333
{
34-
auto p = iv(1, 6);
35-
BOOST_TEST_IS_CLOSE(p.first, 0, atol);
36-
BOOST_TEST_IS_CLOSE(p.second, 0.501, atol);
34+
auto p = iv(1.f, 6.f);
35+
BOOST_TEST_IS_CLOSE(p.first, 0.f, atol);
36+
BOOST_TEST_IS_CLOSE(p.second, 0.501f, atol);
3737
}
3838

3939
{
40-
auto p = iv(2, 5);
41-
BOOST_TEST_IS_CLOSE(p.first, 0.065, atol);
42-
BOOST_TEST_IS_CLOSE(p.second, 0.648, atol);
40+
auto p = iv(2.f, 5.f);
41+
BOOST_TEST_IS_CLOSE(p.first, 0.065f, atol);
42+
BOOST_TEST_IS_CLOSE(p.second, 0.648f, atol);
4343
}
4444

4545
{
46-
auto p = iv(3, 4);
47-
BOOST_TEST_IS_CLOSE(p.first, 0.139, atol);
48-
BOOST_TEST_IS_CLOSE(p.second, 0.766, atol);
46+
auto p = iv(3.f, 4.f);
47+
BOOST_TEST_IS_CLOSE(p.first, 0.139f, atol);
48+
BOOST_TEST_IS_CLOSE(p.second, 0.766f, atol);
4949
}
5050

5151
{
52-
auto p = iv(4, 7 - 4);
53-
BOOST_TEST_IS_CLOSE(p.first, 0.234, atol);
54-
BOOST_TEST_IS_CLOSE(p.second, 0.861, atol);
52+
auto p = iv(4.f, 7.f - 4.f);
53+
BOOST_TEST_IS_CLOSE(p.first, 0.234f, atol);
54+
BOOST_TEST_IS_CLOSE(p.second, 0.861f, atol);
5555
}
5656

5757
// extrapolated from table
5858
{
59-
auto p = iv(5, 2);
60-
BOOST_TEST_IS_CLOSE(p.first, 1 - 0.648, atol);
61-
BOOST_TEST_IS_CLOSE(p.second, 1 - 0.065, atol);
59+
auto p = iv(5.f, 2.f);
60+
BOOST_TEST_IS_CLOSE(p.first, 1.f - 0.648f, atol);
61+
BOOST_TEST_IS_CLOSE(p.second, 1.f - 0.065f, atol);
6262
}
6363

6464
// extrapolated from table
6565
{
66-
auto p = iv(6, 1);
67-
BOOST_TEST_IS_CLOSE(p.first, 1 - 0.501, atol);
68-
BOOST_TEST_IS_CLOSE(p.second, 1, atol);
66+
auto p = iv(6.f, 1.f);
67+
BOOST_TEST_IS_CLOSE(p.first, 1.f - 0.501f, atol);
68+
BOOST_TEST_IS_CLOSE(p.second, 1.f, atol);
6969
}
7070

7171
// extrapolated from table
7272
{
73-
auto p = iv(7, 0);
74-
BOOST_TEST_IS_CLOSE(p.first, 1 - 0.41, atol);
75-
BOOST_TEST_IS_CLOSE(p.second, 1, atol);
73+
auto p = iv(7.f, 0.f);
74+
BOOST_TEST_IS_CLOSE(p.first, 1.f - 0.41f, atol);
75+
BOOST_TEST_IS_CLOSE(p.second, 1.f, atol);
7676
}
7777

7878
// not in table
7979
{
80-
auto p = iv(0, 1);
81-
BOOST_TEST_IS_CLOSE(p.first, 0, atol);
82-
BOOST_TEST_IS_CLOSE(p.second, 0.975, atol);
80+
auto p = iv(0.f, 1.f);
81+
BOOST_TEST_IS_CLOSE(p.first, 0.f, atol);
82+
BOOST_TEST_IS_CLOSE(p.second, 0.975f, atol);
8383

84-
fraction<T> f(0, 1);
84+
fraction<T> f(0.f, 1.f);
8585
const auto y = iv(f);
86-
BOOST_TEST_IS_CLOSE(y.first, 0.0, atol);
87-
BOOST_TEST_IS_CLOSE(y.second, 0.975, atol);
86+
BOOST_TEST_IS_CLOSE(y.first, 0.f, atol);
87+
BOOST_TEST_IS_CLOSE(y.second, 0.975f, atol);
8888
}
8989

9090
// not in table
9191
{
92-
auto p = iv(1, 0);
92+
auto p = iv(1.f, 0.f);
9393
BOOST_TEST_IS_CLOSE(p.first, 0.025, atol);
9494
BOOST_TEST_IS_CLOSE(p.second, 1, atol);
9595

96-
fraction<T> f(1, 0);
96+
fraction<T> f(1.f, 0.f);
9797
const auto y = iv(f);
98-
BOOST_TEST_IS_CLOSE(y.first, 0.025, atol);
99-
BOOST_TEST_IS_CLOSE(y.second, 1, atol);
98+
BOOST_TEST_IS_CLOSE(y.first, 0.025f, atol);
99+
BOOST_TEST_IS_CLOSE(y.second, 1.f, atol);
100100
}
101101
}
102102

0 commit comments

Comments
 (0)