Skip to contents

Computes \(\log \Gamma(x)\) elementwise over x, via a Lanczos approximation (with a Stirling-series tail for large arguments) — faster than base R's lgamma while matching it to within the approximation's own precision. Used pervasively throughout the package's likelihood kernels (beta, negative-binomial, Poisson/count, and other Gamma-function-based densities) wherever a log-factorial-like normalizing term is required, and exported standalone for the same reason as fast_digamma_vec_cpp — measured at 2.18x over lgamma on a length-5000 vector (see the "Utility / Math Kernel Performance" benchmark report for the full methodology and per-kernel results).

Usage

fast_lgamma_vec_cpp(x)

Arguments

x

Numeric vector of arguments (should be positive, or a non-positive non-integer if the reflection formula is supported by the underlying kernel; not validated by this function — see the package's C++ source for the exact domain the Lanczos kernel handles).

Value

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

References

Lanczos approximation and Stirling's approximation for the numerical techniques used; see also Gamma function for orientation. Analogous Python API: SciPy gammaln.

See also