1 // Copyright John Maddock 2015.
2 // Use, modification and distribution are subject to the
3 // Boost Software License, Version 1.0. (See accompanying file
4 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef TABLE_HELPER_HPP
7 #define TABLE_HELPER_HPP
11 #include <boost/version.hpp>
12 #include <boost/lexical_cast.hpp>
15 // Also include headers for whatever else we may be testing:
22 #include <gsl/gsl_sf.h>
23 #include <gsl/gsl_errno.h>
24 #include <gsl/gsl_version.h>
26 void gsl_handler(const char * reason, const char * file, int line, int gsl_errno)
28 if(gsl_errno == GSL_ERANGE) return; // handle zero or infinity in our test code.
29 #ifdef DISTRIBUTIONS_TEST
32 throw std::domain_error(reason);
36 struct gsl_error_handler_setter
38 gsl_error_handler_t * old_handler;
39 gsl_error_handler_setter()
41 old_handler = gsl_set_error_handler(gsl_handler);
43 ~gsl_error_handler_setter()
45 gsl_set_error_handler(old_handler);
49 static const gsl_error_handler_setter handler;
54 // Rmath overloads ftrunc, leading to strange errors from GCC unless we include this:
55 #include <boost/math/special_functions.hpp>
56 #define MATHLIB_STANDALONE
62 extern void cdfbet(int*, double*, double*, double*, double*, double*, double*, int*, double*);
63 extern void cdfbin(int*, double*, double*, double*, double*, double*, double*, int*, double*);
64 extern void cdfchi(int*, double*, double*, double*, double*, int*, double*);
65 extern void cdfchn(int*, double*, double*, double*, double*, double*, int*, double*);
66 extern void cdff(int*, double*, double*, double*, double*, double*, int*, double*);
67 extern void cdffnc(int*, double*, double*, double*, double*, double*, double*, int*s, double*);
68 extern void cdfgam(int*, double*, double*, double*, double*, double*, int*, double*);
69 extern void cdfnbn(int*, double*, double*, double*, double*, double*, double*, int*, double*);
70 extern void cdfnor(int*, double*, double*, double*, double*, double*, int*, double*);
71 extern void cdfpoi(int*, double*, double*, double*, double*, int*, double*);
72 extern void cdft(int*, double*, double*, double*, double*, int*, double*);
73 //extern void cdftnc(int*, double*, double*, double*, double*, double*, int*, double*);
76 inline double dcdflib_beta_cdf(double x, double a, double b)
80 double p, q, bound, y(1-x);
81 cdfbet(&what, &p, &q, &x, &y, &a, &b, &status, &bound);
85 inline double dcdflib_beta_quantile(double p, double a, double b)
89 double x, y, bound, q(1 - p);
90 cdfbet(&what, &p, &q, &x, &y, &a, &b, &status, &bound);
94 inline double dcdflib_binomial_cdf(double x, double s, double sf)
98 double p, q, bound, sfc(1-sf);
99 cdfbin(&what, &p, &q, &x, &s, &sf, &sfc, &status, &bound);
103 inline double dcdflib_binomial_quantile(double p, double s, double sf)
107 double x, bound, q(1 - p), sfc(1-sf);
108 cdfbin(&what, &p, &q, &x, &s, &sf, &sfc, &status, &bound);
112 inline double dcdflib_chi_cdf(double x, double df)
117 cdfchi(&what, &p, &q, &x, &df, &status, &bound);
121 inline double dcdflib_chi_quantile(double p, double df)
125 double x, bound, q(1 - p);
126 cdfchi(&what, &p, &q, &x, &df, &status, &bound);
130 inline double dcdflib_chi_n_cdf(double x, double df, double nc)
135 cdfchn(&what, &p, &q, &x, &df, &nc, &status, &bound);
139 inline double dcdflib_chi_n_quantile(double p, double df, double nc)
143 double x, bound, q(1 - p);
144 cdfchn(&what, &p, &q, &x, &df, &nc, &status, &bound);
148 inline double dcdflib_f_cdf(double x, double df1, double df2)
153 cdff(&what, &p, &q, &x, &df1, &df2, &status, &bound);
157 inline double dcdflib_f_quantile(double p, double df1, double df2)
161 double x, bound, q(1 - p);
162 cdff(&what, &p, &q, &x, &df1, &df2, &status, &bound);
166 inline double dcdflib_f_n_cdf(double x, double df1, double df2, double nc)
171 cdffnc(&what, &p, &q, &x, &df1, &df2, &nc, &status, &bound);
175 inline double dcdflib_f_n_quantile(double p, double df1, double df2, double nc)
179 double x, bound, q(1 - p);
180 cdffnc(&what, &p, &q, &x, &df1, &df2, &nc, &status, &bound);
184 inline double dcdflib_gamma_cdf(double x, double shape, double scale)
190 cdfgam(&what, &p, &q, &x, &shape, &scale, &status, &bound);
194 inline double dcdflib_gamma_quantile(double p, double shape, double scale)
198 double x, bound, q(1 - p);
200 cdfgam(&what, &p, &q, &x, &shape, &scale, &status, &bound);
204 inline double dcdflib_nbin_cdf(double x, double r, double sf)
208 double p, q, bound, sfc(1 - sf);
209 cdfnbn(&what, &p, &q, &x, &r, &sf, &sfc, &status, &bound);
213 inline double dcdflib_nbin_quantile(double p, double r, double sf)
217 double x, bound, q(1 - p), sfc(1 - sf);
218 cdfnbn(&what, &p, &q, &x, &r, &sf, &sfc, &status, &bound);
222 inline double dcdflib_norm_cdf(double x, double mean, double sd)
227 cdfnor(&what, &p, &q, &x, &mean, &sd, &status, &bound);
231 inline double dcdflib_norm_quantile(double p, double mean, double sd)
235 double x, bound, q(1 - p);
236 cdfnor(&what, &p, &q, &x, &mean, &sd, &status, &bound);
240 inline double dcdflib_poisson_cdf(double x, double param)
245 cdfpoi(&what, &p, &q, &x, ¶m, &status, &bound);
249 inline double dcdflib_poisson_quantile(double p, double param)
253 double x, bound, q(1 - p);
254 cdfpoi(&what, &p, &q, &x, ¶m, &status, &bound);
258 inline double dcdflib_t_cdf(double x, double param)
263 cdft(&what, &p, &q, &x, ¶m, &status, &bound);
267 inline double dcdflib_t_quantile(double p, double param)
271 double x, bound, q(1 - p);
272 cdft(&what, &p, &q, &x, ¶m, &status, &bound);
276 inline double dcdflib_t_n_cdf(double x, double param, double nc)
281 cdftnc(&what, &p, &q, &x, ¶m, &nc, &status, &bound);
285 inline double dcdflib_t_n_quantile(double p, double param, double nc)
289 double x, bound, q(1 - p);
290 cdftnc(&what, &p, &q, &x, ¶m, &nc, &status, &bound);
296 extern std::vector<std::vector<double> > data;
298 void report_execution_time(double t, std::string table, std::string row, std::string heading);
299 std::string get_compiler_options_name();
301 inline std::string boost_name()
303 return "boost " + boost::lexical_cast<std::string>(BOOST_VERSION / 100000) + "." + boost::lexical_cast<std::string>((BOOST_VERSION / 100) % 1000);
306 inline std::string compiler_name()
309 return COMPILER_NAME;
311 return BOOST_COMPILER;
315 inline std::string platform_name()
318 return "Windows x64";
320 return BOOST_PLATFORM;
324 #endif // TABLE_HELPER_HPP