{"record":{"id":"2218e79d69d80b0e","repo":"jax-ml/jax","slug":"index-arrays-must-be-integer-typed-got-indices-d","errorCode":null,"errorMessage":"index arrays must be integer typed; got {indices.dtype=} {indptr.dtype=}","messagePattern":"index arrays must be integer typed; got (.+?) (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/linalg.py","lineNumber":526,"sourceCode":"  # X = H(w) vstack(-u vt, 0). But since H(w) is unitary its action must\n  # preserve rank. Thus H(w) vstack(0, eye(n - k)) must be orthogonal to\n  # X; taking just the first m columns H(w) vstack(0, eye(m), 0) yields\n  # an orthogonal extension to X.\n  other = jnp.concatenate(\n      [jnp.eye(m, dtype=X.dtype),\n       jnp.zeros((n - k - m, m), dtype=X.dtype)], axis=0)\n  w = _mm(y, vt.T * ((2 * (1 + s)) ** (-1/2))[jnp.newaxis, :])\n  h = -2 * jnp.linalg.multi_dot(\n      [w, w[k:, :].T, other], precision=jax.lax.Precision.HIGHEST)\n  return h.at[k:].add(other)\n\n\n# Sparse direct solve via QR factorization\ndef _spsolve_abstract_eval(data, indices, indptr, b, *, tol, reorder):\n  if data.dtype != b.dtype:\n    raise ValueError(f\"data types do not match: {data.dtype=} {b.dtype=}\")\n  if not (jnp.issubdtype(indices.dtype, jnp.integer) and jnp.issubdtype(indptr.dtype, jnp.integer)):\n    raise ValueError(f\"index arrays must be integer typed; got {indices.dtype=} {indptr.dtype=}\")\n  if not data.ndim == indices.ndim == indptr.ndim == b.ndim == 1:\n    raise ValueError(\"Arrays must be one-dimensional. \"\n                     f\"Got {data.shape=} {indices.shape=} {indptr.shape=} {b.shape=}\")\n  if indptr.size != b.size + 1 or  data.shape != indices.shape:\n    raise ValueError(f\"Invalid CSR buffer sizes: {data.shape=} {indices.shape=} {indptr.shape=}\")\n  if reorder not in [0, 1, 2, 3]:\n    raise ValueError(f\"{reorder=} not valid, must be one of [1, 2, 3, 4]\")\n  tol = float(tol)\n  return b\n\n\ndef _spsolve_gpu_lowering(ctx, data, indices, indptr, b, *, tol, reorder):\n  return ffi.ffi_lowering(\"cusolver_csrlsvqr_ffi\")(\n      ctx, data, indices, indptr, b, tol=np.float64(tol),\n      reorder=np.int32(reorder))\n\ndef _spsolve_cpu_lowering(ctx, data, indices, indptr, b, tol, reorder):\n  del tol, reorder","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/linalg.py#L508-L544","documentation":"spsolve requires the CSR index arrays (indices and indptr) to be of integer dtype (e.g. int32/int64). Float or other dtypes for the index buffers are rejected during abstract evaluation.","triggerScenarios":"Calling spsolve with a CSR whose indices/indptr were created as floats (e.g. from jnp.array of Python floats) or manually assembled buffers with wrong dtype.","commonSituations":"Manually constructing CSR buffers from external data (CSV/scipy conversion) where indices loaded as float64; slicing/computing indices with arithmetic that promotes to float.","solutions":["Cast indices and indptr to an integer dtype (e.g. jnp.int32) before building the CSR","Prefer constructing the matrix via sparse.CSR.fromdense or from a scipy CSR whose index dtype is already integral"],"exampleFix":"// before\nA = sparse.CSR((data, indices, indptr))  # indices float64\n// after\nA = sparse.CSR((data, indices.astype(jnp.int32), indptr.astype(jnp.int32)))","handlingStrategy":"type-guard","validationCode":"import jnp\nassert jnp.issubdtype(indices.dtype, jnp.integer), indices.dtype\nassert jnp.issubdtype(indptr.dtype, jnp.integer), indptr.dtype","typeGuard":"def valid_index_dtype(a) -> bool:\n    return jax.numpy.issubdtype(a.dtype, jax.numpy.integer)","tryCatchPattern":null,"preventionTips":["Always create index arrays with an explicit integer dtype","Convert scipy CSR arrays (already int32/int64) rather than hand-building from float data"],"tags":["jax","sparse","spsolve","dtype","indices"],"backgroundTag":"index-array-wrong-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}