Skip to content

Commit

Permalink
Add cuda markers to arcsine distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Jul 18, 2024
1 parent c1c7e97 commit d10faa8
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions include/boost/math/distributions/arcsine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define BOOST_MATH_DIST_ARCSINE_HPP

#include <cmath>
#include <boost/math/tools/config.hpp>
#include <boost/math/distributions/fwd.hpp>
#include <boost/math/distributions/complement.hpp> // complements.
#include <boost/math/distributions/detail/common_error_handling.hpp> // error checks.
Expand All @@ -55,7 +56,7 @@ namespace boost
// Common error checking routines for arcsine distribution functions:
// Duplicating for x_min and x_max provides specific error messages.
template <class RealType, class Policy>
inline bool check_x_min(const char* function, const RealType& x, RealType* result, const Policy& pol)
BOOST_MATH_HOST_DEVICE inline bool check_x_min(const char* function, const RealType& x, RealType* result, const Policy& pol)
{
if (!(boost::math::isfinite)(x))
{
Expand All @@ -68,7 +69,7 @@ namespace boost
} // bool check_x_min

template <class RealType, class Policy>
inline bool check_x_max(const char* function, const RealType& x, RealType* result, const Policy& pol)
BOOST_MATH_HOST_DEVICE inline bool check_x_max(const char* function, const RealType& x, RealType* result, const Policy& pol)
{
if (!(boost::math::isfinite)(x))
{
Expand All @@ -82,7 +83,7 @@ namespace boost


template <class RealType, class Policy>
inline bool check_x_minmax(const char* function, const RealType& x_min, const RealType& x_max, RealType* result, const Policy& pol)
BOOST_MATH_HOST_DEVICE inline bool check_x_minmax(const char* function, const RealType& x_min, const RealType& x_max, RealType* result, const Policy& pol)
{ // Check x_min < x_max
if (x_min >= x_max)
{
Expand All @@ -100,7 +101,7 @@ namespace boost
} // bool check_x_minmax

template <class RealType, class Policy>
inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol)
BOOST_MATH_HOST_DEVICE inline bool check_prob(const char* function, const RealType& p, RealType* result, const Policy& pol)
{
if ((p < 0) || (p > 1) || !(boost::math::isfinite)(p))
{
Expand All @@ -113,7 +114,7 @@ namespace boost
} // bool check_prob

template <class RealType, class Policy>
inline bool check_x(const char* function, const RealType& x_min, const RealType& x_max, const RealType& x, RealType* result, const Policy& pol)
BOOST_MATH_HOST_DEVICE inline bool check_x(const char* function, const RealType& x_min, const RealType& x_max, const RealType& x, RealType* result, const Policy& pol)
{ // Check x finite and x_min < x < x_max.
if (!(boost::math::isfinite)(x))
{
Expand All @@ -137,22 +138,22 @@ namespace boost
} // bool check_x

template <class RealType, class Policy>
inline bool check_dist(const char* function, const RealType& x_min, const RealType& x_max, RealType* result, const Policy& pol)
BOOST_MATH_HOST_DEVICE inline bool check_dist(const char* function, const RealType& x_min, const RealType& x_max, RealType* result, const Policy& pol)
{ // Check both x_min and x_max finite, and x_min < x_max.
return check_x_min(function, x_min, result, pol)
&& check_x_max(function, x_max, result, pol)
&& check_x_minmax(function, x_min, x_max, result, pol);
} // bool check_dist

template <class RealType, class Policy>
inline bool check_dist_and_x(const char* function, const RealType& x_min, const RealType& x_max, RealType x, RealType* result, const Policy& pol)
BOOST_MATH_HOST_DEVICE inline bool check_dist_and_x(const char* function, const RealType& x_min, const RealType& x_max, RealType x, RealType* result, const Policy& pol)
{
return check_dist(function, x_min, x_max, result, pol)
&& arcsine_detail::check_x(function, x_min, x_max, x, result, pol);
} // bool check_dist_and_x

template <class RealType, class Policy>
inline bool check_dist_and_prob(const char* function, const RealType& x_min, const RealType& x_max, RealType p, RealType* result, const Policy& pol)
BOOST_MATH_HOST_DEVICE inline bool check_dist_and_prob(const char* function, const RealType& x_min, const RealType& x_max, RealType p, RealType* result, const Policy& pol)
{
return check_dist(function, x_min, x_max, result, pol)
&& check_prob(function, p, result, pol);
Expand All @@ -167,7 +168,7 @@ namespace boost
typedef RealType value_type;
typedef Policy policy_type;

arcsine_distribution(RealType x_min = 0, RealType x_max = 1) : m_x_min(x_min), m_x_max(x_max)
BOOST_MATH_HOST_DEVICE arcsine_distribution(RealType x_min = 0, RealType x_max = 1) : m_x_min(x_min), m_x_max(x_max)
{ // Default beta (alpha = beta = 0.5) is standard arcsine with x_min = 0, x_max = 1.
// Generalized to allow x_min and x_max to be specified.
RealType result;
Expand All @@ -178,11 +179,11 @@ namespace boost
&result, Policy());
} // arcsine_distribution constructor.
// Accessor functions:
RealType x_min() const
BOOST_MATH_HOST_DEVICE RealType x_min() const
{
return m_x_min;
}
RealType x_max() const
BOOST_MATH_HOST_DEVICE RealType x_max() const
{
return m_x_max;
}
Expand All @@ -203,21 +204,21 @@ namespace boost
#endif

template <class RealType, class Policy>
inline const std::pair<RealType, RealType> range(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_HOST_DEVICE inline const std::pair<RealType, RealType> range(const arcsine_distribution<RealType, Policy>& dist)
{ // Range of permissible values for random variable x.
using boost::math::tools::max_value;
return std::pair<RealType, RealType>(static_cast<RealType>(dist.x_min()), static_cast<RealType>(dist.x_max()));
}

template <class RealType, class Policy>
inline const std::pair<RealType, RealType> support(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_HOST_DEVICE inline const std::pair<RealType, RealType> support(const arcsine_distribution<RealType, Policy>& dist)
{ // Range of supported values for random variable x.
// This is range where cdf rises from 0 to 1, and outside it, the pdf is zero.
return std::pair<RealType, RealType>(static_cast<RealType>(dist.x_min()), static_cast<RealType>(dist.x_max()));
}

template <class RealType, class Policy>
inline RealType mean(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_HOST_DEVICE inline RealType mean(const arcsine_distribution<RealType, Policy>& dist)
{ // Mean of arcsine distribution .
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -236,7 +237,7 @@ namespace boost
} // mean

template <class RealType, class Policy>
inline RealType variance(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_HOST_DEVICE inline RealType variance(const arcsine_distribution<RealType, Policy>& dist)
{ // Variance of standard arcsine distribution = (1-0)/8 = 0.125.
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -254,7 +255,7 @@ namespace boost
} // variance

template <class RealType, class Policy>
inline RealType mode(const arcsine_distribution<RealType, Policy>& /* dist */)
BOOST_MATH_HOST_DEVICE inline RealType mode(const arcsine_distribution<RealType, Policy>& /* dist */)
{ //There are always [*two] values for the mode, at ['x_min] and at ['x_max], default 0 and 1,
// so instead we raise the exception domain_error.
return policies::raise_domain_error<RealType>(
Expand All @@ -265,7 +266,7 @@ namespace boost
} // mode

template <class RealType, class Policy>
inline RealType median(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_HOST_DEVICE inline RealType median(const arcsine_distribution<RealType, Policy>& dist)
{ // Median of arcsine distribution (a + b) / 2 == mean.
RealType x_min = dist.x_min();
RealType x_max = dist.x_max();
Expand All @@ -283,7 +284,7 @@ namespace boost
}

template <class RealType, class Policy>
inline RealType skewness(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_HOST_DEVICE inline RealType skewness(const arcsine_distribution<RealType, Policy>& dist)
{
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -302,7 +303,7 @@ namespace boost
} // skewness

template <class RealType, class Policy>
inline RealType kurtosis_excess(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_HOST_DEVICE inline RealType kurtosis_excess(const arcsine_distribution<RealType, Policy>& dist)
{
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -322,7 +323,7 @@ namespace boost
} // kurtosis_excess

template <class RealType, class Policy>
inline RealType kurtosis(const arcsine_distribution<RealType, Policy>& dist)
BOOST_MATH_HOST_DEVICE inline RealType kurtosis(const arcsine_distribution<RealType, Policy>& dist)
{
RealType result;
RealType x_min = dist.x_min();
Expand All @@ -342,7 +343,7 @@ namespace boost
} // kurtosis

template <class RealType, class Policy>
inline RealType pdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& xx)
BOOST_MATH_HOST_DEVICE inline RealType pdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& xx)
{ // Probability Density/Mass Function arcsine.
BOOST_FPU_EXCEPTION_GUARD
BOOST_MATH_STD_USING // For ADL of std functions.
Expand All @@ -368,7 +369,7 @@ namespace boost
} // pdf

template <class RealType, class Policy>
inline RealType cdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& x)
BOOST_MATH_HOST_DEVICE inline RealType cdf(const arcsine_distribution<RealType, Policy>& dist, const RealType& x)
{ // Cumulative Distribution Function arcsine.
BOOST_MATH_STD_USING // For ADL of std functions.

Expand Down Expand Up @@ -401,7 +402,7 @@ namespace boost
} // arcsine cdf

template <class RealType, class Policy>
inline RealType cdf(const complemented2_type<arcsine_distribution<RealType, Policy>, RealType>& c)
BOOST_MATH_HOST_DEVICE inline RealType cdf(const complemented2_type<arcsine_distribution<RealType, Policy>, RealType>& c)
{ // Complemented Cumulative Distribution Function arcsine.
BOOST_MATH_STD_USING // For ADL of std functions.
static const char* function = "boost::math::cdf(arcsine_distribution<%1%> const&, %1%)";
Expand Down Expand Up @@ -437,7 +438,7 @@ namespace boost
} // arcsine ccdf

template <class RealType, class Policy>
inline RealType quantile(const arcsine_distribution<RealType, Policy>& dist, const RealType& p)
BOOST_MATH_HOST_DEVICE inline RealType quantile(const arcsine_distribution<RealType, Policy>& dist, const RealType& p)
{
// Quantile or Percent Point arcsine function or
// Inverse Cumulative probability distribution function CDF.
Expand Down Expand Up @@ -481,7 +482,7 @@ namespace boost
} // quantile

template <class RealType, class Policy>
inline RealType quantile(const complemented2_type<arcsine_distribution<RealType, Policy>, RealType>& c)
BOOST_MATH_HOST_DEVICE inline RealType quantile(const complemented2_type<arcsine_distribution<RealType, Policy>, RealType>& c)
{
// Complement Quantile or Percent Point arcsine function.
// Return the number of expected x for a given
Expand Down

0 comments on commit d10faa8

Please sign in to comment.