jax-ml/jax · error · ValueError
method argument to `loggamma` must be one of {'exact', 'appr
Error message
method argument to `loggamma` must be one of {'exact', 'approximate'}, got {method!r} What it means
jax.random.loggamma accepts only method='exact' or method='approximate', mirroring jax.random.gamma since it is the log-space variant of the same sampler. Any other value is rejected with ValueError because no other sampling algorithm exists.
Source
Thrown at jax/_src/random/core.py:1751
out_sharding: Optional. Specifies how the output array should be sharded
across devices in multi-device computation. Can be a
:class:`~jax.sharding.NamedSharding`, a :class:`~jax.sharding.PartitionSpec`
(``P``), or ``None`` (default). When specified, the output will be sharded
according to the given sharding specification. Primarily used in explicit
sharding mode.
See the `explicit sharding tutorial <https://docs.jax.dev/en/latest/parallel.html>`_
for more details.
Returns:
A random array with the specified dtype and with shape given by ``shape`` if
``shape`` is not None, or else by ``a.shape``.
See Also:
gamma : standard gamma sampler.
"""
key, _ = _check_prng_key("loggamma", key)
if method not in {'exact', 'approximate'}:
raise ValueError("method argument to `loggamma` must be one of "
f"{{'exact', 'approximate'}}, got {method!r}")
dtype = dtypes.check_and_canonicalize_user_dtype(
float if dtype is None else dtype)
if not dtypes.issubdtype(dtype, np.floating):
raise ValueError(f"dtype argument to `gamma` must be a float "
f"dtype, got {dtype}")
if shape is not None:
shape = core.canonicalize_shape(shape)
out_sharding = canonicalize_sharding(out_sharding, "loggamma")
if method == 'approximate':
return maybe_auto_axes(_gamma_approx, out_sharding, shape=shape,
dtype=dtype, log_space=True)(key, a)
return maybe_auto_axes(_gamma, out_sharding, shape=shape, dtype=dtype, log_space=True)(key, a)
@jit(static_argnames=('shape', 'dtype', 'log_space'))
def _gamma(key, a, shape, dtype, log_space=False) -> Array:
if shape is None:View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use method='exact' (default) or method='approximate' verbatim.
- Validate config-driven method strings against the allowed set before use.
- Omit the method argument to get the 'exact' default.
Example fix
// before lg = jax.random.loggamma(key, 0.01, method=None) // after lg = jax.random.loggamma(key, 0.01, method='exact')
Defensive patterns
Strategy: validation
Validate before calling
method = method or 'exact'
assert method in {'exact', 'approximate'} Type guard
def is_valid_loggamma_method(method: str) -> bool:
return method in {'exact', 'approximate'} Prevention
- Omit method for the default 'exact'.
- Centralize method validation for gamma-family samplers.
When it happens
Trigger: Calling jax.random.loggamma(key, a, method=None), method='Fast', or any string not in {'exact','approximate'}.
Common situations: Sharing a method setting across gamma/loggamma/beta/dirichlet calls from one config string; typos; assuming None selects a default (the default is 'exact' via the keyword default, but explicitly passing None is not allowed).
Related errors
- method argument to `gamma` must be one of {'exact', 'approxi
- method argument to `poisson` must be one of {'exact', 'appro
- method argument to `chisquare` must be one of {'exact', 'app
- dirichlet requires alpha.ndim >= 1, got alpha.ndim == {}
- dtype argument to `exponential` must be a float dtype, got {
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/bb7951814638f561.
Report an issue: GitHub.