]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/math/test/test_owens_t.cpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / libs / math / test / test_owens_t.cpp
CommitLineData
7c673cae
FG
1// test_owens_t.cpp
2
3// Copyright Paul A. Bristow 2012.
4// Copyright Benjamin Sobotta 2012.
5
6// Use, modification and distribution are subject to the
7// Boost Software License, Version 1.0.
8// (See accompanying file LICENSE_1_0.txt
9// or copy at http://www.boost.org/LICENSE_1_0.txt)
10
11// Tested using some 30 decimal digit accuracy values from:
12// Fast and accurate calculation of Owen's T-function
13// Mike Patefield, and David Tandy
14// Journal of Statistical Software, 5 (5), 1-25 (2000).
15// http://www.jstatsoft.org/v05/a05/paper Table 3, page 15
16// Values of T(h,a) accurate to thirty figures were calculated using 128 bit arithmetic by
17// evaluating (9) with m = 48, the summation over k being continued until additional terms did
18// not alter the result. The resultant values Tacc(h,a) say, were validated by evaluating (8) with
19// m = 48 (i.e. 96 point Gaussian quadrature).
20
21#define BOOST_MATH_OVERFLOW_ERROR_POLICY ignore_error
22
23#ifdef _MSC_VER
24# pragma warning (disable : 4127) // conditional expression is constant
25# pragma warning (disable : 4305) // 'initializing' : truncation from 'double' to 'const float'
26// ?? TODO get rid of these warnings?
27#endif
28
29#include <boost/math/concepts/real_concept.hpp> // for real_concept.
30using ::boost::math::concepts::real_concept;
31
32#include <boost/math/special_functions/owens_t.hpp> // for owens_t function.
33using boost::math::owens_t;
34#include <boost/math/distributions/normal.hpp>
35
36#define BOOST_TEST_MAIN
37#include <boost/test/unit_test.hpp>
92f5a8d4 38#include <boost/test/tools/floating_point_comparison.hpp>
7c673cae
FG
39#include <boost/array.hpp>
40
41#include "libs/math/test/handle_test_result.hpp"
42#include "libs/math/test/table_type.hpp"
43#include "libs/math/test/functor.hpp"
44#include "test_owens_t.hpp"
45
46//
47// Defining TEST_CPP_DEC_FLOAT enables testing of multiprecision support.
48// This requires the multiprecision library from sandbox/big_number.
49// Note that these tests *do not pass*, but they do give an idea of the
50// error rates that can be expected....
51//
52#ifdef TEST_CPP_DEC_FLOAT
53#include <boost/multiprecision/cpp_dec_float.hpp>
54
55template <class R>
56inline R convert_to(const char* s)
57{
58 try{
59 return boost::lexical_cast<R>(s);
60 }
61 catch(const boost::bad_lexical_cast&)
62 {
63 return 0;
64 }
65}
f67539c2 66#undef SC_
7c673cae
FG
67#define SC_(x) convert_to<T>(BOOST_STRINGIZE(x))
68#endif
69
70#include "owens_t_T7.hpp"
71
72#include <iostream>
73using std::cout;
74using std::endl;
75#include <limits>
76using std::numeric_limits;
77
78void expected_results()
79{
80 //
81 // Define the max and mean errors expected for
82 // various compilers and platforms.
83 //
84 const char* largest_type;
85#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
86 if(boost::math::policies::digits<double, boost::math::policies::policy<> >() == boost::math::policies::digits<long double, boost::math::policies::policy<> >())
87 {
88 largest_type = "(long\\s+)?double|real_concept";
89 }
90 else
91 {
92 largest_type = "long double|real_concept";
93 }
94#else
95 largest_type = "(long\\s+)?double";
96#endif
97
98 //
99 // Catch all cases come last:
100 //
101 if(std::numeric_limits<long double>::digits > 60)
102 {
103 add_expected_result(
104 ".*", // compiler
105 ".*", // stdlib
106 ".*", // platform
107 largest_type, // test type(s)
108 ".*", // test data group
109 "owens_t", 500, 100); // test function
110 }
111 else
112 {
113 add_expected_result(
114 ".*", // compiler
115 ".*", // stdlib
116 ".*", // platform
117 largest_type, // test type(s)
118 ".*", // test data group
119 "owens_t", 60, 5); // test function
120 }
121 //
122 // Finish off by printing out the compiler/stdlib/platform names,
123 // we do this to make it easier to mark up expected error rates.
124 //
125 std::cout << "Tests run with " << BOOST_COMPILER << ", "
126 << BOOST_STDLIB << ", " << BOOST_PLATFORM << std::endl;
127}
128
129BOOST_AUTO_TEST_CASE( test_main )
130{
131 BOOST_MATH_CONTROL_FP;
132
133 expected_results();
134
135 // Basic sanity-check spot values.
136
137 // (Parameter value, arbitrarily zero, only communicates the floating point type).
138 test_spots(0.0F); // Test float.
139 test_spots(0.0); // Test double.
140#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
141 test_spots(0.0L); // Test long double.
20effc67 142#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
7c673cae
FG
143 test_spots(boost::math::concepts::real_concept(0.)); // Test real concept.
144#endif
145#endif
146
147 check_against_T7(0.0F); // Test float.
148 check_against_T7(0.0); // Test double.
149#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
150 check_against_T7(0.0L); // Test long double.
20effc67 151#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
7c673cae
FG
152 check_against_T7(boost::math::concepts::real_concept(0.)); // Test real concept.
153#endif
154#endif
155
156 test_owens_t(0.0F, "float"); // Test float.
157 test_owens_t(0.0, "double"); // Test double.
158#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
159 test_owens_t(0.0L, "long double"); // Test long double.
20effc67 160#if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x582))
7c673cae
FG
161 test_owens_t(boost::math::concepts::real_concept(0.), "real_concept"); // Test real concept.
162#endif
163#endif
164#ifdef TEST_CPP_DEC_FLOAT
f67539c2 165 typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<35> > cpp_dec_float_35;
7c673cae
FG
166 test_owens_t(cpp_dec_float_35(0), "cpp_dec_float_35"); // Test real concept.
167 test_owens_t(boost::multiprecision::cpp_dec_float_50(0), "cpp_dec_float_50"); // Test real concept.
168 test_owens_t(boost::multiprecision::cpp_dec_float_100(0), "cpp_dec_float_100"); // Test real concept.
169#endif
170
171} // BOOST_AUTO_TEST_CASE( test_main )
172
173/*
174
175Output:
176
177 Description: Autorun "J:\Cpp\MathToolkit\test\Math_test\Debug\test_owens_t.exe"
178 Running 1 test case...
179 Tests run with Microsoft Visual C++ version 10.0, Dinkumware standard library version 520, Win32
180 Tolerance = 3.57628e-006.
181 Tolerance = 6.66134e-015.
182 Tolerance = 6.66134e-015.
183 Tolerance = 6.66134e-015.
184 Tolerance = 1.78814e-005.
185 Tolerance = 3.33067e-014.
186 Tolerance = 3.33067e-014.
187 Tolerance = 3.33067e-014.
188 Testing Owens T (medium small values) with type float
189 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190 boost::math::owens_t<float> Max = 0 RMS Mean=0
191
192
193 Testing Owens T (large and diverse values) with type float
194 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195 boost::math::owens_t<float> Max = 0 RMS Mean=0
196
197
198 Testing Owens T (medium small values) with type double
199 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
200 boost::math::owens_t<double> Max = 4.375 RMS Mean=0.9728
201 worst case at row: 81
202 { 4.4206809997558594, 0.1269868016242981, 1.0900281236140834e-006 }
203
204
205 Testing Owens T (large and diverse values) with type double
206 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
207 boost::math::owens_t<double> Max = 3.781 RMS Mean=0.6206
208 worst case at row: 430
209 { 3.4516773223876953, 0.0010718167759478092, 4.413983645332431e-007 }
210
211
212 Testing Owens T (medium small values) with type long double
213 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214 boost::math::owens_t<long double> Max = 4.375 RMS Mean=0.9728
215 worst case at row: 81
216 { 4.4206809997558594, 0.1269868016242981, 1.0900281236140834e-006 }
217
218
219 Testing Owens T (large and diverse values) with type long double
220 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
221 boost::math::owens_t<long double> Max = 3.781 RMS Mean=0.6206
222 worst case at row: 430
223 { 3.4516773223876953, 0.0010718167759478092, 4.413983645332431e-007 }
224
225
226 Testing Owens T (medium small values) with type real_concept
227 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228 boost::math::owens_t<real_concept> Max = 4.375 RMS Mean=1.032
229 worst case at row: 81
230 { 4.4206809997558594, 0.1269868016242981, 1.0900281236140834e-006 }
231
232
233 Testing Owens T (large and diverse values) with type real_concept
234 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
235 boost::math::owens_t<real_concept> Max = 21.04 RMS Mean=1.102
236 worst case at row: 439
237 { 3.4516773223876953, 0.98384737968444824, 0.00013923002576038691 }
238
239
240
241 *** No errors detected
242
243
244*/
245
246
247