Skip to content

Commit a2f5a20

Browse files
authored
Merge pull request #4 from cppalliance/CUDA_3_test
GPU batch 3
2 parents 9ba05bd + bdc7c25 commit a2f5a20

39 files changed

+2259
-228
lines changed

.github/workflows/cuda.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
- name: Build tests
7171
run: |
7272
cd ../boost-root/__build__
73-
cmake --build . --target tests
73+
cmake --build . --target tests -j $(nproc)
7474
- name: Run tests
7575
run: |
7676
cd ../boost-root/__build__
@@ -136,7 +136,7 @@ jobs:
136136
- name: Build tests
137137
run: |
138138
cd ../boost-root/__build__
139-
cmake --build . --target tests
139+
cmake --build . --target tests -j $(nproc)
140140
- name: Run tests
141141
run: |
142142
cd ../boost-root/__build__

include/boost/math/distributions/bernoulli.hpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Copyright John Maddock 2006.
44
// Copyright Paul A. Bristow 2007.
5+
// Copyright Matt Borland 2024.
56

67
// Use, modification and distribution are subject to the
78
// Boost Software License, Version 1.0.
@@ -43,7 +44,7 @@ namespace boost
4344
{
4445
// Common error checking routines for bernoulli distribution functions:
4546
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 */)
4748
{
4849
if(!(boost::math::isfinite)(p) || (p < 0) || (p > 1))
4950
{
@@ -55,23 +56,23 @@ namespace boost
5556
return true;
5657
}
5758
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&)
5960
{
6061
return check_success_fraction(function, p, result, Policy());
6162
}
6263
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&)
6465
{
6566
return true;
6667
}
6768
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 */)
6970
{
7071
return check_dist(function, p, result, Policy(), typename policies::constructor_error_check<Policy>::type());
7172
}
7273

7374
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)
7576
{
7677
if(check_dist(function, p, result, Policy(), typename policies::method_error_check<Policy>::type()) == false)
7778
{
@@ -87,7 +88,7 @@ namespace boost
8788
return true;
8889
}
8990
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 */)
9192
{
9293
if((check_dist(function, p, result, Policy(), typename policies::method_error_check<Policy>::type()) && detail::check_probability(function, prob, result, Policy())) == false)
9394
{
@@ -105,7 +106,7 @@ namespace boost
105106
typedef RealType value_type;
106107
typedef Policy policy_type;
107108

108-
bernoulli_distribution(RealType p = 0.5) : m_p(p)
109+
BOOST_MATH_GPU_ENABLED bernoulli_distribution(RealType p = 0.5) : m_p(p)
109110
{ // Default probability = half suits 'fair' coin tossing
110111
// where probability of heads == probability of tails.
111112
RealType result; // of checks.
@@ -115,7 +116,7 @@ namespace boost
115116
&result, Policy());
116117
} // bernoulli_distribution constructor.
117118

118-
RealType success_fraction() const
119+
BOOST_MATH_GPU_ENABLED RealType success_fraction() const
119120
{ // Probability.
120121
return m_p;
121122
}
@@ -132,21 +133,21 @@ namespace boost
132133
#endif
133134

134135
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 */)
136137
{ // Range of permissible values for random variable k = {0, 1}.
137138
using boost::math::tools::max_value;
138139
return std::pair<RealType, RealType>(static_cast<RealType>(0), static_cast<RealType>(1));
139140
}
140141

141142
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 */)
143144
{ // Range of supported values for random variable k = {0, 1}.
144145
// This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
145146
return std::pair<RealType, RealType>(static_cast<RealType>(0), static_cast<RealType>(1));
146147
}
147148

148149
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)
150151
{ // Mean of bernoulli distribution = p (n = 1).
151152
return dist.success_fraction();
152153
} // mean
@@ -159,13 +160,13 @@ namespace boost
159160
//} // median
160161

161162
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)
163164
{ // Variance of bernoulli distribution =p * q.
164165
return dist.success_fraction() * (1 - dist.success_fraction());
165166
} // variance
166167

167168
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)
169170
{ // Probability Density/Mass Function.
170171
BOOST_FPU_EXCEPTION_GUARD
171172
// Error check:
@@ -190,7 +191,7 @@ namespace boost
190191
} // pdf
191192

192193
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)
194195
{ // Cumulative Distribution Function Bernoulli.
195196
RealType p = dist.success_fraction();
196197
// Error check:
@@ -214,7 +215,7 @@ namespace boost
214215
} // bernoulli cdf
215216

216217
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)
218219
{ // Complemented Cumulative Distribution Function bernoulli.
219220
RealType const& k = c.param;
220221
bernoulli_distribution<RealType, Policy> const& dist = c.dist;
@@ -240,7 +241,7 @@ namespace boost
240241
} // bernoulli cdf complement
241242

242243
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)
244245
{ // Quantile or Percent Point Bernoulli function.
245246
// Return the number of expected successes k either 0 or 1.
246247
// for a given probability p.
@@ -265,7 +266,7 @@ namespace boost
265266
} // quantile
266267

267268
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)
269270
{ // Quantile or Percent Point bernoulli function.
270271
// Return the number of expected successes k for a given
271272
// complement of the probability q.
@@ -294,21 +295,21 @@ namespace boost
294295
} // quantile complemented.
295296

296297
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)
298299
{
299300
return static_cast<RealType>((dist.success_fraction() <= 0.5) ? 0 : 1); // p = 0.5 can be 0 or 1
300301
}
301302

302303
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)
304305
{
305306
BOOST_MATH_STD_USING; // Aid ADL for sqrt.
306307
RealType p = dist.success_fraction();
307308
return (1 - 2 * p) / sqrt(p * (1 - p));
308309
}
309310

310311
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)
312313
{
313314
RealType p = dist.success_fraction();
314315
// Note Wolfram says this is kurtosis in text, but gamma2 is the kurtosis excess,
@@ -319,7 +320,7 @@ namespace boost
319320
}
320321

321322
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)
323324
{
324325
RealType p = dist.success_fraction();
325326
return 1 / (1 - p) + 1/p -6 + 3;

include/boost/math/distributions/complement.hpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// (C) Copyright John Maddock 2006.
22
// (C) Copyright Paul A. Bristow 2006.
3+
// (C) Copyright Matt Borland 2024
34
// Use, modification and distribution are subject to the
45
// Boost Software License, Version 1.0. (See accompanying file
56
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
67

78
#ifndef BOOST_STATS_COMPLEMENT_HPP
89
#define BOOST_STATS_COMPLEMENT_HPP
910

11+
#include <boost/math/tools/config.hpp>
12+
1013
//
1114
// This code really defines our own tuple type.
1215
// It would be nice to reuse boost::math::tuple
@@ -19,7 +22,7 @@ namespace boost{ namespace math{
1922
template <class Dist, class RealType>
2023
struct complemented2_type
2124
{
22-
complemented2_type(
25+
BOOST_MATH_GPU_ENABLED complemented2_type(
2326
const Dist& d,
2427
const RealType& p1)
2528
: dist(d),
@@ -35,7 +38,7 @@ struct complemented2_type
3538
template <class Dist, class RealType1, class RealType2>
3639
struct complemented3_type
3740
{
38-
complemented3_type(
41+
BOOST_MATH_GPU_ENABLED complemented3_type(
3942
const Dist& d,
4043
const RealType1& p1,
4144
const RealType2& p2)
@@ -53,7 +56,7 @@ struct complemented3_type
5356
template <class Dist, class RealType1, class RealType2, class RealType3>
5457
struct complemented4_type
5558
{
56-
complemented4_type(
59+
BOOST_MATH_GPU_ENABLED complemented4_type(
5760
const Dist& d,
5861
const RealType1& p1,
5962
const RealType2& p2,
@@ -74,7 +77,7 @@ struct complemented4_type
7477
template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4>
7578
struct complemented5_type
7679
{
77-
complemented5_type(
80+
BOOST_MATH_GPU_ENABLED complemented5_type(
7881
const Dist& d,
7982
const RealType1& p1,
8083
const RealType2& p2,
@@ -98,7 +101,7 @@ struct complemented5_type
98101
template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5>
99102
struct complemented6_type
100103
{
101-
complemented6_type(
104+
BOOST_MATH_GPU_ENABLED complemented6_type(
102105
const Dist& d,
103106
const RealType1& p1,
104107
const RealType2& p2,
@@ -125,7 +128,7 @@ struct complemented6_type
125128
template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5, class RealType6>
126129
struct complemented7_type
127130
{
128-
complemented7_type(
131+
BOOST_MATH_GPU_ENABLED complemented7_type(
129132
const Dist& d,
130133
const RealType1& p1,
131134
const RealType2& p2,
@@ -153,37 +156,37 @@ struct complemented7_type
153156
};
154157

155158
template <class Dist, class RealType>
156-
inline complemented2_type<Dist, RealType> complement(const Dist& d, const RealType& r)
159+
BOOST_MATH_GPU_ENABLED inline complemented2_type<Dist, RealType> complement(const Dist& d, const RealType& r)
157160
{
158161
return complemented2_type<Dist, RealType>(d, r);
159162
}
160163

161164
template <class Dist, class RealType1, class RealType2>
162-
inline complemented3_type<Dist, RealType1, RealType2> complement(const Dist& d, const RealType1& r1, const RealType2& r2)
165+
BOOST_MATH_GPU_ENABLED inline complemented3_type<Dist, RealType1, RealType2> complement(const Dist& d, const RealType1& r1, const RealType2& r2)
163166
{
164167
return complemented3_type<Dist, RealType1, RealType2>(d, r1, r2);
165168
}
166169

167170
template <class Dist, class RealType1, class RealType2, class RealType3>
168-
inline complemented4_type<Dist, RealType1, RealType2, RealType3> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3)
171+
BOOST_MATH_GPU_ENABLED inline complemented4_type<Dist, RealType1, RealType2, RealType3> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3)
169172
{
170173
return complemented4_type<Dist, RealType1, RealType2, RealType3>(d, r1, r2, r3);
171174
}
172175

173176
template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4>
174-
inline complemented5_type<Dist, RealType1, RealType2, RealType3, RealType4> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4)
177+
BOOST_MATH_GPU_ENABLED inline complemented5_type<Dist, RealType1, RealType2, RealType3, RealType4> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4)
175178
{
176179
return complemented5_type<Dist, RealType1, RealType2, RealType3, RealType4>(d, r1, r2, r3, r4);
177180
}
178181

179182
template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5>
180-
inline complemented6_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5)
183+
BOOST_MATH_GPU_ENABLED inline complemented6_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5)
181184
{
182185
return complemented6_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5>(d, r1, r2, r3, r4, r5);
183186
}
184187

185188
template <class Dist, class RealType1, class RealType2, class RealType3, class RealType4, class RealType5, class RealType6>
186-
inline complemented7_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5, RealType6> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5, const RealType6& r6)
189+
BOOST_MATH_GPU_ENABLED inline complemented7_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5, RealType6> complement(const Dist& d, const RealType1& r1, const RealType2& r2, const RealType3& r3, const RealType4& r4, const RealType5& r5, const RealType6& r6)
187190
{
188191
return complemented7_type<Dist, RealType1, RealType2, RealType3, RealType4, RealType5, RealType6>(d, r1, r2, r3, r4, r5, r6);
189192
}

0 commit comments

Comments
 (0)