{"record":{"id":"8179085124b6a111","repo":"jax-ml/jax","slug":"mulhi-requires-integer-inputs-got-dtype","errorCode":null,"errorMessage":"mulhi requires integer inputs, got {dtype}","messagePattern":"mulhi requires integer inputs, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax_reference.py","lineNumber":118,"sourceCode":"bitwise_or = np.bitwise_or\nbitwise_xor = np.bitwise_xor\n\nadd = np.add\nsub = np.subtract\n\ndef mul(x, y, /, *, out_dtype=None):\n  if out_dtype is not None:\n    x = np.astype(x, out_dtype)\n    y = np.astype(y, out_dtype)\n  return np.multiply(x, y)\n\n\ndef mulhi(x, y):\n  x = np.asarray(x)\n  y = np.asarray(y)\n  dtype = x.dtype\n  if not np.issubdtype(dtype, np.integer):\n    raise TypeError(f'mulhi requires integer inputs, got {dtype}')\n  if dtype != y.dtype:\n    raise TypeError(\n        f'mulhi operands must have the same dtype, got {dtype} and {y.dtype}'\n    )\n  info = np.iinfo(dtype)\n  bits = info.bits\n  is_signed = np.issubdtype(dtype, np.signedinteger)\n  # For 64-bit inputs, use Python object dtype for arbitrary precision.\n  if bits == 64:\n    widen_dtype = np.dtype(object)\n  else:\n    widen_bits = bits * 2\n    widen_dtype = np.dtype(f'{\"i\" if is_signed else \"u\"}{widen_bits // 8}')\n  prod = x.astype(widen_dtype) * y.astype(widen_dtype)\n  return (prod >> bits).astype(dtype)\n\n\ndef div(lhs, rhs):","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax_reference.py#L100-L136","documentation":"jax.lax_reference.mulhi (the NumPy reference implementation of multiply-high) only accepts integer dtypes. Passing floats or other types raises TypeError.","triggerScenarios":"Calling lax_reference.mulhi(np.float32(1.0), np.float32(2.0)) or any non-integer input.","commonSituations":"Using mulhi for fixed-point arithmetic with accidentally promoted float arrays; testing against the reference implementation with default float jnp arrays.","solutions":["Cast inputs to an integer dtype: x.astype(np.int32)","Prevent implicit promotion to float upstream (e.g. division producing floats)"],"exampleFix":"# before\nlax_reference.mulhi(1.5, 2.0)\n# after\nlax_reference.mulhi(np.int32(3), np.int32(7))","handlingStrategy":"type-guard","validationCode":"assert np.issubdtype(np.asarray(x).dtype, np.integer)","typeGuard":"def is_int(x): return np.issubdtype(np.asarray(x).dtype, np.integer)","tryCatchPattern":null,"preventionTips":["Cast to explicit int dtype before fixed-point ops"],"tags":["jax","dtype","integer","mulhi","type-validation"],"backgroundTag":"jax-dtype-validation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}