{"record":{"id":"720850b895339a90","repo":"jax-ml/jax","slug":"dtype-argument-to-rayleigh-must-be-a-float-dtype","errorCode":null,"errorMessage":"dtype argument to `rayleigh` must be a float dtype, got {dtype}","messagePattern":"dtype argument to `rayleigh` must be a float dtype, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/random/core.py","lineNumber":3203,"sourceCode":"      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 dtype and with shape given by ``shape`` if\n    ``shape`` is not None, or else by ``scale.shape``.\n  \"\"\"\n  key, _ = _check_prng_key(\"rayleigh\", 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(\"dtype argument to `rayleigh` must be a float \"\n                     f\"dtype, got {dtype}\")\n  shape = _check_broadcast_shapes(\"rayleigh\", shape, scale)\n  out_sharding = canonicalize_sharding_for_samplers(out_sharding, \"rayleigh\", shape)\n  _check_all_safe_to_cast(\"rayleigh\", dtype, scale)\n  return maybe_auto_axes(_rayleigh, out_sharding,\n                         shape=shape, dtype=dtype)(key, scale)\n\n@jit(static_argnums=(2, 3))\ndef _rayleigh(key, scale, shape, dtype) -> Array:\n  u = uniform(key, shape, dtype)\n  scale = scale.astype(dtype)\n  scale = jnp.broadcast_to(scale, shape)\n  log_u = lax.log(u)\n  n_two = lax._const(scale, -2)\n  sqrt_u = lax.sqrt(lax.mul(log_u, n_two))\n  ray = lax.mul(scale, sqrt_u)\n  return ray\n","sourceCodeStart":3185,"sourceCodeEnd":3221,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/random/core.py#L3185-L3221","documentation":"jax.random.rayleigh only accepts floating-point dtypes for its dtype argument (default float). Any non-float dtype (int, bool, complex) fails dtypes.issubdtype(dtype, np.floating) and raises this ValueError before broadcast/cast checks run.","triggerScenarios":"Calling jax.random.rayleigh(key, scale, shape, dtype=np.uint8) or passing a complex/integer dtype from configuration.","commonSituations":"Parametrizing a sampling utility with a single dtype shared across discrete and continuous samplers; passing np.int_ when generating counts instead of magnitudes.","solutions":["Pass np.float32/np.float64 or omit dtype","Cast integer scale arrays to float so dtype inference is consistent"],"exampleFix":"// before\nr = jax.random.rayleigh(key, scale, dtype=jnp.int32)\n// after\nr = jax.random.rayleigh(key, scale, dtype=jnp.float32)","handlingStrategy":"validation","validationCode":"import numpy as np\nif dtype is not None:\n    assert np.issubdtype(np.dtype(dtype).type, np.floating), f'rayleigh needs float dtype, got {dtype}'","typeGuard":"def is_float_dtype(d) -> bool:\n    import numpy as np\n    return d is None or np.issubdtype(np.dtype(d).type, np.floating)","tryCatchPattern":null,"preventionTips":["Cast integer scale arrays to float before sampling","Centralize dtype validation in sampling utilities"],"tags":["jax","random","dtype-validation"],"backgroundTag":"invalid-dtype-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}