Skip to main content

Module special

Module special 

Source
Expand description

Special functions: lgamma, digamma, erf, erfc, the exponentially scaled Bessel functions, the incomplete gamma and beta functions, polygamma, and zeta.

Each function is written once, against Builder, in the masked, vectorized style of XLA’s and JAX’s own implementations: loops carry a mask of the elements that have not converged, and the elements that have converged keep their state, so each element’s result does not depend on the other elements. The kernels run the algorithms on scalars (unary, binary, ternary); ruxla-prims runs the same code on IR to lower the primitives that JAX lowers by tracing such code.

The algorithms follow:

  • StableHLO’s decomposition of CHLO (ChloLegalizeToStablehlo.cpp) for lgamma, digamma, erf, erfc, bessel_i1e, polygamma, and zeta, which XLA expands;
  • jax._src.lax.special for igamma, igammac, igamma_grad_a, random_gamma_grad, bessel_i0e, and regularized_incomplete_beta.

The operations are evaluated in the same order, so the results match XLA up to the implementations of exp, log, sin, and the like, and up to the fusion of multiplications and additions.

Structs§

Carry
The values a Builder::while_loop carries: masks and floats.

Traits§

Builder
The operations the special functions are written with.

Functions§

bessel_i0e
exp(-|x|) I0(x), as jax._src.lax.special.bessel_i0e_impl.
bessel_i1e
exp(-|x|) I1(x), as StableHLO decomposes chlo.bessel_i1e.
digamma
The digamma function, the derivative of lgamma.
erf
The error function.
erf_inv
The inverse error function: M. Giles’ approximation, as StableHLO decomposes chlo.erf_inv.
erfc
The complementary error function.
eval_binary
Evaluates a special binary operation with a builder.
eval_unary
Evaluates a special unary operation with a builder.
igamma
The regularized lower incomplete gamma function P(a, x).
igamma_grad_a
The derivative of igamma(a, x) with respect to a.
igammac
The regularized upper incomplete gamma function Q(a, x).
lgamma
The logarithm of the absolute value of the gamma function.
polygamma
The polygamma function psi^(n)(x).
random_gamma_grad
The derivative of a sample x of Gamma(a, 1) with respect to a.
regularized_incomplete_beta
The regularized incomplete beta function I_x(a, b), by the continued fraction of DLMF 8.17.22 evaluated with the modified Lentz algorithm.
zeta
The Hurwitz zeta function zeta(x, q).