Skip to content

Commit

Permalink
Replace workaround cstdint macros
Browse files Browse the repository at this point in the history
  • Loading branch information
mborland committed Aug 16, 2024
1 parent e7c7fd5 commit 346a19d
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 53 deletions.
5 changes: 3 additions & 2 deletions include/boost/math/policies/error_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <boost/math/tools/config.hpp>
#include <boost/math/tools/numeric_limits.hpp>
#include <boost/math/tools/type_traits.hpp>
#include <boost/math/tools/cstdint.hpp>

#ifndef BOOST_MATH_HAS_NVRTC

Expand Down Expand Up @@ -1017,7 +1018,7 @@ BOOST_MATH_GPU_ENABLED BOOST_MATH_FORCEINLINE R checked_narrowing_cast(T val, co
}

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED inline void check_series_iterations(const char* function, BOOST_MATH_UINTMAX_T max_iter, const Policy& pol) noexcept(boost::math::is_floating_point_v<T>)
BOOST_MATH_GPU_ENABLED inline void check_series_iterations(const char* function, boost::math::uintmax_t max_iter, const Policy& pol) noexcept(boost::math::is_floating_point_v<T>)
{
if(max_iter >= policies::get_max_series_iterations<Policy>())
raise_evaluation_error<T>(
Expand All @@ -1026,7 +1027,7 @@ BOOST_MATH_GPU_ENABLED inline void check_series_iterations(const char* function,
}

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED inline void check_root_iterations(const char* function, BOOST_MATH_UINTMAX_T max_iter, const Policy& pol) noexcept(boost::math::is_floating_point_v<T>)
BOOST_MATH_GPU_ENABLED inline void check_root_iterations(const char* function, boost::math::uintmax_t max_iter, const Policy& pol) noexcept(boost::math::is_floating_point_v<T>)
{
if(max_iter >= policies::get_max_root_iterations<Policy>())
raise_evaluation_error<T>(
Expand Down
11 changes: 6 additions & 5 deletions include/boost/math/policies/policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <boost/math/tools/mp.hpp>
#include <boost/math/tools/numeric_limits.hpp>
#include <boost/math/tools/type_traits.hpp>
#include <boost/math/tools/cstdint.hpp>

namespace boost{ namespace math{

Expand Down Expand Up @@ -313,7 +314,7 @@ class is_default_policy
};
};

template <class Seq, class T, BOOST_MATH_SIZE_T N>
template <class Seq, class T, boost::math::size_t N>
struct append_N
{
using type = typename append_N<mp::mp_push_back<Seq, T>, T, N-1>::type;
Expand Down Expand Up @@ -402,7 +403,7 @@ class policy
// Typelist of the arguments:
//
using arg_list = mp::mp_list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13>;
static constexpr BOOST_MATH_SIZE_T arg_list_size = mp::mp_size<arg_list>::value;
static constexpr boost::math::size_t arg_list_size = mp::mp_size<arg_list>::value;

template<typename A, typename B, bool b>
struct pick_arg
Expand Down Expand Up @@ -533,7 +534,7 @@ class normalise
{
private:
using arg_list = mp::mp_list<A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A11,A12,A13>;
static constexpr BOOST_MATH_SIZE_T arg_list_size = mp::mp_size<arg_list>::value;
static constexpr boost::math::size_t arg_list_size = mp::mp_size<arg_list>::value;

template<typename A, typename B, bool b>
struct pick_arg
Expand Down Expand Up @@ -882,7 +883,7 @@ struct series_factor_calc<T, Digits, boost::math::true_type, boost::math::false_
{
BOOST_MATH_GPU_ENABLED static constexpr T get() noexcept(boost::math::is_floating_point<T>::value)
{
return 1 / static_cast<T>(static_cast<BOOST_MATH_UINTMAX_T>(1u) << (Digits::value - 1));
return 1 / static_cast<T>(static_cast<boost::math::uintmax_t>(1u) << (Digits::value - 1));
}
};
template <class T, class Digits>
Expand All @@ -901,7 +902,7 @@ BOOST_MATH_GPU_ENABLED constexpr T get_epsilon_imp(boost::math::true_type const&
static_assert(boost::math::numeric_limits<T>::radix == 2, "boost::math::numeric_limits<T>::radix == 2");

typedef typename boost::math::policies::precision<T, Policy>::type p_t;
typedef boost::math::integral_constant<bool, p_t::value <= boost::math::numeric_limits<BOOST_MATH_UINTMAX_T>::digits> is_small_int;
typedef boost::math::integral_constant<bool, p_t::value <= boost::math::numeric_limits<boost::math::uintmax_t>::digits> is_small_int;
typedef boost::math::integral_constant<bool, p_t::value >= boost::math::numeric_limits<T>::digits> is_default_value;
return series_factor_calc<T, p_t, is_small_int, is_default_value>::get();
}
Expand Down
5 changes: 3 additions & 2 deletions include/boost/math/special_functions/beta.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <boost/math/tools/numeric_limits.hpp>
#include <boost/math/tools/tuple.hpp>
#include <boost/math/tools/promotion.hpp>
#include <boost/math/tools/cstdint.hpp>
#include <boost/math/special_functions/gamma.hpp>
#include <boost/math/special_functions/erf.hpp>
#include <boost/math/special_functions/log1p.hpp>
Expand Down Expand Up @@ -732,7 +733,7 @@ BOOST_MATH_GPU_ENABLED T ibeta_series(T a, T b, T x, T s0, const Lanczos&, bool
if(result < tools::min_value<T>())
return s0; // Safeguard: series can't cope with denorms.
ibeta_series_t<T> s(a, b, x, result);
BOOST_MATH_UINTMAX_T max_iter = policies::get_max_series_iterations<Policy>();
boost::math::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
result = boost::math::tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter, s0);
policies::check_series_iterations<T>("boost::math::ibeta<%1%>(%1%, %1%, %1%) in ibeta_series (with lanczos)", max_iter, pol);
return result;
Expand Down Expand Up @@ -794,7 +795,7 @@ BOOST_MATH_GPU_ENABLED T ibeta_series(T a, T b, T x, T s0, const boost::math::la
if(result < tools::min_value<T>())
return s0; // Safeguard: series can't cope with denorms.
ibeta_series_t<T> s(a, b, x, result);
BOOST_MATH_UINTMAX_T max_iter = policies::get_max_series_iterations<Policy>();
boost::math::uintmax_t max_iter = policies::get_max_series_iterations<Policy>();
result = boost::math::tools::sum_series(s, boost::math::policies::get_epsilon<T, Policy>(), max_iter, s0);
policies::check_series_iterations<T>("boost::math::ibeta<%1%>(%1%, %1%, %1%) in ibeta_series (without lanczos)", max_iter, pol);
return result;
Expand Down
8 changes: 0 additions & 8 deletions include/boost/math/tools/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,6 @@ BOOST_MATH_GPU_ENABLED constexpr T cuda_safe_max(const T& a, const T& b) { retur
#define BOOST_MATH_FP_SUBNORMAL FP_SUBNORMAL
#define BOOST_MATH_FP_NORMAL FP_NORMAL

// Missing type from NVRTC
#include <cstdint>
#define BOOST_MATH_SIZE_T std::size_t
#define BOOST_MATH_UINTMAX_T std::uintmax_t

#else // Special section for CUDA NVRTC to ensure we consume no STL headers

#ifndef BOOST_MATH_STANDALONE
Expand Down Expand Up @@ -825,9 +820,6 @@ BOOST_MATH_GPU_ENABLED constexpr void gpu_safe_swap(T& a, T& b) { T t(a); a = b;
#define BOOST_MATH_FP_SUBNORMAL 3
#define BOOST_MATH_FP_NORMAL 4

#define BOOST_MATH_SIZE_T unsigned long
#define BOOST_MATH_UINTMAX_T unsigned long

#define BOOST_MATH_INT_VALUE_SUFFIX(RV, SUF) RV##SUF
#define BOOST_MATH_INT_TABLE_TYPE(RT, IT) IT

Expand Down
25 changes: 13 additions & 12 deletions include/boost/math/tools/fraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <boost/math/tools/tuple.hpp>
#include <boost/math/tools/precision.hpp>
#include <boost/math/tools/complex.hpp>
#include <boost/math/tools/cstdint.hpp>
#include <type_traits>
#include <cstdint>
#include <cmath>
Expand Down Expand Up @@ -112,7 +113,7 @@ namespace detail {
//

template <typename Gen, typename U>
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b_impl(Gen& g, const U& factor, BOOST_MATH_UINTMAX_T& max_terms)
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b_impl(Gen& g, const U& factor, boost::math::uintmax_t& max_terms)
noexcept(BOOST_MATH_IS_FLOAT(typename detail::fraction_traits<Gen>::result_type)
#ifndef BOOST_MATH_ENABLE_SYCL
// SYCL can not handle this condition so we only check float on that platform
Expand Down Expand Up @@ -142,7 +143,7 @@ BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type
C = f;
D = 0;

BOOST_MATH_UINTMAX_T counter(max_terms);
boost::math::uintmax_t counter(max_terms);
do{
v = g();
D = traits::b(v) + traits::a(v) * D;
Expand All @@ -164,7 +165,7 @@ BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type
} // namespace detail

template <typename Gen, typename U>
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b(Gen& g, const U& factor, BOOST_MATH_UINTMAX_T& max_terms)
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b(Gen& g, const U& factor, boost::math::uintmax_t& max_terms)
noexcept(BOOST_MATH_IS_FLOAT(typename detail::fraction_traits<Gen>::result_type)
#ifndef BOOST_MATH_ENABLE_SYCL
&& noexcept(std::declval<Gen>()())
Expand All @@ -182,7 +183,7 @@ BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type
#endif
)
{
BOOST_MATH_UINTMAX_T max_terms = (std::numeric_limits<BOOST_MATH_UINTMAX_T>::max)();
boost::math::uintmax_t max_terms = (std::numeric_limits<boost::math::uintmax_t>::max)();
return detail::continued_fraction_b_impl(g, factor, max_terms);
}

Expand All @@ -200,12 +201,12 @@ BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type
using result_type = typename traits::result_type;

result_type factor = ldexp(1.0f, 1 - bits); // 1 / pow(result_type(2), bits);
BOOST_MATH_UINTMAX_T max_terms = (std::numeric_limits<BOOST_MATH_UINTMAX_T>::max)();
boost::math::uintmax_t max_terms = (std::numeric_limits<boost::math::uintmax_t>::max)();
return detail::continued_fraction_b_impl(g, factor, max_terms);
}

template <typename Gen>
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b(Gen& g, int bits, BOOST_MATH_UINTMAX_T& max_terms)
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_b(Gen& g, int bits, boost::math::uintmax_t& max_terms)
noexcept(BOOST_MATH_IS_FLOAT(typename detail::fraction_traits<Gen>::result_type)
#ifndef BOOST_MATH_ENABLE_SYCL
&& noexcept(std::declval<Gen>()())
Expand Down Expand Up @@ -238,7 +239,7 @@ namespace detail {
// Note that the first a1 and b1 returned by generator Gen are both used.
//
template <typename Gen, typename U>
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a_impl(Gen& g, const U& factor, BOOST_MATH_UINTMAX_T& max_terms)
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a_impl(Gen& g, const U& factor, boost::math::uintmax_t& max_terms)
noexcept(BOOST_MATH_IS_FLOAT(typename detail::fraction_traits<Gen>::result_type)
#ifndef BOOST_MATH_ENABLE_SYCL
&& noexcept(std::declval<Gen>()())
Expand Down Expand Up @@ -268,7 +269,7 @@ BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type
C = f;
D = 0;

BOOST_MATH_UINTMAX_T counter(max_terms);
boost::math::uintmax_t counter(max_terms);

do{
v = g();
Expand All @@ -291,7 +292,7 @@ BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type
} // namespace detail

template <typename Gen, typename U>
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a(Gen& g, const U& factor, BOOST_MATH_UINTMAX_T& max_terms)
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a(Gen& g, const U& factor, boost::math::uintmax_t& max_terms)
noexcept(BOOST_MATH_IS_FLOAT(typename detail::fraction_traits<Gen>::result_type)
#ifndef BOOST_MATH_ENABLE_SYCL
&& noexcept(std::declval<Gen>()())
Expand All @@ -309,7 +310,7 @@ BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type
#endif
)
{
BOOST_MATH_UINTMAX_T max_iter = (std::numeric_limits<BOOST_MATH_UINTMAX_T>::max)();
boost::math::uintmax_t max_iter = (std::numeric_limits<boost::math::uintmax_t>::max)();
return detail::continued_fraction_a_impl(g, factor, max_iter);
}

Expand All @@ -327,13 +328,13 @@ BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type
typedef typename traits::result_type result_type;

result_type factor = ldexp(1.0f, 1-bits); // 1 / pow(result_type(2), bits);
BOOST_MATH_UINTMAX_T max_iter = (std::numeric_limits<BOOST_MATH_UINTMAX_T>::max)();
boost::math::uintmax_t max_iter = (std::numeric_limits<boost::math::uintmax_t>::max)();

return detail::continued_fraction_a_impl(g, factor, max_iter);
}

template <typename Gen>
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a(Gen& g, int bits, BOOST_MATH_UINTMAX_T& max_terms)
BOOST_MATH_GPU_ENABLED inline typename detail::fraction_traits<Gen>::result_type continued_fraction_a(Gen& g, int bits, boost::math::uintmax_t& max_terms)
noexcept(BOOST_MATH_IS_FLOAT(typename detail::fraction_traits<Gen>::result_type)
#ifndef BOOST_MATH_ENABLE_SYCL
&& noexcept(std::declval<Gen>()())
Expand Down
21 changes: 11 additions & 10 deletions include/boost/math/tools/mp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <boost/math/tools/config.hpp>
#include <boost/math/tools/type_traits.hpp>
#include <boost/math/tools/cstdint.hpp>

namespace boost { namespace math { namespace tools { namespace meta_programming {

Expand All @@ -22,8 +23,8 @@ template<typename... T>
struct mp_list {};

// Size_t
template<BOOST_MATH_SIZE_T N>
using mp_size_t = boost::math::integral_constant<BOOST_MATH_SIZE_T, N>;
template<boost::math::size_t N>
using mp_size_t = boost::math::integral_constant<boost::math::size_t, N>;

// Boolean
template<bool B>
Expand Down Expand Up @@ -52,7 +53,7 @@ struct mp_size_impl {};
template<template<typename...> class L, typename... T> // Template template parameter must use class
struct mp_size_impl<L<T...>>
{
using type = boost::math::integral_constant<BOOST_MATH_SIZE_T, sizeof...(T)>;
using type = boost::math::integral_constant<boost::math::size_t, sizeof...(T)>;
};
}

Expand All @@ -78,7 +79,7 @@ namespace detail {
// At
// TODO - Use tree based lookup for larger typelists
// http://odinthenerd.blogspot.com/2017/04/tree-based-lookup-why-kvasirmpl-is.html
template<typename L, BOOST_MATH_SIZE_T>
template<typename L, boost::math::size_t>
struct mp_at_c {};

template<template<typename...> class L, typename T0, typename... T>
Expand Down Expand Up @@ -167,7 +168,7 @@ struct mp_at_c<L<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T...>, 1
};
}

template<typename L, BOOST_MATH_SIZE_T Index>
template<typename L, boost::math::size_t Index>
using mp_at_c = typename detail::mp_at_c<L, Index>::type;

template<typename L, typename Index>
Expand Down Expand Up @@ -338,8 +339,8 @@ using mp_remove_if_q = mp_remove_if<L, Q::template fn>;
template<typename T, T... Index>
struct integer_sequence {};

template<BOOST_MATH_SIZE_T... Index>
using index_sequence = integer_sequence<BOOST_MATH_SIZE_T, Index...>;
template<boost::math::size_t... Index>
using index_sequence = integer_sequence<boost::math::size_t, Index...>;

namespace detail {

Expand Down Expand Up @@ -411,11 +412,11 @@ struct make_integer_sequence_impl
template<typename T, T N>
using make_integer_sequence = typename detail::make_integer_sequence_impl<T, N>::type;

template<BOOST_MATH_SIZE_T N>
using make_index_sequence = make_integer_sequence<BOOST_MATH_SIZE_T, N>;
template<boost::math::size_t N>
using make_index_sequence = make_integer_sequence<boost::math::size_t, N>;

template<typename... T>
using index_sequence_for = make_integer_sequence<BOOST_MATH_SIZE_T, sizeof...(T)>;
using index_sequence_for = make_integer_sequence<boost::math::size_t, sizeof...(T)>;

}}}} // namespaces

Expand Down
Loading

0 comments on commit 346a19d

Please sign in to comment.