{"record":{"id":"99e69c727a999a1b","repo":"jax-ml/jax","slug":"method-argument-to-gamma-must-be-one-of-exact","errorCode":null,"errorMessage":"method argument to `gamma` must be one of {'exact', 'approximate'}, got {method!r}","messagePattern":"method argument to `gamma` must be one of (.+?), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/random/core.py","lineNumber":1686,"sourceCode":"      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    loggamma : sample gamma values in log-space, which can provide improved\n      accuracy for small values of ``a``.\n  \"\"\"\n  key, _ = _check_prng_key(\"gamma\", key)\n  if method not in {'exact', 'approximate'}:\n    raise ValueError(\"method argument to `gamma` 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_for_samplers(out_sharding, \"gamma\", shape)\n  if method == 'approximate':\n    return maybe_auto_axes(_gamma_approx, out_sharding,\n                           shape=shape, dtype=dtype)(key, a)\n  return maybe_auto_axes(_gamma, out_sharding, shape=shape, dtype=dtype)(key, a)\n\n\ndef loggamma(key: ArrayLike,\n             a: RealArray,\n             shape: Shape | None = None,","sourceCodeStart":1668,"sourceCodeEnd":1704,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/random/core.py#L1668-L1704","documentation":"jax.random.gamma accepts only method='exact' (Marsaglia-Tsang rejection sampling, used under jit) or method='approximate' (a faster, less accurate transform). Any other string (including typos or None) is rejected with ValueError because there is no fallback sampling algorithm.","triggerScenarios":"Calling jax.random.gamma(key, a, method='fast'), method=None, method=' Exact' (case/whitespace typo), or any string outside {'exact','approximate'}.","commonSituations":"Typos in hyperparameter configs; passing a method intended for a different library (e.g. numpy Generator method names); a version change where a previously tolerated value was removed or the argument was newly added.","solutions":["Use method='exact' (default) or method='approximate', matching exactly including case.","If the method comes from a config, validate it against {'exact','approximate'} at load time with a clear error listing valid values.","Check the jax.random.gamma docstring for your JAX version to confirm supported methods."],"exampleFix":"// before\nsamples = jax.random.gamma(key, 2.0, method='fast')\n\n// after\nsamples = jax.random.gamma(key, 2.0, method='approximate')","handlingStrategy":"validation","validationCode":"method = method or 'exact'\nassert method in {'exact', 'approximate'}, f\"invalid gamma method: {method!r}\"","typeGuard":"def is_valid_gamma_method(method: str) -> bool:\n    return method in {'exact', 'approximate'}","tryCatchPattern":null,"preventionTips":["Validate method strings when loading config.","Omit method to use the 'exact' default."],"tags":["jax","random","gamma","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"}