Skip to content
fn

gammaln

→Tensor
gammaln(input: Tensor)

Natural logarithm of the absolute value of the gamma function.

Convenience alias for lucid.lgamma. Computes log⁡∣Γ(x)∣\log|\Gamma(x)| with numerical stability for large arguments where Γ(x)\Gamma(x) would itself overflow.

Parameters

inputTensor
Input tensor; any floating-point dtype.

Returns

Tensor

log⁡∣Γ(x)∣\log|\Gamma(x)| element-wise.

Notes

Definition:

log⁡∣Γ(x)∣=log⁡ ⁣∣∫0∞tx−1e−t dt∣.\log|\Gamma(x)| = \log\!\left| \int_0^\infty t^{x-1} e^{-t}\, dt \right|.

For positive integer n, Γ(n)=(n−1)!\Gamma(n) = (n - 1)!, so gammaln(n) = log((n-1)!). gammaln returns +inf at non-positive integers (poles of the gamma function).

Examples

>>> import lucid
>>> from lucid.special import gammaln
>>> gammaln(lucid.tensor([1.0, 5.0, 100.0]))
tensor([0., 3.178, 359.1])