{"record":{"id":"4128f9d70541e330","repo":"jax-ml/jax","slug":"arrays-must-be-one-dimensional-got-data-shape","errorCode":null,"errorMessage":"Arrays must be one-dimensional. Got {data.shape=} {indices.shape=} {indptr.shape=} {b.shape=}","messagePattern":"Arrays must be one-dimensional\\. Got (.+?) (.+?) (.+?) (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/linalg.py","lineNumber":528,"sourceCode":"  # 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\n  args = [data, indices, indptr, b]\n","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/linalg.py#L510-L546","documentation":"spsolve only accepts one-dimensional data, indices, indptr, and b buffers. Any of these being 2-D (e.g. a batched RHS or a matrix-shaped data buffer) fails validation.","triggerScenarios":"Passing b with shape (n, m) for multi-RHS solve; a CSR object whose buffers gained an extra dimension through batching transforms (vmap without sparsify) or reshaping.","commonSituations":"Trying to solve for multiple right-hand sides at once; using vmap over an spsolve call in a way that leaves arrays 2-D; matrix stored with leading batch dimension.","solutions":["Use a single 1-D b; loop or vmap over columns of a multi-RHS problem","Squeeze stray size-1 dimensions from the buffers","Build the CSR without batch dims (n_batch=0)"],"exampleFix":"// before\nx = sparse.linalg.spsolve(A, B)  # B shape (n, m)\n// after\nx = jax.vmap(lambda b: sparse.linalg.spsolve(A, b), in_axes=1, out_axes=1)(B)","handlingStrategy":"validation","validationCode":"assert data.ndim == indices.ndim == indptr.ndim == b.ndim == 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["vmap over the RHS columns for multi-RHS solves","Squeeze accidental extra dims before calling spsolve"],"tags":["jax","sparse","spsolve","shape","dimensions"],"backgroundTag":"unexpected-multidimensional-array","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}