{"record":{"id":"a746081d693b1ac2","repo":"jax-ml/jax","slug":"dtype-argument-to-exponential-must-be-a-float-dt","errorCode":null,"errorMessage":"dtype argument to `exponential` must be a float dtype, got {dtype}","messagePattern":"dtype argument to `exponential` must be a float dtype, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/random/core.py","lineNumber":1472,"sourceCode":"    dtype: optional, a float dtype for the returned values (default float64 if\n      jax_enable_x64 is true, otherwise float32).\n    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 shape and dtype.\n  \"\"\"\n  key, _ = _check_prng_key(\"exponential\", key)\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 `exponential` must be a float \"\n                     f\"dtype, got {dtype}\")\n  shape = core.canonicalize_shape(shape)\n  out_sharding = canonicalize_sharding_for_samplers(out_sharding, \"exponential\", shape)\n  return maybe_auto_axes(_exponential, out_sharding,\n                         shape=shape, dtype=dtype)(key)\n\n@jit(static_argnums=(1, 2))\ndef _exponential(key, shape, dtype) -> Array:\n  _check_shape(\"exponential\", shape)\n  u = uniform(key, shape, dtype)\n  # taking 1 - u to move the domain of log to (0, 1] instead of [0, 1)\n  return lax.neg(lax.log1p(lax.neg(u)))\n\n\ndef _gamma_one(key: Array, alpha, log_space) -> Array:\n  # Ref: A simple method for generating gamma variables, George Marsaglia and Wai Wan Tsang\n  # The algorithm can also be founded in:\n  # https://en.wikipedia.org/wiki/Gamma_distribution#Generating_gamma-distributed_random_variables","sourceCodeStart":1454,"sourceCodeEnd":1490,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/random/core.py#L1454-L1490","documentation":"jax.random.exponential only supports floating-point output dtypes because it computes samples via log-transformation of uniform bits. If the user passes an integer or complex dtype (e.g. jnp.int32), the float-domain math is not defined, so JAX rejects it with ValueError before tracing.","triggerScenarios":"Calling jax.random.exponential(key, shape, dtype=jnp.int32) or any non-floating dtype such as jnp.complex64, or a custom dtype alias that canonicalizes to an integer type.","commonSituations":"Copy-pasting dtype from a different sampler (e.g. rademacher or poisson which accept int dtypes) into exponential; a config file storing a single dtype used for many samplers; assuming dtype=None gives int like some older APIs.","solutions":["Pass a float dtype such as jnp.float32 (the default when dtype=None) or remove the dtype argument entirely.","If a configurable dtype must be used, validate dtypes.issubdtype(dtype, np.floating) before the call and coerce with float if not.","Audit shared dtype constants in your config so integer dtypes are not reused by float-only samplers."],"exampleFix":"// before\nx = jax.random.exponential(key, (1000,), dtype=jnp.int32)\n\n// after\nx = jax.random.exponential(key, (1000,), dtype=jnp.float32)","handlingStrategy":"type-guard","validationCode":"import jax.numpy as jnp, numpy as np\nfrom jax._src import dtypes\nassert dtypes.issubdtype(jnp.dtype(dtype).type, np.floating), 'exponential needs a float dtype'","typeGuard":"def is_float_dtype(dtype) -> bool:\n    return dtypes.issubdtype(jnp.dtype(dtype).type, np.floating)","tryCatchPattern":null,"preventionTips":["Default to omitting dtype for float samplers.","Keep one FLOAT_DTYPE constant for float-only samplers, separate from int samplers."],"tags":["jax","random","exponential","dtype","input-validation"],"backgroundTag":"invalid-dtype-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}