{"record":{"id":"157b9f5b31d51613","repo":"jax-ml/jax","slug":"integer-np-round-not-implemented-for-decimals-0","errorCode":null,"errorMessage":"integer np.round not implemented for decimals < 0","messagePattern":"integer np\\.round not implemented for decimals < 0","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":3481,"sourceCode":"    >>> jnp.round(x)\n    Array([2., 3., 6.], dtype=float32)\n    >>> jnp.round(x, decimals=2)\n    Array([1.53, 3.27, 6.15], dtype=float32)\n\n    For values exactly halfway between rounded values:\n\n    >>> x1 = jnp.array([10.5, 21.5, 12.5, 31.5])\n    >>> jnp.round(x1)\n    Array([10., 22., 12., 32.], dtype=float32)\n  \"\"\"\n  a = util.ensure_arraylike(\"round\", a)\n  decimals = core.concrete_or_error(operator.index, decimals, \"'decimals' argument of jnp.round\")\n  if out is not None:\n    raise NotImplementedError(\"The 'out' argument to jnp.round is not supported.\")\n  dtype = a.dtype\n  if issubdtype(dtype, np.integer):\n    if decimals < 0:\n      raise NotImplementedError(\n        \"integer np.round not implemented for decimals < 0\")\n    return a  # no-op on integer types\n\n  def _round_float(x: ArrayLike) -> Array:\n    if decimals == 0:\n      return lax.round(x, lax.RoundingMethod.TO_NEAREST_EVEN)\n\n    # TODO(phawkins): the strategy of rescaling the value isn't necessarily a\n    # good one since we may be left with an incorrectly rounded value at the\n    # end due to precision problems. As a workaround for float16, convert to\n    # float32,\n    x = lax.convert_element_type(x, np.float32) if dtype == np.float16 else x\n    factor = lax._const(x, 10 ** decimals)\n    out = lax.div(lax.round(lax.mul(x, factor),\n                            lax.RoundingMethod.TO_NEAREST_EVEN), factor)\n    return lax.convert_element_type(out, dtype) if dtype == np.float16 else out\n\n  if decimals > np.log10(dtypes.finfo(dtype).max):","sourceCodeStart":3463,"sourceCodeEnd":3499,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L3463-L3499","documentation":"jnp.round is a no-op for integer dtypes because integers cannot be rounded to fractional digits. Rounding integer arrays to negative decimals (i.e. rounding to tens/hundreds) is not implemented and raises NotImplementedError.","triggerScenarios":"jnp.round(jnp.array([123], dtype=jnp.int32), decimals=-1). decimals >= 0 on integers is fine (no-op).","commonSituations":"Porting NumPy code that rounds integers to significant figures (decimals=-2); generic rounding helpers where dtype is caller-controlled.","solutions":["Convert to float before rounding: jnp.round(a.astype(jnp.float32), decimals=-1) (cast back if needed)","For pure integer math to nearest 10: ((a + 5) // 10) * 10","Guard integer inputs to skip the round call when decimals < 0 is not required"],"exampleFix":"// before\njnp.round(int_arr, decimals=-1)\n// after\njnp.round(int_arr.astype(jnp.float32), decimals=-1).astype(jnp.int32)","handlingStrategy":"type-guard","validationCode":"if jnp.issubdtype(a.dtype, jnp.integer) and decimals < 0:\n    a = a.astype(jnp.float32)","typeGuard":"def needs_float_round(a, decimals) -> bool:\n    return jnp.issubdtype(a.dtype, jnp.integer) and decimals < 0","tryCatchPattern":null,"preventionTips":["Skip rounding integer arrays or cast to float for decimals < 0","Use integer arithmetic ((a + 5) // 10) * 10 for nearest-10 rounding"],"tags":["jax","round","integer-dtype","notimplementederror"],"backgroundTag":"unsupported-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}