{"record":{"id":"a2acdb60ba0622c5","repo":"jax-ml/jax","slug":"dtype-argument-to-jnp-std-must-be-inexact-got-dt","errorCode":null,"errorMessage":"dtype argument to jnp.std must be inexact; got {dtype}","messagePattern":"dtype argument to jnp\\.std must be inexact; got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/reductions.py","lineNumber":1282,"sourceCode":"    Array([[2., 1., 1., 0.]], dtype=float32)\n  \"\"\"\n  if correction is None:\n    correction = ddof\n  elif not isinstance(ddof, int) or ddof != 0:\n    raise ValueError(\"ddof and correction can't be provided simultaneously.\")\n  a = ensure_arraylike(\"std\", a)\n  return _std(a, axis=_ensure_optional_axes(axis), dtype=dtype, out=out, correction=correction, keepdims=keepdims,\n              where=where, mean=mean)\n\n@api.jit(static_argnames=('axis', 'dtype', 'keepdims'))\ndef _std(a: Array, *, axis: Axis = None, dtype: DTypeLike | None = None,\n         out: None = None, correction: int | float = 0, keepdims: bool = False,\n         where: ArrayLike | None = None, mean: ArrayLike | None = None) -> Array:\n  where = check_where(\"std\", where)\n  if dtype is not None:\n    dtype = dtypes.check_and_canonicalize_user_dtype(dtype, \"std\")\n    if not dtypes.issubdtype(dtype, np.inexact):\n      raise ValueError(f\"dtype argument to jnp.std must be inexact; got {dtype}\")\n  if out is not None:\n    raise NotImplementedError(\"The 'out' argument to jnp.std is not supported.\")\n  return lax.sqrt(var(a, axis=axis, dtype=dtype, correction=correction,\n                      keepdims=keepdims, where=where, mean=mean))\n\n\n@export\ndef ptp(a: ArrayLike, axis: Axis = None, out: None = None,\n        keepdims: bool = False) -> Array:\n  r\"\"\"Return the peak-to-peak range along a given axis.\n\n  JAX implementation of :func:`numpy.ptp`.\n\n  Args:\n    a: input array.\n    axis: optional, int or sequence of ints, default=None. Axis along which the\n      range is computed. If None, the range is computed on the flattened array.\n    keepdims: bool, default=False. If true, reduced axes are left in the result","sourceCodeStart":1264,"sourceCodeEnd":1300,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/reductions.py#L1264-L1300","documentation":"jnp.std computes a floating-point result, so its dtype parameter must be an inexact type (float or complex). Passing an integer or boolean dtype raises ValueError after dtype canonicalization.","triggerScenarios":"Calling jnp.std(x, dtype=jnp.int32) or dtype=np.int64; any non-inexact canonicalized dtype reaching _std.","commonSituations":"Copying dtype from the input array (e.g. dtype=x.dtype where x is int) to preserve precision; generic reduction helpers that forward a user dtype verbatim.","solutions":["Omit dtype — JAX picks the default inexact dtype for integer inputs","Pass an inexact dtype such as jnp.float32 or jnp.float64","In generic code, map integer dtypes via jnp.promote_types(x.dtype, jnp.float32)"],"exampleFix":"// before\njnp.std(int_array, dtype=int_array.dtype)\n// after\njnp.std(int_array, dtype=jnp.promote_types(int_array.dtype, jnp.float32))","handlingStrategy":"type-guard","validationCode":"import jax.numpy as jnp, numpy as np\n\ndef std_dtype(x, dtype=None):\n    if dtype is None:\n        return None\n    if not np.issubdtype(dtype, np.inexact):\n        return jnp.promote_types(dtype, jnp.float32)\n    return dtype","typeGuard":"import numpy as np\n\ndef is_inexact(dtype) -> bool:\n    return np.issubdtype(dtype, np.inexact)","tryCatchPattern":null,"preventionTips":["Only forward float/complex dtypes to std/percentile-like APIs","In generic reducers, promote integer dtypes to float before passing","Add unit tests covering integer input arrays"],"tags":["jax","numpy","std","dtype-validation"],"backgroundTag":"unsupported-dtype-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}