{"record":{"id":"9e5103b24c2b7487","repo":"jax-ml/jax","slug":"the-two-inputs-to-nextafter-must-have-the-same-d","errorCode":null,"errorMessage":"The two inputs to `nextafter` must have the same dtype, but got {x.dtype} and {y.dtype}","messagePattern":"The two inputs to `nextafter` must have the same dtype, but got (.+?) and (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/utils.py","lineNumber":369,"sourceCode":"\ndef sign_lowering_helper(x):\n  if jnp.issubdtype(x.dtype, jnp.unsignedinteger):\n    return (x != 0).astype(x.dtype)\n\n  if jnp.issubdtype(x.dtype, jnp.integer):\n    return (x > 0).astype(x.dtype) - (x < 0).astype(x.dtype)\n\n  if jnp.issubdtype(x.dtype, jnp.floating):\n    out = (x > 0.).astype(x.dtype) - (x < 0.).astype(x.dtype)\n    return jnp.where(jnp.isnan(x), jnp.nan, out)\n\n  raise NotImplementedError(f\"sign_lowering_helper not implemented for {x.dtype}\")\n\n\n# based on https://github.com/openxla/xla/blob/a7a09d56c3599123f8148bbf3e44c9ebc04624b9/xla/mlir_hlo/mhlo/transforms/chlo_legalize_to_hlo/chlo_legalize_to_hlo.cc#L1339-L1422\ndef nextafter_lowering_helper(x, y):\n  if x.dtype != y.dtype:\n    raise ValueError(\n        \"The two inputs to `nextafter` must have the same dtype, but got\"\n        f\" {x.dtype} and {y.dtype}\"\n    )\n\n  if x.dtype not in (jnp.float32, jnp.float64):\n    raise ValueError(\n        f\"`nextafter` only supports float32 and float64, but got {x.dtype}\"\n    )\n\n  jnp_float, jnp_uint, np_float, np_uint, np_int = (\n      jnp.float32, jnp.uint32, np.float32, np.uint32, np.int32,\n  ) if x.dtype == jnp.float32 else (\n      jnp.float64, jnp.uint64, np.float64, np.uint64, np.int64,\n  )\n\n  bitwidth = dtypes.itemsize_bits(x.dtype)\n\n  x_as_int = x.view(jnp_uint)","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/utils.py#L351-L387","documentation":"pallas.utils.nextafter_lowering_helper requires both inputs to have identical dtypes; the bitwise next-representable-float algorithm is dtype-specific. Mismatched dtypes (float32 vs float64, or int vs float) raise ValueError.","triggerScenarios":"Calling jnp.nextafter(x_f32, y_f64) or with an integer operand inside a pallas triton kernel; mixing Python scalars that promote unexpectedly.","commonSituations":"Mixed-precision kernels; operands from different tensors where one was upcast earlier in the pipeline.","solutions":["Promote both to a common dtype: x, y = jax.lax.convert_element_type to same float type","Ensure both operands originate from tensors of the same dtype"],"exampleFix":"# before\njnp.nextafter(x_f32, y_f64)\n# after\njnp.nextafter(x_f32, y_f64.astype(jnp.float32))","handlingStrategy":"type-guard","validationCode":"y = y.astype(x.dtype)","typeGuard":"def same_dtype(x, y): return x.dtype == y.dtype","tryCatchPattern":null,"preventionTips":["Promote operands to one dtype before nextafter"],"tags":["jax","pallas","triton","dtype","nextafter"],"backgroundTag":"dtype-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}