Skip to content

Commit

Permalink
Merge pull request #12 from cppalliance/NVRTC_4_test
Browse files Browse the repository at this point in the history
NVRTC Batch 4
  • Loading branch information
mborland authored Aug 14, 2024
2 parents dfc06ee + ce0f99e commit 107a6ec
Show file tree
Hide file tree
Showing 148 changed files with 4,589 additions and 1,751 deletions.
2 changes: 1 addition & 1 deletion include/boost/math/ccmath/copysign.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ constexpr auto copysign(T1 mag, T2 sgn) noexcept
{
if (BOOST_MATH_IS_CONSTANT_EVALUATED(mag))
{
using promoted_type = boost::math::tools::promote_args_2_t<T1, T2>;
using promoted_type = boost::math::tools::promote_args_t<T1, T2>;
return boost::math::ccmath::copysign(static_cast<promoted_type>(mag), static_cast<promoted_type>(sgn));
}
else
Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/ccmath/fdim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ constexpr auto fdim(T1 x, T2 y) noexcept
{
if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
{
using promoted_type = boost::math::tools::promote_args_2_t<T1, T2>;
using promoted_type = boost::math::tools::promote_args_t<T1, T2>;
return boost::math::ccmath::fdim(promoted_type(x), promoted_type(y));
}
else
Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/ccmath/fmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ constexpr auto fmax(T1 x, T2 y) noexcept
{
if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
{
using promoted_type = boost::math::tools::promote_args_2_t<T1, T2>;
using promoted_type = boost::math::tools::promote_args_t<T1, T2>;
return boost::math::ccmath::fmax(static_cast<promoted_type>(x), static_cast<promoted_type>(y));
}
else
Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/ccmath/fmin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ constexpr auto fmin(T1 x, T2 y) noexcept
{
if (BOOST_MATH_IS_CONSTANT_EVALUATED(x))
{
using promoted_type = boost::math::tools::promote_args_2_t<T1, T2>;
using promoted_type = boost::math::tools::promote_args_t<T1, T2>;
return boost::math::ccmath::fmin(static_cast<promoted_type>(x), static_cast<promoted_type>(y));
}
else
Expand Down
2 changes: 1 addition & 1 deletion include/boost/math/ccmath/hypot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ constexpr auto hypot(T1 x, T2 y) noexcept
{
if(BOOST_MATH_IS_CONSTANT_EVALUATED(x))
{
using promoted_type = boost::math::tools::promote_args_2_t<T1, T2>;
using promoted_type = boost::math::tools::promote_args_t<T1, T2>;
return boost::math::ccmath::hypot(static_cast<promoted_type>(x), static_cast<promoted_type>(y));
}
else
Expand Down
20 changes: 18 additions & 2 deletions include/boost/math/constants/constants.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright John Maddock 2005-2006, 2011.
// Copyright Paul A. Bristow 2006-2011.
// Copyright Matt Borland 2024.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Expand All @@ -8,6 +9,9 @@
#define BOOST_MATH_CONSTANTS_CONSTANTS_INCLUDED

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

#ifndef BOOST_MATH_HAS_NVRTC

#include <boost/math/tools/cxx03_warn.hpp>
#include <boost/math/policies/policy.hpp>
#include <boost/math/tools/precision.hpp>
Expand Down Expand Up @@ -243,6 +247,16 @@ namespace boost{ namespace math
namespace long_double_constants{ static constexpr long double name = BOOST_MATH_JOIN(x, L); }\
namespace constants{

#else // NVRTC simplified macro definition

#define BOOST_DEFINE_MATH_CONSTANT(name, value, str_value) template <typename T> BOOST_MATH_GPU_ENABLED constexpr T name() noexcept { return static_cast<T>(value); }

namespace boost {
namespace math {
namespace constants {

#endif

BOOST_DEFINE_MATH_CONSTANT(half, 5.000000000000000000000000000000000000e-01, "5.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-01")
BOOST_DEFINE_MATH_CONSTANT(third, 3.333333333333333333333333333333333333e-01, "3.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333e-01")
BOOST_DEFINE_MATH_CONSTANT(twothirds, 6.666666666666666666666666666666666666e-01, "6.66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667e-01")
Expand Down Expand Up @@ -318,14 +332,12 @@ namespace boost{ namespace math
BOOST_DEFINE_MATH_CONSTANT(one_div_pi, 0.3183098861837906715377675267450287240689192, "0.31830988618379067153776752674502872406891929148091289749533468811779359526845307018022760553250617191214568545351")
BOOST_DEFINE_MATH_CONSTANT(two_div_root_pi, 1.12837916709551257389615890312154517168810125, "1.12837916709551257389615890312154517168810125865799771368817144342128493688298682897348732040421472688605669581272")

#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)
BOOST_DEFINE_MATH_CONSTANT(first_feigenbaum, 4.66920160910299067185320382046620161725818557747576863274, "4.6692016091029906718532038204662016172581855774757686327456513430041343302113147371386897440239480138171")
BOOST_DEFINE_MATH_CONSTANT(plastic, 1.324717957244746025960908854478097340734404056901733364534, "1.32471795724474602596090885447809734073440405690173336453401505030282785124554759405469934798178728032991")
BOOST_DEFINE_MATH_CONSTANT(gauss, 0.834626841674073186281429732799046808993993013490347002449, "0.83462684167407318628142973279904680899399301349034700244982737010368199270952641186969116035127532412906785")
BOOST_DEFINE_MATH_CONSTANT(dottie, 0.739085133215160641655312087673873404013411758900757464965, "0.739085133215160641655312087673873404013411758900757464965680635773284654883547594599376106931766531849801246")
BOOST_DEFINE_MATH_CONSTANT(reciprocal_fibonacci, 3.35988566624317755317201130291892717968890513, "3.35988566624317755317201130291892717968890513373196848649555381532513031899668338361541621645679008729704")
BOOST_DEFINE_MATH_CONSTANT(laplace_limit, 0.662743419349181580974742097109252907056233549115022417, "0.66274341934918158097474209710925290705623354911502241752039253499097185308651127724965480259895818168")
#endif

template <typename T>
BOOST_MATH_GPU_ENABLED inline constexpr T tau() { return two_pi<T>(); }
Expand All @@ -338,7 +350,11 @@ BOOST_MATH_GPU_ENABLED inline constexpr T tau() { return two_pi<T>(); }
// We deliberately include this *after* all the declarations above,
// that way the calculation routines can call on other constants above:
//
// NVRTC will not have a type that needs runtime calculation
//
#ifndef BOOST_MATH_HAS_NVRTC
#include <boost/math/constants/calculate_constants.hpp>
#endif

#endif // BOOST_MATH_CONSTANTS_CONSTANTS_INCLUDED

Expand Down
14 changes: 7 additions & 7 deletions include/boost/math/differentiation/autodiff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace detail {

template <typename RealType, typename... RealTypes>
struct promote_args_n {
using type = typename tools::promote_args_2<RealType, typename promote_args_n<RealTypes...>::type>::type;
using type = typename tools::promote_args<RealType, typename promote_args_n<RealTypes...>::type>::type;
};

template <typename RealType>
Expand Down Expand Up @@ -2002,9 +2002,9 @@ using autodiff_root_type = typename autodiff_fvar_type<RealType, Order>::root_ty

// See boost/math/tools/promotion.hpp
template <typename RealType0, size_t Order0, typename RealType1, size_t Order1>
struct promote_args_2<detail::autodiff_fvar_type<RealType0, Order0>,
struct promote_args<detail::autodiff_fvar_type<RealType0, Order0>,
detail::autodiff_fvar_type<RealType1, Order1>> {
using type = detail::autodiff_fvar_type<typename promote_args_2<RealType0, RealType1>::type,
using type = detail::autodiff_fvar_type<typename promote_args<RealType0, RealType1>::type,
#ifndef BOOST_MATH_NO_CXX14_CONSTEXPR
(std::max)(Order0, Order1)>;
#else
Expand All @@ -2018,13 +2018,13 @@ struct promote_args<detail::autodiff_fvar_type<RealType, Order>> {
};

template <typename RealType0, size_t Order0, typename RealType1>
struct promote_args_2<detail::autodiff_fvar_type<RealType0, Order0>, RealType1> {
using type = detail::autodiff_fvar_type<typename promote_args_2<RealType0, RealType1>::type, Order0>;
struct promote_args<detail::autodiff_fvar_type<RealType0, Order0>, RealType1> {
using type = detail::autodiff_fvar_type<typename promote_args<RealType0, RealType1>::type, Order0>;
};

template <typename RealType0, typename RealType1, size_t Order1>
struct promote_args_2<RealType0, detail::autodiff_fvar_type<RealType1, Order1>> {
using type = detail::autodiff_fvar_type<typename promote_args_2<RealType0, RealType1>::type, Order1>;
struct promote_args<RealType0, detail::autodiff_fvar_type<RealType1, Order1>> {
using type = detail::autodiff_fvar_type<typename promote_args<RealType0, RealType1>::type, Order1>;
};

template <typename destination_t, typename RealType, std::size_t Order>
Expand Down
173 changes: 147 additions & 26 deletions include/boost/math/policies/error_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include <boost/math/tools/config.hpp>
#include <boost/math/tools/numeric_limits.hpp>

#ifndef BOOST_MATH_HAS_NVRTC

#include <iomanip>
#include <string>
#include <cstring>
Expand Down Expand Up @@ -336,32 +339,6 @@ BOOST_MATH_GPU_ENABLED constexpr T raise_overflow_error(
return boost::math::numeric_limits<T>::has_infinity ? boost::math::numeric_limits<T>::infinity() : boost::math::tools::max_value<T>();
}

#ifdef BOOST_MATH_HAS_GPU_SUPPORT

template <>
BOOST_MATH_GPU_ENABLED constexpr float raise_overflow_error<float>(
const char* ,
const char* ,
const ::boost::math::policies::overflow_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(float)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
return static_cast<float>(INFINITY);
}

template <>
BOOST_MATH_GPU_ENABLED constexpr double raise_overflow_error<double>(
const char* ,
const char* ,
const ::boost::math::policies::overflow_error< ::boost::math::policies::ignore_error>&) BOOST_MATH_NOEXCEPT(double)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
return INFINITY;
}

#endif

template <class T>
BOOST_MATH_GPU_ENABLED constexpr T raise_overflow_error(
const char* ,
Expand Down Expand Up @@ -918,5 +895,149 @@ BOOST_MATH_GPU_ENABLED std::pair<T, T> pair_from_single(const T& val) BOOST_MATH

}} // namespaces boost/math

#else // Special values for NVRTC

namespace boost {
namespace math {
namespace policies {

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED constexpr T raise_domain_error(
const char* ,
const char* ,
const T& ,
const Policy&) BOOST_MATH_NOEXCEPT(T)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
return boost::math::numeric_limits<T>::quiet_NaN();
}

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED constexpr T raise_pole_error(
const char* function,
const char* message,
const T& val,
const Policy&) BOOST_MATH_NOEXCEPT(T)
{
return boost::math::numeric_limits<T>::quiet_NaN();
}

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED constexpr T raise_overflow_error(
const char* ,
const char* ,
const Policy&) BOOST_MATH_NOEXCEPT(T)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
return boost::math::numeric_limits<T>::has_infinity ? boost::math::numeric_limits<T>::infinity() : (boost::math::numeric_limits<T>::max)();
}

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED constexpr T raise_overflow_error(
const char* ,
const char* ,
const T&,
const Policy&) BOOST_MATH_NOEXCEPT(T)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
return boost::math::numeric_limits<T>::has_infinity ? boost::math::numeric_limits<T>::infinity() : (boost::math::numeric_limits<T>::max)();
}

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED constexpr T raise_underflow_error(
const char* ,
const char* ,
const Policy&) BOOST_MATH_NOEXCEPT(T)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
return static_cast<T>(0);
}

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED inline constexpr T raise_denorm_error(
const char* ,
const char* ,
const T& val,
const Policy&) BOOST_MATH_NOEXCEPT(T)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
return val;
}

template <class T, class Policy>
BOOST_MATH_GPU_ENABLED constexpr T raise_evaluation_error(
const char* ,
const char* ,
const T& val,
const Policy&) BOOST_MATH_NOEXCEPT(T)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
return val;
}

template <class T, class TargetType, class Policy>
BOOST_MATH_GPU_ENABLED constexpr TargetType raise_rounding_error(
const char* ,
const char* ,
const T& val,
const TargetType&,
const Policy&) BOOST_MATH_NOEXCEPT(T)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
static_assert(boost::math::numeric_limits<TargetType>::is_specialized, "The target type must have std::numeric_limits specialized.");
return val > 0 ? (boost::math::numeric_limits<TargetType>::max)() : (boost::math::numeric_limits<TargetType>::is_integer ? (boost::math::numeric_limits<TargetType>::min)() : -(boost::math::numeric_limits<TargetType>::max)());
}

template <class T, class R, class Policy>
BOOST_MATH_GPU_ENABLED inline constexpr T raise_indeterminate_result_error(
const char* ,
const char* ,
const T& ,
const R& result,
const Policy&) BOOST_MATH_NOEXCEPT(T)
{
// This may or may not do the right thing, but the user asked for the error
// to be ignored so here we go anyway:
return result;
}

template <class R, class Policy, class T>
BOOST_MATH_GPU_ENABLED BOOST_MATH_FORCEINLINE R checked_narrowing_cast(T val, const char* function) noexcept(boost::math::is_floating_point_v<R> && boost::math::is_floating_point_v<T>)
{
// We only have ignore error policy so no reason to check
return static_cast<R>(val);
}

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>)
{
if(max_iter >= policies::get_max_series_iterations<Policy>())
raise_evaluation_error<T>(
function,
"Series evaluation exceeded %1% iterations, giving up now.", static_cast<T>(static_cast<double>(max_iter)), pol);
}

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>)
{
if(max_iter >= policies::get_max_root_iterations<Policy>())
raise_evaluation_error<T>(
function,
"Root finding evaluation exceeded %1% iterations, giving up now.", static_cast<T>(static_cast<double>(max_iter)), pol);
}

} // namespace policies
} // namespace math
} // namespace boost

#endif

#endif // BOOST_MATH_POLICY_ERROR_HANDLING_HPP

Loading

0 comments on commit 107a6ec

Please sign in to comment.