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).
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
fast_digamma_vec_cpp, fast_trigamma_vec_cpp,
fast_lbeta_vec_cpp (built on this function's kernel).
