1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
// Copyright John Maddock 2015.
// 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)
#ifndef TABLE_HELPER_HPP
#define TABLE_HELPER_HPP
#include <vector>
#include <string>
#include <boost/version.hpp>
#include <boost/lexical_cast.hpp>
//
// Also include headers for whatever else we may be testing:
//
#ifdef TEST_LIBSTDCXX
#include <tr1/cmath>
#include <stdexcept>
#endif
#ifdef TEST_GSL
#include <gsl/gsl_sf.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_version.h>
void gsl_handler(const char * reason, const char * file, int line, int gsl_errno)
{
if(gsl_errno == GSL_ERANGE) return; // handle zero or infinity in our test code.
#ifdef DISTRIBUTIONS_TEST
return;
#else
throw std::domain_error(reason);
#endif
}
struct gsl_error_handler_setter
{
gsl_error_handler_t * old_handler;
gsl_error_handler_setter()
{
old_handler = gsl_set_error_handler(gsl_handler);
}
~gsl_error_handler_setter()
{
gsl_set_error_handler(old_handler);
}
};
static const gsl_error_handler_setter handler;
#endif
#ifdef TEST_RMATH
// Rmath overloads ftrunc, leading to strange errors from GCC unless we include this:
#include <boost/math/special_functions.hpp>
#define MATHLIB_STANDALONE
#include <Rmath.h>
#endif
#ifdef TEST_DCDFLIB
extern "C" {
extern void cdfbet(int*, double*, double*, double*, double*, double*, double*, int*, double*);
extern void cdfbin(int*, double*, double*, double*, double*, double*, double*, int*, double*);
extern void cdfchi(int*, double*, double*, double*, double*, int*, double*);
extern void cdfchn(int*, double*, double*, double*, double*, double*, int*, double*);
extern void cdff(int*, double*, double*, double*, double*, double*, int*, double*);
extern void cdffnc(int*, double*, double*, double*, double*, double*, double*, int*s, double*);
extern void cdfgam(int*, double*, double*, double*, double*, double*, int*, double*);
extern void cdfnbn(int*, double*, double*, double*, double*, double*, double*, int*, double*);
extern void cdfnor(int*, double*, double*, double*, double*, double*, int*, double*);
extern void cdfpoi(int*, double*, double*, double*, double*, int*, double*);
extern void cdft(int*, double*, double*, double*, double*, int*, double*);
//extern void cdftnc(int*, double*, double*, double*, double*, double*, int*, double*);
}
inline double dcdflib_beta_cdf(double x, double a, double b)
{
int what = 1;
int status = 0;
double p, q, bound, y(1-x);
cdfbet(&what, &p, &q, &x, &y, &a, &b, &status, &bound);
return p;
}
inline double dcdflib_beta_quantile(double p, double a, double b)
{
int what = 2;
int status = 0;
double x, y, bound, q(1 - p);
cdfbet(&what, &p, &q, &x, &y, &a, &b, &status, &bound);
return x;
}
inline double dcdflib_binomial_cdf(double x, double s, double sf)
{
int what = 1;
int status = 0;
double p, q, bound, sfc(1-sf);
cdfbin(&what, &p, &q, &x, &s, &sf, &sfc, &status, &bound);
return p;
}
inline double dcdflib_binomial_quantile(double p, double s, double sf)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p), sfc(1-sf);
cdfbin(&what, &p, &q, &x, &s, &sf, &sfc, &status, &bound);
return x;
}
inline double dcdflib_chi_cdf(double x, double df)
{
int what = 1;
int status = 0;
double p, q, bound;
cdfchi(&what, &p, &q, &x, &df, &status, &bound);
return p;
}
inline double dcdflib_chi_quantile(double p, double df)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p);
cdfchi(&what, &p, &q, &x, &df, &status, &bound);
return x;
}
inline double dcdflib_chi_n_cdf(double x, double df, double nc)
{
int what = 1;
int status = 0;
double p, q, bound;
cdfchn(&what, &p, &q, &x, &df, &nc, &status, &bound);
return p;
}
inline double dcdflib_chi_n_quantile(double p, double df, double nc)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p);
cdfchn(&what, &p, &q, &x, &df, &nc, &status, &bound);
return x;
}
inline double dcdflib_f_cdf(double x, double df1, double df2)
{
int what = 1;
int status = 0;
double p, q, bound;
cdff(&what, &p, &q, &x, &df1, &df2, &status, &bound);
return p;
}
inline double dcdflib_f_quantile(double p, double df1, double df2)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p);
cdff(&what, &p, &q, &x, &df1, &df2, &status, &bound);
return x;
}
inline double dcdflib_f_n_cdf(double x, double df1, double df2, double nc)
{
int what = 1;
int status = 0;
double p, q, bound;
cdffnc(&what, &p, &q, &x, &df1, &df2, &nc, &status, &bound);
return p;
}
inline double dcdflib_f_n_quantile(double p, double df1, double df2, double nc)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p);
cdffnc(&what, &p, &q, &x, &df1, &df2, &nc, &status, &bound);
return x;
}
inline double dcdflib_gamma_cdf(double x, double shape, double scale)
{
int what = 1;
int status = 0;
double p, q, bound;
scale = 1 / scale;
cdfgam(&what, &p, &q, &x, &shape, &scale, &status, &bound);
return p;
}
inline double dcdflib_gamma_quantile(double p, double shape, double scale)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p);
scale = 1 / scale;
cdfgam(&what, &p, &q, &x, &shape, &scale, &status, &bound);
return x;
}
inline double dcdflib_nbin_cdf(double x, double r, double sf)
{
int what = 1;
int status = 0;
double p, q, bound, sfc(1 - sf);
cdfnbn(&what, &p, &q, &x, &r, &sf, &sfc, &status, &bound);
return p;
}
inline double dcdflib_nbin_quantile(double p, double r, double sf)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p), sfc(1 - sf);
cdfnbn(&what, &p, &q, &x, &r, &sf, &sfc, &status, &bound);
return x;
}
inline double dcdflib_norm_cdf(double x, double mean, double sd)
{
int what = 1;
int status = 0;
double p, q, bound;
cdfnor(&what, &p, &q, &x, &mean, &sd, &status, &bound);
return p;
}
inline double dcdflib_norm_quantile(double p, double mean, double sd)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p);
cdfnor(&what, &p, &q, &x, &mean, &sd, &status, &bound);
return x;
}
inline double dcdflib_poisson_cdf(double x, double param)
{
int what = 1;
int status = 0;
double p, q, bound;
cdfpoi(&what, &p, &q, &x, ¶m, &status, &bound);
return p;
}
inline double dcdflib_poisson_quantile(double p, double param)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p);
cdfpoi(&what, &p, &q, &x, ¶m, &status, &bound);
return x;
}
inline double dcdflib_t_cdf(double x, double param)
{
int what = 1;
int status = 0;
double p, q, bound;
cdft(&what, &p, &q, &x, ¶m, &status, &bound);
return p;
}
inline double dcdflib_t_quantile(double p, double param)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p);
cdft(&what, &p, &q, &x, ¶m, &status, &bound);
return x;
}
/*
inline double dcdflib_t_n_cdf(double x, double param, double nc)
{
int what = 1;
int status = 0;
double p, q, bound;
cdftnc(&what, &p, &q, &x, ¶m, &nc, &status, &bound);
return p;
}
inline double dcdflib_t_n_quantile(double p, double param, double nc)
{
int what = 2;
int status = 0;
double x, bound, q(1 - p);
cdftnc(&what, &p, &q, &x, ¶m, &nc, &status, &bound);
return x;
}
*/
#endif
extern std::vector<std::vector<double> > data;
void report_execution_time(double t, std::string table, std::string row, std::string heading);
std::string get_compiler_options_name();
inline std::string boost_name()
{
return "boost " + boost::lexical_cast<std::string>(BOOST_VERSION / 100000) + "." + boost::lexical_cast<std::string>((BOOST_VERSION / 100) % 1000);
}
inline std::string compiler_name()
{
#ifdef COMPILER_NAME
return COMPILER_NAME;
#else
return BOOST_COMPILER;
#endif
}
inline std::string platform_name()
{
#ifdef _WIN32
return "Windows x64";
#else
return BOOST_PLATFORM;
#endif
}
#endif // TABLE_HELPER_HPP
|