{"record":{"id":"aad04388f0eb382e","repo":"jax-ml/jax","slug":"sign-lowering-helper-not-implemented-for-x-dtype","errorCode":null,"errorMessage":"sign_lowering_helper not implemented for {x.dtype}","messagePattern":"sign_lowering_helper not implemented for (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/utils.py","lineNumber":363,"sourceCode":"  if x.dtype == jnp.float32:\n    return _erf_inv_32_lowering_helper(x)\n  if x.dtype == jnp.float64:\n    return _erf_inv_64_lowering_helper(x)\n  raise NotImplementedError(f\"erf_inv_lowering_helper not implemented for {x.dtype}\")\n\n\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 (","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/utils.py#L345-L381","documentation":"pallas.utils.sign_lowering_helper only handles unsigned integers, signed integers, and floating types. Complex or other exotic dtypes raise NotImplementedError since sign is undefined/unsupported in the Triton lowering.","triggerScenarios":"Calling jnp.sign on a complex array inside a pallas triton kernel; also boolean inputs depending on subtype checks.","commonSituations":"Kernels operating on complex64/complex128 that branch through sign; generic numeric code reused across dtypes hitting the Triton path.","solutions":["Compute sign via real/imag decomposition: sign(x) = sign(x.real) + 1j*sign(x.imag) normalized, or handle complex outside the kernel","Cast/reduce to a supported dtype before the call"],"exampleFix":"# before\ns = jnp.sign(z_complex)  # inside pallas kernel\n# after\ns = jnp.sign(z.real) + 1j * jnp.sign(z.imag)","handlingStrategy":"type-guard","validationCode":"if not jnp.issubdtype(x.dtype, jnp.number) or jnp.issubdtype(x.dtype, jnp.complexfloating):\n    raise TypeError('sign unsupported in pallas for this dtype')","typeGuard":"def sign_supported(x):\n    return jnp.issubdtype(x.dtype, jnp.integer) or jnp.issubdtype(x.dtype, jnp.floating)","tryCatchPattern":null,"preventionTips":["Handle complex sign manually via real/imag parts"],"tags":["jax","pallas","triton","dtype","sign"],"backgroundTag":"unsupported-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}