{"record":{"id":"aa63f4d4d4a8eb31","repo":"jax-ml/jax","slug":"mask-dtype-mask-dtype-is-not-a-boolean-dtype","errorCode":null,"errorMessage":"mask.dtype={mask.dtype} is not a boolean dtype","messagePattern":"mask\\.dtype=(.+?) is not a boolean dtype","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic/sc_primitives.py","lineNumber":529,"sourceCode":"  \"\"\"Blocks until all subcores on the same core reach this instruction.\n\n  The barrier must be used with\n  :class:`jax.experimental.pallas.tpu_sc.VectorSubcoreMesh`.\n  \"\"\"\n  barrier_p.bind()\n\n\nscan_count_p = jax_core.Primitive(\"scan_count\")\nscan_count_p.multiple_results = True\n\n\n@scan_count_p.def_abstract_eval\ndef _scan_count_abstract_eval(x, mask):\n  if x.dtype not in (jnp.uint32, jnp.int32, jnp.float32):\n    raise NotImplementedError(\n        f\"x.dtype={x.dtype} must be uint32, int32 or float32\")\n  if not jnp.issubdtype(mask.dtype, jnp.bool):\n    raise TypeError(f\"mask.dtype={mask.dtype} is not a boolean dtype\")\n  if x.shape != mask.shape:\n    raise ValueError(f\"x.shape={x.shape} != mask.shape={mask.shape}\")\n  return jax_core.ShapedArray(x.shape, jnp.int32), mask\n\n\n@sc_lowering.register_lowering_rule(scan_count_p)\ndef _scan_count_lowering_rule(ctx: sc_lowering.LoweringRuleContext, x, mask):\n  del ctx  # Unused.\n  # Reverse, because the MLIR op returns the mask first.\n  return tpu.scan_count(mask, x)[::-1]\n\n\ndef scan_count(\n    x: jax.Array, mask: jax.Array | None = None\n) -> tuple[jax.Array, jax.Array]:\n  \"\"\"Computes the running duplicate occurrence count of the array.\n\n  Args:","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic/sc_primitives.py#L511-L547","documentation":"scan_count requires mask to have a boolean dtype; integer or float masks are rejected with a TypeError.","triggerScenarios":"scan_count(x, (x > 0).astype(jnp.int32)) or passing a validity bitmap stored as int8.","commonSituations":"Masks imported as int arrays from HLO dumps, tests, or external data; memory-optimized int masks.","solutions":["Cast: mask.astype(jnp.bool_)","Keep masks as outputs of comparisons (jnp.bool_ by default)"],"exampleFix":"// before\nscan_count(x, int_mask)\n\n// after\nscan_count(x, int_mask.astype(jnp.bool_))","handlingStrategy":"type-guard","validationCode":"if not jnp.issubdtype(mask.dtype, jnp.bool_):\n    mask = mask.astype(jnp.bool_)","typeGuard":"def is_bool_mask(mask) -> bool:\n    return jnp.issubdtype(mask.dtype, jnp.bool_)","tryCatchPattern":null,"preventionTips":["Convert stored int masks to bool at load","Generate masks from comparisons","Centralize mask validation"],"tags":["jax","pallas","sparsecore","scan-count","mask-dtype"],"backgroundTag":"mask-must-be-boolean","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}