{"record":{"id":"2003c8ef00e2dd0b","repo":"jax-ml/jax","slug":"data-types-do-not-match-data-dtype-b-dtype","errorCode":null,"errorMessage":"data types do not match: {data.dtype=} {b.dtype=}","messagePattern":"data types do not match: (.+?) (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/linalg.py","lineNumber":524,"sourceCode":"  # After some algebra, we see H(w) X = vstack(-u vt, 0)\n  # Applying H(w) to both sides since H(w)^2 = I we have\n  # 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","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/linalg.py#L506-L542","documentation":"Abstract evaluation for jax.experimental.sparse.linalg.spsolve requires the CSR data buffer and the right-hand side b to have identical dtypes; mixed dtypes are rejected before lowering.","triggerScenarios":"Calling spsolve(csr_matrix, b) where the matrix was built with one dtype (e.g. float64) and b has another (float32), or vice versa.","commonSituations":"Building the sparse matrix from data of one precision and the RHS from another; x64 enabled for one array creation path but not the other; loading b from a file with different precision.","solutions":["Cast b to the matrix dtype before calling spsolve (or cast the matrix data)","Ensure both arrays are created under the same jax_enable_x64 setting"],"exampleFix":"// before\nx = sparse.linalg.spsolve(A, b)  # A float64, b float32\n// after\nx = sparse.linalg.spsolve(A, b.astype(A.dtype))","handlingStrategy":"validation","validationCode":"assert b.dtype == mat.dtype, f'{b.dtype} != {mat.dtype}'\nb = b.astype(mat.dtype)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize one floating precision for the whole solve pipeline","Check dtypes after loading data from files/other libraries"],"tags":["jax","sparse","spsolve","dtype"],"backgroundTag":"dtype-mismatch-linear-solve","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}