From e38209bdc083eed10fff4a4e640717b0aa07994b Mon Sep 17 00:00:00 2001 From: John Maddock Date: Fri, 13 Mar 2009 17:56:28 +0000 Subject: [PATCH] Add instrumentation code and some FPU control options. [SVN r51755] --- .../detail/hypergeometric_cdf.hpp | 4 +- .../detail/hypergeometric_quantile.hpp | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/include/boost/math/distributions/detail/hypergeometric_cdf.hpp b/include/boost/math/distributions/detail/hypergeometric_cdf.hpp index 85edf7afe..638cab6e6 100644 --- a/include/boost/math/distributions/detail/hypergeometric_cdf.hpp +++ b/include/boost/math/distributions/detail/hypergeometric_cdf.hpp @@ -21,7 +21,7 @@ namespace boost{ namespace math{ namespace detail{ # pragma warning(disable:4267) #endif BOOST_MATH_STD_USING - T result = 0; + T result = 0; T mode = floor(T(r + 1) * T(n + 1) / (N + 2)); if(x < mode) { @@ -72,7 +72,7 @@ namespace boost{ namespace math{ namespace detail{ inline T hypergeometric_cdf(unsigned x, unsigned r, unsigned n, unsigned N, bool invert, const Policy&) { BOOST_FPU_EXCEPTION_GUARD - typedef typename tools::promote_args::type result_type; + typedef typename tools::promote_args::type result_type; typedef typename policies::evaluation::type value_type; typedef typename policies::normalise< Policy, diff --git a/include/boost/math/distributions/detail/hypergeometric_quantile.hpp b/include/boost/math/distributions/detail/hypergeometric_quantile.hpp index 2ead896cc..a855a4a77 100644 --- a/include/boost/math/distributions/detail/hypergeometric_quantile.hpp +++ b/include/boost/math/distributions/detail/hypergeometric_quantile.hpp @@ -17,7 +17,10 @@ template inline unsigned round_x_from_p(unsigned x, T p, T cum, T fudge_factor, unsigned lbound, unsigned /*ubound*/, const policies::discrete_quantile&) { if((p < cum * fudge_factor) && (x != lbound)) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x-1); return --x; + } return x; } @@ -25,7 +28,10 @@ template inline unsigned round_x_from_p(unsigned x, T p, T cum, T fudge_factor, unsigned /*lbound*/, unsigned ubound, const policies::discrete_quantile&) { if((cum < p * fudge_factor) && (x != ubound)) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x+1); return ++x; + } return x; } @@ -55,7 +61,10 @@ template inline unsigned round_x_from_q(unsigned x, T q, T cum, T fudge_factor, unsigned lbound, unsigned /*ubound*/, const policies::discrete_quantile&) { if((q * fudge_factor > cum) && (x != lbound)) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x-1); return --x; + } return x; } @@ -63,7 +72,10 @@ template inline unsigned round_x_from_q(unsigned x, T q, T cum, T fudge_factor, unsigned /*lbound*/, unsigned ubound, const policies::discrete_quantile&) { if((q < cum * fudge_factor) && (x != ubound)) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x+1); return ++x; + } return x; } @@ -98,11 +110,21 @@ unsigned hypergeometric_quantile_imp(T p, T q, unsigned r, unsigned n, unsigned #endif typedef typename Policy::discrete_quantile_type discrete_quantile_type; BOOST_MATH_STD_USING + BOOST_FPU_EXCEPTION_GUARD T result; T fudge_factor = 1 + tools::epsilon() * ((N <= boost::math::prime(boost::math::max_prime - 1)) ? 50 : 2 * N); unsigned base = static_cast((std::max)(0, (int)(n + r) - (int)(N))); unsigned lim = (std::min)(r, n); + BOOST_MATH_INSTRUMENT_VARIABLE(p); + BOOST_MATH_INSTRUMENT_VARIABLE(q); + BOOST_MATH_INSTRUMENT_VARIABLE(r); + BOOST_MATH_INSTRUMENT_VARIABLE(n); + BOOST_MATH_INSTRUMENT_VARIABLE(N); + BOOST_MATH_INSTRUMENT_VARIABLE(fudge_factor); + BOOST_MATH_INSTRUMENT_VARIABLE(base); + BOOST_MATH_INSTRUMENT_VARIABLE(lim); + if(p <= 0.5) { unsigned x = base; @@ -117,6 +139,14 @@ unsigned hypergeometric_quantile_imp(T p, T q, unsigned r, unsigned n, unsigned break; ++x; result += diff; +#ifdef BOOST_MATH_INSTRUMENT + if(diff != 0) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x); + BOOST_MATH_INSTRUMENT_VARIABLE(diff); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } +#endif } return round_x_from_p(x, p, result, fudge_factor, base, lim, discrete_quantile_type()); } @@ -132,6 +162,14 @@ unsigned hypergeometric_quantile_imp(T p, T q, unsigned r, unsigned n, unsigned ? x * T(N + x - n - r) * diff / (T(1 + n - x) * T(1 + r - x)) : hypergeometric_pdf(x - 1, r, n, N, pol); --x; +#ifdef BOOST_MATH_INSTRUMENT + if(diff != 0) + { + BOOST_MATH_INSTRUMENT_VARIABLE(x); + BOOST_MATH_INSTRUMENT_VARIABLE(diff); + BOOST_MATH_INSTRUMENT_VARIABLE(result); + } +#endif } return round_x_from_q(x, q, result, fudge_factor, base, lim, discrete_quantile_type()); }