Skip to content

Commit

Permalink
Repair what I got to especially default_policy
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Feb 14, 2024
1 parent 86a0bbb commit 600c262
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 74 deletions.
2 changes: 1 addition & 1 deletion include/boost/math/concepts/distributions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ struct DistributionConcept
template <class R, class P>
static void test_extra_members(const boost::math::hypergeometric_distribution<R, P>& d)
{
unsigned u = d.defective();
unsigned u = static_cast<unsigned>(d.defective());
u = d.sample_count();
u = d.total();
suppress_unused_variable_warning(u);
Expand Down
83 changes: 42 additions & 41 deletions include/boost/math/distributions/cauchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,29 +276,30 @@ inline RealType quantile(const complemented2_type<cauchy_distribution<RealType,

template <class RealType, class Policy>
inline RealType mean(const cauchy_distribution<RealType, 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<RealType>(
"boost::math::mean(cauchy<%1%>&)",
"The Cauchy distribution does not have a mean: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy());
{
// There is no mean:
return
policies::raise_domain_error<RealType>
(
"boost::math::mean(cauchy<%1%>&)",
"The Cauchy distribution does not have a mean: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy()
);
}

template <class RealType, class Policy>
inline RealType variance(const cauchy_distribution<RealType, Policy>& /*dist*/)
{
// There is no variance:
typedef typename Policy::assert_undefined_type assert_type;
static_assert(assert_type::value == 0, "assert type is undefined");

return policies::raise_domain_error<RealType>(
"boost::math::variance(cauchy<%1%>&)",
"The Cauchy distribution does not have a variance: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy());
return
policies::raise_domain_error<RealType>
(
"boost::math::variance(cauchy<%1%>&)",
"The Cauchy distribution does not have a variance: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy()
);
}

template <class RealType, class Policy>
Expand All @@ -316,42 +317,42 @@ template <class RealType, class Policy>
inline RealType skewness(const cauchy_distribution<RealType, Policy>& /*dist*/)
{
// There is no skewness:
typedef typename Policy::assert_undefined_type assert_type;
static_assert(assert_type::value == 0, "assert type is undefined");

return policies::raise_domain_error<RealType>(
"boost::math::skewness(cauchy<%1%>&)",
"The Cauchy distribution does not have a skewness: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy()); // infinity?
return
policies::raise_domain_error<RealType>
(
"boost::math::skewness(cauchy<%1%>&)",
"The Cauchy distribution does not have a skewness: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy()
);
}

template <class RealType, class Policy>
inline RealType kurtosis(const cauchy_distribution<RealType, Policy>& /*dist*/)
{
// There is no kurtosis:
typedef typename Policy::assert_undefined_type assert_type;
static_assert(assert_type::value == 0, "assert type is undefined");

return policies::raise_domain_error<RealType>(
"boost::math::kurtosis(cauchy<%1%>&)",
"The Cauchy distribution does not have a kurtosis: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy());
return
policies::raise_domain_error<RealType>
(
"boost::math::kurtosis(cauchy<%1%>&)",
"The Cauchy distribution does not have a kurtosis: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy()
);
}

template <class RealType, class Policy>
inline RealType kurtosis_excess(const cauchy_distribution<RealType, Policy>& /*dist*/)
{
// There is no kurtosis excess:
typedef typename Policy::assert_undefined_type assert_type;
static_assert(assert_type::value == 0, "assert type is undefined");

return policies::raise_domain_error<RealType>(
"boost::math::kurtosis_excess(cauchy<%1%>&)",
"The Cauchy distribution does not have a kurtosis: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy());
return
policies::raise_domain_error<RealType>
(
"boost::math::kurtosis_excess(cauchy<%1%>&)",
"The Cauchy distribution does not have a kurtosis: "
"the only possible return value is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy()
);
}

template <class RealType, class Policy>
Expand Down
25 changes: 14 additions & 11 deletions include/boost/math/distributions/detail/hypergeometric_pdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ T hypergeometric_pdf_prime_loop_imp(hypergeometric_pdf_prime_loop_data& data, hy
// to sidestep the issue:
//
hypergeometric_pdf_prime_loop_result_entry<T> t = { p, &result };
data.current_prime = prime(++data.prime_index);
++data.prime_index;
data.current_prime = prime(static_cast<unsigned>(data.prime_index));
return hypergeometric_pdf_prime_loop_imp<T>(data, t);
}
if((p < 1) && (tools::min_value<T>() / p > result.value))
Expand All @@ -331,12 +332,14 @@ T hypergeometric_pdf_prime_loop_imp(hypergeometric_pdf_prime_loop_data& data, hy
// to sidestep the issue:
//
hypergeometric_pdf_prime_loop_result_entry<T> t = { p, &result };
data.current_prime = prime(++data.prime_index);
++data.prime_index;
data.current_prime = prime(static_cast<unsigned>(data.prime_index));
return hypergeometric_pdf_prime_loop_imp<T>(data, t);
}
result.value *= p;
}
data.current_prime = prime(++data.prime_index);
++data.prime_index;
data.current_prime = prime(static_cast<unsigned>(data.prime_index));
}
//
// When we get to here we have run out of prime factors,
Expand Down Expand Up @@ -397,16 +400,16 @@ T hypergeometric_pdf_factorial_imp(std::uint64_t x, std::uint64_t r, std::uint64
BOOST_MATH_ASSERT(N <= boost::math::max_factorial<T>::value);
T result = boost::math::unchecked_factorial<T>(n);
T num[3] = {
boost::math::unchecked_factorial<T>(r),
boost::math::unchecked_factorial<T>(N - n),
boost::math::unchecked_factorial<T>(N - r)
boost::math::unchecked_factorial<T>(static_cast<unsigned>(r)),
boost::math::unchecked_factorial<T>(static_cast<unsigned>(N - n)),
boost::math::unchecked_factorial<T>(static_cast<unsigned>(N - r))
};
T denom[5] = {
boost::math::unchecked_factorial<T>(N),
boost::math::unchecked_factorial<T>(x),
boost::math::unchecked_factorial<T>(n - x),
boost::math::unchecked_factorial<T>(r - x),
boost::math::unchecked_factorial<T>(N - n - r + x)
boost::math::unchecked_factorial<T>(static_cast<unsigned>(N)),
boost::math::unchecked_factorial<T>(static_cast<unsigned>(x)),
boost::math::unchecked_factorial<T>(static_cast<unsigned>(n - x)),
boost::math::unchecked_factorial<T>(static_cast<unsigned>(r - x)),
boost::math::unchecked_factorial<T>(static_cast<unsigned>(N - n - r + x))
};
std::size_t i = 0;
std::size_t j = 0;
Expand Down
28 changes: 19 additions & 9 deletions include/boost/math/distributions/non_central_beta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,24 +806,34 @@ namespace boost
// standard_deviation provided by derived accessors.
template <class RealType, class Policy>
inline RealType skewness(const non_central_beta_distribution<RealType, Policy>& /*dist*/)
{ // skewness = sqrt(l).
{
// LCOV_EXCL_START
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<RealType>(function, "This function is not yet implemented, the only sensible result is %1%.", // LCOV_EXCL_LINE
std::numeric_limits<RealType>::quiet_NaN(), Policy()); // infinity? LCOV_EXCL_LINE
return
policies::raise_evaluation_error<RealType>
(
function,
"This function is not yet implemented, the only sensible result is %1%.", // LCOV_EXCL_LINE
std::numeric_limits<RealType>::quiet_NaN(), Policy()
);
// LCOV_EXCL_STOP
}

template <class RealType, class Policy>
inline RealType kurtosis_excess(const non_central_beta_distribution<RealType, Policy>& /*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<RealType>(function, "This function is not yet implemented, the only sensible result is %1%.", // LCOV_EXCL_LINE
std::numeric_limits<RealType>::quiet_NaN(), Policy()); // infinity? LCOV_EXCL_LINE
return
policies::raise_evaluation_error<RealType>
(
function,
"This function is not yet implemented, the only sensible result is %1%.",
std::numeric_limits<RealType>::quiet_NaN(), Policy()
);
// LCOV_EXCL_STOP
} // kurtosis_excess

template <class RealType, class Policy>
Expand Down
22 changes: 10 additions & 12 deletions test/compile_test/instantiate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#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
#endif

template <class RealType>
struct instantiate_runner_result
{
Expand All @@ -17,12 +21,6 @@ struct instantiate_runner_result
template <class RealType>
bool instantiate_runner_result<RealType>::value;

#if defined(BOOST_MATH_ASSERT_UNDEFINED_POLICY)
#undef BOOST_MATH_ASSERT_UNDEFINED_POLICY
#endif

#define BOOST_MATH_ASSERT_UNDEFINED_POLICY false

#include <boost/math/tools/config.hpp>

#if !defined(BOOST_MATH_STANDALONE)
Expand Down Expand Up @@ -90,7 +88,7 @@ void instantiate(RealType)
function_requires<DistributionConcept<bernoulli_distribution<RealType> > >();
function_requires<DistributionConcept<beta_distribution<RealType> > >();
function_requires<DistributionConcept<binomial_distribution<RealType> > >();
//function_requires<DistributionConcept<cauchy_distribution<RealType> > >();
function_requires<DistributionConcept<cauchy_distribution<RealType> > >();
function_requires<DistributionConcept<chi_squared_distribution<RealType> > >();
function_requires<DistributionConcept<exponential_distribution<RealType> > >();
function_requires<DistributionConcept<extreme_value_distribution<RealType> > >();
Expand All @@ -108,7 +106,7 @@ void instantiate(RealType)
function_requires<DistributionConcept<lognormal_distribution<RealType> > >();
function_requires<DistributionConcept<negative_binomial_distribution<RealType> > >();
function_requires<DistributionConcept<non_central_chi_squared_distribution<RealType> > >();
//function_requires<DistributionConcept<non_central_beta_distribution<RealType> > >();
function_requires<DistributionConcept<non_central_beta_distribution<RealType> > >();
function_requires<DistributionConcept<non_central_f_distribution<RealType> > >();
function_requires<DistributionConcept<non_central_t_distribution<RealType> > >();
function_requires<DistributionConcept<normal_distribution<RealType> > >();
Expand All @@ -127,7 +125,7 @@ void instantiate(RealType)
function_requires<DistributionConcept<bernoulli_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<beta_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<binomial_distribution<RealType, test_policy> > >();
//function_requires<DistributionConcept<cauchy_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<cauchy_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<chi_squared_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<exponential_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<extreme_value_distribution<RealType, test_policy> > >();
Expand All @@ -144,7 +142,7 @@ void instantiate(RealType)
function_requires<DistributionConcept<lognormal_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<negative_binomial_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<non_central_chi_squared_distribution<RealType, test_policy> > >();
//function_requires<DistributionConcept<non_central_beta_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<non_central_beta_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<non_central_f_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<non_central_t_distribution<RealType, test_policy> > >();
function_requires<DistributionConcept<normal_distribution<RealType, test_policy> > >();
Expand All @@ -162,7 +160,7 @@ void instantiate(RealType)
function_requires<DistributionConcept<dist_test::bernoulli > >();
function_requires<DistributionConcept<dist_test::beta > >();
function_requires<DistributionConcept<dist_test::binomial > >();
//function_requires<DistributionConcept<dist_test::cauchy > >();
function_requires<DistributionConcept<dist_test::cauchy > >();
function_requires<DistributionConcept<dist_test::chi_squared > >();
function_requires<DistributionConcept<dist_test::exponential > >();
function_requires<DistributionConcept<dist_test::extreme_value > >();
Expand All @@ -178,7 +176,7 @@ void instantiate(RealType)
function_requires<DistributionConcept<dist_test::lognormal > >();
function_requires<DistributionConcept<dist_test::negative_binomial > >();
function_requires<DistributionConcept<dist_test::non_central_chi_squared > >();
//function_requires<DistributionConcept<dist_test::non_central_beta > >();
function_requires<DistributionConcept<dist_test::non_central_beta > >();
function_requires<DistributionConcept<dist_test::non_central_f > >();
function_requires<DistributionConcept<dist_test::non_central_t > >();
function_requires<DistributionConcept<dist_test::normal > >();
Expand Down

0 comments on commit 600c262

Please sign in to comment.