{"record":{"id":"80bb75249d99d059","repo":"jax-ml/jax","slug":"unsupported-index-v-of-type-type-v","errorCode":null,"errorMessage":"Unsupported index: {v} of type {type(v)}","messagePattern":"Unsupported index: (.+?) of type (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/pallas/mosaic_gpu/lowering.py","lineNumber":4471,"sourceCode":"  return arith_dialect.constant(ir.IntegerType.get_signless(64), v)\n\n\ndef _as_index(v: object) -> ir.Value:\n  match v:\n    case int():\n      return arith_dialect.constant(ir.IndexType.get(), v)\n    case ir.Value() if isinstance(v.type, ir.IndexType):\n      return v\n    case ir.Value() if isinstance(v.type, ir.IntegerType):\n      return arith_dialect.index_cast(ir.IndexType.get(), v)\n    case mgpu.FragmentedArray(layout=mgpu.WGSplatFragLayout()):\n      return _as_index(v.registers.item())\n    case jax_literals.TypedNdArray() if (\n        np.issubdtype(v.dtype, np.integer) and v.ndim == 0\n    ):\n      return arith_dialect.constant(ir.IndexType.get(), int(v))\n    case _:\n      raise ValueError(f\"Unsupported index: {v} of type {type(v)}\")\n\n\ndef merge_indexers(\n    indexers: Sequence[indexing.NDIndexer]) -> indexing.NDIndexer:\n  \"\"\"Merges multiple indexers into a single indexer.\n\n  This function computes a new indexer such that applying the\n  new indexer produces the same result as applying the sequence\n  of input indexers in order from first-to-last.\n  \"\"\"\n  if len(indexers) == 0:\n    raise ValueError(\"Cannot merge empty list of indexers\")\n  if len(indexers) == 1:\n    return indexers[0]\n  root_shape = indexers[0].shape\n  current_indices = [indexing.Slice(0, size, 1) for size in root_shape]\n  removed_dimensions = set()\n  for indexer in indexers:","sourceCodeStart":4453,"sourceCodeEnd":4489,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/pallas/mosaic_gpu/lowering.py#L4453-L4489","documentation":"The Mosaic GPU lowering could not convert a value into an index-typed MLIR value because its Python/JAX type is unrecognized. _as_index only accepts Python ints, index-capable ir.Values, and 0-d integer TypedNdArray literals. Anything else (floats, arrays with ndim>0, triton-style objects) hits this ValueError.","triggerScenarios":"Using a non-integer or non-scalar value (float, 1-d array, string, custom object) as an index/start/size inside a Mosaic GPU kernel's BlockSpec or slicing logic.","commonSituations":"Computing BlockSpec index functions that accidentally return numpy float arrays (e.g. numpy division producing floats) instead of int scalars; passing jnp arrays instead of python ints.","solutions":["Ensure index functions return Python/numpy integer scalars (use int() or // integer division)","Check for accidental float division (/) in index computation; use //","If passing a jnp scalar, convert with int() first"],"exampleFix":"# before\ndef idx(block_idx): return block_idx[0] / 4  # float!\n# after\ndef idx(block_idx): return block_idx[0] // 4","handlingStrategy":"type-guard","validationCode":"assert isinstance(v, (int, np.integer)) and getattr(v, 'ndim', 0) == 0, f\"bad index {v!r}\"","typeGuard":"def is_valid_index(v) -> bool:\n    import numpy as np\n    return isinstance(v, (int, np.integer)) or (hasattr(v, 'ndim') and v.ndim == 0 and np.issubdtype(v.dtype, np.integer))","tryCatchPattern":"try:\n    _as_index(v)\nexcept ValueError as e:\n    raise TypeError(f\"convert index first: {e}\") from e","preventionTips":["Always return int scalars from index functions","Use // not / in index math"],"tags":["pallas","mosaic-gpu","indexing","type-error"],"backgroundTag":"invalid-index-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}