Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65694 - in trunk: boost/math/distributions libs/math/test libs/math/test/compile_test
From: john_at_[hidden]
Date: 2010-09-30 13:16:17


Author: johnmaddock
Date: 2010-09-30 13:16:14 EDT (Thu, 30 Sep 2010)
New Revision: 65694
URL: http://svn.boost.org/trac/boost/changeset/65694

Log:
Add concept checks for new distributions.
Fix Linux gcc failures for new distributions.
Added:
   trunk/libs/math/test/compile_test/dist_inv_chi_sq_incl_test.cpp (contents, props changed)
   trunk/libs/math/test/compile_test/dist_inv_gamma_incl_test.cpp (contents, props changed)
Text files modified:
   trunk/boost/math/distributions/inverse_chi_squared.hpp | 15 ++++++++++++---
   trunk/libs/math/test/Jamfile.v2 | 2 ++
   trunk/libs/math/test/compile_test/instantiate.hpp | 4 ++++
   trunk/libs/math/test/test_inverse_chi_squared_distribution.cpp | 2 +-
   4 files changed, 19 insertions(+), 4 deletions(-)

Modified: trunk/boost/math/distributions/inverse_chi_squared.hpp
==============================================================================
--- trunk/boost/math/distributions/inverse_chi_squared.hpp (original)
+++ trunk/boost/math/distributions/inverse_chi_squared.hpp 2010-09-30 13:16:14 EDT (Thu, 30 Sep 2010)
@@ -142,7 +142,9 @@
    // RealType shape = df /2; // inv_gamma shape
    // RealType scale = df * scale/2; // inv_gamma scale
    // RealType result = gamma_p_derivative(shape, scale / x, Policy()) * scale / (x * x);
- RealType result = gamma_p_derivative(df/2, df * scale/2 / x, Policy()) * df * scale/2 / (x * x);
+ RealType result = gamma_p_derivative(df/2, df * scale/2 / x, Policy()) * df * scale/2;
+ if(result != 0) // prevent 0 / 0:
+ result /= (x * x);
    return result;
 } // pdf
 
@@ -200,7 +202,10 @@
    // RealType shape = df /2; // inv_gamma shape,
    // RealType scale = df * scale/2; // inv_gamma scale,
    // result = scale / gamma_q_inv(shape, p, Policy());
- RealType result = df * scale/2 / gamma_q_inv(df /2, p, Policy());
+ RealType result = gamma_q_inv(df /2, p, Policy());
+ if(result == 0)
+ return policies::raise_overflow_error<RealType, Policy>(function, "Random variable is infinite.", Policy());
+ result = df * (scale / 2) / result;
       return result;
 } // quantile
 
@@ -257,7 +262,11 @@
    // RealType shape = df /2; // inv_gamma shape,
    // RealType scale = df * scale/2; // inv_gamma scale,
    // result = scale / gamma_p_inv(shape, q, Policy()); // using inv_gamma.
- return (df * scale / 2) / gamma_p_inv(df/2, q, Policy());
+ RealType result = gamma_p_inv(df/2, q, Policy());
+ if(result == 0)
+ return policies::raise_overflow_error<RealType, Policy>(function, "Random variable is infinite.", Policy());
+ result = (df * scale / 2) / result;
+ return result;
 } // quantile(const complement
 
 template <class RealType, class Policy>

Modified: trunk/libs/math/test/Jamfile.v2
==============================================================================
--- trunk/libs/math/test/Jamfile.v2 (original)
+++ trunk/libs/math/test/Jamfile.v2 2010-09-30 13:16:14 EDT (Thu, 30 Sep 2010)
@@ -671,6 +671,8 @@
 run compile_test/dist_find_scale_incl_test.cpp compile_test/main.cpp ;
 run compile_test/dist_fisher_f_incl_test.cpp compile_test/main.cpp ;
 run compile_test/dist_gamma_incl_test.cpp compile_test/main.cpp ;
+run compile_test/dist_inv_gamma_incl_test.cpp compile_test/main.cpp ;
+run compile_test/dist_inv_chi_sq_incl_test.cpp compile_test/main.cpp ;
 run compile_test/dist_hypergeo_incl_test.cpp compile_test/main.cpp ;
 run compile_test/dist_laplace_incl_test.cpp compile_test/main.cpp ;
 run compile_test/dist_logistic_incl_test.cpp compile_test/main.cpp ;

Added: trunk/libs/math/test/compile_test/dist_inv_chi_sq_incl_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/math/test/compile_test/dist_inv_chi_sq_incl_test.cpp 2010-09-30 13:16:14 EDT (Thu, 30 Sep 2010)
@@ -0,0 +1,25 @@
+// Copyright John Maddock 2006.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// Basic sanity check that header <boost/math/distributions/gamma.hpp>
+// #includes all the files that it needs to.
+//
+#include <boost/math/distributions/inverse_chi_squared.hpp>
+//
+// Note this header includes no other headers, this is
+// important if this test is to be meaningful:
+//
+#include "test_compile_result.hpp"
+
+void compile_and_link_test()
+{
+ TEST_DIST_FUNC(inverse_chi_squared)
+}
+
+template class boost::math::inverse_chi_squared_distribution<float, boost::math::policies::policy<> >;
+template class boost::math::inverse_chi_squared_distribution<double, boost::math::policies::policy<> >;
+#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
+template class boost::math::inverse_chi_squared_distribution<long double, boost::math::policies::policy<> >;
+#endif

Added: trunk/libs/math/test/compile_test/dist_inv_gamma_incl_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/math/test/compile_test/dist_inv_gamma_incl_test.cpp 2010-09-30 13:16:14 EDT (Thu, 30 Sep 2010)
@@ -0,0 +1,25 @@
+// Copyright John Maddock 2006.
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// Basic sanity check that header <boost/math/distributions/gamma.hpp>
+// #includes all the files that it needs to.
+//
+#include <boost/math/distributions/inverse_gamma.hpp>
+//
+// Note this header includes no other headers, this is
+// important if this test is to be meaningful:
+//
+#include "test_compile_result.hpp"
+
+void compile_and_link_test()
+{
+ TEST_DIST_FUNC(inverse_gamma)
+}
+
+template class boost::math::inverse_gamma_distribution<float, boost::math::policies::policy<> >;
+template class boost::math::inverse_gamma_distribution<double, boost::math::policies::policy<> >;
+#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
+template class boost::math::inverse_gamma_distribution<long double, boost::math::policies::policy<> >;
+#endif

Modified: trunk/libs/math/test/compile_test/instantiate.hpp
==============================================================================
--- trunk/libs/math/test/compile_test/instantiate.hpp (original)
+++ trunk/libs/math/test/compile_test/instantiate.hpp 2010-09-30 13:16:14 EDT (Thu, 30 Sep 2010)
@@ -68,6 +68,8 @@
    function_requires<DistributionConcept<extreme_value_distribution<RealType> > >();
    function_requires<DistributionConcept<fisher_f_distribution<RealType> > >();
    function_requires<DistributionConcept<gamma_distribution<RealType> > >();
+ function_requires<DistributionConcept<inverse_gamma_distribution<RealType> > >();
+ function_requires<DistributionConcept<inverse_chi_squared_distribution<RealType> > >();
    function_requires<DistributionConcept<laplace_distribution<RealType> > >();
    function_requires<DistributionConcept<logistic_distribution<RealType> > >();
    function_requires<DistributionConcept<lognormal_distribution<RealType> > >();
@@ -95,6 +97,8 @@
    function_requires<DistributionConcept<extreme_value_distribution<RealType, test_policy> > >();
    function_requires<DistributionConcept<fisher_f_distribution<RealType, test_policy> > >();
    function_requires<DistributionConcept<gamma_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<inverse_gamma_distribution<RealType, test_policy> > >();
+ function_requires<DistributionConcept<inverse_chi_squared_distribution<RealType, test_policy> > >();
    function_requires<DistributionConcept<logistic_distribution<RealType, test_policy> > >();
    function_requires<DistributionConcept<lognormal_distribution<RealType, test_policy> > >();
    function_requires<DistributionConcept<non_central_chi_squared_distribution<RealType, test_policy> > >();

Modified: trunk/libs/math/test/test_inverse_chi_squared_distribution.cpp
==============================================================================
--- trunk/libs/math/test/test_inverse_chi_squared_distribution.cpp (original)
+++ trunk/libs/math/test/test_inverse_chi_squared_distribution.cpp 2010-09-30 13:16:14 EDT (Thu, 30 Sep 2010)
@@ -369,7 +369,7 @@
   BOOST_CHECK_EQUAL(ichsq32.scale(), 2); // scale == 2
   
   inverse_chi_squared ichsq11(1, 1); // Using explicit degrees_of_freedom parameter, and default scale = 1).
- BOOST_CHECK_EQUAL(mode(ichsq11), 0.33333333333333333333333333333333333333333L);
+ BOOST_CHECK_CLOSE_FRACTION(mode(ichsq11), 0.33333333333333333333333333333333333333333L, tol4eps);
   // (1 * 1)/ (1 + 2) = 1/3 using Wikipedia nu * xi /(nu + 2)
   BOOST_CHECK_EQUAL(ichsq11.degrees_of_freedom(), 1.); // df == 1 (default).
   BOOST_CHECK_EQUAL(ichsq11.scale(), 1.); // scale == 1.


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk