{"record":{"id":"01f6fc9d9f07fb86","repo":"jax-ml/jax","slug":"reorder-not-valid-must-be-one-of-1-2-3-4","errorCode":null,"errorMessage":"{reorder=} not valid, must be one of [1, 2, 3, 4]","messagePattern":"(.+?) not valid, must be one of \\[1, 2, 3, 4\\]","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/linalg.py","lineNumber":533,"sourceCode":"  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\n  def _callback(data, indices, indptr, b, **kwargs):\n    A = scipy.sparse.csr_matrix((data, indices, indptr), shape=(b.size, b.size))\n    return (scipy.sparse.linalg.spsolve(A, b).astype(b.dtype),)\n\n  result, _, _ = mlir.emit_python_callback(","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/linalg.py#L515-L551","documentation":"spsolve's reorder parameter (controlling the matrix reordering scheme passed to the GPU solver, e.g. cusolver) must be one of the integer codes 0-3. Any other value is rejected.","triggerScenarios":"Calling spsolve(..., reorder=k) with k outside {0,1,2,3}, e.g. passing 4 (the message text mistakenly says 1-4) or a string.","commonSituations":"Porting cusolver code that documents COLPERM values differently; typos or passing the parameter by keyword with a wrong constant.","solutions":["Use an integer reorder in [0, 1, 2, 3] (typically 0 = no reorder, 1-3 = reordering schemes)","If a different reordering scheme is needed, check the JAX/cusolver API version for supported codes"],"exampleFix":"// before\nx = sparse.linalg.spsolve(A, b, reorder=4)\n// after\nx = sparse.linalg.spsolve(A, b, reorder=1)","handlingStrategy":"validation","validationCode":"assert reorder in (0, 1, 2, 3), f'bad reorder={reorder}'","typeGuard":"def is_valid_reorder(r) -> bool:\n    return isinstance(r, int) and 0 <= r <= 3","tryCatchPattern":null,"preventionTips":["Use the documented codes 0-3 (note the message text listing 1-4 is a bug)","Define named constants for reorder schemes"],"tags":["jax","sparse","spsolve","gpu","parameter-validation"],"backgroundTag":"invalid-enum-parameter","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}