{"record":{"id":"02564fd219b3ebf8","repo":"jax-ml/jax","slug":"dtype-argument-to-double-sided-maxwell-must-be-a","errorCode":null,"errorMessage":"dtype argument to `double_sided_maxwell` must be a float dtype, got {dtype}","messagePattern":"dtype argument to `double_sided_maxwell` must be a float dtype, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/random/core.py","lineNumber":2923,"sourceCode":"  where :math:`z = (x - \\mu) / \\sigma`, with the center :math:`\\mu` specified by\n  ``loc`` and the scale :math:`\\sigma` specified by ``scale``.\n\n  Args:\n    key: a PRNG key.\n    loc: The location parameter of the distribution.\n    scale: The scale parameter of the distribution.\n    shape: The shape added to the parameters loc and scale broadcastable shape.\n    dtype: The type used for samples.\n\n  Returns:\n    A jnp.array of samples.\n\n  \"\"\"\n  key, _ = _check_prng_key(\"double_sided_maxwell\", 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 `double_sided_maxwell` must be a float\"\n                     f\" dtype, got {dtype}\")\n  shape = core.canonicalize_shape(shape)\n  return _double_sided_maxwell(key, loc, scale, shape, dtype)\n\n\n@jit(static_argnums=(3, 4))\ndef _double_sided_maxwell(key, loc, scale, shape, dtype) -> Array:\n  params_shapes = lax.broadcast_shapes(np.shape(loc), np.shape(scale))\n  if not shape:\n    shape = params_shapes\n\n  shape = shape + params_shapes\n  maxwell_key, rademacher_key = _split(key)\n  maxwell_rvs = maxwell(maxwell_key, shape=shape, dtype=dtype)\n  # Generate random signs for the symmetric variates.\n  random_sign = rademacher(rademacher_key, shape=shape, dtype=dtype)\n  assert random_sign.shape == maxwell_rvs.shape\n","sourceCodeStart":2905,"sourceCodeEnd":2941,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/random/core.py#L2905-L2941","documentation":"jax.random.double_sided_maxwell validates its optional dtype argument and only accepts floating-point dtypes. The dtype is canonicalized via dtypes.check_and_canonicalize_user_dtype (defaulting to Python float) and then checked with dtypes.issubdtype(dtype, np.floating). Passing any integer, bool, or complex dtype raises this ValueError before sampling.","triggerScenarios":"Calling jax.random.double_sided_maxwell(key, loc, scale, shape, dtype=np.int32), dtype=jnp.bfloat16 is fine but dtype=jnp.complex64 or any np.integer/np.bool_ dtype is not.","commonSituations":"Copy-pasting a dtype from another sampler (e.g. geometric which requires int), passing a dtype inferred from an integer array, or passing the string 'int32' instead of a float dtype.","solutions":["Pass a float dtype such as np.float32, jnp.float32, or np.float64, or omit dtype to use the default","If you got the dtype from other data, cast it first: np.float32 if np.issubdtype(d, np.floating) else np.float32","Check for accidental bool/int constants like dtype=0 or dtype=int"],"exampleFix":"// before\nsamples = jax.random.double_sided_maxwell(key, 0.0, 1.0, (1000,), dtype=np.int32)\n// after\nsamples = jax.random.double_sided_maxwell(key, 0.0, 1.0, (1000,), dtype=np.float32)","handlingStrategy":"validation","validationCode":"import numpy as np\n\ndef safe_double_sided_maxwell(key, loc, scale, shape, dtype=None):\n    if dtype is not None and not np.issubdtype(np.dtype(dtype).type, np.floating):\n        raise ValueError('dtype must be float; got %s' % dtype)\n    return jax.random.double_sided_maxwell(key, loc, scale, shape, dtype)","typeGuard":"def is_float_dtype(dtype) -> bool:\n    import numpy as np, jax.numpy as jnp\n    if dtype is None or dtype is float: return True\n    try: d = jnp.dtype(dtype)\n    except TypeError: return False\n    return np.issubdtype(d.type, np.floating)","tryCatchPattern":null,"preventionTips":["Default dtype-aware wrappers around jax.random samplers","Keep one dtype-config for continuous samplers (float) and another for discrete (int)"],"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"}