Eigen::internal::digamma_impl< Scalar > Struct Template Reference

#include <SpecialFunctionsImpl.h>

Static Public Member Functions

static EIGEN_DEVICE_FUNC Scalar run (Scalar x)
 

Member Function Documentation

◆ run()

template<typename Scalar >
static EIGEN_DEVICE_FUNC Scalar Eigen::internal::digamma_impl< Scalar >::run ( Scalar  x)
inlinestatic
164  {
165  /*
166  *
167  * Psi (digamma) function (modified for Eigen)
168  *
169  *
170  * SYNOPSIS:
171  *
172  * double x, y, psi();
173  *
174  * y = psi( x );
175  *
176  *
177  * DESCRIPTION:
178  *
179  * d -
180  * psi(x) = -- ln | (x)
181  * dx
182  *
183  * is the logarithmic derivative of the gamma function.
184  * For integer x,
185  * n-1
186  * -
187  * psi(n) = -EUL + > 1/k.
188  * -
189  * k=1
190  *
191  * If x is negative, it is transformed to a positive argument by the
192  * reflection formula psi(1-x) = psi(x) + pi cot(pi x).
193  * For general positive x, the argument is made greater than 10
194  * using the recurrence psi(x+1) = psi(x) + 1/x.
195  * Then the following asymptotic expansion is applied:
196  *
197  * inf. B
198  * - 2k
199  * psi(x) = log(x) - 1/2x - > -------
200  * - 2k
201  * k=1 2k x
202  *
203  * where the B2k are Bernoulli numbers.
204  *
205  * ACCURACY (float):
206  * Relative error (except absolute when |psi| < 1):
207  * arithmetic domain # trials peak rms
208  * IEEE 0,30 30000 1.3e-15 1.4e-16
209  * IEEE -30,0 40000 1.5e-15 2.2e-16
210  *
211  * ACCURACY (double):
212  * Absolute error, relative when |psi| > 1 :
213  * arithmetic domain # trials peak rms
214  * IEEE -33,0 30000 8.2e-7 1.2e-7
215  * IEEE 0,33 100000 7.3e-7 7.7e-8
216  *
217  * ERROR MESSAGES:
218  * message condition value returned
219  * psi singularity x integer <=0 INFINITY
220  */
221 
222  Scalar p, q, nz, s, w, y;
223  bool negative = false;
224 
225  const Scalar nan = NumTraits<Scalar>::quiet_NaN();
226  const Scalar m_pi = Scalar(EIGEN_PI);
227 
228  const Scalar zero = Scalar(0);
229  const Scalar one = Scalar(1);
230  const Scalar half = Scalar(0.5);
231  nz = zero;
232 
233  if (x <= zero) {
234  negative = true;
235  q = x;
236  p = numext::floor(q);
237  if (p == q) {
238  return nan;
239  }
240  /* Remove the zeros of tan(m_pi x)
241  * by subtracting the nearest integer from x
242  */
243  nz = q - p;
244  if (nz != half) {
245  if (nz > half) {
246  p += one;
247  nz = q - p;
248  }
249  nz = m_pi / numext::tan(m_pi * nz);
250  } else {
251  nz = zero;
252  }
253  x = one - x;
254  }
255 
256  /* use the recurrence psi(x+1) = psi(x) + 1/x. */
257  s = x;
258  w = zero;
259  while (s < Scalar(10)) {
260  w += one / s;
261  s += one;
262  }
263 
265 
266  y = numext::log(s) - (half / s) - y - w;
267 
268  return (negative) ? y - nz : y;
269  }
#define EIGEN_PI
Definition: MathFunctions.h:16
RowVector3d w
Definition: Matrix_resize_int.cpp:3
float * p
Definition: Tutorial_Map_using.cpp:9
SCALAR Scalar
Definition: bench_gemm.cpp:45
RealScalar s
Definition: level1_cplx_impl.h:130
const Scalar & y
Definition: RandomImpl.h:36
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T log(const T &x)
Definition: MathFunctions.h:1332
EIGEN_DEVICE_FUNC const Scalar & q
Definition: SpecialFunctionsImpl.h:2019
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar() floor(const Scalar &x)
Definition: MathFunctions.h:1200
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T tan(const T &x)
Definition: MathFunctions.h:1603
EIGEN_DEVICE_FUNC const Scalar & x
Definition: SpecialFunctionsImpl.h:2024
const unsigned nz
Definition: ConstraintElementsUnitTest.cpp:32
static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run(const Scalar)
Definition: SpecialFunctionsImpl.h:128
EIGEN_DONT_INLINE Scalar zero()
Definition: svd_common.h:232

References EIGEN_PI, Eigen::numext::floor(), Eigen::numext::log(), Mesh_Parameters::nz, p, Eigen::numext::q, Eigen::internal::digamma_impl_maybe_poly< Scalar >::run(), s, Eigen::numext::tan(), w, Eigen::numext::x, Eigen::internal::y, and zero().

Referenced by Eigen::internal::igammac_cf_impl< Scalar, mode >::run(), and Eigen::internal::igamma_series_impl< Scalar, mode >::run().


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