2
2
3
3
// Copyright John Maddock 2006.
4
4
// Copyright Paul A. Bristow 2007.
5
+ // Copyright Matt Borland 2024.
5
6
6
7
// Use, modification and distribution are subject to the
7
8
// Boost Software License, Version 1.0.
@@ -43,7 +44,7 @@ namespace boost
43
44
{
44
45
// Common error checking routines for bernoulli distribution functions:
45
46
template <class RealType , class Policy >
46
- inline bool check_success_fraction (const char * function, const RealType& p, RealType* result, const Policy& /* pol */ )
47
+ BOOST_MATH_GPU_ENABLED inline bool check_success_fraction (const char * function, const RealType& p, RealType* result, const Policy& /* pol */ )
47
48
{
48
49
if (!(boost::math::isfinite)(p) || (p < 0 ) || (p > 1 ))
49
50
{
@@ -55,23 +56,23 @@ namespace boost
55
56
return true ;
56
57
}
57
58
template <class RealType , class Policy >
58
- inline bool check_dist (const char * function, const RealType& p, RealType* result, const Policy& /* pol */ , const std::true_type&)
59
+ BOOST_MATH_GPU_ENABLED inline bool check_dist (const char * function, const RealType& p, RealType* result, const Policy& /* pol */ , const std::true_type&)
59
60
{
60
61
return check_success_fraction (function, p, result, Policy ());
61
62
}
62
63
template <class RealType , class Policy >
63
- inline bool check_dist (const char * , const RealType& , RealType* , const Policy& /* pol */ , const std::false_type&)
64
+ BOOST_MATH_GPU_ENABLED inline bool check_dist (const char * , const RealType& , RealType* , const Policy& /* pol */ , const std::false_type&)
64
65
{
65
66
return true ;
66
67
}
67
68
template <class RealType , class Policy >
68
- inline bool check_dist (const char * function, const RealType& p, RealType* result, const Policy& /* pol */ )
69
+ BOOST_MATH_GPU_ENABLED inline bool check_dist (const char * function, const RealType& p, RealType* result, const Policy& /* pol */ )
69
70
{
70
71
return check_dist (function, p, result, Policy (), typename policies::constructor_error_check<Policy>::type ());
71
72
}
72
73
73
74
template <class RealType , class Policy >
74
- inline bool check_dist_and_k (const char * function, const RealType& p, RealType k, RealType* result, const Policy& pol)
75
+ BOOST_MATH_GPU_ENABLED inline bool check_dist_and_k (const char * function, const RealType& p, RealType k, RealType* result, const Policy& pol)
75
76
{
76
77
if (check_dist (function, p, result, Policy (), typename policies::method_error_check<Policy>::type ()) == false )
77
78
{
@@ -87,7 +88,7 @@ namespace boost
87
88
return true ;
88
89
}
89
90
template <class RealType , class Policy >
90
- inline bool check_dist_and_prob (const char * function, RealType p, RealType prob, RealType* result, const Policy& /* pol */ )
91
+ BOOST_MATH_GPU_ENABLED inline bool check_dist_and_prob (const char * function, RealType p, RealType prob, RealType* result, const Policy& /* pol */ )
91
92
{
92
93
if ((check_dist (function, p, result, Policy (), typename policies::method_error_check<Policy>::type ()) && detail::check_probability (function, prob, result, Policy ())) == false )
93
94
{
@@ -105,7 +106,7 @@ namespace boost
105
106
typedef RealType value_type;
106
107
typedef Policy policy_type;
107
108
108
- bernoulli_distribution (RealType p = 0.5 ) : m_p(p)
109
+ BOOST_MATH_GPU_ENABLED bernoulli_distribution (RealType p = 0.5 ) : m_p(p)
109
110
{ // Default probability = half suits 'fair' coin tossing
110
111
// where probability of heads == probability of tails.
111
112
RealType result; // of checks.
@@ -115,7 +116,7 @@ namespace boost
115
116
&result, Policy ());
116
117
} // bernoulli_distribution constructor.
117
118
118
- RealType success_fraction () const
119
+ BOOST_MATH_GPU_ENABLED RealType success_fraction () const
119
120
{ // Probability.
120
121
return m_p;
121
122
}
@@ -132,21 +133,21 @@ namespace boost
132
133
#endif
133
134
134
135
template <class RealType , class Policy >
135
- inline const std::pair<RealType, RealType> range (const bernoulli_distribution<RealType, Policy>& /* dist */ )
136
+ BOOST_MATH_GPU_ENABLED inline const std::pair<RealType, RealType> range (const bernoulli_distribution<RealType, Policy>& /* dist */ )
136
137
{ // Range of permissible values for random variable k = {0, 1}.
137
138
using boost::math::tools::max_value;
138
139
return std::pair<RealType, RealType>(static_cast <RealType>(0 ), static_cast <RealType>(1 ));
139
140
}
140
141
141
142
template <class RealType , class Policy >
142
- inline const std::pair<RealType, RealType> support (const bernoulli_distribution<RealType, Policy>& /* dist */ )
143
+ BOOST_MATH_GPU_ENABLED inline const std::pair<RealType, RealType> support (const bernoulli_distribution<RealType, Policy>& /* dist */ )
143
144
{ // Range of supported values for random variable k = {0, 1}.
144
145
// This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
145
146
return std::pair<RealType, RealType>(static_cast <RealType>(0 ), static_cast <RealType>(1 ));
146
147
}
147
148
148
149
template <class RealType , class Policy >
149
- inline RealType mean (const bernoulli_distribution<RealType, Policy>& dist)
150
+ BOOST_MATH_GPU_ENABLED inline RealType mean (const bernoulli_distribution<RealType, Policy>& dist)
150
151
{ // Mean of bernoulli distribution = p (n = 1).
151
152
return dist.success_fraction ();
152
153
} // mean
@@ -159,13 +160,13 @@ namespace boost
159
160
// } // median
160
161
161
162
template <class RealType , class Policy >
162
- inline RealType variance (const bernoulli_distribution<RealType, Policy>& dist)
163
+ BOOST_MATH_GPU_ENABLED inline RealType variance (const bernoulli_distribution<RealType, Policy>& dist)
163
164
{ // Variance of bernoulli distribution =p * q.
164
165
return dist.success_fraction () * (1 - dist.success_fraction ());
165
166
} // variance
166
167
167
168
template <class RealType , class Policy >
168
- RealType pdf (const bernoulli_distribution<RealType, Policy>& dist, const RealType& k)
169
+ BOOST_MATH_GPU_ENABLED RealType pdf (const bernoulli_distribution<RealType, Policy>& dist, const RealType& k)
169
170
{ // Probability Density/Mass Function.
170
171
BOOST_FPU_EXCEPTION_GUARD
171
172
// Error check:
@@ -190,7 +191,7 @@ namespace boost
190
191
} // pdf
191
192
192
193
template <class RealType , class Policy >
193
- inline RealType cdf (const bernoulli_distribution<RealType, Policy>& dist, const RealType& k)
194
+ BOOST_MATH_GPU_ENABLED inline RealType cdf (const bernoulli_distribution<RealType, Policy>& dist, const RealType& k)
194
195
{ // Cumulative Distribution Function Bernoulli.
195
196
RealType p = dist.success_fraction ();
196
197
// Error check:
@@ -214,7 +215,7 @@ namespace boost
214
215
} // bernoulli cdf
215
216
216
217
template <class RealType , class Policy >
217
- inline RealType cdf (const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
218
+ BOOST_MATH_GPU_ENABLED inline RealType cdf (const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
218
219
{ // Complemented Cumulative Distribution Function bernoulli.
219
220
RealType const & k = c.param ;
220
221
bernoulli_distribution<RealType, Policy> const & dist = c.dist ;
@@ -240,7 +241,7 @@ namespace boost
240
241
} // bernoulli cdf complement
241
242
242
243
template <class RealType , class Policy >
243
- inline RealType quantile (const bernoulli_distribution<RealType, Policy>& dist, const RealType& p)
244
+ BOOST_MATH_GPU_ENABLED inline RealType quantile (const bernoulli_distribution<RealType, Policy>& dist, const RealType& p)
244
245
{ // Quantile or Percent Point Bernoulli function.
245
246
// Return the number of expected successes k either 0 or 1.
246
247
// for a given probability p.
@@ -265,7 +266,7 @@ namespace boost
265
266
} // quantile
266
267
267
268
template <class RealType , class Policy >
268
- inline RealType quantile (const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
269
+ BOOST_MATH_GPU_ENABLED inline RealType quantile (const complemented2_type<bernoulli_distribution<RealType, Policy>, RealType>& c)
269
270
{ // Quantile or Percent Point bernoulli function.
270
271
// Return the number of expected successes k for a given
271
272
// complement of the probability q.
@@ -294,21 +295,21 @@ namespace boost
294
295
} // quantile complemented.
295
296
296
297
template <class RealType , class Policy >
297
- inline RealType mode (const bernoulli_distribution<RealType, Policy>& dist)
298
+ BOOST_MATH_GPU_ENABLED inline RealType mode (const bernoulli_distribution<RealType, Policy>& dist)
298
299
{
299
300
return static_cast <RealType>((dist.success_fraction () <= 0.5 ) ? 0 : 1 ); // p = 0.5 can be 0 or 1
300
301
}
301
302
302
303
template <class RealType , class Policy >
303
- inline RealType skewness (const bernoulli_distribution<RealType, Policy>& dist)
304
+ BOOST_MATH_GPU_ENABLED inline RealType skewness (const bernoulli_distribution<RealType, Policy>& dist)
304
305
{
305
306
BOOST_MATH_STD_USING; // Aid ADL for sqrt.
306
307
RealType p = dist.success_fraction ();
307
308
return (1 - 2 * p) / sqrt (p * (1 - p));
308
309
}
309
310
310
311
template <class RealType , class Policy >
311
- inline RealType kurtosis_excess (const bernoulli_distribution<RealType, Policy>& dist)
312
+ BOOST_MATH_GPU_ENABLED inline RealType kurtosis_excess (const bernoulli_distribution<RealType, Policy>& dist)
312
313
{
313
314
RealType p = dist.success_fraction ();
314
315
// Note Wolfram says this is kurtosis in text, but gamma2 is the kurtosis excess,
@@ -319,7 +320,7 @@ namespace boost
319
320
}
320
321
321
322
template <class RealType , class Policy >
322
- inline RealType kurtosis (const bernoulli_distribution<RealType, Policy>& dist)
323
+ BOOST_MATH_GPU_ENABLED inline RealType kurtosis (const bernoulli_distribution<RealType, Policy>& dist)
323
324
{
324
325
RealType p = dist.success_fraction ();
325
326
return 1 / (1 - p) + 1 /p -6 + 3 ;
0 commit comments