Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions math/mathcore/inc/Math/CladDerivator.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
#include <plugins/include/clad/Differentiator/Differentiator.h>
#include "TMath.h"

// For the digamma function, that is the derivative of lgamma. We get it via
// mathmore from the GSL, so the pullbacks that use digamma are only available
// with mathmore=ON.
#ifdef R__HAS_MATHMORE
#include "Math/SpecFuncMathMore.h"
#endif

#include <stdexcept>

namespace clad {
Expand Down Expand Up @@ -103,16 +96,12 @@ ValueAndPushforward<T, T> Erfc_pushforward(T x, T d_x)
return {::TMath::Erfc(x), -Erf_pushforward(x, d_x).pushforward};
}

#ifdef R__HAS_MATHMORE

template <typename T>
ValueAndPushforward<T, T> LnGamma_pushforward(T z, T d_z)
{
return {::TMath::LnGamma(z), ::ROOT::Math::digamma(z) * d_z};
return {::TMath::LnGamma(z), ::clad::custom_derivatives::std::clad_digamma(z) * d_z};
}

#endif

template <typename T>
ValueAndPushforward<T, T> Exp_pushforward(T x, T d_x)
{
Expand Down Expand Up @@ -633,8 +622,6 @@ inline void landau_cdf_pullback(double x, double xi, double x0, double d_out, do
*d_xi += _d_v * -((x - x0) / (xi * xi));
}

#ifdef R__HAS_MATHMORE

inline void inc_gamma_c_pullback(double a, double x, double _d_y, double *_d_a, double *_d_x);

inline void inc_gamma_pullback(double a, double x, double _d_y, double *_d_a, double *_d_x)
Expand Down Expand Up @@ -674,9 +661,8 @@ inline void inc_gamma_pullback(double a, double x, double _d_y, double *_d_a, do
ax = a * _t1 - x - ::std::lgamma(a);
if (ax < -kMAXLOG) {
*_d_x += (a * _d_ax / x) - _d_ax;
*_d_a +=
_d_ax *
(_t1 - ::ROOT::Math::digamma(a)); // numerical_diff::forward_central_difference(::std::lgamma, a, 0, 0, a);
*_d_a += _d_ax * (_t1 - ::clad::custom_derivatives::std::clad_digamma(
a)); // numerical_diff::forward_central_difference(::std::lgamma, a, 0, 0, a);
_d_ax = 0.;
return;
}
Expand Down Expand Up @@ -753,9 +739,8 @@ inline void inc_gamma_pullback(double a, double x, double _d_y, double *_d_a, do
}
{
*_d_x += (a * _d_ax / x) - _d_ax;
*_d_a +=
_d_ax *
(_t1 - ::ROOT::Math::digamma(a)); // numerical_diff::forward_central_difference(::std::lgamma, a, 0, 0, a);
*_d_a += _d_ax * (_t1 - ::clad::custom_derivatives::std::clad_digamma(
a)); // numerical_diff::forward_central_difference(::std::lgamma, a, 0, 0, a);
_d_ax = 0.;
}
}
Expand Down Expand Up @@ -822,9 +807,8 @@ inline void inc_gamma_c_pullback(double a, double x, double _d_y, double *_d_a,
ax = a * _t1 - x - ::std::lgamma(a);
if (ax < -kMAXLOG) {
*_d_x += a * _d_ax / x - _d_ax;
*_d_a +=
_d_ax *
(_t1 - ::ROOT::Math::digamma(a)); // numerical_diff::forward_central_difference(::std::lgamma, a, 0, 0, a);
*_d_a += _d_ax * (_t1 - ::clad::custom_derivatives::std::clad_digamma(
a)); // numerical_diff::forward_central_difference(::std::lgamma, a, 0, 0, a);
_d_ax = 0.;
return;
}
Expand Down Expand Up @@ -1085,15 +1069,12 @@ inline void inc_gamma_c_pullback(double a, double x, double _d_y, double *_d_a,
}
{
*_d_x += a * _d_ax / x - _d_ax;
*_d_a +=
_d_ax *
(_t1 - ::ROOT::Math::digamma(a)); // numerical_diff::forward_central_difference(::std::lgamma, a, 0, 0, a);
*_d_a += _d_ax * (_t1 - ::clad::custom_derivatives::std::clad_digamma(
a)); // numerical_diff::forward_central_difference(::std::lgamma, a, 0, 0, a);
_d_ax = 0.;
}
}

#endif // R__HAS_MATHMORE

} // namespace Math
} // namespace ROOT

Expand Down
3 changes: 0 additions & 3 deletions math/mathmore/inc/Math/SpecFuncMathMore.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,6 @@ namespace Math {

double wigner_9j(int two_ja, int two_jb, int two_jc, int two_jd, int two_je, int two_jf, int two_jg, int two_jh, int two_ji);

double digamma(double x);


} // namespace Math
} // namespace ROOT

Expand Down
8 changes: 0 additions & 8 deletions math/mathmore/src/SpecFuncMathMore.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "gsl/gsl_sf_zeta.h"
#include "gsl/gsl_sf_airy.h"
#include "gsl/gsl_sf_coupling.h"
#include "gsl/gsl_sf_psi.h"


namespace ROOT {
Expand Down Expand Up @@ -475,12 +474,5 @@ double wigner_9j(int ja, int jb, int jc, int jd, int je, int jf, int jg, int jh,
return gsl_sf_coupling_9j(ja,jb,jc,jd,je,jf,jg,jh,ji);
}

// Psi (Digamma) Function.

double digamma(double x)
{
return gsl_sf_psi(x);
}

} // namespace Math
} // namespace ROOT
Loading