{"record":{"id":"bb7951814638f561","repo":"jax-ml/jax","slug":"method-argument-to-loggamma-must-be-one-of-exa","errorCode":null,"errorMessage":"method argument to `loggamma` must be one of {'exact', 'approximate'}, got {method!r}","messagePattern":"method argument to `loggamma` must be one of (.+?), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/random/core.py","lineNumber":1751,"sourceCode":"    out_sharding: Optional. Specifies how the output array should be sharded\n      across devices in multi-device computation. Can be a\n      :class:`~jax.sharding.NamedSharding`, a :class:`~jax.sharding.PartitionSpec`\n      (``P``), or ``None`` (default). When specified, the output will be sharded\n      according to the given sharding specification. Primarily used in explicit\n      sharding mode.\n      See the `explicit sharding tutorial <https://docs.jax.dev/en/latest/parallel.html>`_\n      for more details.\n\n  Returns:\n    A random array with the specified dtype and with shape given by ``shape`` if\n    ``shape`` is not None, or else by ``a.shape``.\n\n  See Also:\n    gamma : standard gamma sampler.\n  \"\"\"\n  key, _ = _check_prng_key(\"loggamma\", key)\n  if method not in {'exact', 'approximate'}:\n    raise ValueError(\"method argument to `loggamma` must be one of \"\n                     f\"{{'exact', 'approximate'}}, got {method!r}\")\n  dtype = dtypes.check_and_canonicalize_user_dtype(\n      float if dtype is None else dtype)\n  if not dtypes.issubdtype(dtype, np.floating):\n    raise ValueError(f\"dtype argument to `gamma` must be a float \"\n                     f\"dtype, got {dtype}\")\n  if shape is not None:\n    shape = core.canonicalize_shape(shape)\n  out_sharding = canonicalize_sharding(out_sharding, \"loggamma\")\n  if method == 'approximate':\n    return maybe_auto_axes(_gamma_approx, out_sharding, shape=shape,\n                           dtype=dtype, log_space=True)(key, a)\n  return maybe_auto_axes(_gamma, out_sharding, shape=shape, dtype=dtype, log_space=True)(key, a)\n\n\n@jit(static_argnames=('shape', 'dtype', 'log_space'))\ndef _gamma(key, a, shape, dtype, log_space=False) -> Array:\n  if shape is None:","sourceCodeStart":1733,"sourceCodeEnd":1769,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/random/core.py#L1733-L1769","documentation":"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.","triggerScenarios":"Calling jax.random.loggamma(key, a, method=None), method='Fast', or any string not in {'exact','approximate'}.","commonSituations":"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).","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."],"exampleFix":"// before\nlg = jax.random.loggamma(key, 0.01, method=None)\n\n// after\nlg = jax.random.loggamma(key, 0.01, method='exact')","handlingStrategy":"validation","validationCode":"method = method or 'exact'\nassert method in {'exact', 'approximate'}","typeGuard":"def is_valid_loggamma_method(method: str) -> bool:\n    return method in {'exact', 'approximate'}","tryCatchPattern":null,"preventionTips":["Omit method for the default 'exact'.","Centralize method validation for gamma-family samplers."],"tags":["jax","random","loggamma","method","input-validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}