fn

gammaln

Tensor
gammaln(x: Tensor)
source

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

xTensor
Input tensor; any floating-point dtype.

Returns

Tensor

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

Notes

Definition:

logΓ(x)=log ⁣0tx1etdt.\log|\Gamma(x)| = \log\!\left| \int_0^\infty t^{x-1} e^{-t}\, dt \right|.

For positive integer n, Γ(n)=(n1)!\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.0000, 3.1781, 359.1342])