25
25
#ifndef BOOST_MATH_DIST_BETA_HPP
26
26
#define BOOST_MATH_DIST_BETA_HPP
27
27
28
+ #include < boost/math/tools/config.hpp>
29
+ #include < boost/math/tools/tuple.hpp>
28
30
#include < boost/math/distributions/fwd.hpp>
29
31
#include < boost/math/special_functions/beta.hpp> // for beta.
30
32
#include < boost/math/distributions/complement.hpp> // complements.
31
33
#include < boost/math/distributions/detail/common_error_handling.hpp> // error checks
32
34
#include < boost/math/special_functions/fpclassify.hpp> // isnan.
33
35
#include < boost/math/tools/roots.hpp> // for root finding.
36
+ #include < boost/math/policies/error_handling.hpp>
34
37
35
38
#if defined (BOOST_MSVC)
36
39
# pragma warning(push)
37
40
# pragma warning(disable: 4702) // unreachable code
38
41
// in domain_error_imp in error_handling
39
42
#endif
40
43
41
- #include < utility>
42
-
43
44
namespace boost
44
45
{
45
46
namespace math
@@ -48,7 +49,7 @@ namespace boost
48
49
{
49
50
// Common error checking routines for beta distribution functions:
50
51
template <class RealType , class Policy >
51
- inline bool check_alpha (const char * function, const RealType& alpha, RealType* result, const Policy& pol)
52
+ BOOST_MATH_GPU_ENABLED inline bool check_alpha (const char * function, const RealType& alpha, RealType* result, const Policy& pol)
52
53
{
53
54
if (!(boost::math::isfinite)(alpha) || (alpha <= 0 ))
54
55
{
@@ -61,7 +62,7 @@ namespace boost
61
62
} // bool check_alpha
62
63
63
64
template <class RealType , class Policy >
64
- inline bool check_beta (const char * function, const RealType& beta, RealType* result, const Policy& pol)
65
+ BOOST_MATH_GPU_ENABLED inline bool check_beta (const char * function, const RealType& beta, RealType* result, const Policy& pol)
65
66
{
66
67
if (!(boost::math::isfinite)(beta) || (beta <= 0 ))
67
68
{
@@ -74,7 +75,7 @@ namespace boost
74
75
} // bool check_beta
75
76
76
77
template <class RealType , class Policy >
77
- inline bool check_prob (const char * function, const RealType& p, RealType* result, const Policy& pol)
78
+ BOOST_MATH_GPU_ENABLED inline bool check_prob (const char * function, const RealType& p, RealType* result, const Policy& pol)
78
79
{
79
80
if ((p < 0 ) || (p > 1 ) || !(boost::math::isfinite)(p))
80
81
{
@@ -87,7 +88,7 @@ namespace boost
87
88
} // bool check_prob
88
89
89
90
template <class RealType , class Policy >
90
- inline bool check_x (const char * function, const RealType& x, RealType* result, const Policy& pol)
91
+ BOOST_MATH_GPU_ENABLED inline bool check_x (const char * function, const RealType& x, RealType* result, const Policy& pol)
91
92
{
92
93
if (!(boost::math::isfinite)(x) || (x < 0 ) || (x > 1 ))
93
94
{
@@ -100,28 +101,28 @@ namespace boost
100
101
} // bool check_x
101
102
102
103
template <class RealType , class Policy >
103
- inline bool check_dist (const char * function, const RealType& alpha, const RealType& beta, RealType* result, const Policy& pol)
104
+ BOOST_MATH_GPU_ENABLED inline bool check_dist (const char * function, const RealType& alpha, const RealType& beta, RealType* result, const Policy& pol)
104
105
{ // Check both alpha and beta.
105
106
return check_alpha (function, alpha, result, pol)
106
107
&& check_beta (function, beta, result, pol);
107
108
} // bool check_dist
108
109
109
110
template <class RealType , class Policy >
110
- inline bool check_dist_and_x (const char * function, const RealType& alpha, const RealType& beta, RealType x, RealType* result, const Policy& pol)
111
+ BOOST_MATH_GPU_ENABLED inline bool check_dist_and_x (const char * function, const RealType& alpha, const RealType& beta, RealType x, RealType* result, const Policy& pol)
111
112
{
112
113
return check_dist (function, alpha, beta, result, pol)
113
114
&& beta_detail::check_x (function, x, result, pol);
114
115
} // bool check_dist_and_x
115
116
116
117
template <class RealType , class Policy >
117
- inline bool check_dist_and_prob (const char * function, const RealType& alpha, const RealType& beta, RealType p, RealType* result, const Policy& pol)
118
+ BOOST_MATH_GPU_ENABLED inline bool check_dist_and_prob (const char * function, const RealType& alpha, const RealType& beta, RealType p, RealType* result, const Policy& pol)
118
119
{
119
120
return check_dist (function, alpha, beta, result, pol)
120
121
&& check_prob (function, p, result, pol);
121
122
} // bool check_dist_and_prob
122
123
123
124
template <class RealType , class Policy >
124
- inline bool check_mean (const char * function, const RealType& mean, RealType* result, const Policy& pol)
125
+ BOOST_MATH_GPU_ENABLED inline bool check_mean (const char * function, const RealType& mean, RealType* result, const Policy& pol)
125
126
{
126
127
if (!(boost::math::isfinite)(mean) || (mean <= 0 ))
127
128
{
@@ -133,7 +134,7 @@ namespace boost
133
134
return true ;
134
135
} // bool check_mean
135
136
template <class RealType , class Policy >
136
- inline bool check_variance (const char * function, const RealType& variance, RealType* result, const Policy& pol)
137
+ BOOST_MATH_GPU_ENABLED inline bool check_variance (const char * function, const RealType& variance, RealType* result, const Policy& pol)
137
138
{
138
139
if (!(boost::math::isfinite)(variance) || (variance <= 0 ))
139
140
{
@@ -157,7 +158,7 @@ namespace boost
157
158
typedef RealType value_type;
158
159
typedef Policy policy_type;
159
160
160
- beta_distribution (RealType l_alpha = 1 , RealType l_beta = 1 ) : m_alpha(l_alpha), m_beta(l_beta)
161
+ BOOST_MATH_GPU_ENABLED beta_distribution (RealType l_alpha = 1 , RealType l_beta = 1 ) : m_alpha(l_alpha), m_beta(l_beta)
161
162
{
162
163
RealType result;
163
164
beta_detail::check_dist (
@@ -167,11 +168,11 @@ namespace boost
167
168
&result, Policy ());
168
169
} // beta_distribution constructor.
169
170
// Accessor functions:
170
- RealType alpha () const
171
+ BOOST_MATH_GPU_ENABLED RealType alpha () const
171
172
{
172
173
return m_alpha;
173
174
}
174
- RealType beta () const
175
+ BOOST_MATH_GPU_ENABLED RealType beta () const
175
176
{ // .
176
177
return m_beta;
177
178
}
@@ -183,11 +184,11 @@ namespace boost
183
184
// http://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm
184
185
// http://www.epi.ucdavis.edu/diagnostictests/betabuster.html
185
186
186
- static RealType find_alpha (
187
+ BOOST_MATH_GPU_ENABLED static RealType find_alpha (
187
188
RealType mean, // Expected value of mean.
188
189
RealType variance) // Expected value of variance.
189
190
{
190
- static const char * function = " boost::math::beta_distribution<%1%>::find_alpha" ;
191
+ constexpr auto function = " boost::math::beta_distribution<%1%>::find_alpha" ;
191
192
RealType result = 0 ; // of error checks.
192
193
if (false ==
193
194
(
@@ -201,11 +202,11 @@ namespace boost
201
202
return mean * (( (mean * (1 - mean)) / variance)- 1 );
202
203
} // RealType find_alpha
203
204
204
- static RealType find_beta (
205
+ BOOST_MATH_GPU_ENABLED static RealType find_beta (
205
206
RealType mean, // Expected value of mean.
206
207
RealType variance) // Expected value of variance.
207
208
{
208
- static const char * function = " boost::math::beta_distribution<%1%>::find_beta" ;
209
+ constexpr auto function = " boost::math::beta_distribution<%1%>::find_beta" ;
209
210
RealType result = 0 ; // of error checks.
210
211
if (false ==
211
212
(
@@ -223,12 +224,12 @@ namespace boost
223
224
// Estimate alpha & beta from either alpha or beta, and x and probability.
224
225
// Uses for these parameter estimators are unclear.
225
226
226
- static RealType find_alpha (
227
+ BOOST_MATH_GPU_ENABLED static RealType find_alpha (
227
228
RealType beta, // from beta.
228
229
RealType x, // x.
229
230
RealType probability) // cdf
230
231
{
231
- static const char * function = " boost::math::beta_distribution<%1%>::find_alpha" ;
232
+ constexpr auto function = " boost::math::beta_distribution<%1%>::find_alpha" ;
232
233
RealType result = 0 ; // of error checks.
233
234
if (false ==
234
235
(
@@ -245,13 +246,13 @@ namespace boost
245
246
return static_cast <RealType>(ibeta_inva (beta, x, probability, Policy ()));
246
247
} // RealType find_alpha(beta, a, probability)
247
248
248
- static RealType find_beta (
249
+ BOOST_MATH_GPU_ENABLED static RealType find_beta (
249
250
// ibeta_invb(T b, T x, T p); (alpha, x, cdf,)
250
251
RealType alpha, // alpha.
251
252
RealType x, // probability x.
252
253
RealType probability) // probability cdf.
253
254
{
254
- static const char * function = " boost::math::beta_distribution<%1%>::find_beta" ;
255
+ constexpr auto function = " boost::math::beta_distribution<%1%>::find_beta" ;
255
256
RealType result = 0 ; // of error checks.
256
257
if (false ==
257
258
(
@@ -281,37 +282,37 @@ namespace boost
281
282
#endif
282
283
283
284
template <class RealType , class Policy >
284
- inline const std ::pair<RealType, RealType> range (const beta_distribution<RealType, Policy>& /* dist */ )
285
+ BOOST_MATH_GPU_ENABLED inline const boost::math ::pair<RealType, RealType> range (const beta_distribution<RealType, Policy>& /* dist */ )
285
286
{ // Range of permissible values for random variable x.
286
287
using boost::math::tools::max_value;
287
- return std ::pair<RealType, RealType>(static_cast <RealType>(0 ), static_cast <RealType>(1 ));
288
+ return boost::math ::pair<RealType, RealType>(static_cast <RealType>(0 ), static_cast <RealType>(1 ));
288
289
}
289
290
290
291
template <class RealType , class Policy >
291
- inline const std ::pair<RealType, RealType> support (const beta_distribution<RealType, Policy>& /* dist */ )
292
+ BOOST_MATH_GPU_ENABLED inline const boost::math ::pair<RealType, RealType> support (const beta_distribution<RealType, Policy>& /* dist */ )
292
293
{ // Range of supported values for random variable x.
293
294
// This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
294
- return std ::pair<RealType, RealType>(static_cast <RealType>(0 ), static_cast <RealType>(1 ));
295
+ return boost::math ::pair<RealType, RealType>(static_cast <RealType>(0 ), static_cast <RealType>(1 ));
295
296
}
296
297
297
298
template <class RealType , class Policy >
298
- inline RealType mean (const beta_distribution<RealType, Policy>& dist)
299
+ BOOST_MATH_GPU_ENABLED inline RealType mean (const beta_distribution<RealType, Policy>& dist)
299
300
{ // Mean of beta distribution = np.
300
301
return dist.alpha () / (dist.alpha () + dist.beta ());
301
302
} // mean
302
303
303
304
template <class RealType , class Policy >
304
- inline RealType variance (const beta_distribution<RealType, Policy>& dist)
305
+ BOOST_MATH_GPU_ENABLED inline RealType variance (const beta_distribution<RealType, Policy>& dist)
305
306
{ // Variance of beta distribution = np(1-p).
306
307
RealType a = dist.alpha ();
307
308
RealType b = dist.beta ();
308
309
return (a * b) / ((a + b ) * (a + b) * (a + b + 1 ));
309
310
} // variance
310
311
311
312
template <class RealType , class Policy >
312
- inline RealType mode (const beta_distribution<RealType, Policy>& dist)
313
+ BOOST_MATH_GPU_ENABLED inline RealType mode (const beta_distribution<RealType, Policy>& dist)
313
314
{
314
- static const char * function = " boost::math::mode(beta_distribution<%1%> const&)" ;
315
+ constexpr auto function = " boost::math::mode(beta_distribution<%1%> const&)" ;
315
316
316
317
RealType result;
317
318
if ((dist.alpha () <= 1 ))
@@ -343,7 +344,7 @@ namespace boost
343
344
// But WILL be provided by the derived accessor as quantile(0.5).
344
345
345
346
template <class RealType , class Policy >
346
- inline RealType skewness (const beta_distribution<RealType, Policy>& dist)
347
+ BOOST_MATH_GPU_ENABLED inline RealType skewness (const beta_distribution<RealType, Policy>& dist)
347
348
{
348
349
BOOST_MATH_STD_USING // ADL of std functions.
349
350
RealType a = dist.alpha ();
@@ -352,7 +353,7 @@ namespace boost
352
353
} // skewness
353
354
354
355
template <class RealType , class Policy >
355
- inline RealType kurtosis_excess (const beta_distribution<RealType, Policy>& dist)
356
+ BOOST_MATH_GPU_ENABLED inline RealType kurtosis_excess (const beta_distribution<RealType, Policy>& dist)
356
357
{
357
358
RealType a = dist.alpha ();
358
359
RealType b = dist.beta ();
@@ -363,17 +364,17 @@ namespace boost
363
364
} // kurtosis_excess
364
365
365
366
template <class RealType , class Policy >
366
- inline RealType kurtosis (const beta_distribution<RealType, Policy>& dist)
367
+ BOOST_MATH_GPU_ENABLED inline RealType kurtosis (const beta_distribution<RealType, Policy>& dist)
367
368
{
368
369
return 3 + kurtosis_excess (dist);
369
370
} // kurtosis
370
371
371
372
template <class RealType , class Policy >
372
- inline RealType pdf (const beta_distribution<RealType, Policy>& dist, const RealType& x)
373
+ BOOST_MATH_GPU_ENABLED inline RealType pdf (const beta_distribution<RealType, Policy>& dist, const RealType& x)
373
374
{ // Probability Density/Mass Function.
374
375
BOOST_FPU_EXCEPTION_GUARD
375
376
376
- static const char * function = " boost::math::pdf(beta_distribution<%1%> const&, %1%)" ;
377
+ constexpr auto function = " boost::math::pdf(beta_distribution<%1%> const&, %1%)" ;
377
378
378
379
BOOST_MATH_STD_USING // for ADL of std functions
379
380
@@ -428,11 +429,11 @@ namespace boost
428
429
} // pdf
429
430
430
431
template <class RealType , class Policy >
431
- inline RealType cdf (const beta_distribution<RealType, Policy>& dist, const RealType& x)
432
+ BOOST_MATH_GPU_ENABLED inline RealType cdf (const beta_distribution<RealType, Policy>& dist, const RealType& x)
432
433
{ // Cumulative Distribution Function beta.
433
434
BOOST_MATH_STD_USING // for ADL of std functions
434
435
435
- static const char * function = " boost::math::cdf(beta_distribution<%1%> const&, %1%)" ;
436
+ constexpr auto function = " boost::math::cdf(beta_distribution<%1%> const&, %1%)" ;
436
437
437
438
RealType a = dist.alpha ();
438
439
RealType b = dist.beta ();
@@ -459,12 +460,12 @@ namespace boost
459
460
} // beta cdf
460
461
461
462
template <class RealType , class Policy >
462
- inline RealType cdf (const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
463
+ BOOST_MATH_GPU_ENABLED inline RealType cdf (const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
463
464
{ // Complemented Cumulative Distribution Function beta.
464
465
465
466
BOOST_MATH_STD_USING // for ADL of std functions
466
467
467
- static const char * function = " boost::math::cdf(beta_distribution<%1%> const&, %1%)" ;
468
+ constexpr auto function = " boost::math::cdf(beta_distribution<%1%> const&, %1%)" ;
468
469
469
470
RealType const & x = c.param ;
470
471
beta_distribution<RealType, Policy> const & dist = c.dist ;
@@ -495,7 +496,7 @@ namespace boost
495
496
} // beta cdf
496
497
497
498
template <class RealType , class Policy >
498
- inline RealType quantile (const beta_distribution<RealType, Policy>& dist, const RealType& p)
499
+ BOOST_MATH_GPU_ENABLED inline RealType quantile (const beta_distribution<RealType, Policy>& dist, const RealType& p)
499
500
{ // Quantile or Percent Point beta function or
500
501
// Inverse Cumulative probability distribution function CDF.
501
502
// Return x (0 <= x <= 1),
@@ -505,7 +506,7 @@ namespace boost
505
506
// will be less than or equal to that value
506
507
// is whatever probability you supplied as an argument.
507
508
508
- static const char * function = " boost::math::quantile(beta_distribution<%1%> const&, %1%)" ;
509
+ constexpr auto function = " boost::math::quantile(beta_distribution<%1%> const&, %1%)" ;
509
510
510
511
RealType result = 0 ; // of argument checks:
511
512
RealType a = dist.alpha ();
@@ -530,12 +531,12 @@ namespace boost
530
531
} // quantile
531
532
532
533
template <class RealType , class Policy >
533
- inline RealType quantile (const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
534
+ BOOST_MATH_GPU_ENABLED inline RealType quantile (const complemented2_type<beta_distribution<RealType, Policy>, RealType>& c)
534
535
{ // Complement Quantile or Percent Point beta function .
535
536
// Return the number of expected x for a given
536
537
// complement of the probability q.
537
538
538
- static const char * function = " boost::math::quantile(beta_distribution<%1%> const&, %1%)" ;
539
+ constexpr auto function = " boost::math::quantile(beta_distribution<%1%> const&, %1%)" ;
539
540
540
541
//
541
542
// Error checks:
0 commit comments