From 17f14ba3bfc105c7da8574782721a9de293994ab Mon Sep 17 00:00:00 2001 From: Christopher Kormanyos Date: Fri, 16 Feb 2024 06:10:17 +0100 Subject: [PATCH] Reduce scope of changes --- include/boost/math/concepts/distributions.hpp | 2 +- include/boost/math/distributions/cauchy.hpp | 89 +++++++++---------- .../detail/hypergeometric_pdf.hpp | 25 +++--- .../math/distributions/non_central_beta.hpp | 28 ++---- .../special_functions/detail/bessel_y0.hpp | 2 - test/Jamfile.v2 | 2 +- test/compile_test/instantiate.hpp | 4 +- test/test_instantiate1.cpp | 5 +- ...test_and_run.cpp => test_instantiate3.cpp} | 4 +- 9 files changed, 69 insertions(+), 92 deletions(-) rename test/{test_compile_test_and_run.cpp => test_instantiate3.cpp} (89%) diff --git a/include/boost/math/concepts/distributions.hpp b/include/boost/math/concepts/distributions.hpp index 65378a278..538bbe702 100644 --- a/include/boost/math/concepts/distributions.hpp +++ b/include/boost/math/concepts/distributions.hpp @@ -343,7 +343,7 @@ struct DistributionConcept template static void test_extra_members(const boost::math::hypergeometric_distribution& d) { - unsigned u = static_cast(d.defective()); + unsigned u = d.defective(); u = d.sample_count(); u = d.total(); suppress_unused_variable_warning(u); diff --git a/include/boost/math/distributions/cauchy.hpp b/include/boost/math/distributions/cauchy.hpp index 99f0a01a8..d914cca77 100644 --- a/include/boost/math/distributions/cauchy.hpp +++ b/include/boost/math/distributions/cauchy.hpp @@ -17,9 +17,8 @@ #include #include #include - -#include #include +#include namespace boost{ namespace math { @@ -276,30 +275,29 @@ inline RealType quantile(const complemented2_type inline RealType mean(const cauchy_distribution&) -{ - // There is no mean: - return - policies::raise_domain_error - ( - "boost::math::mean(cauchy<%1%>&)", - "The Cauchy distribution does not have a mean: " - "the only possible return value is %1%.", - std::numeric_limits::quiet_NaN(), Policy() - ); +{ // There is no mean: + typedef typename Policy::assert_undefined_type assert_type; + static_assert(assert_type::value == 0, "assert type is undefined"); + + return policies::raise_domain_error( + "boost::math::mean(cauchy<%1%>&)", + "The Cauchy distribution does not have a mean: " + "the only possible return value is %1%.", + std::numeric_limits::quiet_NaN(), Policy()); } template inline RealType variance(const cauchy_distribution& /*dist*/) { // There is no variance: - return - policies::raise_domain_error - ( - "boost::math::variance(cauchy<%1%>&)", - "The Cauchy distribution does not have a variance: " - "the only possible return value is %1%.", - std::numeric_limits::quiet_NaN(), Policy() - ); + typedef typename Policy::assert_undefined_type assert_type; + static_assert(assert_type::value == 0, "assert type is undefined"); + + return policies::raise_domain_error( + "boost::math::variance(cauchy<%1%>&)", + "The Cauchy distribution does not have a variance: " + "the only possible return value is %1%.", + std::numeric_limits::quiet_NaN(), Policy()); } template @@ -317,47 +315,42 @@ template inline RealType skewness(const cauchy_distribution& /*dist*/) { // There is no skewness: + typedef typename Policy::assert_undefined_type assert_type; + static_assert(assert_type::value == 0, "assert type is undefined"); - using assert_type = typename Policy::domain_error_type; - - static_assert(!(assert_type::value), "Error Policy is undefined"); - - return - policies::raise_domain_error - ( - "boost::math::skewness(cauchy<%1%>&)", - "The Cauchy distribution does not have a skewness: " - "the only possible return value is %1%.", - std::numeric_limits::quiet_NaN(), Policy() - ); + return policies::raise_domain_error( + "boost::math::skewness(cauchy<%1%>&)", + "The Cauchy distribution does not have a skewness: " + "the only possible return value is %1%.", + std::numeric_limits::quiet_NaN(), Policy()); // infinity? } template inline RealType kurtosis(const cauchy_distribution& /*dist*/) { // There is no kurtosis: - return - policies::raise_domain_error - ( - "boost::math::kurtosis(cauchy<%1%>&)", - "The Cauchy distribution does not have a kurtosis: " - "the only possible return value is %1%.", - std::numeric_limits::quiet_NaN(), Policy() - ); + typedef typename Policy::assert_undefined_type assert_type; + static_assert(assert_type::value == 0, "assert type is undefined"); + + return policies::raise_domain_error( + "boost::math::kurtosis(cauchy<%1%>&)", + "The Cauchy distribution does not have a kurtosis: " + "the only possible return value is %1%.", + std::numeric_limits::quiet_NaN(), Policy()); } template inline RealType kurtosis_excess(const cauchy_distribution& /*dist*/) { // There is no kurtosis excess: - return - policies::raise_domain_error - ( - "boost::math::kurtosis_excess(cauchy<%1%>&)", - "The Cauchy distribution does not have a kurtosis: " - "the only possible return value is %1%.", - std::numeric_limits::quiet_NaN(), Policy() - ); + typedef typename Policy::assert_undefined_type assert_type; + static_assert(assert_type::value == 0, "assert type is undefined"); + + return policies::raise_domain_error( + "boost::math::kurtosis_excess(cauchy<%1%>&)", + "The Cauchy distribution does not have a kurtosis: " + "the only possible return value is %1%.", + std::numeric_limits::quiet_NaN(), Policy()); } template diff --git a/include/boost/math/distributions/detail/hypergeometric_pdf.hpp b/include/boost/math/distributions/detail/hypergeometric_pdf.hpp index dcdc5ac7b..9eeef270d 100644 --- a/include/boost/math/distributions/detail/hypergeometric_pdf.hpp +++ b/include/boost/math/distributions/detail/hypergeometric_pdf.hpp @@ -321,8 +321,7 @@ T hypergeometric_pdf_prime_loop_imp(hypergeometric_pdf_prime_loop_data& data, hy // to sidestep the issue: // hypergeometric_pdf_prime_loop_result_entry t = { p, &result }; - ++data.prime_index; - data.current_prime = prime(static_cast(data.prime_index)); + data.current_prime = prime(++data.prime_index); return hypergeometric_pdf_prime_loop_imp(data, t); } if((p < 1) && (tools::min_value() / p > result.value)) @@ -332,14 +331,12 @@ T hypergeometric_pdf_prime_loop_imp(hypergeometric_pdf_prime_loop_data& data, hy // to sidestep the issue: // hypergeometric_pdf_prime_loop_result_entry t = { p, &result }; - ++data.prime_index; - data.current_prime = prime(static_cast(data.prime_index)); + data.current_prime = prime(++data.prime_index); return hypergeometric_pdf_prime_loop_imp(data, t); } result.value *= p; } - ++data.prime_index; - data.current_prime = prime(static_cast(data.prime_index)); + data.current_prime = prime(++data.prime_index); } // // When we get to here we have run out of prime factors, @@ -400,16 +397,16 @@ T hypergeometric_pdf_factorial_imp(std::uint64_t x, std::uint64_t r, std::uint64 BOOST_MATH_ASSERT(N <= boost::math::max_factorial::value); T result = boost::math::unchecked_factorial(n); T num[3] = { - boost::math::unchecked_factorial(static_cast(r)), - boost::math::unchecked_factorial(static_cast(N - n)), - boost::math::unchecked_factorial(static_cast(N - r)) + boost::math::unchecked_factorial(r), + boost::math::unchecked_factorial(N - n), + boost::math::unchecked_factorial(N - r) }; T denom[5] = { - boost::math::unchecked_factorial(static_cast(N)), - boost::math::unchecked_factorial(static_cast(x)), - boost::math::unchecked_factorial(static_cast(n - x)), - boost::math::unchecked_factorial(static_cast(r - x)), - boost::math::unchecked_factorial(static_cast(N - n - r + x)) + boost::math::unchecked_factorial(N), + boost::math::unchecked_factorial(x), + boost::math::unchecked_factorial(n - x), + boost::math::unchecked_factorial(r - x), + boost::math::unchecked_factorial(N - n - r + x) }; std::size_t i = 0; std::size_t j = 0; diff --git a/include/boost/math/distributions/non_central_beta.hpp b/include/boost/math/distributions/non_central_beta.hpp index 07a85b3a2..b32a605f2 100644 --- a/include/boost/math/distributions/non_central_beta.hpp +++ b/include/boost/math/distributions/non_central_beta.hpp @@ -806,34 +806,24 @@ namespace boost // standard_deviation provided by derived accessors. template inline RealType skewness(const non_central_beta_distribution& /*dist*/) - { - // LCOV_EXCL_START + { // skewness = sqrt(l). const char* function = "boost::math::non_central_beta_distribution<%1%>::skewness()"; + typedef typename Policy::assert_undefined_type assert_type; + static_assert(assert_type::value == 0, "Assert type is undefined."); - return - policies::raise_evaluation_error - ( - function, - "This function is not yet implemented, the only sensible result is %1%.", // LCOV_EXCL_LINE - std::numeric_limits::quiet_NaN(), Policy() - ); - // LCOV_EXCL_STOP + return policies::raise_evaluation_error(function, "This function is not yet implemented, the only sensible result is %1%.", // LCOV_EXCL_LINE + std::numeric_limits::quiet_NaN(), Policy()); // infinity? LCOV_EXCL_LINE } template inline RealType kurtosis_excess(const non_central_beta_distribution& /*dist*/) { - // LCOV_EXCL_START const char* function = "boost::math::non_central_beta_distribution<%1%>::kurtosis_excess()"; + typedef typename Policy::assert_undefined_type assert_type; + static_assert(assert_type::value == 0, "Assert type is undefined."); - return - policies::raise_evaluation_error - ( - function, - "This function is not yet implemented, the only sensible result is %1%.", - std::numeric_limits::quiet_NaN(), Policy() - ); - // LCOV_EXCL_STOP + return policies::raise_evaluation_error(function, "This function is not yet implemented, the only sensible result is %1%.", // LCOV_EXCL_LINE + std::numeric_limits::quiet_NaN(), Policy()); // infinity? LCOV_EXCL_LINE } // kurtosis_excess template diff --git a/include/boost/math/special_functions/detail/bessel_y0.hpp b/include/boost/math/special_functions/detail/bessel_y0.hpp index 7db990bb0..ed43189f8 100644 --- a/include/boost/math/special_functions/detail/bessel_y0.hpp +++ b/include/boost/math/special_functions/detail/bessel_y0.hpp @@ -145,8 +145,6 @@ T bessel_y0(T x, const Policy&) static const char* function = "boost::math::bessel_y0<%1%>(%1%,%1%)"; - static_cast(function[0U]); - BOOST_MATH_ASSERT(x > 0); if (x <= 3) // x in (0, 3] diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 7845181b7..f8ba2e889 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -226,7 +226,6 @@ test-suite special_fun : [ run test_factorials.cpp pch ../../test/build//boost_unit_test_framework ] [ run test_gamma.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ] [ run test_gamma_edge.cpp ] - [ run test_compile_test_and_run.cpp ] [ run test_gamma_mp.cpp ../../test/build//boost_unit_test_framework : : : release TEST=1 [ check-target-builds ../config//is_ci_sanitizer_run "Sanitizer CI run" : no ] : test_gamma_mp_1 ] [ run test_gamma_mp.cpp ../../test/build//boost_unit_test_framework : : : release TEST=2 [ check-target-builds ../config//is_ci_sanitizer_run "Sanitizer CI run" : no ] : test_gamma_mp_2 ] [ run test_gamma_mp.cpp ../../test/build//boost_unit_test_framework : : : release TEST=3 [ check-target-builds ../config//is_ci_sanitizer_run "Sanitizer CI run" : no ] : test_gamma_mp_3 ] @@ -504,6 +503,7 @@ test-suite special_fun : : test_igamma_inva_real_concept ] [ run test_instantiate1.cpp test_instantiate2.cpp ] [ run test_instantiate1.cpp test_instantiate2.cpp : : : off : test_instantiate_no_eh ] + [ run test_instantiate3.cpp ] [ run test_jacobi.cpp pch_light ../../test/build//boost_unit_test_framework ] [ run test_laguerre.cpp test_instances//test_instances pch_light ../../test/build//boost_unit_test_framework ] diff --git a/test/compile_test/instantiate.hpp b/test/compile_test/instantiate.hpp index 022ad4d32..7e4ea43a4 100644 --- a/test/compile_test/instantiate.hpp +++ b/test/compile_test/instantiate.hpp @@ -8,8 +8,8 @@ #ifndef BOOST_LIBS_MATH_TEST_INSTANTIATE_HPP #define BOOST_LIBS_MATH_TEST_INSTANTIATE_HPP -#if !defined(BOOST_MATH_ASSERT_UNDEFINED_POLICY) -#define BOOST_MATH_ASSERT_UNDEFINED_POLICY false +#ifndef BOOST_MATH_ASSERT_UNDEFINED_POLICY +# define BOOST_MATH_ASSERT_UNDEFINED_POLICY false #endif template diff --git a/test/test_instantiate1.cpp b/test/test_instantiate1.cpp index 72816a4d8..a930c14ca 100644 --- a/test/test_instantiate1.cpp +++ b/test/test_instantiate1.cpp @@ -11,11 +11,12 @@ extern void other_test(); int main(int argc, char* []) { - instantiate(double(0)); - if(argc > 10000) { + instantiate(double(0)); instantiate_mixed(double(0)); other_test(); } } + + diff --git a/test/test_compile_test_and_run.cpp b/test/test_instantiate3.cpp similarity index 89% rename from test/test_compile_test_and_run.cpp rename to test/test_instantiate3.cpp index 66cadc5a6..5501d5616 100644 --- a/test/test_compile_test_and_run.cpp +++ b/test/test_instantiate3.cpp @@ -35,7 +35,5 @@ auto main() -> int { local::instantiate_runner(); - const auto result_is_ok = (boost::report_errors() == 0); - - return (result_is_ok ? 0 : -1); + return boost::report_errors(); }