Eigen::internal::igamma_series_impl< Scalar, mode > Struct Template Reference

#include <SpecialFunctionsImpl.h>

Static Public Member Functions

static EIGEN_DEVICE_FUNC Scalar run (Scalar a, Scalar x)
 

Member Function Documentation

◆ run()

template<typename Scalar , IgammaComputationMode mode>
static EIGEN_DEVICE_FUNC Scalar Eigen::internal::igamma_series_impl< Scalar, mode >::run ( Scalar  a,
Scalar  x 
)
inlinestatic
964  {
965  const Scalar zero = 0;
966  const Scalar one = 1;
967  const Scalar machep = cephes_helper<Scalar>::machep();
968 
969  Scalar ax = main_igamma_term<Scalar>(a, x);
970 
971  // This is independent of mode. If this value is zero,
972  // then the function value is zero. If the function value is zero,
973  // then we are in a neighborhood where the function value evaluates to zero,
974  // so the derivative is zero.
975  if (ax == zero) {
976  return zero;
977  }
978 
979  ax /= a;
980 
981  /* power series */
982  Scalar r = a;
983  Scalar c = one;
984  Scalar ans = one;
985 
986  Scalar dc_da = zero;
987  Scalar dans_da = zero;
988 
989  for (int i = 0; i < igamma_num_iterations<Scalar, mode>(); i++) {
990  r += one;
991  Scalar term = x / r;
992  Scalar dterm_da = -x / (r * r);
993  dc_da = term * dc_da + dterm_da * c;
994  dans_da += dc_da;
995  c *= term;
996  ans += c;
997 
998  if (mode == VALUE) {
999  if (c <= machep * ans) {
1000  break;
1001  }
1002  } else {
1003  if (numext::abs(dc_da) <= machep * numext::abs(dans_da)) {
1004  break;
1005  }
1006  }
1007  }
1008 
1009  Scalar dlogax_da = numext::log(x) - digamma_impl<Scalar>::run(a + one);
1010  Scalar dax_da = ax * dlogax_da;
1011 
1012  switch (mode) {
1013  case VALUE:
1014  return ans * ax;
1015  case DERIVATIVE:
1016  return ans * dax_da + dans_da * ax;
1017  case SAMPLE_DERIVATIVE:
1018  default: // this is needed to suppress clang warning
1019  return -(dans_da + ans * dlogax_da) * x / a;
1020  }
1021  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
SCALAR Scalar
Definition: bench_gemm.cpp:45
const Scalar * a
Definition: level2_cplx_impl.h:32
@ SAMPLE_DERIVATIVE
Definition: SpecialFunctionsImpl.h:806
@ VALUE
Definition: SpecialFunctionsImpl.h:806
@ DERIVATIVE
Definition: SpecialFunctionsImpl.h:806
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T log(const T &x)
Definition: MathFunctions.h:1332
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE std::enable_if_t< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real > abs(const T &x)
Definition: MathFunctions.h:1355
EIGEN_DEVICE_FUNC const Scalar & x
Definition: SpecialFunctionsImpl.h:2024
r
Definition: UniformPSDSelfTest.py:20
int c
Definition: calibrate.py:100
ax
Definition: plotDoE.py:39
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar machep()
Definition: SpecialFunctionsImpl.h:765
static EIGEN_DEVICE_FUNC Scalar run(Scalar x)
Definition: SpecialFunctionsImpl.h:164
EIGEN_DONT_INLINE Scalar zero()
Definition: svd_common.h:232

References a, Eigen::numext::abs(), plotDoE::ax, calibrate::c, Eigen::internal::DERIVATIVE, i, Eigen::numext::log(), Eigen::internal::cephes_helper< Scalar >::machep(), UniformPSDSelfTest::r, Eigen::internal::digamma_impl< Scalar >::run(), Eigen::internal::SAMPLE_DERIVATIVE, Eigen::internal::VALUE, Eigen::numext::x, and zero().


The documentation for this struct was generated from the following file: