{"record":{"id":"6cc6681e2f4b2238","repo":"jax-ml/jax","slug":"dtype-argument-to-t-must-be-a-float-dtype-got","errorCode":null,"errorMessage":"dtype argument to `t` must be a float dtype, got {dtype}","messagePattern":"dtype argument to `t` must be a float dtype, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/random/core.py","lineNumber":2628,"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 ``df.shape``.\n  \"\"\"\n  key, _ = _check_prng_key(\"t\", 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 `t` must be a float \"\n                     f\"dtype, got {dtype}\")\n  shape = _check_broadcast_shapes(\"t\", shape, df)\n  out_sharding = canonicalize_sharding_for_samplers(out_sharding, \"t\", shape)\n  _check_all_safe_to_cast(\"t\", dtype, df)\n  return maybe_auto_axes(_t, out_sharding,\n                         shape=shape, dtype=dtype)(key, df)\n\n@jit(static_argnums=(2, 3))\ndef _t(key, df, shape, dtype) -> Array:\n  if shape is None:\n    shape = np.shape(df)\n  else:\n    _check_shape(\"t\", shape, np.shape(df))\n\n  df = lax.convert_element_type(df, dtype)\n  key_n, key_g = _split(key)\n  n = normal(key_n, shape, dtype)\n  two = lax._const(n, 2)","sourceCodeStart":2610,"sourceCodeEnd":2646,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/random/core.py#L2610-L2646","documentation":"jax.random.t (Student's t) requires a floating-point dtype; the sampler combines gamma and normal variates in float arithmetic. Non-float dtypes raise ValueError. Additionally shape must broadcast against df.shape and df must be safely castable to dtype, both checked right after this dtype check.","triggerScenarios":"jax.random.t(key, df, dtype=jnp.int32) or any dtype failing dtypes.issubdtype(dtype, np.floating).","commonSituations":"Sampling noise models with a config-supplied dtype; porting scipy.stats.t code; using one dtype constant across a benchmark suite of samplers.","solutions":["Pass jnp.float32/jnp.float64 or omit dtype.","Verify shape broadcasts against np.shape(df) to avoid the follow-up _check_broadcast_shapes error.","Validate configurable dtypes against np.floating before the call."],"exampleFix":"// before\nx = jax.random.t(key, 5.0, dtype=jnp.int32)\n\n// after\nx = jax.random.t(key, 5.0, dtype=jnp.float32)","handlingStrategy":"type-guard","validationCode":"from jax._src import dtypes\nassert dtypes.issubdtype(dtypes.check_and_canonicalize_user_dtype(dtype or float), np.floating)","typeGuard":"def is_float_dtype(dtype) -> bool:\n    from jax._src import dtypes\n    import numpy as np\n    return dtypes.issubdtype(dtypes.check_and_canonicalize_user_dtype(dtype or float), np.floating)","tryCatchPattern":null,"preventionTips":["Ensure shape broadcasts against df.shape as well."],"tags":["jax","random","t-distribution","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"}