Skip to content

Commit 6abab5e

Browse files
Merge pull request #29 from auto-differentiation/bugfix/boost_189_fix
Boost 1.89 Fixes
2 parents 5a521c9 + 6245c50 commit 6abab5e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

ql/qlrisks.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,35 @@ namespace boost {
378378
const xad::AReal<double>& z,
379379
const Policy& pol) {
380380
return boost::math::powm1(xad::AReal<double>(a), z, pol);
381+
}
382+
383+
// overrides for special functions that break with expression templates
384+
namespace detail {
385+
#if BOOST_VERSION >= 108900
386+
// we needed to copy this from here and make adjustments to the return statement, to ensure that it works with expression templates:
387+
// https://github.com/boostorg/math/blob/develop/include/boost/math/special_functions/beta.hpp#L1136
388+
template <class Policy>
389+
BOOST_MATH_GPU_ENABLED xad::AReal<double> ibeta_large_ab(xad::AReal<double> a, xad::AReal<double> b, xad::AReal<double> x, xad::AReal<double> y, bool invert, bool normalised, const Policy& pol)
390+
{
391+
BOOST_MATH_STD_USING
392+
393+
xad::AReal<double> x0 = a / (a + b);
394+
xad::AReal<double> y0 = b / (a + b);
395+
xad::AReal<double> nu = x0 * log(x / x0) + y0 * log(y / y0);
396+
if ((nu > 0) || (x == x0) || (y == y0))
397+
nu = 0;
398+
nu = sqrt(-2 * nu);
399+
400+
if ((nu != 0) && (nu / (x - x0) < 0))
401+
nu = -nu;
402+
403+
xad::AReal<double> mul = 1;
404+
if (!normalised)
405+
mul = boost::math::beta(a, b, pol);
406+
407+
return mul * ((invert ? xad::AReal<double>((1 + boost::math::erf(xad::AReal<double>(-nu * sqrt((a + b) / 2)), pol)) / 2) : xad::AReal<double>(boost::math::erfc(xad::AReal<double>(-nu * sqrt((a + b) / 2)), pol) / 2)));
408+
}
409+
#endif
381410
}
382411
}
383412

test-suite/utilities_xad.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace QuantLib {
9191

9292
// used to avoid no-assertion messages in Boost 1.35
9393
class quantlib_test_case {
94-
ext::function<void()> test_;
94+
std::function<void()> test_;
9595

9696
public:
9797
template <class F>

0 commit comments

Comments
 (0)