{"record":{"id":"f99ee73d8e51b335","repo":"jax-ml/jax","slug":"integer-argument-required-got-dtype-arr-dtype","errorCode":null,"errorMessage":"integer argument required; got dtype={arr.dtype}","messagePattern":"integer argument required; got dtype=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/reductions.py","lineNumber":215,"sourceCode":"                        else dtypes.finfo(a_dtype).max, dtype=a_dtype)\n  try:\n    return literals.TypedNdArray(np.array(init_val, dtype=a_dtype))\n  except OverflowError:\n    assert dtypes.issubdtype(a_dtype, np.integer)\n    sign, info = np.sign(init_val), dtypes.iinfo(a_dtype)\n    return literals.TypedNdArray(np.array(info.min if sign < 0 else info.max, dtype=a_dtype))\n\ndef _cast_to_bool(operand: Array) -> Array:\n  if dtypes.issubdtype(operand.dtype, np.complexfloating):\n    operand = operand.real\n  return lax.convert_element_type(operand, np.bool_)\n\ndef _cast_to_numeric(operand: Array) -> Array:\n  return promote_dtypes_numeric(operand)[0]\n\ndef _require_integer(arr: Array) -> Array:\n  if not dtypes.isdtype(arr.dtype, (\"bool\", \"integral\")):\n    raise ValueError(f\"integer argument required; got dtype={arr.dtype}\")\n  return arr\n\ndef _ensure_optional_axes(x: Axis) -> Axis:\n  def force(x):\n    if x is None:\n      return None\n    try:\n      return operator.index(x)\n    except TypeError:\n      return tuple(i if isinstance(i, str) else operator.index(i) for i in x)\n  return core.concrete_or_error(\n    force, x, \"The axis argument must be known statically.\")\n\n\n@api.jit(static_argnames=('axis', 'dtype', 'keepdims', 'promote_integers'), inline=True)\ndef _reduce_sum(a: ArrayLike, axis: Axis = None, dtype: DTypeLike | None = None,\n                out: None = None, keepdims: bool = False,\n                initial: ArrayLike | None = None, where: ArrayLike | None = None,","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/reductions.py#L197-L233","documentation":"An internal JAX reductions helper requires an integer (or boolean) dtype array but received a floating-point or other non-integral dtype. This guard is used where indices/axes semantics are assumed.","triggerScenarios":"Triggered by internal paths in jax._src.numpy.reductions (e.g. argsort-adjacent or count-based helpers) when an array with float dtype reaches a helper expecting integral input; typically surfaced via public APIs like jnp.count_nonzero or reduction internals receiving float data where ints are required.","commonSituations":"Passing float arrays where an index/count array is expected; dtype promotion unexpectedly producing floats (e.g. via weak typing or jnp.asarray of Python floats).","solutions":["Cast the input to an integer dtype before the call: arr.astype(jnp.int32)","Check the argument types of the public API you called — this helper is internal, so the real mistake is in the caller's data","Inspect the stack trace to find which public jnp function routed here and validate its arguments"],"exampleFix":"// before\nresult = jnp.count_nonzero(mask, axis=axis)  # mask is float\n// after\nresult = jnp.count_nonzero(mask.astype(bool), axis=axis)","handlingStrategy":"validation","validationCode":"arr = jnp.asarray(arr)\nif not jnp.issubdtype(arr.dtype, jnp.integer):\n    arr = arr.astype(jnp.int32)","typeGuard":"def is_integer_array(a) -> bool:\n    import jax.numpy as jnp\n    return jnp.issubdtype(jnp.asarray(a).dtype, jnp.integer)","tryCatchPattern":null,"preventionTips":["Cast index/count arrays to int dtypes explicitly","Watch for float promotion when mixing arrays with Python floats"],"tags":["jax","reductions","dtype","internal"],"backgroundTag":"dtype-validation-failed","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}