{"record":{"id":"caf4e8e6905db935","repo":"jax-ml/jax","slug":"output-is-signed-must-be-non-none-if-and-only-if-t","errorCode":null,"errorMessage":"output_is_signed must be non-None if and only if the MLIR type is an integer type, got {output_is_signed=} for {elt}","messagePattern":"output_is_signed must be non-None if and only if the MLIR type is an integer type, got (.+?) for (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/fragmented_array.py","lineNumber":2036,"sourceCode":"        return utils.bitcast(result_int, original_arg_ty)\n      else:\n        assert vec_bitwidth > 32\n        slice_len = 32 // utils.bitwidth(arg_ty.element_type)\n        offset = 0\n        slices = []\n        while offset < vec_len:\n          slice_end = min(offset + slice_len, vec_len)\n          args_slice = [utils.vector_slice(a, slice(offset, slice_end)) for a in args]\n          slices.append(fast_instr(*args_slice))\n          offset = slice_end\n        return utils.vector_concat(slices)\n    return fast_instr\n\n  def bitcast(\n      self, elt: ir.Type, *, output_is_signed: bool | None = None\n  ) -> FragmentedArray:\n    if (output_is_signed is not None) != isinstance(elt, ir.IntegerType):\n      raise TypeError(\n          \"output_is_signed must be non-None if and only if the MLIR type is an\"\n          f\" integer type, got {output_is_signed=} for {elt}\"\n      )\n\n    if elt == self.mlir_dtype:\n      return self\n    if utils.bitwidth(elt) != utils.bitwidth(self.mlir_dtype):\n      raise ValueError(\"Only bitcast between types of the same bitwidth supported\")\n    reg_type = self.registers.flat[0].type\n    if isinstance(reg_type, ir.VectorType):\n      reg_shape = ir.VectorType(reg_type).shape\n      ty = ir.VectorType.get(reg_shape, elt)\n    else:\n      ty = elt\n\n    return self._pointwise(\n        lambda x: arith.bitcast(ty, x), output_is_signed=output_is_signed, restrict_bitwidth=False\n    )","sourceCodeStart":2018,"sourceCodeEnd":2054,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/fragmented_array.py#L2018-L2054","documentation":"FragmentedArray.bitcast validates that output_is_signed must be non-None exactly when the target MLIR type elt is an integer type. Passing output_is_signed for a float target, or omitting it for an integer target, raises this TypeError.","triggerScenarios":"fa.bitcast(ir.F32Type.get(), output_is_signed=False) (signedness given for non-int), or fa.bitcast(ir.IntegerType.get_signless(32)) with output_is_signed=None (int target without signedness).","commonSituations":"Reinterpreting register bits between int and float for fast exponent tricks or quantization, and forgetting that Mosaic tracks signedness for integer types explicitly.","solutions":["For integer targets always pass output_is_signed=True/False","For float/other targets omit output_is_signed entirely","Use ir.IntegerType.get_signless(...) only together with explicit output_is_signed"],"exampleFix":"# before\nf = i32_frag.bitcast(ir.F32Type.get(), output_is_signed=False)\n# after\nf = i32_frag.bitcast(ir.F32Type.get())\n# and for int targets:\ni = f32_frag.bitcast(ir.IntegerType.get_signless(32), output_is_signed=True)","handlingStrategy":"validation","validationCode":"if (output_is_signed is not None) != isinstance(elt, ir.IntegerType):\n    raise TypeError('bitcast signedness/type mismatch')","typeGuard":"def bitcast_args_ok(elt, output_is_signed) -> bool:\n    return (output_is_signed is not None) == isinstance(elt, ir.IntegerType)","tryCatchPattern":null,"preventionTips":["Always pair integer targets with explicit output_is_signed","Omit output_is_signed for float targets"],"tags":["mosaic","gpu","bitcast","type-error","signedness"],"backgroundTag":"invalid-argument-combination","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}