Skip to contents

Computes the digamma function \(\psi(x) = d/dx \log \Gamma(x)\) elementwise over x, via an asymptotic expansion with a recurrence (reflection) shift for small arguments to keep the expansion accurate — the standard technique for evaluating digamma/trigamma to double precision without a lookup table. Used internally inside the package's negative-binomial, beta, zero-inflated/hurdle, and KK21 count-response likelihood, score, and Hessian kernels (wherever a Poisson/NegBin/Beta log-likelihood derivative requires \(\psi\)), and exported standalone because it is consistently faster than base R's digamma — measured at 6.78x on a length-5000 vector (see the "Utility / Math Kernel Performance" benchmark report for the full methodology and per-kernel results).

Usage

fast_digamma_vec_cpp(x)

Arguments

x

Numeric vector of arguments (should be finite and, per the digamma function's domain, not a non-positive integer, where \(\psi\) has poles; no domain validation is performed by this function).

Value

A numeric vector of \(\psi(x)\) values, the same length as x.

References

Abramowitz, M., and Stegun, I. A. (1972). Handbook of Mathematical Functions, Section 6.3, for the asymptotic expansion and recurrence relation used. See also digamma function for orientation. Analogous Python API: SciPy digamma.