{"record":{"id":"a9fc1f960b1e482d","repo":"jax-ml/jax","slug":"trunc-div-supports-only-integer-types-got-self-m","errorCode":null,"errorMessage":"trunc_div supports only integer types, got {self.mlir_dtype}","messagePattern":"trunc_div supports only integer types, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/mosaic/gpu/fragmented_array.py","lineNumber":1635,"sourceCode":"      return self._e8m0_reciprocal()\n    return self._pointwise(lambda s, o: arith.divf(o, s), other)\n\n  def __floordiv__(self, other):\n    if isinstance(self.mlir_dtype, ir.FloatType):\n      return self._pointwise(\n          lambda s, o: mlir_math.floor(arith.divf(s, o)), other\n      )\n    elif isinstance(self.mlir_dtype, ir.IntegerType):\n      if self.is_signed:\n        return self._pointwise(arith.floordivsi, other)\n      else:\n        return self._pointwise(arith.divui, other)\n    else:\n      return NotImplemented\n\n  def trunc_div(self, other):\n    if not isinstance(self.mlir_dtype, ir.IntegerType):\n      raise ValueError(\n          f\"trunc_div supports only integer types, got {self.mlir_dtype}\"\n      )\n    if self.is_signed:\n      return self._pointwise(arith.divsi, other)\n    else:\n      return self._pointwise(arith.divui, other)\n\n  def __rfloordiv__(self, other):\n    if isinstance(self.mlir_dtype, ir.FloatType):\n      return self._pointwise(\n          lambda s, o: mlir_math.floor(arith.divf(o, s)), other\n      )\n    elif isinstance(self.mlir_dtype, ir.IntegerType):\n      if self.is_signed:\n        return self._pointwise(lambda s, o: arith.floordivsi(o, s), other)\n      else:\n        return self._pointwise(lambda s, o: arith.divui(o, s), other)\n    else:","sourceCodeStart":1617,"sourceCodeEnd":1653,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/mosaic/gpu/fragmented_array.py#L1617-L1653","documentation":"FragmentedArray.trunc_div lowers to arith.divsi/divui, which only exist for integer types. If the array's mlir_dtype is a float (f16/bf16/f32), there is no signed/unsigned truncating division to emit, so it raises ValueError and asks you to use float division instead.","triggerScenarios":"Calling trunc_div (or an API that dispatches to it, like _div for integer inputs) on a FragmentedArray whose dtype is a FloatType, e.g. arr.trunc_div(other) where arr is f32.","commonSituations":"Generic kernel code that picks trunc_div for 'round toward zero' semantics without checking dtype; reusing integer-kernel helper code with float operands; dtype parameterized by user config so integers work but float configs crash.","solutions":["Use float division (__truediv__/arith.divf) for float dtypes","Branch on isinstance(arr.mlir_dtype, ir.IntegerType) before choosing trunc_div","If C-style truncation of floats is needed, compute divf then convert toward zero explicitly (e.g. floor for positive semantics)"],"exampleFix":"# before\nq = a.trunc_div(b)  # a is f32\n# after\nq = a / b  # arith.divf for float types","handlingStrategy":"type-guard","validationCode":"from jax._src.lib import _mlir_dialects as d\nassert isinstance(x.mlir_dtype, d.ir.IntegerType), \"trunc_div needs an integer dtype\"","typeGuard":"def is_int_frag(x) -> bool:\n    from jax._src.lib import _mlir_dialects as d\n    return isinstance(x.mlir_dtype, d.ir.IntegerType)","tryCatchPattern":"try:\n    q = x.trunc_div(y)\nexcept ValueError as e:\n    if 'trunc_div' in str(e):\n        q = x / y\n    else:\n        raise","preventionTips":["Dispatch division by dtype: trunc_div for ints, / for floats","Wrap dtype-dependent op selection in a helper"],"tags":["jax","mosaic-gpu","division","dtype-check","integer-only"],"backgroundTag":"wrong-dtype-for-operation","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}